nodejs-map 0.0.0-stage → 0.1.1

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 (238) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -2
  3. package/dist/app/assets/LearnView-Cqz9Ux8w.js +3 -0
  4. package/dist/app/assets/LearnView-Cqz9Ux8w.js.map +1 -0
  5. package/dist/app/assets/LearnView-Nrw6YQU8.css +1 -0
  6. package/dist/app/assets/app.worker-DZKurLgd.js +8 -0
  7. package/dist/app/assets/app.worker-DZKurLgd.js.map +1 -0
  8. package/dist/app/assets/atlas.worker-DGHewGIv.js +2 -0
  9. package/dist/app/assets/atlas.worker-DGHewGIv.js.map +1 -0
  10. package/dist/app/assets/cm-BTWjV_Gb.js +13 -0
  11. package/dist/app/assets/cm-BTWjV_Gb.js.map +1 -0
  12. package/dist/app/assets/dist-B37Ex44M.js +2 -0
  13. package/dist/app/assets/dist-B37Ex44M.js.map +1 -0
  14. package/dist/app/assets/dist-Dv4HNg5q.js +2 -0
  15. package/dist/app/assets/dist-Dv4HNg5q.js.map +1 -0
  16. package/dist/app/assets/index-BRoted4h.css +1 -0
  17. package/dist/app/assets/index-eLItdROg.js +18 -0
  18. package/dist/app/assets/index-eLItdROg.js.map +1 -0
  19. package/dist/app/assets/map-CISW7_cc.css +1 -0
  20. package/dist/app/assets/map-mCCk9DTc.js +132 -0
  21. package/dist/app/assets/map-mCCk9DTc.js.map +1 -0
  22. package/dist/app/assets/sdf-label-font-1nAa0TP8.png +0 -0
  23. package/dist/app/config.json +5 -0
  24. package/dist/app/favicon.svg +1 -0
  25. package/dist/app/index.html +21 -0
  26. package/dist/atlas/v26.13.1/build-report.json +178 -0
  27. package/dist/atlas/v26.13.1/chunks/lib.bootstrap.0.json +1 -0
  28. package/dist/atlas/v26.13.1/chunks/lib.core.0.json +1 -0
  29. package/dist/atlas/v26.13.1/chunks/lib.crypto.0.json +1 -0
  30. package/dist/atlas/v26.13.1/chunks/lib.devtools.0.json +1 -0
  31. package/dist/atlas/v26.13.1/chunks/lib.events.0.json +1 -0
  32. package/dist/atlas/v26.13.1/chunks/lib.fs.0.json +1 -0
  33. package/dist/atlas/v26.13.1/chunks/lib.modules.0.json +1 -0
  34. package/dist/atlas/v26.13.1/chunks/lib.net.0.json +1 -0
  35. package/dist/atlas/v26.13.1/chunks/lib.net.1.json +1 -0
  36. package/dist/atlas/v26.13.1/chunks/lib.platform.0.json +1 -0
  37. package/dist/atlas/v26.13.1/chunks/lib.process.0.json +1 -0
  38. package/dist/atlas/v26.13.1/chunks/lib.rest.0.json +1 -0
  39. package/dist/atlas/v26.13.1/chunks/lib.streams.0.json +1 -0
  40. package/dist/atlas/v26.13.1/chunks/lib.timers.0.json +1 -0
  41. package/dist/atlas/v26.13.1/chunks/lib.workers.0.json +1 -0
  42. package/dist/atlas/v26.13.1/chunks/lib.zlib.0.json +1 -0
  43. package/dist/atlas/v26.13.1/chunks/src.callbacks.0.json +1 -0
  44. package/dist/atlas/v26.13.1/chunks/src.crypto.0.json +1 -0
  45. package/dist/atlas/v26.13.1/chunks/src.diag.0.json +1 -0
  46. package/dist/atlas/v26.13.1/chunks/src.fs.0.json +1 -0
  47. package/dist/atlas/v26.13.1/chunks/src.inspector.0.json +1 -0
  48. package/dist/atlas/v26.13.1/chunks/src.loop.0.json +1 -0
  49. package/dist/atlas/v26.13.1/chunks/src.modules.0.json +1 -0
  50. package/dist/atlas/v26.13.1/chunks/src.napi.0.json +1 -0
  51. package/dist/atlas/v26.13.1/chunks/src.net.0.json +1 -0
  52. package/dist/atlas/v26.13.1/chunks/src.net.1.json +1 -0
  53. package/dist/atlas/v26.13.1/chunks/src.process.0.json +1 -0
  54. package/dist/atlas/v26.13.1/chunks/src.rest.0.json +1 -0
  55. package/dist/atlas/v26.13.1/chunks/src.support.0.json +1 -0
  56. package/dist/atlas/v26.13.1/chunks/src.zlib.0.json +1 -0
  57. package/dist/atlas/v26.13.1/chunks/uv.api.0.json +1 -0
  58. package/dist/atlas/v26.13.1/chunks/uv.backends.0.json +1 -0
  59. package/dist/atlas/v26.13.1/chunks/uv.fs.0.json +1 -0
  60. package/dist/atlas/v26.13.1/chunks/uv.loop.0.json +1 -0
  61. package/dist/atlas/v26.13.1/chunks/uv.net.0.json +1 -0
  62. package/dist/atlas/v26.13.1/chunks/uv.rest.0.json +1 -0
  63. package/dist/atlas/v26.13.1/chunks/uv.threadpool.0.json +1 -0
  64. package/dist/atlas/v26.13.1/chunks/v8.api.0.json +1 -0
  65. package/dist/atlas/v26.13.1/chunks/v8.asmjs.0.json +1 -0
  66. package/dist/atlas/v26.13.1/chunks/v8.ast.0.json +1 -0
  67. package/dist/atlas/v26.13.1/chunks/v8.base.0.json +1 -0
  68. package/dist/atlas/v26.13.1/chunks/v8.baseline.0.json +1 -0
  69. package/dist/atlas/v26.13.1/chunks/v8.bigint.0.json +1 -0
  70. package/dist/atlas/v26.13.1/chunks/v8.builtins.0.json +1 -0
  71. package/dist/atlas/v26.13.1/chunks/v8.codegen.0.json +1 -0
  72. package/dist/atlas/v26.13.1/chunks/v8.codegen.riscv.0.json +1 -0
  73. package/dist/atlas/v26.13.1/chunks/v8.common.0.json +1 -0
  74. package/dist/atlas/v26.13.1/chunks/v8.compiler-dispatcher.0.json +1 -0
  75. package/dist/atlas/v26.13.1/chunks/v8.compiler.0.json +1 -0
  76. package/dist/atlas/v26.13.1/chunks/v8.compiler.backend.0.json +1 -0
  77. package/dist/atlas/v26.13.1/chunks/v8.compiler.turboshaft.0.json +1 -0
  78. package/dist/atlas/v26.13.1/chunks/v8.d8.0.json +1 -0
  79. package/dist/atlas/v26.13.1/chunks/v8.date.0.json +1 -0
  80. package/dist/atlas/v26.13.1/chunks/v8.debug.0.json +1 -0
  81. package/dist/atlas/v26.13.1/chunks/v8.deoptimizer.0.json +1 -0
  82. package/dist/atlas/v26.13.1/chunks/v8.diagnostics.0.json +1 -0
  83. package/dist/atlas/v26.13.1/chunks/v8.dumpling.0.json +1 -0
  84. package/dist/atlas/v26.13.1/chunks/v8.execution.0.json +1 -0
  85. package/dist/atlas/v26.13.1/chunks/v8.extensions.0.json +1 -0
  86. package/dist/atlas/v26.13.1/chunks/v8.flags.0.json +1 -0
  87. package/dist/atlas/v26.13.1/chunks/v8.fuzzilli.0.json +1 -0
  88. package/dist/atlas/v26.13.1/chunks/v8.handles.0.json +1 -0
  89. package/dist/atlas/v26.13.1/chunks/v8.heap.0.json +1 -0
  90. package/dist/atlas/v26.13.1/chunks/v8.heap.cppgc.0.json +1 -0
  91. package/dist/atlas/v26.13.1/chunks/v8.ic.0.json +1 -0
  92. package/dist/atlas/v26.13.1/chunks/v8.init.0.json +1 -0
  93. package/dist/atlas/v26.13.1/chunks/v8.inspector.0.json +1 -0
  94. package/dist/atlas/v26.13.1/chunks/v8.interpreter.0.json +1 -0
  95. package/dist/atlas/v26.13.1/chunks/v8.json.0.json +1 -0
  96. package/dist/atlas/v26.13.1/chunks/v8.libplatform.0.json +1 -0
  97. package/dist/atlas/v26.13.1/chunks/v8.libsampler.0.json +1 -0
  98. package/dist/atlas/v26.13.1/chunks/v8.logging.0.json +1 -0
  99. package/dist/atlas/v26.13.1/chunks/v8.maglev.0.json +1 -0
  100. package/dist/atlas/v26.13.1/chunks/v8.numbers.0.json +1 -0
  101. package/dist/atlas/v26.13.1/chunks/v8.objects.0.json +1 -0
  102. package/dist/atlas/v26.13.1/chunks/v8.parsing.0.json +1 -0
  103. package/dist/atlas/v26.13.1/chunks/v8.profiler.0.json +1 -0
  104. package/dist/atlas/v26.13.1/chunks/v8.regexp.0.json +1 -0
  105. package/dist/atlas/v26.13.1/chunks/v8.root.0.json +1 -0
  106. package/dist/atlas/v26.13.1/chunks/v8.roots.0.json +1 -0
  107. package/dist/atlas/v26.13.1/chunks/v8.runtime.0.json +1 -0
  108. package/dist/atlas/v26.13.1/chunks/v8.sandbox.0.json +1 -0
  109. package/dist/atlas/v26.13.1/chunks/v8.snapshot.0.json +1 -0
  110. package/dist/atlas/v26.13.1/chunks/v8.strings.0.json +1 -0
  111. package/dist/atlas/v26.13.1/chunks/v8.tasks.0.json +1 -0
  112. package/dist/atlas/v26.13.1/chunks/v8.torque.0.json +1 -0
  113. package/dist/atlas/v26.13.1/chunks/v8.tracing.0.json +1 -0
  114. package/dist/atlas/v26.13.1/chunks/v8.trap-handler.0.json +1 -0
  115. package/dist/atlas/v26.13.1/chunks/v8.utils.0.json +1 -0
  116. package/dist/atlas/v26.13.1/chunks/v8.wasm.0.json +1 -0
  117. package/dist/atlas/v26.13.1/chunks/v8.zone.0.json +1 -0
  118. package/dist/atlas/v26.13.1/edges.json +1 -0
  119. package/dist/atlas/v26.13.1/files.json +1 -0
  120. package/dist/atlas/v26.13.1/index.json +1 -0
  121. package/dist/atlas/v26.13.1/search.json +1 -0
  122. package/dist/cli.js +6268 -0
  123. package/dist/examples.json +1 -0
  124. package/dist/learn/async-await.json +1 -0
  125. package/dist/learn/backpressure.json +1 -0
  126. package/dist/learn/big-picture.json +1 -0
  127. package/dist/learn/blocking-the-loop.json +1 -0
  128. package/dist/learn/breakpoints.json +1 -0
  129. package/dist/learn/call-stack.json +1 -0
  130. package/dist/learn/first-run.json +1 -0
  131. package/dist/learn/follow-readfile.json +1 -0
  132. package/dist/learn/four-threads-six-jobs.json +1 -0
  133. package/dist/learn/glossary.json +1 -0
  134. package/dist/learn/hiding-areas.json +1 -0
  135. package/dist/learn/http-one-request.json +1 -0
  136. package/dist/learn/http-two-requests.json +1 -0
  137. package/dist/learn/img/big-picture.webp +0 -0
  138. package/dist/learn/img/first-run-queues.webp +0 -0
  139. package/dist/learn/img/hide-restore-strip.webp +0 -0
  140. package/dist/learn/img/hide-view-menu.webp +0 -0
  141. package/dist/learn/img/map-call-path.webp +0 -0
  142. package/dist/learn/img/marks-in-a-run.webp +0 -0
  143. package/dist/learn/img/paused-at-breakpoint.webp +0 -0
  144. package/dist/learn/img/paused-in-node-fs.webp +0 -0
  145. package/dist/learn/img/playback-bar.webp +0 -0
  146. package/dist/learn/img/save-and-share.webp +0 -0
  147. package/dist/learn/img/tour-areas.webp +0 -0
  148. package/dist/learn/index.json +390 -0
  149. package/dist/learn/keep-alive.json +1 -0
  150. package/dist/learn/loop-phases.json +1 -0
  151. package/dist/learn/many-clients.json +1 -0
  152. package/dist/learn/microtasks-belong-to-v8.json +1 -0
  153. package/dist/learn/next-tick.json +1 -0
  154. package/dist/learn/observed-and-inferred.json +1 -0
  155. package/dist/learn/one-libuv-timer.json +1 -0
  156. package/dist/learn/order-and-esm.json +1 -0
  157. package/dist/learn/pipeline-errors.json +1 -0
  158. package/dist/learn/playback.json +1 -0
  159. package/dist/learn/pool-size.json +1 -0
  160. package/dist/learn/prerequisites.json +1 -0
  161. package/dist/learn/probe-build.json +1 -0
  162. package/dist/learn/promises-and-microtasks.json +1 -0
  163. package/dist/learn/reading-a-file.json +1 -0
  164. package/dist/learn/rec/async-await-chain.nmrec.gz +0 -0
  165. package/dist/learn/rec/backpressure.nmrec.gz +0 -0
  166. package/dist/learn/rec/beforeexit-and-exit.nmrec.gz +0 -0
  167. package/dist/learn/rec/block-loop.nmrec.gz +0 -0
  168. package/dist/learn/rec/dns-lookup-thread-pool.nmrec.gz +0 -0
  169. package/dist/learn/rec/esm-twist.nmrec.gz +0 -0
  170. package/dist/learn/rec/eventemitter-is-synchronous.nmrec.gz +0 -0
  171. package/dist/learn/rec/first-run.nmrec.gz +0 -0
  172. package/dist/learn/rec/fs-promises-await.nmrec.gz +0 -0
  173. package/dist/learn/rec/fs-sync-vs-async.nmrec.gz +0 -0
  174. package/dist/learn/rec/http-blocking-fixed.nmrec.gz +0 -0
  175. package/dist/learn/rec/http-blocking.nmrec.gz +0 -0
  176. package/dist/learn/rec/http-keep-alive.nmrec.gz +0 -0
  177. package/dist/learn/rec/http-roundtrip.nmrec.gz +0 -0
  178. package/dist/learn/rec/http-two-requests.nmrec.gz +0 -0
  179. package/dist/learn/rec/interval-and-clear.nmrec.gz +0 -0
  180. package/dist/learn/rec/nested-ticks-and-microtasks.nmrec.gz +0 -0
  181. package/dist/learn/rec/next-tick.nmrec.gz +0 -0
  182. package/dist/learn/rec/pbkdf2-six-jobs-four-threads.nmrec.gz +0 -0
  183. package/dist/learn/rec/phase-check.nmrec.gz +0 -0
  184. package/dist/learn/rec/phase-close.nmrec.gz +0 -0
  185. package/dist/learn/rec/phase-io.nmrec.gz +0 -0
  186. package/dist/learn/rec/pipeline-error.nmrec.gz +0 -0
  187. package/dist/learn/rec/pool-users.nmrec.gz +0 -0
  188. package/dist/learn/rec/pool-with-two-threads.nmrec.gz +0 -0
  189. package/dist/learn/rec/promise-microtasks.nmrec.gz +0 -0
  190. package/dist/learn/rec/readfile-thread-pool.nmrec.gz +0 -0
  191. package/dist/learn/rec/run-to-completion.nmrec.gz +0 -0
  192. package/dist/learn/rec/split-work.nmrec.gz +0 -0
  193. package/dist/learn/rec/stream-pipeline-file.nmrec.gz +0 -0
  194. package/dist/learn/rec/streams-memory.nmrec.gz +0 -0
  195. package/dist/learn/rec/tcp-many-clients.nmrec.gz +0 -0
  196. package/dist/learn/rec/tcp-round-trip.nmrec.gz +0 -0
  197. package/dist/learn/rec/tick-before-promise.nmrec.gz +0 -0
  198. package/dist/learn/rec/timeout-vs-immediate-io.nmrec.gz +0 -0
  199. package/dist/learn/rec/timeout-vs-immediate-main.nmrec.gz +0 -0
  200. package/dist/learn/rec/timer-lateness.nmrec.gz +0 -0
  201. package/dist/learn/rec/timer-vs-file-read.nmrec.gz +0 -0
  202. package/dist/learn/rec/timers-phase.nmrec.gz +0 -0
  203. package/dist/learn/rec/unref-timer.nmrec.gz +0 -0
  204. package/dist/learn/save-and-share.json +1 -0
  205. package/dist/learn/slow-handler.json +1 -0
  206. package/dist/learn/splitting-work.json +1 -0
  207. package/dist/learn/staying-alive.json +1 -0
  208. package/dist/learn/stepping-into-node.json +1 -0
  209. package/dist/learn/streams-basics.json +1 -0
  210. package/dist/learn/tcp-step-by-step.json +1 -0
  211. package/dist/learn/the-map.json +1 -0
  212. package/dist/learn/three-marks.json +1 -0
  213. package/dist/learn/timeout-vs-immediate.json +1 -0
  214. package/dist/learn/timers-are-not-now.json +1 -0
  215. package/dist/learn/tour.json +1 -0
  216. package/dist/learn/what-it-is.json +1 -0
  217. package/dist/learn/what-uses-the-pool.json +1 -0
  218. package/dist/lessons/async-await-chain.nmrec.gz +0 -0
  219. package/dist/lessons/beforeexit-and-exit.nmrec.gz +0 -0
  220. package/dist/lessons/dns-lookup-thread-pool.nmrec.gz +0 -0
  221. package/dist/lessons/esm-twist.nmrec.gz +0 -0
  222. package/dist/lessons/eventemitter-is-synchronous.nmrec.gz +0 -0
  223. package/dist/lessons/fs-promises-await.nmrec.gz +0 -0
  224. package/dist/lessons/fs-sync-vs-async.nmrec.gz +0 -0
  225. package/dist/lessons/index.json +621 -0
  226. package/dist/lessons/interval-and-clear.nmrec.gz +0 -0
  227. package/dist/lessons/nested-ticks-and-microtasks.nmrec.gz +0 -0
  228. package/dist/lessons/pbkdf2-six-jobs-four-threads.nmrec.gz +0 -0
  229. package/dist/lessons/pool-with-two-threads.nmrec.gz +0 -0
  230. package/dist/lessons/readfile-thread-pool.nmrec.gz +0 -0
  231. package/dist/lessons/tcp-round-trip.nmrec.gz +0 -0
  232. package/dist/lessons/tick-before-promise.nmrec.gz +0 -0
  233. package/dist/lessons/timeout-vs-immediate-io.nmrec.gz +0 -0
  234. package/dist/lessons/timeout-vs-immediate-main.nmrec.gz +0 -0
  235. package/dist/lessons/timer-vs-file-read.nmrec.gz +0 -0
  236. package/dist/lessons/timers-phase.nmrec.gz +0 -0
  237. package/dist/preload.cjs +507 -0
  238. package/package.json +25 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ProCodrr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,96 @@
1
- # Temporary Holding Version
1
+ # nodejs-map
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ See what happens inside real Node.js while your program runs.
4
+
5
+ `nodejs-map` runs your code on your own Node.js, on your own machine, and
6
+ shows two things side by side in the browser:
7
+
8
+ - **A map of Node.js** that you can zoom like a street map: your code, Node's
9
+ JavaScript library, the C++ bindings, V8 and libuv, down to single source
10
+ files and functions, each linked to the exact line on GitHub.
11
+ - **A debugger and live view**: set breakpoints, pause and step as in Chrome
12
+ DevTools, and watch the call stack, the `nextTick` queue, the promise queue,
13
+ timers, the event loop phases, the thread pool and pending I/O as they change.
14
+
15
+ Every run can be saved as a recording and replayed later, step by step,
16
+ forwards and backwards. The package also carries 18 short recorded lessons
17
+ (nextTick and promises, timers and immediates, the thread pool, file reads,
18
+ sockets, process exit).
19
+
20
+ ## Use
21
+
22
+ ```
23
+ npx nodejs-map # start in the current folder and open the browser
24
+ npx nodejs-map file.js # the same, with file.js opened in the editor
25
+ ```
26
+
27
+ Options: `--port <n>`, `--no-open`, `--node <path>` (run programs with another
28
+ Node binary), `--help`.
29
+
30
+ Without a browser, to save what one run did:
31
+
32
+ ```
33
+ npx nodejs-map record file.js --out file.nmrec.gz --include-source
34
+ ```
35
+
36
+ ## Safety
37
+
38
+ 1. The helper listens on `127.0.0.1` only, on a random port.
39
+ 2. Every request must carry a secret that is made anew at each start and is
40
+ part of the address the helper prints; requests from other web sites are
41
+ refused (the helper also checks the `Host` and `Origin` headers).
42
+ 3. Code runs only when you press **Run**, and only files inside the folder you
43
+ started `nodejs-map` in (or the text in the editor). Opening a recording or
44
+ a shared link never runs anything.
45
+ 4. The debugger port of your program is bound to `127.0.0.1` and is never
46
+ given to the browser; the helper relays a short, fixed list of debugger
47
+ actions.
48
+
49
+ Your code, its output and your recordings stay on your machine. The page
50
+ makes one kind of request to the outside: when you open a code location, it
51
+ fetches that file of Node's own source from `raw.githubusercontent.com`,
52
+ because Node's source is not shipped in this package.
53
+
54
+ ## Observed, inferred, model
55
+
56
+ Everything on screen says how it is known:
57
+
58
+ - **observed**: Node itself reported it (an `async_hooks` callback, a trace
59
+ event, the debugger);
60
+ - **inferred**: worked out from other signals by a rule, and the rule names the
61
+ places in Node's source it relies on;
62
+ - **model**: an illustration.
63
+
64
+ An inferred or modelled thing is never shown as observed. On a standard Node
65
+ build, for example, the timers and check phases of the event loop are
66
+ observed, the poll phase is inferred, and which thread-pool thread ran a job
67
+ is observed but arrives with a delay.
68
+
69
+ One more thing to know: at a breakpoint only JavaScript stops. The clock, the
70
+ thread pool and the operating system keep running, which can change what your
71
+ program does next. The paused view says so.
72
+
73
+ ## What to expect from this first release
74
+
75
+ - Tested on Windows and Linux with Node.js 26.13.1. macOS has not been tested
76
+ yet.
77
+ - The map is built for Node.js v26.13.1. On another 26.x version the tool
78
+ still runs and says that the map was built for a different version.
79
+ - Watching a program slows it down. A small program takes about 0.2 s longer
80
+ from start to finish. Programs that create very many timers or promises are
81
+ slowed much more, because every one of them is recorded: a stress test with
82
+ 100,000 chained promises took 1.6 s instead of 0.08 s.
83
+ - Worker threads run but are not shown.
84
+ - Stopping between event loop phases needs a patched build of Node, which is
85
+ not part of this package yet. On a standard build those controls are
86
+ visible and say why they are off.
87
+
88
+ ## Requirements
89
+
90
+ - Node.js 26 or newer.
91
+ - A current desktop browser.
92
+ - No other dependencies; nothing is installed globally.
93
+
94
+ ## Licence
95
+
96
+ MIT. Node.js source code is not included in this package: the map links to it.
@@ -0,0 +1,3 @@
1
+ import{C as e,S as t,a as n,b as r,c as i,i as a,l as o,n as s,o as c,r as l,s as u,t as d,u as f,v as p,w as m,x as h,y as g}from"./index-eLItdROg.js";var _={tip:`Tip`,honest:`What the tool cannot tell you`,warn:`A common mistake`};function v(e,t,n){switch(e.kind){case`text`:return e.text;case`code`:case`strong`:case`em`:case`kbd`:return m(e.kind,{key:n},e.text);case`ui`:return m(`span`,{key:n,class:`learn-ui`},e.text);case`lesson`:return m(`a`,{key:n,href:e.href},e.text);case`external`:return m(`a`,{key:n,href:e.href,target:`_blank`,rel:`noopener noreferrer`},e.text,m(`span`,{class:`sr-only`},` (opens in a new tab)`));case`path`:return m(`button`,{key:n,type:`button`,class:`learn-path`,title:`Show this call path on the map`,onClick:()=>t.onPath(e.id)},e.text)}}function y(e,t){return i(e,t).map((e,n)=>v(e,t,n))}var b=/(\/\/[^\n]*|\/\*[\s\S]*?\*\/)|('(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"|`(?:[^`\\]|\\[\s\S])*`)|\b(\d[\d_.]*n?)\b|\b(const|let|var|function|return|if|else|for|while|do|of|in|new|await|async|import|export|from|class|extends|try|catch|finally|throw|typeof|instanceof|this|null|undefined|true|false|break|continue|switch|case|default|yield|delete|void)\b/g,x=/(#[^\n]*)/g,S=[`syn-comment`,`syn-string`,`syn-number`,`syn-keyword`];function C(e,t){if(t===`text`)return[e];let n=new RegExp(t===`js`?b:x),r=[],i=0,a;for(;(a=n.exec(e))!==null;){if(a[0]===``){n.lastIndex++;continue}a.index>i&&r.push(e.slice(i,a.index));let t=a.slice(1).findIndex(e=>e!==void 0);r.push(m(`span`,{key:a.index,class:S[t]??``},a[0])),i=a.index+a[0].length}return i<e.length&&r.push(e.slice(i)),r}function w(e,t,n){switch(e.t){case`p`:return m(`p`,{key:n},y(e.text,t));case`h`:return m(e.level===2?`h3`:`h4`,{key:n,id:e.id?`learn-h-${e.id}`:void 0},e.text);case`list`:return m(e.ordered?`ol`:`ul`,{key:n,class:`learn-list`},e.items.map((e,n)=>m(`li`,{key:n},y(e,t))));case`note`:return m(`div`,{key:n,class:`learn-note learn-note--${e.kind}`,role:`note`},m(`p`,{class:`learn-note__kind`},_[e.kind]),m(`p`,null,y(e.text,t)));case`code`:return m(`pre`,{key:n,class:`learn-code`,tabIndex:0},m(`code`,null,C(e.text,e.lang)));case`example`:return m(`div`,{key:n,class:`learn-example-slot`},t.example(e.example));case`image`:{let r=t.fileUrl(e.src),i=r?m(`img`,{src:r,alt:e.alt,width:e.width,height:e.height,loading:`lazy`,decoding:`async`}):null,a=t.openImage,o=i&&r&&a?m(`button`,{type:`button`,class:`learn-zoom`,"aria-haspopup":`dialog`,title:`Click to enlarge`,onClick:()=>a({src:r,alt:e.alt,caption:e.caption??null,width:e.width,height:e.height})},i,m(`span`,{class:`learn-zoom__hint`,"aria-hidden":`true`},`Click to enlarge`)):i;return m(`figure`,{key:n,class:`learn-figure`},o??m(`p`,{class:`muted`},`[Image: ${e.alt}]`),e.caption?m(`figcaption`,null,e.caption):null)}case`check`:return m(`details`,{key:n,class:`learn-check`},m(`summary`,null,m(`span`,{class:`learn-check__label`},`Check yourself: `),y(e.question,t)),m(`p`,{class:`learn-check__answer`},y(e.answer,t)))}}function T(e,t){return e.map((e,n)=>w(e,t,n))}var E={start:`Start`,core:`Core`,deep:`Deep`},D=.5;function O(e,t){let n=e.w>0&&e.h>0&&t.w>0&&t.h>0?Math.min(t.w/e.w,t.h/e.h):1,r=Math.max(4,n);return{fit:Math.min(n,r),min:n*D,max:r}}var k=(e,t)=>Math.min(t.max,Math.max(t.min,e));function A(e,t){let{fit:n}=O(e,t);return{scale:n,x:(t.w-e.w*n)/2,y:(t.h-e.h*n)/2}}function j(e,t,n,r,i){let a=k(t,i),o=a/e.scale;return{scale:a,x:n-(n-e.x)*o,y:r-(r-e.y)*o}}var M=(e,t,n,r,i)=>j(e,e.scale*t,n,r,i);function N(e,t){let n=t===1?e*16:t===2?e*400:e;return Math.exp(-Math.max(-40,Math.min(40,n))*.01)}function P(e,t,n){let r=t.w*e.scale,i=t.h*e.scale,a=(e,t,n)=>t<=n?Math.min(n-t,Math.max(0,e)):Math.min(0,Math.max(n-t,e));return{scale:e.scale,x:a(e.x,r,n.w),y:a(e.y,i,n.h)}}var F=(e,t)=>Math.abs(e.scale-t.fit)<t.fit*.01,I=1.25,L=60,R=320,z=24;function B({image:e,onClose:n}){let i=h(null),a=h(null),o=h(null),s=h(null),c=h({w:e.width,h:e.height}),[l,u]=t(null),f=h(null),[m,_]=t(!1),v=h(!0),y=()=>{v.current&&(v.current=!1,n())},b=()=>{let e=a.current?.getBoundingClientRect();return{w:e?.width??0,h:e?.height??0}},x=()=>O(c.current,b()),S=(e,t=!1)=>{let n=P(e,c.current,b());f.current=n,_(t),u(n)},C=(e=!1)=>S(A(c.current,b()),e),w=()=>{let e=b();return[e.w/2,e.h/2]},T=e=>{let t=f.current;t&&S(M(t,e,...w(),x()),!0)},E=(e,t,n=!1)=>{let r=f.current;r&&S({...r,x:r.x+e,y:r.y+t},n)},D=(e,t)=>{let n=f.current;if(!n)return;let r=x();F(n,r)?S(j(n,r.fit*2,e,t,r),!0):C(!0)},k=(e,t)=>{let n=a.current?.getBoundingClientRect();return[e-(n?.left??0),t-(n?.top??0)]};g(()=>{let e=i.current;if(!e)return;let t=document.activeElement instanceof HTMLElement?document.activeElement:null;e.open||e.showModal(),s.current?.focus(),C();let n=()=>C();return addEventListener(`resize`,n),()=>{removeEventListener(`resize`,n),e.open&&e.close(),t?.isConnected&&t.focus()}},[]),g(()=>{let e=i.current;if(!e)return;let t=e=>{e.preventDefault();let t=f.current;if(t){if(e.ctrlKey||e.metaKey){let[n,r]=k(e.clientX,e.clientY);S(M(t,N(e.deltaY,e.deltaMode),n,r,x()))}else{let n=e.deltaMode===1?16:1;S({...t,x:t.x-e.deltaX*n,y:t.y-e.deltaY*n})}}},n=1,r=e=>{e.preventDefault(),n=1},a=e=>{e.preventDefault();let t=e,r=f.current;if(!r||!t.scale)return;let[i,a]=k(t.clientX,t.clientY);S(M(r,t.scale/n,i,a,x())),n=t.scale};return e.addEventListener(`wheel`,t,{passive:!1}),e.addEventListener(`gesturestart`,r),e.addEventListener(`gesturechange`,a),e.addEventListener(`gestureend`,r),()=>{e.removeEventListener(`wheel`,t),e.removeEventListener(`gesturestart`,r),e.removeEventListener(`gesturechange`,a),e.removeEventListener(`gestureend`,r)}},[]),r(()=>{let e=o.current;e&&l&&(e.style.width=`${c.current.w}px`,e.style.height=`${c.current.h}px`,e.style.transform=`translate(${l.x}px, ${l.y}px) scale(${l.scale})`)},[l]);let B=h(new Map),V=h(null),H=h(!1),U=h(null),W=()=>{let[e,t]=[...B.current.values()];return!e||!t?null:{dist:Math.hypot(e.x-t.x,e.y-t.y),mid:k((e.x+t.x)/2,(e.y+t.y)/2)}},G=e=>{e.button===0&&(e.currentTarget.setPointerCapture(e.pointerId),B.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),B.current.size===1&&(H.current=!1),V.current=B.current.size===2?W():null,B.current.size>1&&(H.current=!0))},K=e=>{let t=B.current.get(e.pointerId);if(!t)return;let n={x:e.clientX,y:e.clientY};if(B.current.set(e.pointerId,n),B.current.size===1){Math.hypot(n.x-t.x,n.y-t.y)>0&&(H.current=H.current||Math.abs(n.x-t.x)+Math.abs(n.y-t.y)>2,E(n.x-t.x,n.y-t.y));return}let r=V.current,i=W(),a=f.current;if(!r||!i||!a||r.dist===0)return;let o=M(a,i.dist/r.dist,r.mid[0],r.mid[1],x());S({...o,x:o.x+i.mid[0]-r.mid[0],y:o.y+i.mid[1]-r.mid[1]}),V.current=i},q=e=>{if(!B.current.delete(e.pointerId)||(V.current=B.current.size===2?W():null,B.current.size>0||H.current||e.type===`pointercancel`))return;let t={t:e.timeStamp,x:e.clientX,y:e.clientY},n=U.current;n&&t.t-n.t<R&&Math.hypot(t.x-n.x,t.y-n.y)<z?(U.current=null,D(...k(t.x,t.y))):U.current=t},J=e=>{let t=e.ctrlKey||e.metaKey,n=!0;e.key===`+`||e.key===`=`?T(I):e.key===`-`||e.key===`_`?T(1/I):e.key===`0`?C(!0):e.key===`ArrowLeft`&&!t?E(L,0,!0):e.key===`ArrowRight`&&!t?E(-60,0,!0):e.key===`ArrowUp`&&!t?E(0,L,!0):e.key===`ArrowDown`&&!t?E(0,-60,!0):n=!1,n&&(e.preventDefault(),e.stopPropagation())},Y=l?Math.round(l.scale*100):null;return p(`dialog`,{ref:i,class:`imgview`,role:`dialog`,"aria-label":e.alt,onCancel:e=>{e.preventDefault(),y()},onClose:y,onKeyDown:J,children:[p(`div`,{class:`imgview__bar`,role:`toolbar`,"aria-label":`Zoom`,children:[p(`button`,{type:`button`,class:`ctl ctl--icon imgview__btn`,"aria-label":`Zoom out`,title:`Zoom out (-)`,onClick:()=>T(1/I),children:p(`span`,{"aria-hidden":`true`,children:`−`})}),p(`span`,{class:`imgview__pct num`,role:`status`,"aria-live":`polite`,children:Y===null?``:`${Y}%`}),p(`button`,{type:`button`,class:`ctl ctl--icon imgview__btn`,"aria-label":`Zoom in`,title:`Zoom in (+)`,onClick:()=>T(I),children:p(`span`,{"aria-hidden":`true`,children:`+`})}),p(`button`,{type:`button`,class:`ctl imgview__btn`,title:`Fit the image to the window (0)`,onClick:()=>C(!0),children:`Fit`}),p(`span`,{class:`imgview__help muted`,children:`Pinch or Ctrl+wheel to zoom · drag to pan · Esc to close`}),p(`button`,{ref:s,type:`button`,class:`ctl ctl--icon imgview__btn imgview__close`,"aria-label":`Close image`,title:`Close (Esc)`,onClick:y,children:p(d,{name:`close`})})]}),p(`div`,{ref:a,class:`imgview__stage${l?` is-ready`:``}${m?` is-animated`:``}`,onPointerDown:G,onPointerMove:K,onPointerUp:q,onPointerCancel:q,onLostPointerCapture:q,children:p(`img`,{ref:o,class:`imgview__img`,src:e.src,alt:e.alt,draggable:!1,onLoad:e=>{let t=e.currentTarget;t.naturalWidth>0&&(t.naturalWidth!==c.current.w||t.naturalHeight!==c.current.h)&&(c.current={w:t.naturalWidth,h:t.naturalHeight},C())}})}),e.caption?p(`p`,{class:`imgview__caption`,children:e.caption}):null]})}function V({lessonId:e,example:t,scroll:r}){let i=s.value,a=t.steps?.length??0;return p(`section`,{class:`learn-example`,"aria-label":`Example: ${t.title||t.name}`,children:[p(`header`,{class:`learn-example__head`,children:[p(`span`,{class:`learn-example__title`,children:t.title||t.name}),p(`span`,{class:`muted mono`,children:t.name})]}),t.racy?p(`p`,{class:`learn-example__racy`,role:`note`,children:`The order of this program's output is a race: it can differ from one run to the next.`}):null,p(`pre`,{class:`learn-code learn-code--example`,tabIndex:0,"aria-label":`The program ${t.name}`,children:p(`code`,{children:C(t.text,`js`)})}),t.output.length>0?p(`details`,{class:`learn-example__output`,children:[p(`summary`,{children:[`What it printed when this lesson was made`,t.racy?` (one possible order)`:``]}),p(`pre`,{class:`learn-code learn-code--output`,children:t.output.join(`
2
+ `)})]}):null,p(`div`,{class:`learn-example__acts`,children:[t.recording?p(`button`,{type:`button`,class:`ctl ctl--primary learn-play`,onClick:()=>void n(e,t,r()),children:[`Play the walk-through`,a>0?p(`span`,{class:`learn-example__n`,children:[` (`,a,` steps)`]}):null]}):null,i?p(`button`,{type:`button`,class:`ctl learn-run`,onClick:()=>void c(e,t,r()),children:`Run it yourself`}):null]})]})}function H({current:t,onPick:n}){let r=l.index.value,i=l.done.value;return r.status===`ready`?p(e,{children:[p(`h2`,{class:`learn__navtitle`,children:`Chapters and lessons`}),p(`ol`,{class:`learn__chapters`,children:r.index.chapters.map(e=>p(`li`,{class:`learn__chapter`,children:[p(`h3`,{class:`learn__chaptertitle`,children:e.title}),p(`ol`,{class:`learn__lessons`,children:e.lessons.map(e=>{let r=i.has(e.id);return p(`li`,{children:p(`a`,{class:`learn__lesson${r?` is-done`:``}`,href:f({view:`learn`,lesson:e.id}),"aria-current":e.id===t?`page`:void 0,onClick:n,children:[p(`span`,{class:`learn__tick`,"aria-hidden":`true`}),p(`span`,{class:`learn__lessontitle`,children:e.title}),p(`span`,{class:`learn__meta muted`,children:[E[e.level],` · `,e.minutes,` min`,r?p(`span`,{class:`sr-only`,children:` · done`}):null]})]})},e.id)})})]},e.id))})]}):null}function U({lesson:t,scroll:n,onImage:r}){let i={hasLesson:e=>l.hasLesson(e),fileUrl:e=>l.fileUrl(e),onPath:e=>a(t.id,e,n()),openImage:r,example:e=>{let r=t.examples[e];return r?p(V,{lessonId:t.id,example:r,scroll:n}):p(`p`,{class:`muted`,children:`This example is missing from the lesson file.`})}},s=l.done.value.has(t.id),c=l.index.value,u=c.status===`ready`?o(c.index).find(e=>e.id===t.id):void 0;return p(e,{children:[T(t.blocks,i),p(`div`,{class:`learn__done`,children:[p(`button`,{type:`button`,class:`ctl`,"aria-pressed":s,onClick:()=>l.setDone(t.id,!s),children:s?`Done: marked in this browser`:`Mark this lesson as done`}),u?p(`span`,{class:`muted`,children:[E[u.level],` · about `,u.minutes,` min`]}):null]}),p(`nav`,{class:`learn__pager`,"aria-label":`Previous and next lesson`,children:[t.prev?p(`a`,{class:`learn__pagerlink`,href:f({view:`learn`,lesson:t.prev.id}),rel:`prev`,children:[p(`span`,{class:`muted`,children:`Previous`}),p(`span`,{children:t.prev.title})]}):p(`span`,{}),t.next?p(`a`,{class:`learn__pagerlink learn__pagerlink--next`,href:f({view:`learn`,lesson:t.next.id}),rel:`next`,children:[p(`span`,{class:`muted`,children:`Next`}),p(`span`,{children:t.next.title})]}):null]})]})}function W(){let e=u.narrow.value,n=l.index.value,r=l.lesson.value,[i,a]=t(!1),[o,s]=t(null),c=h(null),d=h(null),f=()=>c.current?.scrollTop??0,m=r.status===`ready`?r.lesson.id:null;g(()=>{if(r.status!==`ready`)return;let e=l.takeScroll(r.lesson.id);d.current?.focus({preventScroll:!0}),c.current&&(c.current.scrollTop=e??0)},[r]),g(()=>{if(!i)return;let e=e=>{e.key===`Escape`&&a(!1)};return addEventListener(`keydown`,e),()=>removeEventListener(`keydown`,e)},[i]);let _;return _=n.status===`none`?p(`p`,{class:`empty`,children:`This copy of nodejs-map has no course.`}):n.status===`loading`?p(`p`,{class:`empty`,children:`Loading the course...`}):n.status===`failed`?p(`p`,{class:`empty warn-text`,children:[`The course could not be loaded: `,n.reason]}):r.status===`failed`?p(`p`,{class:`empty warn-text`,role:`alert`,children:[`This lesson could not be opened: `,r.reason,`.`]}):r.status===`ready`?p(`article`,{class:`learn__article`,"aria-labelledby":`learn-title`,children:[p(`h2`,{id:`learn-title`,class:`learn__title`,tabIndex:-1,ref:d,children:r.lesson.title}),r.lesson.summary?p(`p`,{class:`learn__summary`,children:r.lesson.summary}):null,p(U,{lesson:r.lesson,scroll:f,onImage:s},r.lesson.id)]}):p(`p`,{class:`empty`,children:`Opening the lesson...`}),p(`div`,{class:`learn${e?` learn--narrow`:``}`,children:[e?p(`button`,{type:`button`,class:`ctl learn__drawerbtn`,"aria-expanded":i,"aria-controls":`learn-nav`,onClick:()=>a(!i),children:`Chapters and lessons`}):null,p(`nav`,{id:`learn-nav`,class:`learn__nav${e&&!i?` is-closed`:``}`,"aria-label":`Chapters and lessons`,hidden:e&&!i,children:p(H,{current:m,onPick:()=>a(!1)})}),p(`main`,{class:`learn__main`,ref:c,id:`learn-main`,children:p(`div`,{class:`learn__column`,children:_})}),o?p(B,{image:o,onClose:()=>s(null)},o.src):null]})}export{W as LearnView};
3
+ //# sourceMappingURL=LearnView-Cqz9Ux8w.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LearnView-Cqz9Ux8w.js","names":["h","useRef","useState","useEffect","useLayoutEffect","_jsxs","_jsx","_jsxs","_jsx","_Fragment","useState","useRef","useEffect","$","d","playExample","F","inlinePieces","openPathFromLesson","lessonsOf","helperMode","runExample","learn","ui","Icon","routeHash","a","k","T","A","NOTE_LABEL","piece","p","ctx","key","renderInline","inline","i","JS_TOKENS","SH_TOKENS","CLASSES","highlight","text","lang","re","out","at","m","group","g","renderBlock","block","item","src","img","open","shown","renderBlocks","blocks","b","LEVEL_LABEL","MIN_OF_FIT","limitsFor","image","stage","fit","max","clampScale","scale","limits","fitView","zoomTo","view","px","py","next","zoomBy","factor","wheelFactor","deltaY","deltaMode","clampPan","w","h","fix","pos","size","room","isFit","STEP","PAN_STEP","TAP_MS","TAP_PX","ImageViewer","onClose","dialog","closeButton","natural","setViewState","viewRef","animate","setAnimate","alive","requestClose","stageSize","r","apply","animated","v","center","s","zoomButton","pan","dx","dy","toggleAt","l","local","clientX","clientY","opener","onResize","onWheel","unit","gestureScale","onGestureStart","onGestureChange","el","pointers","pinch","moved","lastTap","pinchState","onPointerDown","onPointerMove","was","now","before","after","zoomed","onPointerUp","tap","last","onKeyDown","ctrl","handled","percent","ExampleBlock","lessonId","example","scroll","helper","steps","CourseNav","current","onPick","state","done","chapter","isDone","Lesson","lesson","onImage","id","file","entry","LearnView","narrow","index","drawer","setDrawer","viewing","setViewing","main","title","back","onKey","body"],"sources":["../../src/learn/blocks.ts","../../src/learn/zoom.ts","../../src/learn/ImageViewer.tsx","../../src/learn/LearnView.tsx"],"sourcesContent":["/**\n * The blocks of a lesson as Preact elements. Plain `h()` calls (no JSX, no hooks) so that\n * the unit tests can build and inspect the tree in Node.\n *\n * Every text of the course stays a text node: nothing here sets HTML. Links are the ones\n * lib/learn.ts allows (lessons that exist, https), images only files inside the course.\n */\nimport { h } from 'preact';\nimport type { ComponentChildren, VNode } from 'preact';\nimport type { LearnBlock, LearnInline } from '@nodejs-map/protocol';\nimport { inlinePieces } from '../lib/learn.ts';\nimport type { InlinePiece, RenderContext } from '../lib/learn.ts';\n\nexport interface BlockContext extends RenderContext {\n /** The reader chose a call path named in the text. */\n onPath(id: string): void;\n /** Address of a file the lesson names (an image); null when it is outside the course. */\n fileUrl(file: string): string | null;\n /** The example block for this id (it has buttons and state, so it is the view's). */\n example(id: string): ComponentChildren;\n /** Opens an image of the lesson in the zoomable viewer. Without it images are plain. */\n openImage?(image: { src: string; alt: string; caption: string | null; width: number; height: number }): void;\n}\n\nconst NOTE_LABEL: Readonly<Record<'tip' | 'honest' | 'warn', string>> = {\n tip: 'Tip',\n honest: 'What the tool cannot tell you',\n warn: 'A common mistake',\n};\n\nfunction piece(p: InlinePiece, ctx: BlockContext, key: number): ComponentChildren {\n switch (p.kind) {\n case 'text':\n return p.text;\n case 'code':\n case 'strong':\n case 'em':\n case 'kbd':\n return h(p.kind, { key }, p.text);\n case 'ui':\n return h('span', { key, class: 'learn-ui' }, p.text);\n case 'lesson':\n return h('a', { key, href: p.href }, p.text);\n case 'external':\n return h('a', { key, href: p.href, target: '_blank', rel: 'noopener noreferrer' }, p.text, h('span', { class: 'sr-only' }, ' (opens in a new tab)'));\n case 'path':\n return h('button', { key, type: 'button', class: 'learn-path', title: 'Show this call path on the map', onClick: () => ctx.onPath(p.id) }, p.text);\n }\n}\n\nexport function renderInline(inline: readonly LearnInline[], ctx: BlockContext): ComponentChildren[] {\n return inlinePieces(inline, ctx).map((p, i) => piece(p, ctx, i));\n}\n\n// ---- a light syntax highlighter for code to read ---------------------------------------\n\nconst JS_TOKENS =\n /(\\/\\/[^\\n]*|\\/\\*[\\s\\S]*?\\*\\/)|('(?:[^'\\\\\\n]|\\\\.)*'|\"(?:[^\"\\\\\\n]|\\\\.)*\"|`(?:[^`\\\\]|\\\\[\\s\\S])*`)|\\b(\\d[\\d_.]*n?)\\b|\\b(const|let|var|function|return|if|else|for|while|do|of|in|new|await|async|import|export|from|class|extends|try|catch|finally|throw|typeof|instanceof|this|null|undefined|true|false|break|continue|switch|case|default|yield|delete|void)\\b/g;\nconst SH_TOKENS = /(#[^\\n]*)/g;\nconst CLASSES = ['syn-comment', 'syn-string', 'syn-number', 'syn-keyword'] as const;\n\n/** The text split into plain strings and coloured spans. All of it stays text. */\nexport function highlight(text: string, lang: 'js' | 'sh' | 'text'): ComponentChildren[] {\n if (lang === 'text') return [text];\n const re = new RegExp(lang === 'js' ? JS_TOKENS : SH_TOKENS);\n const out: ComponentChildren[] = [];\n let at = 0;\n let m: RegExpExecArray | null;\n while ((m = re.exec(text)) !== null) {\n if (m[0] === '') {\n re.lastIndex++;\n continue;\n }\n if (m.index > at) out.push(text.slice(at, m.index));\n const group = m.slice(1).findIndex((g) => g !== undefined);\n out.push(h('span', { key: m.index, class: CLASSES[group] ?? '' }, m[0]));\n at = m.index + m[0].length;\n }\n if (at < text.length) out.push(text.slice(at));\n return out;\n}\n\n// ---- blocks ---------------------------------------------------------------------------\n\nexport function renderBlock(block: LearnBlock, ctx: BlockContext, key: number): VNode | ComponentChildren {\n switch (block.t) {\n case 'p':\n return h('p', { key }, renderInline(block.text, ctx));\n case 'h':\n // The lesson title is the h2 of the page; the lesson's own headings sit under it.\n return h(block.level === 2 ? 'h3' : 'h4', { key, id: block.id ? `learn-h-${block.id}` : undefined }, block.text);\n case 'list':\n return h(\n block.ordered ? 'ol' : 'ul',\n { key, class: 'learn-list' },\n block.items.map((item, i) => h('li', { key: i }, renderInline(item, ctx))),\n );\n case 'note':\n return h('div', { key, class: `learn-note learn-note--${block.kind}`, role: 'note' }, h('p', { class: 'learn-note__kind' }, NOTE_LABEL[block.kind]), h('p', null, renderInline(block.text, ctx)));\n case 'code':\n return h('pre', { key, class: 'learn-code', tabIndex: 0 }, h('code', null, highlight(block.text, block.lang)));\n case 'example':\n return h('div', { key, class: 'learn-example-slot' }, ctx.example(block.example));\n case 'image': {\n const src = ctx.fileUrl(block.src);\n const img = src ? h('img', { src, alt: block.alt, width: block.width, height: block.height, loading: 'lazy', decoding: 'async' }) : null;\n const open = ctx.openImage;\n // The image is its own button: a click or Enter opens it in the zoomable viewer.\n const shown =\n img && src && open\n ? h(\n 'button',\n {\n type: 'button',\n class: 'learn-zoom',\n 'aria-haspopup': 'dialog',\n title: 'Click to enlarge',\n onClick: () => open({ src, alt: block.alt, caption: block.caption ?? null, width: block.width, height: block.height }),\n },\n img,\n h('span', { class: 'learn-zoom__hint', 'aria-hidden': 'true' }, 'Click to enlarge'),\n )\n : img;\n return h(\n 'figure',\n { key, class: 'learn-figure' },\n shown ?? h('p', { class: 'muted' }, `[Image: ${block.alt}]`),\n block.caption ? h('figcaption', null, block.caption) : null,\n );\n }\n case 'check':\n return h(\n 'details',\n { key, class: 'learn-check' },\n h('summary', null, h('span', { class: 'learn-check__label' }, 'Check yourself: '), renderInline(block.question, ctx)),\n h('p', { class: 'learn-check__answer' }, renderInline(block.answer, ctx)),\n );\n }\n}\n\nexport function renderBlocks(blocks: readonly LearnBlock[], ctx: BlockContext): ComponentChildren[] {\n return blocks.map((b, i) => renderBlock(b, ctx, i));\n}\n\nexport const LEVEL_LABEL: Readonly<Record<'start' | 'core' | 'deep', string>> = { start: 'Start', core: 'Core', deep: 'Deep' };\n","/**\n * The maths of the image viewer (ImageViewer.tsx), kept pure for the unit tests.\n *\n * A view is where the image is drawn in the stage: its top-left corner (x, y) in stage\n * pixels and its scale (1 = natural size). Zooming about a point keeps the image pixel\n * under that point where it is.\n */\n\nexport interface Size {\n w: number;\n h: number;\n}\n\nexport interface View {\n x: number;\n y: number;\n scale: number;\n}\n\nexport interface Limits {\n /** The scale that fits the whole image in the stage. */\n fit: number;\n min: number;\n max: number;\n}\n\n/** Down to half of the fitted size; up to 400% of the natural size. */\nexport const MIN_OF_FIT = 0.5;\nexport const MAX_SCALE = 4;\n\nexport function limitsFor(image: Size, stage: Size): Limits {\n const fit = image.w > 0 && image.h > 0 && stage.w > 0 && stage.h > 0 ? Math.min(stage.w / image.w, stage.h / image.h) : 1;\n const max = Math.max(MAX_SCALE, fit);\n return { fit: Math.min(fit, max), min: fit * MIN_OF_FIT, max };\n}\n\nexport const clampScale = (scale: number, limits: Limits): number => Math.min(limits.max, Math.max(limits.min, scale));\n\n/** The whole image, centred. */\nexport function fitView(image: Size, stage: Size): View {\n const { fit } = limitsFor(image, stage);\n return { scale: fit, x: (stage.w - image.w * fit) / 2, y: (stage.h - image.h * fit) / 2 };\n}\n\n/** Scales the view to `scale` (clamped) about the stage point (px, py): that point stays fixed. */\nexport function zoomTo(view: View, scale: number, px: number, py: number, limits: Limits): View {\n const next = clampScale(scale, limits);\n const k = next / view.scale;\n return { scale: next, x: px - (px - view.x) * k, y: py - (py - view.y) * k };\n}\n\n/** Multiplies the scale by `factor` about (px, py). */\nexport const zoomBy = (view: View, factor: number, px: number, py: number, limits: Limits): View => zoomTo(view, view.scale * factor, px, py, limits);\n\n/** The zoom factor for a wheel step: a trackpad pinch sends small deltas, a mouse wheel larger ones. */\nexport function wheelFactor(deltaY: number, deltaMode: number): number {\n const px = deltaMode === 1 ? deltaY * 16 : deltaMode === 2 ? deltaY * 400 : deltaY;\n return Math.exp(-Math.max(-40, Math.min(40, px)) * 0.01);\n}\n\n/**\n * Keeps the image on screen: an image larger than the stage leaves no gap at its edges; a\n * smaller one stays inside. A view that is already within these bounds is unchanged.\n */\nexport function clampPan(view: View, image: Size, stage: Size): View {\n const w = image.w * view.scale;\n const h = image.h * view.scale;\n const fix = (pos: number, size: number, room: number): number => (size <= room ? Math.min(room - size, Math.max(0, pos)) : Math.min(0, Math.max(room - size, pos)));\n return { scale: view.scale, x: fix(view.x, w, stage.w), y: fix(view.y, h, stage.h) };\n}\n\n/** True when the view is (about) the fitted one. */\nexport const isFit = (view: View, limits: Limits): boolean => Math.abs(view.scale - limits.fit) < limits.fit * 0.01;\n","/**\n * A lesson image in a full-window viewer, with the map's gestures: trackpad pinch and\n * Ctrl/Cmd+wheel zoom at the pointer, the wheel and two-finger scroll pan, a drag pans,\n * touch pinch zooms and pans, a double click or double tap toggles between the fitted\n * size and twice that. Buttons and keys do the same (+, -, 0, arrows; Escape closes).\n *\n * A native modal <dialog>: the page behind cannot be reached, focus stays inside, and it\n * goes back to the image's button on close. The page neither scrolls nor zooms while the\n * viewer is open: every wheel and gesture event over it is taken.\n */\nimport { useEffect, useLayoutEffect, useRef, useState } from 'preact/hooks';\nimport { Icon } from '../shell/icons.tsx';\nimport { clampPan, fitView, isFit, limitsFor, wheelFactor, zoomBy, zoomTo } from './zoom.ts';\nimport type { Size, View } from './zoom.ts';\n\nexport interface ViewedImage {\n src: string;\n alt: string;\n caption: string | null;\n width: number;\n height: number;\n}\n\nconst STEP = 1.25;\nconst PAN_STEP = 60;\nconst TAP_MS = 320;\nconst TAP_PX = 24;\n\nexport function ImageViewer({ image, onClose }: { image: ViewedImage; onClose(): void }) {\n const dialog = useRef<HTMLDialogElement>(null);\n const stage = useRef<HTMLDivElement>(null);\n const img = useRef<HTMLImageElement>(null);\n const closeButton = useRef<HTMLButtonElement>(null);\n const natural = useRef<Size>({ w: image.width, h: image.height });\n const [view, setViewState] = useState<View | null>(null);\n const viewRef = useRef<View | null>(null);\n const [animate, setAnimate] = useState(false);\n /** False once closing: the element's late close event must not close another image. */\n const alive = useRef(true);\n const requestClose = (): void => {\n if (!alive.current) return;\n alive.current = false;\n onClose();\n };\n\n const stageSize = (): Size => {\n const r = stage.current?.getBoundingClientRect();\n return { w: r?.width ?? 0, h: r?.height ?? 0 };\n };\n const limits = () => limitsFor(natural.current, stageSize());\n const apply = (next: View, animated = false): void => {\n const v = clampPan(next, natural.current, stageSize());\n viewRef.current = v;\n setAnimate(animated);\n setViewState(v);\n };\n const fit = (animated = false): void => apply(fitView(natural.current, stageSize()), animated);\n const center = (): [number, number] => {\n const s = stageSize();\n return [s.w / 2, s.h / 2];\n };\n const zoomButton = (factor: number): void => {\n const v = viewRef.current;\n if (v) apply(zoomBy(v, factor, ...center(), limits()), true);\n };\n const pan = (dx: number, dy: number, animated = false): void => {\n const v = viewRef.current;\n if (v) apply({ ...v, x: v.x + dx, y: v.y + dy }, animated);\n };\n const toggleAt = (px: number, py: number): void => {\n const v = viewRef.current;\n if (!v) return;\n const l = limits();\n if (isFit(v, l)) apply(zoomTo(v, l.fit * 2, px, py, l), true);\n else fit(true);\n };\n const local = (clientX: number, clientY: number): [number, number] => {\n const r = stage.current?.getBoundingClientRect();\n return [clientX - (r?.left ?? 0), clientY - (r?.top ?? 0)];\n };\n\n // Open as a modal; on close the focus goes back to the control that opened it.\n useEffect(() => {\n const d = dialog.current;\n if (!d) return;\n const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;\n if (!d.open) d.showModal();\n closeButton.current?.focus();\n fit();\n const onResize = (): void => fit();\n addEventListener('resize', onResize);\n return () => {\n removeEventListener('resize', onResize);\n if (d.open) d.close();\n if (opener?.isConnected) opener.focus();\n };\n }, []);\n\n // Wheel and Safari's gesture events: listeners that may cancel (Preact's are passive-free,\n // but the browser treats a wheel listener on the window as passive unless told otherwise).\n useEffect(() => {\n const d = dialog.current;\n if (!d) return;\n const onWheel = (e: WheelEvent): void => {\n e.preventDefault();\n const v = viewRef.current;\n if (!v) return;\n if (e.ctrlKey || e.metaKey) {\n const [px, py] = local(e.clientX, e.clientY);\n apply(zoomBy(v, wheelFactor(e.deltaY, e.deltaMode), px, py, limits()));\n } else {\n const unit = e.deltaMode === 1 ? 16 : 1;\n apply({ ...v, x: v.x - e.deltaX * unit, y: v.y - e.deltaY * unit });\n }\n };\n let gestureScale = 1;\n const onGestureStart = (e: Event): void => {\n e.preventDefault();\n gestureScale = 1;\n };\n const onGestureChange = (e: Event): void => {\n e.preventDefault();\n const g = e as Event & { scale: number; clientX: number; clientY: number };\n const v = viewRef.current;\n if (!v || !g.scale) return;\n const [px, py] = local(g.clientX, g.clientY);\n apply(zoomBy(v, g.scale / gestureScale, px, py, limits()));\n gestureScale = g.scale;\n };\n d.addEventListener('wheel', onWheel, { passive: false });\n d.addEventListener('gesturestart', onGestureStart);\n d.addEventListener('gesturechange', onGestureChange);\n d.addEventListener('gestureend', onGestureStart);\n return () => {\n d.removeEventListener('wheel', onWheel);\n d.removeEventListener('gesturestart', onGestureStart);\n d.removeEventListener('gesturechange', onGestureChange);\n d.removeEventListener('gestureend', onGestureStart);\n };\n }, []);\n\n // The transform is set through the CSSOM (no style attribute: the page's CSP).\n useLayoutEffect(() => {\n const el = img.current;\n if (!el || !view) return;\n el.style.width = `${natural.current.w}px`;\n el.style.height = `${natural.current.h}px`;\n el.style.transform = `translate(${view.x}px, ${view.y}px) scale(${view.scale})`;\n }, [view]);\n\n // Pointers: one drags, two pinch. A quick second tap or click at the same place toggles the zoom.\n const pointers = useRef(new Map<number, { x: number; y: number }>());\n const pinch = useRef<{ dist: number; mid: [number, number] } | null>(null);\n const moved = useRef(false);\n const lastTap = useRef<{ t: number; x: number; y: number } | null>(null);\n const pinchState = (): { dist: number; mid: [number, number] } | null => {\n const [a, b] = [...pointers.current.values()];\n if (!a || !b) return null;\n return { dist: Math.hypot(a.x - b.x, a.y - b.y), mid: local((a.x + b.x) / 2, (a.y + b.y) / 2) };\n };\n const onPointerDown = (e: PointerEvent): void => {\n if (e.button !== 0) return;\n (e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);\n pointers.current.set(e.pointerId, { x: e.clientX, y: e.clientY });\n if (pointers.current.size === 1) moved.current = false;\n pinch.current = pointers.current.size === 2 ? pinchState() : null;\n if (pointers.current.size > 1) moved.current = true;\n };\n const onPointerMove = (e: PointerEvent): void => {\n const was = pointers.current.get(e.pointerId);\n if (!was) return;\n const now = { x: e.clientX, y: e.clientY };\n pointers.current.set(e.pointerId, now);\n if (pointers.current.size === 1) {\n if (Math.hypot(now.x - was.x, now.y - was.y) > 0) {\n moved.current = moved.current || Math.abs(now.x - was.x) + Math.abs(now.y - was.y) > 2;\n pan(now.x - was.x, now.y - was.y);\n }\n return;\n }\n const before = pinch.current;\n const after = pinchState();\n const v = viewRef.current;\n if (!before || !after || !v || before.dist === 0) return;\n const zoomed = zoomBy(v, after.dist / before.dist, before.mid[0], before.mid[1], limits());\n apply({ ...zoomed, x: zoomed.x + after.mid[0] - before.mid[0], y: zoomed.y + after.mid[1] - before.mid[1] });\n pinch.current = after;\n };\n const onPointerUp = (e: PointerEvent): void => {\n if (!pointers.current.delete(e.pointerId)) return;\n pinch.current = pointers.current.size === 2 ? pinchState() : null;\n if (pointers.current.size > 0 || moved.current || e.type === 'pointercancel') return;\n const tap = { t: e.timeStamp, x: e.clientX, y: e.clientY };\n const last = lastTap.current;\n if (last && tap.t - last.t < TAP_MS && Math.hypot(tap.x - last.x, tap.y - last.y) < TAP_PX) {\n lastTap.current = null;\n toggleAt(...local(tap.x, tap.y));\n } else lastTap.current = tap;\n };\n\n const onKeyDown = (e: KeyboardEvent): void => {\n const ctrl = e.ctrlKey || e.metaKey;\n let handled = true;\n if (e.key === '+' || e.key === '=') zoomButton(STEP);\n else if (e.key === '-' || e.key === '_') zoomButton(1 / STEP);\n else if (e.key === '0') fit(true);\n else if (e.key === 'ArrowLeft' && !ctrl) pan(PAN_STEP, 0, true);\n else if (e.key === 'ArrowRight' && !ctrl) pan(-PAN_STEP, 0, true);\n else if (e.key === 'ArrowUp' && !ctrl) pan(0, PAN_STEP, true);\n else if (e.key === 'ArrowDown' && !ctrl) pan(0, -PAN_STEP, true);\n else handled = false;\n if (handled) {\n // Ctrl/Cmd with + - 0 would zoom the browser: here it zooms the image.\n e.preventDefault();\n e.stopPropagation();\n }\n };\n\n const percent = view ? Math.round(view.scale * 100) : null;\n return (\n <dialog\n ref={dialog}\n class=\"imgview\"\n role=\"dialog\"\n aria-label={image.alt}\n onCancel={(e) => {\n e.preventDefault();\n requestClose();\n }}\n onClose={requestClose}\n onKeyDown={onKeyDown}\n >\n <div class=\"imgview__bar\" role=\"toolbar\" aria-label=\"Zoom\">\n <button type=\"button\" class=\"ctl ctl--icon imgview__btn\" aria-label=\"Zoom out\" title=\"Zoom out (-)\" onClick={() => zoomButton(1 / STEP)}>\n <span aria-hidden=\"true\">−</span>\n </button>\n <span class=\"imgview__pct num\" role=\"status\" aria-live=\"polite\">\n {percent === null ? '' : `${percent}%`}\n </span>\n <button type=\"button\" class=\"ctl ctl--icon imgview__btn\" aria-label=\"Zoom in\" title=\"Zoom in (+)\" onClick={() => zoomButton(STEP)}>\n <span aria-hidden=\"true\">+</span>\n </button>\n <button type=\"button\" class=\"ctl imgview__btn\" title=\"Fit the image to the window (0)\" onClick={() => fit(true)}>\n Fit\n </button>\n <span class=\"imgview__help muted\">Pinch or Ctrl+wheel to zoom · drag to pan · Esc to close</span>\n <button ref={closeButton} type=\"button\" class=\"ctl ctl--icon imgview__btn imgview__close\" aria-label=\"Close image\" title=\"Close (Esc)\" onClick={requestClose}>\n <Icon name=\"close\" />\n </button>\n </div>\n <div\n ref={stage}\n class={`imgview__stage${view ? ' is-ready' : ''}${animate ? ' is-animated' : ''}`}\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={onPointerUp}\n onPointerCancel={onPointerUp}\n onLostPointerCapture={onPointerUp}\n >\n <img\n ref={img}\n class=\"imgview__img\"\n src={image.src}\n alt={image.alt}\n draggable={false}\n onLoad={(e) => {\n const el = e.currentTarget as HTMLImageElement;\n if (el.naturalWidth > 0 && (el.naturalWidth !== natural.current.w || el.naturalHeight !== natural.current.h)) {\n natural.current = { w: el.naturalWidth, h: el.naturalHeight };\n fit();\n }\n }}\n />\n </div>\n {image.caption ? <p class=\"imgview__caption\">{image.caption}</p> : null}\n </dialog>\n );\n}\n","/**\n * The Learn page: the course's chapters and lessons on the left, one lesson in a readable\n * column on the right. Loaded as its own chunk the first time the page is opened.\n *\n * A phone shows one column; the chapter list is a drawer behind a button.\n */\nimport { useEffect, useRef, useState } from 'preact/hooks';\nimport type { LearnExample, LearnLesson } from '@nodejs-map/protocol';\nimport { lessonsOf } from '../lib/learn.ts';\nimport { routeHash } from '../lib/route.ts';\nimport { helperMode, learn, openPathFromLesson, playExample, runExample, ui } from '../stores/index.ts';\nimport { LEVEL_LABEL, highlight, renderBlocks } from './blocks.ts';\nimport type { BlockContext } from './blocks.ts';\nimport { ImageViewer } from './ImageViewer.tsx';\nimport type { ViewedImage } from './ImageViewer.tsx';\nimport './learn.css';\n\nfunction ExampleBlock({ lessonId, example, scroll }: { lessonId: string; example: LearnExample; scroll: () => number }) {\n const helper = helperMode.value;\n const steps = example.steps?.length ?? 0;\n return (\n <section class=\"learn-example\" aria-label={`Example: ${example.title || example.name}`}>\n <header class=\"learn-example__head\">\n <span class=\"learn-example__title\">{example.title || example.name}</span>\n <span class=\"muted mono\">{example.name}</span>\n </header>\n {example.racy ? (\n <p class=\"learn-example__racy\" role=\"note\">\n The order of this program's output is a race: it can differ from one run to the next.\n </p>\n ) : null}\n <pre class=\"learn-code learn-code--example\" tabIndex={0} aria-label={`The program ${example.name}`}>\n <code>{highlight(example.text, 'js')}</code>\n </pre>\n {example.output.length > 0 ? (\n <details class=\"learn-example__output\">\n <summary>What it printed when this lesson was made{example.racy ? ' (one possible order)' : ''}</summary>\n <pre class=\"learn-code learn-code--output\">{example.output.join('\\n')}</pre>\n </details>\n ) : null}\n <div class=\"learn-example__acts\">\n {example.recording ? (\n <button type=\"button\" class=\"ctl ctl--primary learn-play\" onClick={() => void playExample(lessonId, example, scroll())}>\n Play the walk-through\n {steps > 0 ? <span class=\"learn-example__n\"> ({steps} steps)</span> : null}\n </button>\n ) : null}\n {helper ? (\n <button type=\"button\" class=\"ctl learn-run\" onClick={() => void runExample(lessonId, example, scroll())}>\n Run it yourself\n </button>\n ) : null}\n </div>\n </section>\n );\n}\n\nfunction CourseNav({ current, onPick }: { current: string | null; onPick: () => void }) {\n const state = learn.index.value;\n const done = learn.done.value;\n if (state.status !== 'ready') return null;\n return (\n <>\n <h2 class=\"learn__navtitle\">Chapters and lessons</h2>\n <ol class=\"learn__chapters\">\n {state.index.chapters.map((chapter) => (\n <li key={chapter.id} class=\"learn__chapter\">\n <h3 class=\"learn__chaptertitle\">{chapter.title}</h3>\n <ol class=\"learn__lessons\">\n {chapter.lessons.map((l) => {\n const isDone = done.has(l.id);\n return (\n <li key={l.id}>\n <a class={`learn__lesson${isDone ? ' is-done' : ''}`} href={routeHash({ view: 'learn', lesson: l.id })} aria-current={l.id === current ? 'page' : undefined} onClick={onPick}>\n <span class=\"learn__tick\" aria-hidden=\"true\" />\n <span class=\"learn__lessontitle\">{l.title}</span>\n <span class=\"learn__meta muted\">\n {LEVEL_LABEL[l.level]} · {l.minutes} min{isDone ? <span class=\"sr-only\"> · done</span> : null}\n </span>\n </a>\n </li>\n );\n })}\n </ol>\n </li>\n ))}\n </ol>\n </>\n );\n}\n\nfunction Lesson({ lesson, scroll, onImage }: { lesson: LearnLesson; scroll: () => number; onImage(image: ViewedImage): void }) {\n const ctx: BlockContext = {\n hasLesson: (id) => learn.hasLesson(id),\n fileUrl: (file) => learn.fileUrl(file),\n onPath: (id) => openPathFromLesson(lesson.id, id, scroll()),\n openImage: onImage,\n example: (id) => {\n const example = lesson.examples[id];\n return example ? <ExampleBlock lessonId={lesson.id} example={example} scroll={scroll} /> : <p class=\"muted\">This example is missing from the lesson file.</p>;\n },\n };\n const isDone = learn.done.value.has(lesson.id);\n const state = learn.index.value;\n const entry = state.status === 'ready' ? lessonsOf(state.index).find((l) => l.id === lesson.id) : undefined;\n return (\n <>\n {renderBlocks(lesson.blocks, ctx)}\n <div class=\"learn__done\">\n <button type=\"button\" class=\"ctl\" aria-pressed={isDone} onClick={() => learn.setDone(lesson.id, !isDone)}>\n {isDone ? 'Done: marked in this browser' : 'Mark this lesson as done'}\n </button>\n {entry ? <span class=\"muted\">{LEVEL_LABEL[entry.level]} · about {entry.minutes} min</span> : null}\n </div>\n <nav class=\"learn__pager\" aria-label=\"Previous and next lesson\">\n {lesson.prev ? (\n <a class=\"learn__pagerlink\" href={routeHash({ view: 'learn', lesson: lesson.prev.id })} rel=\"prev\">\n <span class=\"muted\">Previous</span>\n <span>{lesson.prev.title}</span>\n </a>\n ) : (\n <span />\n )}\n {lesson.next ? (\n <a class=\"learn__pagerlink learn__pagerlink--next\" href={routeHash({ view: 'learn', lesson: lesson.next.id })} rel=\"next\">\n <span class=\"muted\">Next</span>\n <span>{lesson.next.title}</span>\n </a>\n ) : null}\n </nav>\n </>\n );\n}\n\nexport function LearnView() {\n const narrow = ui.narrow.value;\n const index = learn.index.value;\n const state = learn.lesson.value;\n const [drawer, setDrawer] = useState(false);\n const [viewing, setViewing] = useState<ViewedImage | null>(null);\n const main = useRef<HTMLElement>(null);\n const title = useRef<HTMLHeadingElement>(null);\n const scroll = (): number => main.current?.scrollTop ?? 0;\n const lessonId = state.status === 'ready' ? state.lesson.id : null;\n\n // A new lesson (or the page opened again): the focus goes to its title, and the column\n // to where the reader left it, or to the top.\n useEffect(() => {\n if (state.status !== 'ready') return;\n const back = learn.takeScroll(state.lesson.id);\n title.current?.focus({ preventScroll: true });\n if (main.current) main.current.scrollTop = back ?? 0;\n }, [state]);\n\n useEffect(() => {\n if (!drawer) return;\n const onKey = (e: KeyboardEvent): void => {\n if (e.key === 'Escape') setDrawer(false);\n };\n addEventListener('keydown', onKey);\n return () => removeEventListener('keydown', onKey);\n }, [drawer]);\n\n let body;\n if (index.status === 'none') body = <p class=\"empty\">This copy of nodejs-map has no course.</p>;\n else if (index.status === 'loading') body = <p class=\"empty\">Loading the course...</p>;\n else if (index.status === 'failed') body = <p class=\"empty warn-text\">The course could not be loaded: {index.reason}</p>;\n else if (state.status === 'failed')\n body = (\n <p class=\"empty warn-text\" role=\"alert\">\n This lesson could not be opened: {state.reason}.\n </p>\n );\n else if (state.status === 'ready')\n body = (\n <article class=\"learn__article\" aria-labelledby=\"learn-title\">\n <h2 id=\"learn-title\" class=\"learn__title\" tabIndex={-1} ref={title}>\n {state.lesson.title}\n </h2>\n {state.lesson.summary ? <p class=\"learn__summary\">{state.lesson.summary}</p> : null}\n <Lesson key={state.lesson.id} lesson={state.lesson} scroll={scroll} onImage={setViewing} />\n </article>\n );\n else body = <p class=\"empty\">Opening the lesson...</p>;\n\n return (\n <div class={`learn${narrow ? ' learn--narrow' : ''}`}>\n {narrow ? (\n <button type=\"button\" class=\"ctl learn__drawerbtn\" aria-expanded={drawer} aria-controls=\"learn-nav\" onClick={() => setDrawer(!drawer)}>\n Chapters and lessons\n </button>\n ) : null}\n <nav id=\"learn-nav\" class={`learn__nav${narrow && !drawer ? ' is-closed' : ''}`} aria-label=\"Chapters and lessons\" hidden={narrow && !drawer}>\n <CourseNav current={lessonId} onPick={() => setDrawer(false)} />\n </nav>\n <main class=\"learn__main\" ref={main} id=\"learn-main\">\n <div class=\"learn__column\">{body}</div>\n </main>\n {viewing ? <ImageViewer key={viewing.src} image={viewing} onClose={() => setViewing(null)} /> : null}\n </div>\n );\n}\n"],"mappings":"A,wJAwBA,IAAM8B,EAAkE,CACtE,IAAK,MACL,OAAQ,gCACR,KAAM,kBACR,EAEA,SAASC,EAAMC,EAAgBC,EAAmBC,EAAgC,CAChF,OAAQF,EAAE,KAAV,CACE,IAAK,OACH,OAAOA,EAAE,KACX,IAAK,OACL,IAAK,SACL,IAAK,KACL,IAAK,MACH,OAAOhC,EAAEgC,EAAE,KAAM,CAAEE,KAAI,EAAGF,EAAE,IAAI,EAClC,IAAK,KACH,OAAOhC,EAAE,OAAQ,CAAEkC,MAAK,MAAO,UAAW,EAAGF,EAAE,IAAI,EACrD,IAAK,SACH,OAAOhC,EAAE,IAAK,CAAEkC,MAAK,KAAMF,EAAE,IAAK,EAAGA,EAAE,IAAI,EAC7C,IAAK,WACH,OAAOhC,EAAE,IAAK,CAAEkC,MAAK,KAAMF,EAAE,KAAM,OAAQ,SAAU,IAAK,qBAAsB,EAAGA,EAAE,KAAMhC,EAAE,OAAQ,CAAE,MAAO,SAAU,EAAG,uBAAuB,CAAC,EACrJ,IAAK,OACH,OAAOA,EAAE,SAAU,CAAEkC,MAAK,KAAM,SAAU,MAAO,aAAc,MAAO,iCAAkC,YAAeD,EAAI,OAAOD,EAAE,EAAE,CAAE,EAAGA,EAAE,IAAI,CACrJ,CACF,CAEA,SAAgBG,EAAaC,EAAgCH,EAAwC,CACnG,OAAOhB,EAAamB,EAAQ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U,CAAA,CAClC,CAAA,EACLN,EAAUnK,EAACqF,EAAD,CAA+B,MAAO8E,EAAS,YAAeC,EAAW,IAAI,CAAI,EAA/DD,EAAQ,GAAuD,EAAI,IAC7F,C,EAET,C"}
@@ -0,0 +1 @@
1
+ .learn{background:var(--bg);grid-template-columns:minmax(220px,300px) minmax(0,1fr);min-height:0;display:grid}.learn__nav{background:var(--surface);border-right:1px solid var(--line);padding:14px 12px 24px;overflow:auto}.learn__navtitle{font-size:var(--fs-0);letter-spacing:.06em;text-transform:uppercase;color:var(--ink-3);margin-bottom:8px;font-weight:600}.learn__chapter+.learn__chapter{margin-top:14px}.learn__chaptertitle{font-size:var(--fs-2);margin-bottom:4px;font-weight:700}.learn__lesson{border-radius:var(--radius);color:var(--ink);min-height:var(--hit);grid-template-columns:14px minmax(0,1fr);column-gap:6px;padding:5px 6px;text-decoration:none;display:grid}.learn__lesson:hover{background:var(--surface-2)}.learn__lesson[aria-current=page]{background:var(--accent-soft);box-shadow:inset 3px 0 0 var(--accent)}.learn__tick{border:1px solid var(--line-strong);border-radius:50%;grid-row:1/span 2;width:12px;height:12px;margin-top:3px}.learn__lesson.is-done .learn__tick{border-color:var(--ok);background:var(--ok);position:relative}.learn__lesson.is-done .learn__tick:after{content:"";border:solid var(--surface);border-width:0 2px 2px 0;width:3px;height:6px;position:absolute;top:1px;left:3px;transform:rotate(45deg)}.learn__meta{font-size:var(--fs-1);grid-column:2}.learn__main{min-height:0;overflow:auto}.learn__column{max-width:70ch;font-size:var(--fs-3);margin:0 auto;padding:20px 20px 48px;line-height:1.6}.learn__article>*+*{margin-top:.9em}.learn__title{font-size:1.6rem;line-height:1.25}.learn__summary{color:var(--ink-2)}.learn__article h3{margin-top:1.6em;font-size:1.15rem}.learn__article h4{margin-top:1.3em;font-size:1rem}.learn-list{padding-left:1.4em}ul.learn-list{list-style:outside}ol.learn-list{list-style:decimal}.learn-list li+li{margin-top:.3em}.learn-ui{border:1px solid var(--line-strong);border-radius:var(--radius);background:var(--surface);white-space:nowrap;padding:0 6px;font-size:.88em;font-weight:600;line-height:1.5;display:inline-block}.learn-path{color:var(--accent);text-underline-offset:2px;cursor:pointer;background:0 0;border:0;padding:0;-webkit-text-decoration:underline dotted;text-decoration:underline dotted}.learn-note{border-left:4px solid var(--accent);border-radius:var(--radius);background:var(--surface);padding:10px 14px}.learn-note__kind{font-size:var(--fs-1);letter-spacing:.04em;text-transform:uppercase;color:var(--ink-2);font-weight:700}.learn-note--tip{border-left-color:var(--ok)}.learn-note--honest{border-left-color:var(--c-model);border-left-style:double;border-left-width:6px}.learn-note--warn{border-left-color:var(--warn);background:var(--warn-soft)}.learn-code{border:1px solid var(--line);border-radius:var(--radius);background:var(--surface);font-size:var(--fs-2);padding:10px 12px;line-height:1.5;overflow:auto}.syn-comment{color:var(--syn-comment);font-style:italic}.syn-string{color:var(--syn-string)}.syn-number{color:var(--syn-number)}.syn-keyword{color:var(--syn-keyword)}.learn-figure img{border:1px solid var(--line);border-radius:var(--radius);max-width:100%;height:auto;display:block}.learn-figure figcaption{font-size:var(--fs-2);color:var(--ink-2);margin-top:6px}.learn-check{border:1px dashed var(--line-strong);border-radius:var(--radius);background:var(--surface);padding:8px 12px}.learn-check summary{cursor:pointer}.learn-check__label{font-weight:700}.learn-check__answer{margin-top:8px}.learn-example{border:1px solid var(--line-strong);border-radius:var(--radius);background:var(--surface-2);gap:8px;padding:12px;display:grid}.learn-example__head{flex-wrap:wrap;justify-content:space-between;align-items:baseline;gap:4px 12px;display:flex}.learn-example__title{font-weight:700}.learn-example__racy{font-size:var(--fs-2);color:var(--warn)}.learn-example__output summary{cursor:pointer;font-size:var(--fs-2)}.learn-code--output{margin-top:6px}.learn-example__acts{flex-wrap:wrap;gap:8px;display:flex}.learn-example__n{font-weight:400}.learn__done{border-top:1px solid var(--line);font-size:var(--fs-2);flex-wrap:wrap;align-items:center;gap:8px 14px;margin-top:2em;padding-top:14px;display:flex}.learn__pager{justify-content:space-between;gap:12px;margin-top:14px;display:flex}.learn__pagerlink{border:1px solid var(--line);border-radius:var(--radius);background:var(--surface);max-width:48%;padding:8px 12px;text-decoration:none;display:grid}.learn__pagerlink--next{text-align:right;margin-left:auto}.learn--narrow{grid-template-rows:auto minmax(0,1fr);grid-template-columns:minmax(0,1fr);position:relative}.learn__drawerbtn{justify-self:start;margin:6px 8px}.learn--narrow .learn__nav{inset:calc(var(--hit) + 12px) 0 0 0;z-index:5;border-right:0;border-top:1px solid var(--line);box-shadow:var(--shadow);position:absolute}.learn--narrow .learn__column{padding:12px 16px 40px}.learn-zoom{cursor:zoom-in;background:0 0;border:0;max-width:100%;padding:0;display:block;position:relative}.learn-zoom:focus-visible{outline-offset:3px}.learn-zoom__hint{border:1px solid var(--line-strong);border-radius:var(--radius);background:var(--surface);color:var(--ink);font-size:var(--fs-1);box-shadow:var(--shadow);opacity:0;pointer-events:none;padding:2px 8px;line-height:1.5;position:absolute;bottom:8px;right:8px}.learn-zoom:hover .learn-zoom__hint,.learn-zoom:focus-visible .learn-zoom__hint{opacity:1}@media (prefers-reduced-motion:no-preference){.learn-zoom__hint{transition:opacity .12s ease-out}}.imgview{background:color-mix(in srgb, var(--bg) 94%, #000);width:100vw;max-width:none;height:100dvh;max-height:none;color:var(--ink);overscroll-behavior:none;border:0;margin:0;padding:0;overflow:hidden}.imgview[open]{grid-template-rows:auto minmax(0,1fr) auto;grid-template-columns:minmax(0,1fr);display:grid}.imgview::backdrop{background:#0009}.imgview__bar{border-bottom:1px solid var(--line);background:var(--surface);align-items:center;gap:6px;min-width:0;padding:6px 10px;display:flex}.imgview__btn{font-size:var(--fs-3);font-weight:700}.imgview__pct{text-align:center;min-width:5ch}.imgview__help{text-overflow:ellipsis;white-space:nowrap;min-width:0;font-size:var(--fs-1);flex:auto;overflow:hidden}.imgview__close{margin-left:auto}.imgview__stage{touch-action:none;overscroll-behavior:none;cursor:grab;-webkit-user-select:none;user-select:none;min-height:0;position:relative;overflow:hidden}.imgview__stage:active{cursor:grabbing}.imgview__img{transform-origin:0 0;will-change:transform;visibility:hidden;-webkit-user-drag:none;max-width:none;position:absolute;top:0;left:0}.imgview__stage.is-ready .imgview__img{visibility:visible}@media (prefers-reduced-motion:no-preference){.imgview__stage.is-animated .imgview__img{transition:transform .14s ease-out}}.imgview__caption{padding:8px 14px calc(8px + env(safe-area-inset-bottom));border-top:1px solid var(--line);background:var(--surface);color:var(--ink-2);font-size:var(--fs-2);text-align:center}@media (width<=760px){.imgview__help{display:none}}
@@ -0,0 +1,8 @@
1
+ const e=[`cb.nextTick`,`cb.microtask`,`cb.timers`,`cb.immediate`,`cb.pool`,`cb.io`,`cb.close`,`cb.other`,`stdout`,`stderr`,`pause`,`pool`,`note`];var t=class{#e=[];#t=0;#n=!1;#r=/* @__PURE__ */ new Set;get events(){return this.#e}get length(){return this.#e.length}get version(){return this.#t}get status(){return this.#n?`ended`:this.#e.length===0?`empty`:`live`}get live(){return!this.#n&&this.#e.length>0}apply(e){let t=this.#e.length,n=typeof e!=`object`||!e?NaN:e.base,r=typeof e==`object`&&e&&Array.isArray(e.events)?e.events:null;if(!Number.isInteger(n)||n<0||r===null)return this.#i(`bad-base`);if(n>t)return this.#i(`gap`);let i=n,a=0;for(;i<t&&a<r.length&&this.#e[i]===r[a];)i++,a++;let o=i<t;if(!o&&a===r.length)return this.#a(t,t,!1,!1,!1);o&&(this.#e.length=i);for(let e=a;e<r.length;e++)this.#e.push(r[e]);return this.#a(i,t,o,!1,!0)}load(e){let t=this.#e.length;return this.#e=Array.isArray(e)?e.slice():[],this.#n=!0,this.#a(0,t,t>0,!0,!0)}end(){let e=this.#e.length;return this.#n?this.#a(e,e,!1,!1,!1):(this.#n=!0,this.#a(e,e,!1,!1,!0))}reset(){let e=this.#e.length;return this.#e=[],this.#n=!1,this.#a(0,e,e>0,!0,!0)}subscribe(e){return this.#r.add(e),()=>{this.#r.delete(e)}}#i(e){let t=this.#e.length;return{from:t,previousLength:t,length:t,truncated:!1,replaced:!1,status:this.status,version:this.#t,rejected:e}}#a(e,t,n,r,i){i&&this.#t++;let a={from:e,previousLength:t,length:this.#e.length,truncated:n,replaced:r,status:this.status,version:this.#t,rejected:null};if(i)for(let e of[...this.#r])e(a);return a}};const n=[`nextTick`,`microtask`,`timers`,`immediate`,`pool`,`io`,`close`],r=e=>Object.assign(Object.create(null),e),i=r({nextTick:0,microtask:1,timers:2,immediate:3,pool:4,io:5,close:6}),a=[null,`timers`,`pending`,`idle`,`prepare`,`poll`,`check`,`closing`],o=r({timers:1,pending:2,idle:3,prepare:4,poll:5,check:6,closing:7});function s(e){let t=typeof e==`string`?i[e]:void 0;return t===void 0?-1:t}function c(e){let t=typeof e==`string`?o[e]:void 0;return t===void 0?0:t}const l=/* @__PURE__ */ new Set([`loop.sample`,`signal`,`scope`,`pool.thread`,`promise.settled`,`item.new`,`item.gone`,`timer.set`,`pool.link`,`clock.frozen`,`clock.unfrozen`]),u=1024,d=e=>typeof e==`number`&&Number.isFinite(e),f=e=>typeof e==`number`&&Number.isInteger(e)&&e>=0,p=e=>typeof e==`string`,m=e=>typeof e==`object`&&!!e,h=e=>m(e)&&p(e.url)&&d(e.line)&&(e.col===void 0||d(e.col)),g=e=>e===void 0||h(e);function _(e){if(!m(e))return 2;let t=e;if(!p(t.k)||!d(t.t))return 2;let n=t.c;if(n!==`observed`&&n!==`inferred`&&n!==`model`||t.rule!==void 0&&!p(t.rule)||t.at!==void 0&&!p(t.at)||t.tid!==void 0&&!d(t.tid))return 2;switch(t.k){case`run.start`:return m(t.node)&&m(t.caps)&&p(t.mode)&&p(t.program)&&d(t.poolSize)?0:2;case`run.end`:return(t.code===null||t.code===void 0||d(t.code))&&(t.signal===null||t.signal===void 0||p(t.signal))?0:2;case`output`:return(t.stream===`stdout`||t.stream===`stderr`)&&p(t.text)&&g(t.loc)?0:2;case`item.new`:return f(t.id)&&p(t.type)&&f(t.trigger)&&(t.label===void 0||p(t.label))&&g(t.loc)?0:2;case`callback.start`:return f(t.id)&&p(t.type)?0:2;case`callback.end`:case`item.gone`:case`promise.settled`:return f(t.id)?0:2;case`timer.set`:return f(t.id)&&d(t.delayMs)&&typeof t.repeat==`boolean`?0:2;case`loop.sample`:return d(t.loopCount)&&d(t.events)&&d(t.eventsWaiting)?0:2;case`scope`:return p(t.name)&&d(t.durUs)?0:2;case`pool.thread`:return(t.edge===`start`||t.edge===`end`)&&p(t.name)?0:2;case`signal`:return p(t.cat)&&p(t.name)&&p(t.ph)?0:2;case`queue.add`:case`queue.remove`:return s(t.queue)>=0&&f(t.id)?0:2;case`loop.turn`:return d(t.n)?0:2;case`phase.enter`:case`phase.leave`:return c(t.phase)>0&&(t.turn===void 0||d(t.turn))&&(t.afterPoll===void 0||typeof t.afterPoll==`boolean`)&&(t.pollTimeoutMs===void 0||d(t.pollTimeoutMs))?0:2;case`timer.fired`:return t.lateMs===void 0||d(t.lateMs)?0:2;case`pool.queued`:return p(t.job)&&p(t.kind)&&(t.op===void 0||p(t.op))&&(t.id===void 0||f(t.id))?0:2;case`pool.delivered`:case`pool.cancelled`:return p(t.job)?0:2;case`pool.started`:case`pool.finished`:case`pool.posted`:return p(t.job)&&f(t.thread)&&t.thread>=1&&t.thread<=u?0:2;case`pool.link`:return p(t.job)&&f(t.id)?0:2;case`pool.size`:return f(t.size)&&t.size>=1&&t.size<=u?0:2;case`debug.paused`:return p(t.reason)&&Array.isArray(t.frames)&&typeof t.timeKeptRunning==`boolean`?0:2;case`debug.resumed`:return d(t.pausedMs)?0:2;case`gate.stopped`:return p(t.gate)&&(t.job===void 0||p(t.job))&&(t.phase===void 0||c(t.phase)>0)?0:2;case`gate.released`:return d(t.stoppedMs)?0:2;case`clock.frozen`:return t.why===void 0||p(t.why)?0:2;case`clock.unfrozen`:return d(t.hiddenMs)?0:2;case`note`:return(t.level===`info`||t.level===`warn`)&&p(t.text)?0:2;default:return 1}}function v(e,t){let n=e.length;if(n<=16){for(;n>0&&e[n-1]>=t;)n--;return n}let r=0;for(;r<n;){let i=r+n>>>1;e[i]<t?r=i+1:n=i}return r}function y(e,t){let n=v(e,t);return n===0?-1:e[n-1]}function b(e,t){return{c:e.c,rule:e.rule===void 0?null:e.rule,index:t,t:e.t}}const x={observed:0,inferred:1,model:2};function S(e,t){return x[e]>=x[t]?e:t}var C=class{n=0;flags=/* @__PURE__ */ new Uint8Array(1024);blockFlags=/* @__PURE__ */ new Uint8Array(4);tMono=/* @__PURE__ */ new Float64Array(1024);tlState=/* @__PURE__ */ new Uint8Array(1024);tlClass=/* @__PURE__ */ new Uint8Array(1024);items=/* @__PURE__ */ new Map;order=[];output=[];outputChars=[];notes=[];turns=[];turnNumbers=[];pauses=[];#e=null;#t=null;#n=[];#r=[];#i(){let e=this.flags.length*2,t=t=>{let n=new Uint8Array(e);return n.set(t),n};this.flags=t(this.flags);let n=new Uint8Array(e>>8);n.set(this.blockFlags),this.blockFlags=n,this.tlState=t(this.tlState),this.tlClass=t(this.tlClass);let r=new Float64Array(e);r.set(this.tMono),this.tMono=r}#a(e,t){this.#n.push(t),this.#r.push(e.id)}#o(e,t,n){let r=this.items.get(e);return r===void 0?(r={id:e,ref:{id:e,type:n,label:null,trigger:0,loc:null,created:null},early:null,newIndex:-1,firstIndex:t,starts:[],ends:[],goneIndex:-1,settledIndex:-1,children:[],jobNames:[],jobIndexes:[],timer:null},this.items.set(e,r),this.order.push(r),this.#a(r,t)):n!==`?`&&r.newIndex<0&&r.ref.type===`?`&&(r.ref={...r.ref,type:n}),r}add(e,t){t>=this.flags.length&&this.#i();let n=t===0?0:this.tMono[t-1];this.tlState[t]=0,this.tlClass[t]=0;let r=_(e);if(r!==0){let i=r===1?192:64;this.flags[t]=i,t&255?this.blockFlags[t>>8]=this.blockFlags[t>>8]|i:this.blockFlags[t>>8]=i;let a=r===1?e.t:n;return this.tMono[t]=t===0||a>n?a:n,this.n=t+1,i}this.tMono[t]=t===0||e.t>n?e.t:n;let i=+!l.has(e.k);switch(e.k){case`item.new`:{let n={id:e.id,type:e.type,label:e.label===void 0?null:e.label,trigger:e.trigger,loc:e.loc===void 0?null:e.loc,created:b(e,t)},r=this.items.get(e.id);if(r===void 0){let r=this.#o(e.id,t,e.type);r.ref=n,r.newIndex=t;let i=this.items.get(e.trigger);i!==void 0&&i!==r&&(i.children.push(t),this.#a(i,t))}else if(r.newIndex<0){r.early=r.ref,r.ref=n,r.newIndex=t,this.#a(r,t);let i=this.items.get(e.trigger);i!==void 0&&i!==r&&(i.children.push(t),this.#a(i,t))}break}case`callback.start`:{let n=this.#o(e.id,t,e.type);n.starts.push(t),this.#a(n,t),i|=2;break}case`callback.end`:{let n=this.#o(e.id,t,`?`);n.ends.push(t),this.#a(n,t);break}case`item.gone`:{let n=this.#o(e.id,t,`?`);n.goneIndex<0&&(n.goneIndex=t);let r=n.timer;r!==null&&r.clearedIndex<0&&r.arms[r.arms.length-1]>w(n.starts)&&(r.clearedIndex=t),this.#a(n,t);break}case`promise.settled`:{let n=this.#o(e.id,t,`?`);n.settledIndex<0&&(n.settledIndex=t),this.#a(n,t);break}case`timer.set`:{let n=this.#o(e.id,t,`?`);n.timer===null?n.timer={setIndex:t,delayMs:e.delayMs,repeat:e.repeat,arms:[t],clearedIndex:-1}:n.timer.arms.push(t),this.#a(n,t);break}case`queue.add`:{let n=this.#o(e.id,t,`?`),r=n.timer;e.queue===`timers`&&r!==null&&r.clearedIndex<0&&w(n.starts)>r.arms[r.arms.length-1]&&(r.arms.push(t),this.#a(n,t));break}case`queue.remove`:{let n=this.items.get(e.id),r=n===void 0?null:n.timer;n!==void 0&&r!==null&&e.queue===`timers`&&r.clearedIndex<0&&(r.repeat||r.arms[r.arms.length-1]>w(n.starts))&&(r.clearedIndex=t,this.#a(n,t));break}case`pool.queued`:e.id!==void 0&&this.#s(e.id,e.job,t);break;case`pool.link`:this.#s(e.id,e.job,t);break;case`output`:{let n=this.outputChars.length===0?0:this.outputChars[this.outputChars.length-1],r={seq:this.output.length,index:t,t:e.t,stream:e.stream,text:e.text};e.loc!==void 0&&(r.loc=e.loc),this.output.push(r),this.outputChars.push(n+e.text.length),i|=16;break}case`note`:this.notes.push(t);break;case`loop.turn`:this.turns.push(t),this.turnNumbers.push(e.n),i|=8;break;case`phase.enter`:i|=4;break;case`debug.paused`:{let n={kind:`debug`,index:t,t:e.t,endIndex:null,ms:null,reason:e.reason,timeKeptRunning:e.timeKeptRunning};this.pauses.push(n),this.#e=n,i|=32;break}case`debug.resumed`:this.#e!==null&&(this.#e.endIndex=t,this.#e.ms=e.pausedMs,this.#e=null);break;case`gate.stopped`:{let n={kind:`gate`,index:t,t:e.t,endIndex:null,ms:null,reason:e.gate,timeKeptRunning:!1};this.pauses.push(n),this.#t=n,i|=32;break}case`gate.released`:this.#t!==null&&(this.#t.endIndex=t,this.#t.ms=e.stoppedMs,this.#t=null)}return this.flags[t]=i,t&255?this.blockFlags[t>>8]=this.blockFlags[t>>8]|i:this.blockFlags[t>>8]=i,this.n=t+1,i}nextWith(e,t){let n=this.flags,r=this.blockFlags,i=this.n,a=Math.max(0,t);for(;a<i;){if((r[a>>8]&e)===0){a=(a>>8)+1<<8;continue}let t=Math.min(i,(a>>8)+1<<8);for(;a<t;a++)if((n[a]&e)!==0)return a}return-1}previousWith(e,t){let n=this.flags,r=this.blockFlags,i=Math.min(this.n-1,t);for(;i>=0;){if((r[i>>8]&e)===0){i=(i>>8<<8)-1;continue}let t=i>>8<<8;for(;i>=t;i--)if((n[i]&e)!==0)return i}return-1}#s(e,t,n){let r=this.#o(e,n,`?`);r.jobNames.push(t),r.jobIndexes.push(n),this.#a(r,n)}truncate(e){if(e>=this.n)return;let t=this.#n,n=this.#r;for(;t.length>0&&t[t.length-1]>=e;){t.pop();let r=this.items.get(n.pop());if(r===void 0)continue;if(r.firstIndex>=e){this.items.delete(r.id);continue}r.newIndex>=e&&(r.ref=r.early,r.early=null,r.newIndex=-1),T(r.starts,e),T(r.ends,e),T(r.children,e);let i=v(r.jobIndexes,e);r.jobIndexes.length=i,r.jobNames.length=i,r.goneIndex>=e&&(r.goneIndex=-1),r.settledIndex>=e&&(r.settledIndex=-1);let a=r.timer;a!==null&&(a.setIndex>=e?r.timer=null:(T(a.arms,e),a.clearedIndex>=e&&(a.clearedIndex=-1)))}let r=this.order;for(;r.length>0&&r[r.length-1].firstIndex>=e;)r.pop();for(;this.output.length>0&&this.output[this.output.length-1].index>=e;)this.output.pop(),this.outputChars.pop();T(this.notes,e);let i=v(this.turns,e);this.turns.length=i,this.turnNumbers.length=i;let a=this.pauses;for(;a.length>0&&a[a.length-1].index>=e;)a.pop();if(this.#e=this.#c(`debug`,e),this.#t=this.#c(`gate`,e),e&255){let t=0;for(let n=e&-256;n<e;n++)t|=this.flags[n];this.blockFlags[e>>8]=t}this.n=e}#c(e,t){for(let n=this.pauses.length-1;n>=0;n--){let r=this.pauses[n];if(r.kind===e)return r.endIndex!==null&&r.endIndex>=t&&(r.endIndex=null,r.ms=null),r.endIndex===null?r:null}return null}itemsBefore(e){let t=this.order,n=0,r=t.length;for(;n<r;){let i=n+r>>>1;t[i].firstIndex<e?n=i+1:r=i}return n}refAt(e,t){return e.newIndex>=0&&e.newIndex>=t&&e.early!==null?e.early:e.ref}timerStateAt(e,t,n){let r=e.timer;return r===null||r.setIndex>=t?0:r.clearedIndex>=0&&r.clearedIndex<t?4:n?2:y(r.arms,t)>y(e.starts,t)?1:3}};function w(e){return e.length===0?-1:e[e.length-1]}function T(e,t){let n=e.length;for(;n>0&&e[n-1]>=t;)n--;e.length=n}var E=class extends Error{line;constructor(e,t){super(t===void 0?e:`line ${t}: ${e}`),this.name=`RecordingError`,this.line=t}};const D={text:1e6,name:512,frames:200,args:32,sources:64};function O(e,t){throw new E(`${e}: ${t}`)}const k=e=>(t,n)=>(typeof t!=`string`&&O(n,`must be a string`),t.length>e&&O(n,`string longer than ${e}`),t),A=k(D.name),ee=k(D.text),te=(e,t)=>(typeof e==`number`&&Number.isFinite(e)||O(t,`must be a finite number`),e),j=(e,t)=>(te(e,t),e<0&&O(t,`must not be negative`),e),ne=(e,t)=>(typeof e==`number`&&Number.isSafeInteger(e)||O(t,`must be an integer`),e),re=(e,t)=>((typeof e!=`number`||!Number.isInteger(e)||e<1||e>1024)&&O(t,`must be a whole number from 1 to 1024`),e),M=(e,t)=>(ne(e,t),e<0&&O(t,`must not be negative`),e),N=(e,t)=>(typeof e!=`boolean`&&O(t,`must be true or false`),e),P=(...e)=>(t,n)=>(typeof t==`string`&&e.includes(t)||O(n,`must be one of ${e.join(`, `)}`),t),ie=e=>(t,n)=>t===null?null:e(t,n),F=e=>({check:e}),I=e=>({check:e,optional:!0});function ae(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function L(e,t,n,r){ae(t)||O(n,`must be an object`);let i={};for(let i of Object.keys(t))!Object.hasOwn(e,i)&&!(r&&r.has(i))&&O(n,`unknown field "${i}"`);for(let r of Object.keys(e)){let a=e[r],o=Object.hasOwn(t,r)?t[r]:void 0;o===void 0?a.optional||O(n,`missing field "${r}"`):i[r]=a.check(o,n===``?r:`${n}.${r}`)}return i}const R=e=>(t,n)=>L(e,t,n),oe={url:F(A),line:F(M),col:I(M)},se={fn:F(A),loc:F(R(oe)),origin:F(P(`user`,`node`,`other`)),at:I(A)},ce={version:F(A),v8:F(A),uv:F(A),platform:F(A),arch:F(A)},le=P(`observed`,`inferred`,`model`),ue={provider:F(P(`user`,`pinned`,`probe`)),jsDebugger:F(N),asyncItems:F(N),poolThreads:F(P(`delayed`,`live`,`none`)),phasesTimersCheck:F(P(`observed`,`inferred`,`model`,`none`)),phasesOther:F(P(`observed`,`inferred`,`model`,`none`)),gates:F(R({phase:F(N),timer:F(N),poolStart:F(N),poolPost:F(N)})),frozenClock:F(N)},de=P(`timers`,`pending`,`idle`,`prepare`,`poll`,`check`,`closing`),fe=P(`nextTick`,`microtask`,`timers`,`immediate`,`pool`,`io`,`close`),pe=(e,t)=>(Array.isArray(e)||O(t,`must be a list`),e.length>D.frames&&O(t,`more than ${D.frames} frames`),e.map((e,n)=>L(se,e,`${t}[${n}]`))),me=(e,t)=>{ae(e)||O(t,`must be an object`);let n=Object.keys(e);n.length>D.args&&O(t,`more than ${D.args} keys`);let r=Object.create(null);for(let i of n){i.length>D.name&&O(t,`key too long`);let n=e[i];n===null||typeof n==`boolean`||typeof n==`number`&&Number.isFinite(n)||typeof n==`string`&&n.length<=D.text?r[i]=n:O(`${t}.${i}`,`must be a string, a finite number, true, false or null`)}return Object.assign({},r)},he={k:F(A),t:F(te),tq:I(P(`approx`,`tie`)),src:F(P(`hooks`,`trace`,`cdp`,`probe`,`helper`,`rule`)),c:F(le),rule:I(k(32)),at:I(A),tid:I(M)},ge={"run.start":{node:F(R(ce)),caps:F(R(ue)),mode:F(P(`free`,`debug`)),program:F(A),poolSize:F(M)},"run.end":{code:F(ie(ne)),signal:F(ie(A))},output:{stream:F(P(`stdout`,`stderr`)),text:F(ee),loc:I(R(oe))},"item.new":{id:F(M),type:F(A),trigger:F(M),label:I(A),loc:I(R(oe))},"callback.start":{id:F(M),type:F(A),close:I(N)},"callback.end":{id:F(M)},"item.gone":{id:F(M)},"promise.settled":{id:F(M)},"timer.set":{id:F(M),delayMs:F(j),repeat:F(N)},"loop.sample":{loopCount:F(M),events:F(M),eventsWaiting:F(M)},scope:{name:F(A),durUs:F(j)},"pool.thread":{edge:F(P(`start`,`end`)),name:F(A)},signal:{cat:F(A),name:F(A),ph:F(k(8)),ref:I(A),args:I(me)},"queue.add":{queue:F(fe),id:F(M)},"queue.remove":{queue:F(fe),id:F(M),why:F(P(`cancel`,`gone`))},"loop.turn":{n:F(M)},"phase.enter":{phase:F(de),turn:I(M),afterPoll:I(N),pollTimeoutMs:I(te)},"phase.leave":{phase:F(de),turn:I(M),afterPoll:I(N)},"timer.fired":{lateMs:I(te)},"pool.queued":{job:F(A),kind:F(P(`fs`,`dns`,`crypto`,`zlib`,`user`,`unknown`)),op:I(A),id:I(M)},"pool.started":{job:F(A),thread:F(M)},"pool.finished":{job:F(A),thread:F(M)},"pool.posted":{job:F(A),thread:F(M)},"pool.delivered":{job:F(A)},"pool.cancelled":{job:F(A)},"pool.link":{job:F(A),id:F(M)},"pool.size":{size:F(re)},"debug.paused":{reason:F(P(`breakpoint`,`step`,`pause`,`exception`,`entry`,`other`)),frames:F(pe),timeKeptRunning:F(N)},"debug.resumed":{pausedMs:F(j)},"gate.stopped":{gate:F(P(`phase`,`turn`,`timer`,`poolStart`,`poolPost`,`poolDone`,`manual`)),phase:I(de),job:I(A)},"gate.released":{stoppedMs:F(j)},"clock.frozen":{why:I(P(`gate`,`breakpoint`))},"clock.unfrozen":{hiddenMs:F(j)},note:{level:F(P(`info`,`warn`)),text:F(k(2e3))}},_e=new Set(Object.keys(ge)),ve=/* @__PURE__ */ new Map;for(let e of Object.keys(ge))ve.set(e,{...he,...ge[e]});function ye(e){return typeof e==`string`&&_e.has(e)}function be(e){if(!ae(e))throw new E(`an event must be an object`);let t=e.k;if(!ye(t))throw new E(`unknown event kind ${typeof t==`string`?JSON.stringify(t.slice(0,60)):typeof t}`);let n=L(ve.get(t),e,t);if(n.c!==`observed`&&typeof n.rule!=`string`)throw new E(`${t}: an ${String(n.c)} event must name its rule`);return n}const xe={format:F(P(`nodejs-map-recording`)),version:F(M),created:F(k(64)),tool:F(k(64)),node:F(R(ce)),atlas:F(R({tag:F(k(64)),commit:F(k(64))})),title:I(A),description:I(k(4e3)),sources:I((e,t)=>(Array.isArray(e)||O(t,`must be a list`),e.length>D.sources&&O(t,`more than ${D.sources} sources`),e.map((e,n)=>L({name:F(A),text:F(ee)},e,`${t}[${n}]`))))};function Se(e){let t=L(xe,e,`header`);if(t.version>1)throw new E(`this recording is format version ${t.version}; this reader understands up to 1`);if(t.version<1)throw new E(`header.version: must be 1 or more`);if(Number.isNaN(Date.parse(t.created)))throw new E(`header.created: not a date`);return t}const Ce=4e6,we=/^[A-Za-z][A-Za-z0-9]{0,31}:[ifbnsj]$/,Te=/* @__PURE__ */ new Set([`k`,`t`,`src`,`c`,`constructor`,`prototype`]);function Ee(e){switch(typeof e){case`number`:return Number.isSafeInteger(e)?`i`:`f`;case`string`:return`s`;case`boolean`:return`b`;default:return e===null?`n`:`j`}}var De=class{#e=/* @__PURE__ */ new Map;#t=/* @__PURE__ */ new Map;#n=0;header(e){return JSON.stringify(Se(e))+`
2
+ `}events(e){let t=[];for(let n of e)this.#i(n,t);return t.join(``)}#r(e,t){let n=this.#t.get(e);return n===void 0&&(n=this.#t.size,this.#t.set(e,n),t.push(`["s",`+JSON.stringify(e)+`]
3
+ `)),n}#i(e,t){let n=`${String(e.k)}|${String(e.src)}|${String(e.c)}`,r=[],i=[];for(let t of Object.keys(e)){if(t===`k`||t===`t`||t===`src`||t===`c`)continue;let a=e[t];if(a===void 0)continue;let o=Ee(a);r.push(t),i.push(o),n+=`|${t}:${o}`}let a=this.#e.get(n);a===void 0&&(a={index:this.#e.size,names:r,types:i},this.#e.set(n,a),t.push(JSON.stringify([`d`,e.k,e.src,e.c,r.map((e,t)=>`${e}:${i[t]}`)])+`
4
+ `));let o=e.t;if(typeof o!=`number`||!Number.isFinite(o))throw new E(`${String(e.k)}: t must be a finite number`);let s=Math.round(o*1e3),c=`[${a.index},${s-this.#n}`;this.#n=s;for(let n=0;n<r.length;n++){let a=e[r[n]];switch(i[n]){case`i`:case`f`:c+=`,`+String(a);break;case`b`:c+=a?`,1`:`,0`;break;case`n`:c+=`,0`;break;case`s`:c+=`,`+this.#r(a,t);break;default:c+=`,`+this.#r(JSON.stringify(a),t)}}t.push(c+`]
5
+ `)}};function Oe(e){let t=new De;return t.header({...e.header,version:1})+t.events(e.events)}var ke=class{#e=``;#t=0;#n;#r=[];#i=[];#a=0;#o=0;get header(){return this.#n}get count(){return this.#o}push(e){let t=[],n=this.#e+e,r=0;for(;;){let e=n.indexOf(`
6
+ `,r);if(e<0)break;this.#s(n.slice(r,e),t),r=e+1}if(n=n.slice(r),n.length>Ce)throw new E(`line too long`,this.#t+1);return this.#e=n,t}finish(){let e=[],t=this.#e;if(this.#e=``,t.trim()!==``&&this.#s(t,e),this.#n===void 0)throw new E(`empty recording: no header line`);return e}#s(e,t){this.#t++;let n=e.endsWith(`\r`)?e.slice(0,-1):e;if(n.length>Ce)throw new E(`line too long`,this.#t);if(n===``){if(this.#n===void 0)throw new E(`the first line must be the header`,this.#t);return}let r;try{r=JSON.parse(n)}catch{throw new E(`not valid JSON`,this.#t)}try{if(this.#n===void 0){this.#n=Se(r);return}if(!Array.isArray(r)||r.length<2)throw new E(`expected a definition or an event row`);let e=r[0];if(e===`s`)this.#c(r);else if(e===`d`)this.#l(r);else if(typeof e==`number`)t.push(this.#d(r)),this.#o++;else throw new E(`unknown line type`)}catch(e){throw e instanceof E&&e.line===void 0?new E(e.message,this.#t):e}}#c(e){if(e.length!==2||typeof e[1]!=`string`)throw new E(`bad string definition`);if(this.#i.length>=4e6)throw new E(`too many strings`);this.#i.push(e[1])}#l(e){let[,t,n,r,i]=e;if(e.length!==5||typeof t!=`string`||typeof n!=`string`||typeof r!=`string`||!Array.isArray(i))throw new E(`bad shape definition`);if(this.#r.length>=8192)throw new E(`too many shapes`);if(i.length>32)throw new E(`too many fields in a shape`);let a=[],o=[];for(let e of i){if(typeof e!=`string`||!we.test(e))throw new E(`bad field in a shape`);let t=e.lastIndexOf(`:`),n=e.slice(0,t);if(Te.has(n)||a.includes(n))throw new E(`field "${n}" not allowed in a shape`);a.push(n),o.push(e.slice(t+1))}this.#r.push({k:t,src:n,c:r,names:a,types:o})}#u(e){if(typeof e!=`number`||!Number.isInteger(e)||e<0||e>=this.#i.length)throw new E(`string number out of range`);return this.#i[e]}#d(e){let t=e[0],n=Number.isInteger(t)&&t>=0?this.#r[t]:void 0;if(n===void 0)throw new E(`shape number out of range`);let r=e[1];if(typeof r!=`number`||!Number.isSafeInteger(r))throw new E(`bad time delta`);if(e.length!==n.names.length+2)throw new E(`wrong number of values for the shape`);if(this.#a+=r,!Number.isSafeInteger(this.#a))throw new E(`time out of range`);let i={k:n.k,t:this.#a/1e3,src:n.src,c:n.c};for(let t=0;t<n.names.length;t++){let r=e[t+2],a;switch(n.types[t]){case`i`:case`f`:if(typeof r!=`number`)throw new E(`expected a number`);a=r;break;case`b`:if(r!==0&&r!==1)throw new E(`expected 0 or 1`);a=r===1;break;case`n`:a=null;break;case`s`:a=this.#u(r);break;default:try{a=JSON.parse(this.#u(r))}catch(e){throw e instanceof E?e:new E(`bad JSON value`)}}i[n.names[t]]=a}return be(i)}};function Ae(e){let t=new ke,n=t.push(e);for(let e of t.finish())n.push(e);return{header:t.header,events:n}}const z={callbackScopeCtor:`o:cb.InternalMakeCallback`,callbackScopeClose:`s:src/api/callback.cc#node::InternalCallbackScope::Close`,runTimers:`s:src/env.cc#node::Environment::RunTimers`,scheduleTimer:`s:src/env.cc#node::Environment::ScheduleTimer`,checkImmediate:`s:src/env.cc#node::Environment::CheckImmediate`,toggleImmediateRef:`s:src/env.cc#node::Environment::ToggleImmediateRef`,uvRunTimers:`s:deps/uv/src/timer.c#uv__run_timers`,processTimers:`s:lib/internal/timers.js#getTimerCallbacks/processTimers`,listOnTimeout:`o:timers.listOnTimeout`,processImmediate:`s:lib/internal/timers.js#getTimerCallbacks/processImmediate`,timeoutCtor:`s:lib/internal/timers.js#Timeout.prototype.constructor`,immediateCtor:`s:lib/internal/timers.js#Immediate.prototype.constructor`,timerInsert:`s:lib/internal/timers.js#insert`,nextTick:`s:lib/internal/process/task_queues.js#nextTick`,processTicks:`s:lib/internal/process/task_queues.js#processTicksAndRejections`,queueMicrotask:`s:lib/internal/process/task_queues.js#queueMicrotask`,runMicrotask:`s:lib/internal/process/task_queues.js#runMicrotask`,promiseInitHook:`s:lib/internal/async_hooks.js#promiseInitHook`,promiseBeforeHook:`s:lib/internal/async_hooks.js#promiseBeforeHook`,uvRunUnix:`s:deps/uv/src/unix/core.c#uv_run`,uvRunWin:`s:deps/uv/src/win/core.c#uv_run`,uvPollWin:`s:deps/uv/src/win/core.c#uv__poll`,uvProcessReqs:`s:deps/uv/src/win/core.c#uv__process_reqs`,uvIoPollLinux:`s:deps/uv/src/unix/linux.c#uv__io_poll`,uvAsyncIo:`s:deps/uv/src/unix/async.c#uv__async_io`,uvAsyncWakeupWin:`s:deps/uv/src/win/async.c#uv__process_async_wakeup_req`,worker:`s:deps/uv/src/threadpool.c#worker`,post:`s:deps/uv/src/threadpool.c#post`,workSubmit:`s:deps/uv/src/threadpool.c#uv__work_submit`,workDone:`s:deps/uv/src/threadpool.c#uv__work_done`,initThreads:`s:deps/uv/src/threadpool.c#init_threads`,scheduleWork:`s:src/threadpoolwork-inl.h#node::ThreadPoolWork::ScheduleWork`,fsWorkUnix:`s:deps/uv/src/unix/fs.c#uv__fs_work`,fsWorkWin:`s:deps/uv/src/win/fs.c#uv__fs_work`,getaddrinfoUnix:`s:deps/uv/src/unix/getaddrinfo.c#uv_getaddrinfo`,getaddrinfoWin:`s:deps/uv/src/win/getaddrinfo.c#uv_getaddrinfo`,uvMetricsInfo:`s:src/node_perf.cc#node::performance::UvMetricsInfo`,queryResponse:`s:src/cares_wrap.h#node::cares_wrap::QueryWrap::QueueResponseCallback`,handleOnClose:`s:src/handle_wrap.cc#node::HandleWrap::OnClose`,closingUnix:`s:deps/uv/src/unix/core.c#uv__run_closing_handles`,closingWin:`s:deps/uv/src/win/core.c#uv__process_endgames`,ioFeed:`s:deps/uv/src/unix/core.c#uv__io_feed`,runPending:`s:deps/uv/src/unix/core.c#uv__run_pending`,streamIo:`s:deps/uv/src/unix/stream.c#uv__stream_io`,writeReqFinish:`s:deps/uv/src/unix/stream.c#uv__write_req_finish`,shutdownUnix:`s:deps/uv/src/unix/stream.c#uv_shutdown`},B={phaseTimers:`o:phase.timers`,phasePending:`o:phase.pending`,phasePoll:`o:phase.poll`,phaseCheck:`o:phase.check`,tickDrain:`o:tick.drain`,microtaskDrain:`o:microtask.run`,promiseReactionEnqueue:`o:v8.enqueueMicrotask`,promiseReactionRun:`o:v8.promiseReactionJob`,performPromiseThen:`o:v8.performPromiseThen`,triggerReactions:`o:v8.triggerReactions`,poolSubmit:`o:pool.submit`,poolWorker:`o:pool.worker`,poolDone:`o:pool.done`,makeCallback:`o:cb.InternalMakeCallback`,uvRun:`o:loop.run`,dnsQueryResponse:`o:dns.queryResponse`,nativeImmediatesRun:`o:immediate.native`,shutdownQueue:`o:uv.shutdown`,shutdownRun:`o:uv.shutdownDone`,closeCallbacks:`o:loop.finishClose`,handleOnClose:`o:cb.handleOnClose`},je=[{id:`C0`,title:`A callback started or ended`,statement:`Node calls the async_hooks "before" hook just before it runs the JavaScript callback of an async item and "after" when the callback has returned. We report these two moments as they are.`,yields:`observed`,platform:`all`,cites:[z.callbackScopeCtor,z.callbackScopeClose,z.listOnTimeout,z.processImmediate,z.processTicks]},{id:`T0`,title:`The timers phase ran timer callbacks`,statement:`Node reports a timed scope named RunTimers each time libuv's timers step calls Node's one timer. From its start to its end the loop is in the timers phase and is running due setTimeout and setInterval callbacks.`,yields:`observed`,platform:`all`,cites:[z.runTimers,z.uvRunTimers,z.scheduleTimer,B.phaseTimers]},{id:`T1`,title:`A timer callback implies the timers phase`,statement:`A callback of an item of type Timeout started and no RunTimers scope has been reported for that moment (trace events arrive later than hooks). Timeout callbacks are only ever run by processTimers, which libuv calls in its timers step, so the loop is in the timers phase.`,yields:`inferred`,platform:`all`,cites:[z.processTimers,z.listOnTimeout,z.runTimers,B.phaseTimers]},{id:`T2`,title:`A timer callback inside a reported timers scope`,statement:`A Timeout callback started between the start and the end of a RunTimers scope that Node reported. Both facts are observed, so this callback ran in the timers phase.`,yields:`observed`,platform:`all`,cites:[z.runTimers,z.listOnTimeout]},{id:`I0`,title:`The check phase ran`,statement:`Node reports a timed scope named CheckImmediate from the callback of a libuv check handle that is always active. It runs once in every loop turn, in the check phase, whether or not the program used setImmediate.`,yields:`observed`,platform:`all`,cites:[z.checkImmediate,B.phaseCheck]},{id:`I1`,title:`An immediate callback implies the check phase`,statement:`A callback of an item of type Immediate started and no CheckImmediate scope has been reported for that moment. Immediate callbacks are only run by processImmediate, which Node calls from the check phase.`,yields:`inferred`,platform:`all`,cites:[z.processImmediate,z.checkImmediate,B.phaseCheck]},{id:`I2`,title:`An immediate callback inside a reported check scope`,statement:`An Immediate callback started between the start and the end of a CheckImmediate scope that Node reported.`,yields:`observed`,platform:`all`,cites:[z.checkImmediate,z.processImmediate]},{id:`P1u`,title:`A thread pool result is delivered inside the poll step (Linux, macOS)`,statement:`A callback of a thread-pool-backed item (file system, dns.lookup, crypto, zlib) started outside the timers and check phases. On Unix a finished job wakes the loop through an async handle, and libuv runs the callback from uv__io_poll, so the loop is in the poll phase.`,yields:`inferred`,platform:`unix`,cites:[z.uvRunUnix,z.uvIoPollLinux,z.uvAsyncIo,z.workDone,B.phasePoll]},{id:`P1w`,title:`A thread pool result is delivered after the poll step (Windows)`,statement:`A callback of a thread-pool-backed item started outside the timers and check phases. On Windows uv__poll only collects finished requests; their callbacks run in uv__process_reqs, which uv_run calls right after the poll and again at the top of the next turn. We show this as the pending step.`,yields:`inferred`,platform:`win32`,cites:[z.uvRunWin,z.uvPollWin,z.uvProcessReqs,z.uvAsyncWakeupWin,z.workDone,B.phasePending]},{id:`P2`,title:`A handle callback that is not its close callback is delivered by the poll step`,statement:`A callback of a handle (TCP socket or server, pipe, terminal, UDP socket, child process, signal, file watcher) started outside the timers and check phases, and the helper saw that it is not the handle's close callback (rule CL1). Data, connections and other events of a handle are read in the poll step: on Unix libuv calls back from there; on Windows uv__poll only collects them and the callbacks run in uv__process_reqs right after, which we show as the pending step after the poll. On Windows the same holds for write, shutdown, connect and send requests. No phase is inferred, rather than a wrong one, in these cases: write, shutdown, connect and send requests on Unix (libuv finishes them from uv__stream_io in the poll step when data was still waiting to be written, and otherwise queues the stream with uv__io_feed so that the callback runs in a pending pass: a shutdown with no write waiting runs in the pending step, one behind queued writes in the poll step, and the type does not say which); message ports and every other kind of item, whose callbacks can be made from several steps; a handle whose close state the helper could not read.`,yields:`inferred`,platform:`all`,cites:[z.uvRunUnix,z.uvRunWin,z.uvProcessReqs,z.streamIo,z.ioFeed,z.runPending,z.writeReqFinish,z.shutdownUnix,B.shutdownQueue,B.shutdownRun,B.phasePoll,B.phasePending]},{id:`CL1`,title:`A handle's close callback runs in the closing step`,statement:`A callback of a handle started, and the handle object carries the property Node sets when close(callback) is called (handle_onclose). After close() the handle gets no other callback, so this one is the close callback: libuv makes it in the closing step at the end of the turn (uv__run_closing_handles on Unix, uv__process_endgames on Windows), and Node passes it on from HandleWrap::OnClose.`,yields:`inferred`,platform:`all`,cites:[z.handleOnClose,z.closingUnix,z.closingWin,z.uvRunUnix,z.uvRunWin,B.handleOnClose,B.closeCallbacks]},{id:`I3`,title:`A dns.resolve answer is delivered in the check phase`,statement:`A callback of a QUERYWRAP item (dns.resolve and its relatives, answered by c-ares) started outside a reported scope. Node does not call back when the answer arrives on the socket: QueryWrap::QueueResponseCallback defers it with SetImmediate, so it runs with the native immediates in the check phase, on every system.`,yields:`inferred`,platform:`all`,cites:[z.queryResponse,z.checkImmediate,B.dnsQueryResponse,B.nativeImmediatesRun,B.phaseCheck]},{id:`K1`,title:`A nextTick callback ran from the tick queue`,statement:`A callback of an item of type TickObject started. process.nextTick creates exactly one TickObject per call and processTicksAndRejections runs them in order when the current callback scope closes, before the loop continues.`,yields:`inferred`,platform:`all`,cites:[z.nextTick,z.processTicks,z.callbackScopeClose,B.tickDrain]},{id:`M1`,title:`A microtask ran`,statement:`A callback of an item of type PROMISE or Microtask started. Promise reactions and queueMicrotask callbacks are jobs on V8's microtask queue, drained after the nextTick queue and whenever a callback scope closes.`,yields:`inferred`,platform:`all`,cites:[z.promiseBeforeHook,z.runMicrotask,z.processTicks,z.callbackScopeClose,B.microtaskDrain,B.promiseReactionRun]},{id:`L1`,title:`Loop counters`,statement:`performance.nodeTiming.uvMetricsInfo returns libuv's own counters. loopCount is increased once per turn, just before the poll step. We read it when a top-level callback starts, so the value is exact but the moment a turn began is not known from it.`,yields:`observed`,platform:`all`,cites:[z.uvMetricsInfo,z.uvRunUnix,z.uvRunWin]},{id:`L2`,title:`Loop turns from the check phase`,statement:`CheckImmediate is reported once per loop turn (rule I0). The timers step that follows it belongs to the same turn. The first callback or scope after that starts the next turn; we place the turn boundary there.`,yields:`inferred`,platform:`all`,cites:[z.checkImmediate,z.uvRunUnix,z.uvRunWin,B.uvRun]},{id:`L3`,title:`Loop turns from the loop counter`,statement:`The loop counter read when a callback starts (rule L1) is higher than at the previous callback, so at least one new turn began in between. Until trace events arrive we place the turn boundary at this callback. Turns in which no callback of ours ran are skipped.`,yields:`inferred`,platform:`all`,cites:[z.uvMetricsInfo,z.uvRunUnix,z.uvRunWin,B.uvRun]},{id:`W0`,title:`A job was submitted to, or came back from, the thread pool`,statement:`Node's ThreadPoolWork reports a trace event with the job's address when it submits work to libuv and another when the result is delivered on the main thread.`,yields:`observed`,platform:`all`,cites:[z.scheduleWork,z.workSubmit,z.workDone,B.poolSubmit,B.poolDone]},{id:`W1`,title:`Which async item a pool job belongs to`,statement:`The trace event for a submitted job follows the creation of an async item of a thread-pool-backed type on the main thread, in the same synchronous call. We take that item as the owner of the job. The trace event itself carries no async id.`,yields:`inferred`,platform:`all`,cites:[z.scheduleWork,z.workSubmit]},{id:`W2`,title:`A pool thread started a job`,statement:`Node's ThreadPoolWork reports a trace event from the pool thread when the work function begins. The event carries the real thread id and the kind of job, but not which job.`,yields:`observed`,platform:`all`,cites:[z.scheduleWork,z.worker,B.poolWorker]},{id:`W2b`,title:`Which job a pool thread started`,statement:`libuv keeps one first-in first-out work queue for all pool threads. The n-th "started" report for a kind of job is therefore the n-th submitted job of that kind. Two threads that take jobs within the same microsecond can report in swapped order.`,yields:`inferred`,platform:`all`,cites:[z.worker,z.post,z.workSubmit]},{id:`W3`,title:`A pool thread finished a job`,statement:`The pool thread reports a trace event when the work function returns. The thread and the time are observed; the job is the one that thread started (rule W2b).`,yields:`inferred`,platform:`all`,cites:[z.scheduleWork,z.worker]},{id:`W4`,title:`The result of a pool job was delivered`,statement:`The pool thread appends the finished job to the loop's done queue and wakes the loop; uv__work_done runs the after-work callbacks on the main thread in that order. The "result delivered" trace event with the job's address marks this, and the callback of the owning item follows.`,yields:`inferred`,platform:`all`,cites:[z.worker,z.workDone,B.poolDone]},{id:`W5`,title:`A job is waiting for a free pool thread`,statement:`A job was submitted while as many jobs as the pool has threads were running. It waits in the queue. This count is incomplete: file system requests and dns.lookup hold pool threads without reporting from them, and dns.lookup may use at most half of the threads.`,yields:`inferred`,platform:`all`,cites:[z.worker,z.post,z.initThreads]},{id:`W6`,title:`File system requests and dns.lookup use the pool without thread reports`,statement:`Classic file system requests and dns.lookup are handed to the pool by libuv itself, not through ThreadPoolWork. Node reports their start and end on the main thread only. We show them as queued pool work; which thread ran them, and when, is not available on an official build.`,yields:`inferred`,platform:`all`,cites:[z.fsWorkUnix,z.fsWorkWin,z.getaddrinfoUnix,z.getaddrinfoWin,z.workSubmit]},{id:`X1`,title:`The first use of the thread pool blocks the main thread`,statement:`The pool threads are created on the first submission, and the submitting thread waits until all of them have started. A gap on the main thread right after the first submission is this wait.`,yields:`inferred`,platform:`all`,cites:[z.workSubmit,z.initThreads]},{id:`W7`,title:`The pool size is read when the pool is first used`,statement:`libuv creates the pool threads at the first submission and reads UV_THREADPOOL_SIZE only then (no value: 4 threads; 0 or text that is not a number: 1; at most 1024). A program can therefore still set the variable before its first pool request. The helper reads the variable when the first thread-pool-backed async item is created and reports the size when it differs from the one the run started with. A use of the pool that creates no such item (a native add-on, a worker thread) is not seen.`,yields:`inferred`,platform:`all`,cites:[z.initThreads,z.workSubmit]},{id:`G1`,title:`Thread reports are missing for a pool job`,statement:`Every ThreadPoolWork job reports one start and one end from its pool thread. When a job was submitted and delivered but one of the two reports is absent, it was dropped while trace events were being read from the target. The job ran; its thread or times are not known.`,yields:`inferred`,platform:`all`,cites:[z.scheduleWork]},{id:`QT`,title:`A new Timeout waits in the timer lists`,statement:`An async item of type Timeout was created. setTimeout and setInterval construct a Timeout and insert it into the timer lists in the same call, so the item is waiting in the timers queue.`,yields:`inferred`,platform:`all`,cites:[z.timeoutCtor,z.timerInsert]},{id:`QT2`,title:`A repeating timer waits again after it ran`,statement:`The callback of a Timeout created by setInterval returned and the timer was not cleared. listOnTimeout inserts a repeating timer again after each run.`,yields:`inferred`,platform:`all`,cites:[z.listOnTimeout,z.timerInsert]},{id:`QI`,title:`A new Immediate waits in the immediate queue`,statement:`An async item of type Immediate was created. The Immediate constructor appends itself to the immediate queue.`,yields:`inferred`,platform:`all`,cites:[z.immediateCtor,z.processImmediate,z.toggleImmediateRef]},{id:`QK`,title:`A new TickObject waits in the nextTick queue`,statement:`An async item of type TickObject was created. process.nextTick pushes exactly one TickObject onto the tick queue per call.`,yields:`inferred`,platform:`all`,cites:[z.nextTick]},{id:`QM`,title:`A queueMicrotask callback waits in the microtask queue`,statement:`An async item of type Microtask was created. queueMicrotask creates it and enqueues the callback on V8's microtask queue in the same call.`,yields:`inferred`,platform:`all`,cites:[z.queueMicrotask,B.promiseReactionEnqueue]},{id:`QP`,title:`A promise reaction is queued when its promise settles`,statement:`then, catch, finally and await register a reaction on a promise and create a second promise for it (async_hooks reports that one with the first as its trigger). V8 puts the reaction job on the microtask queue when the first promise settles, or at once when it has already settled. The helper sees settling through the promiseResolve hook, which fires on fulfil and reject and not when a promise is merely resolved with another promise. So the reaction is shown in the microtask queue from the later of the two moments, creation and settling, until its callback starts. A promise that is only created while another promise's callback runs is not a reaction (its trigger is the running callback); neither is a promise that settles or runs before its trigger has settled (the wrapper an await makes around a plain value). Reactions of a promise whose settling was not seen are not shown as queued; they simply run.`,yields:`inferred`,platform:`all`,cites:[z.promiseInitHook,B.performPromiseThen,B.triggerReactions,B.promiseReactionEnqueue]},{id:`QP2`,title:`A reaction that was shown as queued did not run in its turn`,statement:`The microtask queue is first-in first-out and is emptied completely before the next timer, immediate or I/O callback. When a reaction that rule QP put in the queue is overtaken by a later microtask, or is still listed when such a callback starts, it was not in the queue: rule QP was wrong for this promise. The entry is removed here rather than left standing.`,yields:`inferred`,platform:`all`,cites:[B.promiseReactionEnqueue,B.triggerReactions]},{id:`QW`,title:`A new thread-pool-backed request waits for the pool`,statement:`An async item of a thread-pool-backed type was created (FSREQCALLBACK, FSREQPROMISE, GETADDRINFOREQWRAP, GETNAMEINFOREQWRAP, a crypto *REQUEST, zlib). Node creates the item and submits the work in the same call, so the request is with the thread pool until its callback starts.`,yields:`inferred`,platform:`all`,cites:[z.workSubmit,z.scheduleWork,B.poolSubmit]},{id:`QR`,title:`A new one-shot I/O request waits on the operating system`,statement:`An async item of a one-shot request type was created (a connect, write or shutdown request). It waits for the operating system until its callback starts.`,yields:`inferred`,platform:`all`,cites:[B.phasePoll,B.makeCallback]},{id:`QX`,title:`A waiting item went away without running`,statement:`An item that was waiting was reported as destroyed before any callback of it started (for example clearTimeout, clearImmediate or clearInterval). It left its queue.`,yields:`inferred`,platform:`all`,cites:[z.timeoutCtor,z.immediateCtor]}],Me=/* @__PURE__ */ new Set([`C0`,`T2`,`I2`,`L1`,`W2`,`W4`,`W5`,`W6`,`X1`]),Ne=je.filter(e=>!Me.has(e.id));je.filter(e=>Me.has(e.id)),new Map(Ne.map(e=>[e.id,e]));function Pe(e){return Fe.has(e)}const Fe=/* @__PURE__ */ new Set([`FSREQCALLBACK`,`FSREQPROMISE`,`FILEHANDLECLOSEREQ`,`GETADDRINFOREQWRAP`,`GETNAMEINFOREQWRAP`,`ZLIB`,`ARGON2REQUEST`,`CHECKPRIMEREQUEST`,`CIPHERREQUEST`,`DERIVEBITSREQUEST`,`HASHREQUEST`,`KEYEXPORTREQUEST`,`KEYGENREQUEST`,`KEYPAIRGENREQUEST`,`PBKDF2REQUEST`,`RANDOMBYTESREQUEST`,`RANDOMPRIMEREQUEST`,`SCRYPTREQUEST`,`SIGNREQUEST`,`VERIFYREQUEST`]);function Ie(e){return e===`TCPCONNECTWRAP`||e===`PIPECONNECTWRAP`||e===`WRITEWRAP`||e===`SHUTDOWNWRAP`||e===`UDPSENDWRAP`}const Le=/* @__PURE__ */ new Set([`TCPWRAP`,`TCPSERVERWRAP`,`PIPEWRAP`,`PIPESERVERWRAP`,`TTYWRAP`,`UDPWRAP`,`PROCESSWRAP`,`SIGNALWRAP`,`FSEVENTWRAP`,`STATWATCHER`,`MESSAGEPORT`]);function Re(){let e=[];for(let t=0;t<7;t++)e.push({items:[],head:0});return{status:`idle`,startIndex:-1,endIndex:-1,mainScript:!1,mainSrcIndex:-1,idleIndex:-1,stack:[],turn:-1,turnIndex:-1,phase:0,phaseIndex:-1,lastPhase:0,lastPhaseEntered:-1,lastPhaseLeft:-1,pollIndex:-1,scopeIndex:-1,sampleIndex:-1,queues:e,where:/* @__PURE__ */ new Map,timersActive:/* @__PURE__ */ new Set,timersRecent:[],tSet:0,tWaiting:0,tRunning:0,tDone:0,tCleared:0,firedCount:0,firedIndex:-1,poolSizeIndex:-1,threads:[],jobs:/* @__PURE__ */ new Map,poolWaiting:[],poolDone:[],doneUntied:0,tids:/* @__PURE__ */ new Map,pQueued:0,pStarted:0,pFinished:0,pPosted:0,pDelivered:0,pCancelled:0,pDropped:0,poolPosts:!1,outputCount:0,noteCount:0,paused:!1,pausedIndex:-1,lastPausedIndex:-1,lastResumedIndex:-1,pauses:0,gateStopped:!1,gateIndex:-1,gateReleasedIndex:-1,gateStops:0,clockFrozen:!1,clockIndex:-1,clockUnfrozenIndex:-1,hiddenMs:0,focusIndex:-1,unknown:0,malformed:0,inconsistent:0}}function ze(e){let t=[];for(let n of e.queues)t.push({items:n.head===0?n.items.slice():n.items.slice(n.head),head:0});return{...e,stack:e.stack.slice(),queues:t,where:new Map(e.where),timersActive:new Set(e.timersActive),timersRecent:e.timersRecent.slice(),threads:e.threads.slice(),jobs:new Map(e.jobs),poolWaiting:e.poolWaiting.slice(),poolDone:e.poolDone.slice(),tids:new Map(e.tids)}}function Be(e){let t=64+e.stack.length+e.where.size*2+e.timersActive.size+e.timersRecent.length+e.threads.length+e.jobs.size*2+e.poolWaiting.length+e.poolDone.length+e.tids.size*2;for(let n of e.queues)t+=n.items.length-n.head;return t}function Ve(e,t,n){e.queues[t].items.push(n),e.where.set(n.id,(e.where.get(n.id)??0)|1<<t)}function He(e,t){let n=e.items;for(let r=e.head;r<n.length;r++)if(n[r].id===t)return r;return-1}function Ue(e,t,n){let r=e.where.get(n);if(r===void 0||!(r&1<<t))return null;let i=e.queues[t],a=He(i,n),o=r&~(1<<t);if(o===0?e.where.delete(n):e.where.set(n,o),a<0)return null;let s=i.items[a];return a===i.head?(i.head++,i.head===i.items.length?(i.items=[],i.head=0):i.head>=1024&&i.head*2>=i.items.length&&(i.items=i.items.slice(i.head),i.head=0)):i.items.splice(a,1),s}function V(e,t){let n=e.stack;for(let e=n.length-1;e>=0;e--)if(n[e].id===t)return!0;return!1}function We(e,t,n){t===1?e.tWaiting+=n:t===2?e.tRunning+=n:t===3?e.tDone+=n:t===4&&(e.tCleared+=n)}function H(e,t,n,r,i){let a=t.timerStateAt(n,i+1,V(e,n.id));if(a===r)return;r===0&&e.tSet++,We(e,r,-1),We(e,a,1);let o=a===1||a===2;if(o&&r!==1&&r!==2){e.timersActive.add(n.id);let t=e.timersRecent.indexOf(n.id);t>=0&&e.timersRecent.splice(t,1)}else if(!o){e.timersActive.delete(n.id);let t=e.timersRecent.indexOf(n.id);t>=0&&e.timersRecent.splice(t,1),e.timersRecent.push(n.id),e.timersRecent.length>32&&e.timersRecent.shift()}}function Ge(e,t,n,r){let i=[];for(let e of n){let n=t.items.get(e.id);if(n===void 0||n.timer===null)continue;let a=!1;for(let e of i)e[0]===n&&(a=!0);a||i.push([n,t.timerStateAt(n,r,!0)])}return i}function Ke(e,t){let n=e.indexOf(t);return n<0?!1:(e.splice(n,1),!0)}function qe(e,t){for(;e.threads.length<t;)e.threads.push({job:null,tid:-1,jobs:0})}function U(e,t){if(t.state===0){Ke(e.poolWaiting,t.job);return}let n=t.thread>0?e.threads[t.thread-1]:void 0;n!==void 0&&n.job===t.job&&(e.threads[t.thread-1]={job:null,tid:n.tid,jobs:n.jobs}),t.done&&Ye(e,t)}function Je(e,t){e.jobs.set(t.job,t.done?t:{...t,done:!0}),e.poolDone.push(t.job),t.id<0&&e.doneUntied++}function Ye(e,t){Ke(e.poolDone,t.job)&&t.id<0&&e.doneUntied--}function Xe(e,t,n,r,i){qe(e,t);let a=e.threads[t-1];a.job!==null&&a.job!==n&&(e.inconsistent++,e.jobs.delete(a.job)),e.threads[t-1]={job:n,tid:r===void 0?a.tid:r,jobs:a.jobs+ +!!i}}function Ze(e,t,n){let r=t.jobNames;for(let i=0;i<r.length&&t.jobIndexes[i]<n;i++){let n=e.jobs.get(r[i]);if(n!==void 0&&n.id===t.id){if(n.state===0)Ke(e.poolWaiting,n.job);else if(n.done)Ye(e,n);else continue;e.jobs.delete(n.job),e.pDelivered++}}}function Qe(e,t,n,r){if(n.id>=0){let i=t.items.get(n.id),a=n.queuedIndex>=0?n.queuedIndex:n.startedIndex;if(i!==void 0&&(i.goneIndex>=0&&i.goneIndex<=r||y(i.starts,r+1)>a)){e.jobs.delete(n.job),e.pDelivered++;return}}Je(e,n);for(let t=0;e.doneUntied>32&&t<e.poolDone.length;){let n=e.poolDone[t];e.jobs.get(n).id<0?(e.poolDone.splice(t,1),e.jobs.delete(n),e.pDropped++,e.doneUntied--):t++}}function $e(e,t){return e===`TickObject`?{via:2,rule:`K1`}:e===`PROMISE`||e===`Microtask`?{via:3,rule:`M1`}:e===`Timeout`?{via:1,rule:`T1`}:e===`Immediate`?{via:1,rule:`I1`}:Pe(e)?{via:1,rule:t===`win32`?`P1w`:`P1u`}:Ie(e)||Le.has(e)?{via:1,rule:`P2`}:null}function W(e){e.status=e.endIndex>=0?`ended`:e.startIndex<0?`idle`:e.paused?`paused`:e.gateStopped?`gate`:`running`}function G(e,t){e.phase!==0&&(e.lastPhase=e.phase,e.lastPhaseEntered=e.phaseIndex,e.lastPhaseLeft=t,e.phase=0,e.phaseIndex=-1)}function et(e,t){let n=e.stack.length-1;n>=0?e.stack[n]={...e.stack[n],srcIndex:t}:e.mainScript&&(e.mainSrcIndex=t)}function K(e,t){e.mainScript&&(e.mainScript=!1,e.stack.length===0&&(e.idleIndex=t))}function tt(e,t,n,r,i,a){if(r&64)return r&128?e.unknown++:e.malformed++,0;t.at!==void 0&&t.at!==``&&(e.focusIndex=n);let o=0;switch(t.k){case`run.start`:e.startIndex>=0&&e.inconsistent++,e.startIndex=n,e.endIndex=-1,e.mainScript=!0,e.mainSrcIndex=-1,e.poolPosts=t.caps.poolThreads===`live`,e.poolSizeIndex=-1,qe(e,Math.max(0,Math.min(1024,Math.floor(t.poolSize)))),W(e);break;case`run.end`:{e.endIndex=n;let t=Ge(e,i,e.stack,n);e.stack.length>0&&(e.stack=[]);for(let[r,a]of t)H(e,i,r,a,n);e.mainScript=!1,e.idleIndex=n,G(e,n),e.paused&&(e.paused=!1,e.lastPausedIndex=e.pausedIndex,e.lastResumedIndex=-1),e.gateStopped=!1,e.clockFrozen=!1,W(e);break}case`output`:t.loc!==void 0&&et(e,n),e.outputCount++,o=t.stream===`stdout`?9:10;break;case`item.new`:{t.loc!==void 0&&et(e,n);let r=i.items.get(t.id);r!==void 0&&r.newIndex!==n&&e.inconsistent++;break}case`callback.start`:{let r=i.items.get(t.id),s=i.timerStateAt(r,n,V(e,t.id));e.mainScript=!1;let c=e.stack.length,l=t.type,u=0,d=-1,f=null,p=-1,m=e.where.get(t.id);if(m!==void 0)for(let n=0;n<7;n++){if(!(m&1<<n))continue;if(n===5&&Le.has(l)){let r=e.queues[5],i=He(r,t.id);if(i>=0){let e=r.items[i];r.items[i]={id:e.id,index:e.index,runs:e.runs+1},p<0&&(p=n,d=e.index)}continue}let r=Ue(e,n,t.id);r!==null&&p<0&&(p=n,d=r.index)}if(p>=0)u=p===0?2:p===1?3:1;else{let t=e.startIndex>=0?a[e.startIndex]:void 0,n=$e(l,t!==void 0&&t.k===`run.start`?t.node.platform:``);n!==null&&(u=n.via,f=n.rule)}e.stack.push({id:t.id,index:n,via:u,viaIndex:d,viaRule:f,queue:p,phase:c===0?e.phase:0,phaseIndex:c===0?e.phaseIndex:-1,depth:c,srcIndex:-1}),Ze(e,r,n),s!==0&&H(e,i,r,s,n),o=p>=0?p+1:8;break}case`callback.end`:{let r=e.stack,a=r.length-1;for(;a>=0&&r[a].id!==t.id;)a--;if(a<0){e.inconsistent++;break}a!==r.length-1&&e.inconsistent++;let o=Ge(e,i,r.slice(a),n);r.length=a,a===0&&(e.idleIndex=n);for(let[t,r]of o)H(e,i,t,r,n);break}case`item.gone`:{let r=i.items.get(t.id),a=i.timerStateAt(r,n,V(e,t.id)),o=e.where.get(t.id);if(o!==void 0)for(let n=0;n<7;n++)o&1<<n&&Ue(e,n,t.id);Ze(e,r,n),a!==0&&H(e,i,r,a,n);break}case`promise.settled`:break;case`timer.set`:{let r=i.items.get(t.id);r.timer!==null&&r.timer.setIndex!==n&&e.inconsistent++,H(e,i,r,i.timerStateAt(r,n,V(e,t.id)),n);break}case`loop.sample`:e.sampleIndex=n;break;case`scope`:(t.name===`RunTimers`||t.name===`CheckImmediate`)&&K(e,n),e.scopeIndex=n;break;case`pool.thread`:{if(t.tid===void 0)break;let r=e.tids.get(t.tid),i=(r===void 0?0:r.starts)+ +(t.edge===`start`),a=(r===void 0?0:r.ends)+ +(t.edge===`end`);e.tids.set(t.tid,{tid:t.tid,busy:t.edge===`start`,name:t.name,index:n,starts:i,ends:a});break}case`signal`:break;case`queue.add`:{let r=s(t.queue),a=i.items.get(t.id),o=r===2?i.timerStateAt(a,n,V(e,t.id)):0;(e.where.get(t.id)??0)&1<<r||Ve(e,r,{id:t.id,index:n,runs:0}),o!==0&&H(e,i,a,o,n);break}case`queue.remove`:{let r=s(t.queue),a=i.items.get(t.id),o=r===2&&a!==void 0?i.timerStateAt(a,n,V(e,t.id)):0;Ue(e,r,t.id),a!==void 0&&o!==0&&H(e,i,a,o,n);break}case`loop.turn`:K(e,n),G(e,n),e.turn=t.n,e.turnIndex=n;break;case`phase.enter`:K(e,n),G(e,n),e.phase=c(t.phase),e.phaseIndex=n,t.pollTimeoutMs!==void 0&&(e.pollIndex=n),t.turn!==void 0&&t.turn!==e.turn&&(e.turn=t.turn,e.turnIndex=n);break;case`phase.leave`:{let r=c(t.phase);e.phase===r?G(e,n):e.phase===0?(e.lastPhase=r,e.lastPhaseEntered=-1,e.lastPhaseLeft=n):e.inconsistent++;break}case`timer.fired`:K(e,n),e.firedCount++,e.firedIndex=n;break;case`pool.queued`:{let r=e.jobs.get(t.job);r!==void 0&&(e.inconsistent++,U(e,r)),e.jobs.set(t.job,{job:t.job,kind:t.kind,op:t.op===void 0?null:t.op,id:t.id===void 0?-1:t.id,linkIndex:t.id===void 0?-1:n,state:0,thread:0,queuedIndex:n,startedIndex:-1,finishedIndex:-1,postedIndex:-1,done:!1,atIndex:t.at===void 0?-1:n}),e.poolWaiting.push(t.job),e.pQueued++,o=12;break}case`pool.started`:{let r=e.jobs.get(t.job);r===void 0?r={job:t.job,kind:`unknown`,op:null,id:-1,linkIndex:-1,state:0,thread:0,queuedIndex:-1,startedIndex:-1,finishedIndex:-1,postedIndex:-1,done:!1,atIndex:-1}:(r.state!==0&&e.inconsistent++,U(e,r)),Xe(e,t.thread,t.job,t.tid,!0),e.jobs.set(t.job,{...r,state:1,thread:t.thread,startedIndex:n,done:!1,atIndex:t.at===void 0?r.atIndex:n}),e.pStarted++,o=12;break}case`pool.finished`:{let r=e.jobs.get(t.job);r===void 0?r={job:t.job,kind:`unknown`,op:null,id:-1,linkIndex:-1,state:0,thread:0,queuedIndex:-1,startedIndex:-1,finishedIndex:-1,postedIndex:-1,done:!1,atIndex:-1}:((r.state===1&&r.thread!==t.thread||r.state>=2)&&e.inconsistent++,U(e,r)),e.pFinished++;let a={...r,state:2,thread:t.thread,finishedIndex:n,done:!1,atIndex:t.at===void 0?r.atIndex:n};e.poolPosts?(Xe(e,t.thread,t.job,t.tid,!1),e.jobs.set(t.job,a)):Qe(e,i,a,n),o=12;break}case`pool.posted`:{e.poolPosts=!0;let r=e.jobs.get(t.job);r===void 0?r={job:t.job,kind:`unknown`,op:null,id:-1,linkIndex:-1,state:0,thread:0,queuedIndex:-1,startedIndex:-1,finishedIndex:-1,postedIndex:-1,done:!1,atIndex:-1}:(r.state===3&&e.inconsistent++,U(e,r)),e.pPosted++,Qe(e,i,{...r,state:3,thread:t.thread,postedIndex:n,done:!1,atIndex:t.at===void 0?r.atIndex:n},n),o=12;break}case`pool.delivered`:{let n=e.jobs.get(t.job);if(o=12,n===void 0)break;(n.state===0||n.state===1)&&e.inconsistent++,U(e,n),e.jobs.delete(t.job),e.pDelivered++;break}case`pool.cancelled`:{let n=e.jobs.get(t.job);if(o=12,n===void 0)break;if(n.state!==0){e.inconsistent++;break}U(e,n),e.jobs.delete(t.job),e.pCancelled++;break}case`pool.size`:for(e.poolSizeIndex=n,qe(e,t.size);e.threads.length>t.size;){let t=e.threads[e.threads.length-1];if(t.job!==null||t.jobs>0)break;e.threads.pop()}o=12;break;case`pool.link`:{let r=e.jobs.get(t.job);if(r===void 0)break;r.done?(Ye(e,r),e.jobs.delete(t.job),Qe(e,i,{...r,id:t.id,linkIndex:n,done:!1},n)):e.jobs.set(t.job,{...r,id:t.id,linkIndex:n});break}case`debug.paused`:e.paused=!0,e.pausedIndex=n,e.pauses++,W(e),o=11;break;case`debug.resumed`:e.lastPausedIndex=e.paused?e.pausedIndex:-1,e.lastResumedIndex=n,e.paused=!1,e.pausedIndex=-1,W(e);break;case`gate.stopped`:e.gateStopped=!0,e.gateIndex=n,e.gateStops++,W(e),o=11;break;case`gate.released`:e.gateStopped=!1,e.gateReleasedIndex=n,W(e);break;case`clock.frozen`:e.clockFrozen=!0,e.clockIndex=n;break;case`clock.unfrozen`:e.clockFrozen=!1,e.clockUnfrozenIndex=n,e.hiddenMs+=t.hiddenMs;break;case`note`:e.noteCount++,o=13}return o}const nt=`replay:main`,rt=`replay:due`;new Map([{id:nt,title:`The main script is running`,statement:`The run has started and no callback has started and the event loop has reported nothing yet. Node runs its start-up code and then the main script before it enters the loop, so the main thread is running one of the two. For an ES module the body itself runs inside promise callbacks, which then show as callbacks.`,yields:`inferred`,platform:`all`,cites:[`s:lib/internal/modules/run_main.js#executeUserEntryPoint`,`o:loop.run`]},{id:rt,title:`When a timer is due`,statement:`A timer was armed (set, or put back after a run) with a delay. We show it as due at the time of that event plus the delay, and measure lateness against that. Node starts the delay from the loop's cached clock, which was read at the start of the current loop turn, so the real due time can be earlier than shown by the time the current callback had already been running.`,yields:`inferred`,platform:`all`,cites:[`s:lib/internal/timers.js#Timeout.prototype.constructor`,`s:lib/internal/timers.js#insert`,`o:timers.listOnTimeout`]},{id:`replay:handle`,title:`A handle keeps waiting after its callback`,statement:`An item whose type is a libuv handle (a socket, a server, a pipe, a child process, a watcher) was waiting on the operating system and one of its callbacks ran. A handle stays registered with the loop until it is closed, so it is still shown as waiting. It leaves when it is reported destroyed.`,yields:`inferred`,platform:`all`,cites:[`s:src/handle_wrap.cc#node::HandleWrap::OnClose`,`o:phase.poll`]},{id:`replay:delivered`,title:`The result of a pool job reached the loop`,statement:`The callback of an item started, or the item was destroyed, while a pool job of that item was shown as finished or as still queued. The after-work callback on the main thread is what leads to that callback, so the work is done and its result is no longer waiting to be delivered. (File system requests and dns.lookup report nothing from the pool thread; for them the callback is the only sign that the work ran.)`,yields:`inferred`,platform:`all`,cites:[`s:deps/uv/src/threadpool.c#uv__work_done`,`o:pool.done`]}].map(e=>[e.id,e]));const it={maxEntries:200,maxOutput:200,maxNotes:50,maxLog:50,items:`none`};function at(e,t){if(t===void 0)return e;let n=(e,t)=>typeof e==`number`&&e>=0?Math.floor(e):t;return{maxEntries:n(t.maxEntries,e.maxEntries),maxOutput:n(t.maxOutput,e.maxOutput),maxNotes:n(t.maxNotes,e.maxNotes),maxLog:n(t.maxLog,e.maxLog),items:t.items===`all`||t.items===`none`?t.items:e.items}}const ot=[`unknown`,`phase`,`nextTick`,`microtask`],st=[null,`waiting`,`running`,`done`,`cleared`];function q(e,t){return b(e.events[t],t)}function J(e,t){return t<0?null:q(e,t)}function ct(e,t){for(let n of e.stack)if(n.id===t)return!0;return!1}function Y(e,t,n){let r=e.index.items.get(t);return r===void 0||r.firstIndex>=n?{id:t,type:`?`,label:null,trigger:0,loc:null,created:null}:e.index.refAt(r,n)}function lt(e,t,n,r){let i=n.timer;if(i===null||i.setIndex>=r)return null;let a=e.events,o=y(i.arms,r),s=y(n.starts,r),c=st[e.index.timerStateAt(n,r,ct(t,n.id))],l=q(e,o),u=i.delayMs*1e3,d=null;if(s>=0){let e=y(i.arms,s);e>=0&&(d=(a[s].t-(a[e].t+u))/1e3)}return{item:e.index.refAt(n,r),delayMs:i.delayMs,repeat:i.repeat,set:q(e,i.setIndex),armed:l,dueT:l.t+u,dueFrom:{c:`inferred`,rule:rt,index:o,t:l.t},state:c,runs:v(n.starts,r),lastRun:J(e,s),lateMs:d,cleared:i.clearedIndex>=0&&i.clearedIndex<r?q(e,i.clearedIndex):null}}function ut(e,t,r,i){let a=e.index.refAt(r,i),o=v(r.starts,i),s=v(r.ends,i),c=r.goneIndex>=0&&r.goneIndex<i,l=t.where.get(r.id)??0,u=[];for(let e=0;e<7;e++)l&1<<e&&u.push(n[e]);let d;d=c?`gone`:ct(t,r.id)?`running`:u.length>0?`waiting`:o>0?`ran`:`created`;let f=v(r.jobIndexes,i);return{id:a.id,type:a.type,label:a.label,trigger:a.trigger,loc:a.loc,created:a.created,state:d,queues:u,runs:o,lastStart:o>0?q(e,r.starts[o-1]):null,lastEnd:s>0?q(e,r.ends[s-1]):null,gone:c?q(e,r.goneIndex):null,settled:r.settledIndex>=0&&r.settledIndex<i?q(e,r.settledIndex):null,timer:lt(e,t,r,i),job:f>0?r.jobNames[f-1]:null,children:v(r.children,i)}}function dt(e,t,r){let i=q(e,t.index),o=null;return t.viaIndex>=0?o=q(e,t.viaIndex):t.viaRule!==null&&(o={c:`inferred`,rule:t.viaRule,index:t.index,t:i.t}),{item:Y(e,t.id,r),from:i,via:ot[t.via],viaFrom:o,queue:t.queue>=0?n[t.queue]:null,phase:a[t.phase],phaseFrom:J(e,t.phaseIndex),phaseAfterPoll:_t(e,t.phaseIndex),depth:t.depth}}const ft=[`waiting`,`running`,`finished`,`posted`];function pt(e,t){if(!t.gateStopped||t.gateIndex<0)return null;let n=e.events[t.gateIndex];return n.k===`gate.stopped`&&n.job!==void 0&&(n.gate===`poolStart`||n.gate===`poolPost`||n.gate===`poolDone`)?n:null}function mt(e,t,n,r){let i=t.atIndex>=0?e.events[t.atIndex]:void 0;return{job:t.job,kind:t.kind,op:t.op,state:ft[t.state],item:t.id>=0?Y(e,t.id,n):null,itemFrom:J(e,t.linkIndex),thread:t.thread>0?t.thread:null,queued:J(e,t.queuedIndex),started:J(e,t.startedIndex),finished:J(e,t.finishedIndex),posted:J(e,t.postedIndex),at:i!==void 0&&i.at!==void 0?i.at:null,held:r!==null&&r.job===t.job?r.gate:null}}function ht(e,t){let n=t.startIndex>=0?e.events[t.startIndex]:void 0,r=t.endIndex>=0?e.events[t.endIndex]:void 0,i=n!==void 0&&n.k===`run.start`?n:void 0,a=r!==void 0&&r.k===`run.end`?r:void 0;return{status:t.status,node:i===void 0?null:i.node,caps:i===void 0?null:i.caps,program:i===void 0?null:i.program,mode:i===void 0?null:i.mode,poolSize:i===void 0?null:i.poolSize,exitCode:a===void 0||a.code===void 0?null:a.code,signal:a===void 0||a.signal===void 0?null:a.signal,started:J(e,t.startIndex),ended:J(e,t.endIndex)}}function gt(e,t,n){if(t.stack.length>0){let r=t.stack.map(t=>dt(e,t,n));return{doing:`callback`,from:r[r.length-1].from,stack:r}}if(t.mainScript&&t.startIndex>=0){let n=q(e,t.startIndex);return{doing:`main`,from:{c:`inferred`,rule:nt,index:n.index,t:n.t},stack:[]}}return{doing:`nothing`,from:J(e,t.idleIndex),stack:[]}}function _t(e,t){if(t<0)return!1;let n=e.events[t];return(n.k===`phase.enter`||n.k===`phase.leave`)&&n.afterPoll===!0}function vt(e,t){let n=t.scopeIndex>=0?e.events[t.scopeIndex]:void 0,r=t.sampleIndex>=0?e.events[t.sampleIndex]:void 0,i=t.pollIndex>=0?e.events[t.pollIndex]:void 0;return{turn:t.turnIndex>=0?t.turn:null,turnFrom:J(e,t.turnIndex),phase:a[t.phase],phaseFrom:t.phase===0?null:J(e,t.phaseIndex),afterPoll:t.phase!==0&&_t(e,t.phaseIndex),poll:i!==void 0&&i.k===`phase.enter`&&i.pollTimeoutMs!==void 0?{timeoutMs:i.pollTimeoutMs,current:t.phase!==0&&t.phaseIndex===t.pollIndex,from:q(e,t.pollIndex)}:null,lastPhase:t.lastPhase===0?null:{phase:a[t.lastPhase],afterPoll:_t(e,t.lastPhaseEntered)||_t(e,t.lastPhaseLeft),entered:J(e,t.lastPhaseEntered),left:q(e,t.lastPhaseLeft)},lastScope:n!==void 0&&n.k===`scope`?{name:n.name,durUs:n.durUs,from:q(e,t.scopeIndex)}:null,lastSample:r!==void 0&&r.k===`loop.sample`?{loopCount:r.loopCount,events:r.events,eventsWaiting:r.eventsWaiting,from:q(e,t.sampleIndex)}:null}}function yt(e,t,n,r,i,a){let o=n.items.length-n.head,s=Math.min(o,i),c=[];for(let t=0;t<s;t++){let i=n.items[n.head+t],a=e.events[i.index];c.push({item:Y(e,i.id,r),from:b(a,i.index),at:a.at===void 0?null:a.at,runs:i.runs})}return{name:t,total:o,entries:c,truncated:s<o,leftAtEnd:a&&o>0}}function bt(e,t,n,r){let i=[];for(let r of t.timersActive){let t=e.index.items.get(r),a=t===void 0?null:t.timer;t===void 0||a===null||a.setIndex>=n||i.push({rec:t,due:e.events[y(a.arms,n)].t+a.delayMs*1e3,set:a.setIndex})}i.sort((e,t)=>e.due-t.due||e.set-t.set);let a=i.length>r,o=[];for(let a=0;a<i.length&&a<r;a++){let r=lt(e,t,i[a].rec,n);r!==null&&o.push(r)}let s=[];for(let r of t.timersRecent){let i=e.index.items.get(r),a=i===void 0?null:lt(e,t,i,n);a!==null&&s.push(a)}let c=t.firedIndex>=0?e.events[t.firedIndex]:void 0;return{active:o,recent:s,counts:{set:t.tSet,waiting:t.tWaiting,running:t.tRunning,done:t.tDone,cleared:t.tCleared},fired:{count:t.firedCount,last:c!==void 0&&c.k===`timer.fired`?{lateMs:c.lateMs===void 0?null:c.lateMs,from:q(e,t.firedIndex)}:null},truncated:a,leftAtEnd:t.endIndex>=0&&t.tWaiting>0}}function xt(e,t,n,r,i){let a=t.poolSizeIndex>=0?e.events[t.poolSizeIndex]:void 0,o=a!==void 0&&a.k===`pool.size`?a.size:i,s=a!==void 0&&a.k===`pool.size`?q(e,t.poolSizeIndex):J(e,t.startIndex),c=pt(e,t),l=null;if(c!==null){let r=c.job,i=t.jobs.get(r),a=null;if(c.gate!==`poolDone`){if(i!==void 0&&i.state!==0&&i.thread>0)a=i.thread;else if(c.tid!==void 0){let e=t.threads.findIndex(e=>e.tid===c.tid);e>=0&&(a=e+1)}}l={gate:c.gate,job:r,where:c.gate===`poolDone`?`loop`:`thread`,thread:a,view:i===void 0?null:mt(e,i,n,c),from:q(e,t.gateIndex)}}let u=[];for(let r=0;r<t.threads.length;r++){let i=t.threads[r],a=i.job===null?void 0:t.jobs.get(i.job);u.push({thread:r+1,job:a===void 0?null:mt(e,a,n,c),tid:i.tid>=0?i.tid:null,jobs:i.jobs,extra:o!==null&&r+1>o})}let d=i=>{let a=[];for(let o=0;o<i.length&&a.length<r;o++){let r=t.jobs.get(i[o]);r!==void 0&&a.push(mt(e,r,n,c))}return a},f=[];for(let n of t.tids.values())f.push({tid:n.tid,busy:n.busy,name:n.name,from:q(e,n.index),starts:n.starts,ends:n.ends});return f.sort((e,t)=>e.tid-t.tid),{size:o,sizeFrom:s,threads:u,waiting:d(t.poolWaiting),done:d(t.poolDone),held:l,tids:f,counts:{queued:t.pQueued,started:t.pStarted,finished:t.pFinished,posted:t.pPosted,delivered:t.pDelivered,cancelled:t.pCancelled,droppedUnlinked:t.pDropped},truncated:t.poolWaiting.length>r||t.poolDone.length>r,leftAtEnd:t.endIndex>=0&&t.jobs.size>0}}function St(e,t){let n=t.paused&&t.pausedIndex>=0?e.events[t.pausedIndex]:void 0,r=n!==void 0&&n.k===`debug.paused`?n:void 0,i=null;if(t.lastResumedIndex>=0){let n=e.events[t.lastResumedIndex],r=t.lastPausedIndex>=0?e.events[t.lastPausedIndex]:void 0;n.k===`debug.resumed`&&(i={pausedMs:n.pausedMs,timeKeptRunning:r!==void 0&&r.k===`debug.paused`&&r.timeKeptRunning,paused:J(e,t.lastPausedIndex),resumed:q(e,t.lastResumedIndex)})}let a=t.gateStopped&&t.gateIndex>=0?e.events[t.gateIndex]:void 0,o=a!==void 0&&a.k===`gate.stopped`?a:void 0,s=t.gateReleasedIndex>=0?e.events[t.gateReleasedIndex]:void 0,c=t.clockUnfrozenIndex>=0?e.events[t.clockUnfrozenIndex]:void 0,l=t.clockFrozen&&t.clockIndex>=0?e.events[t.clockIndex]:void 0;return{paused:t.paused,reason:r===void 0?null:r.reason,frames:r===void 0?[]:r.frames,timeKeptRunning:r!==void 0&&r.timeKeptRunning,from:r===void 0?null:q(e,t.pausedIndex),lastPause:i,pauses:t.pauses,gate:{stopped:t.gateStopped,gate:o===void 0?null:o.gate,phase:o===void 0||o.phase===void 0?null:o.phase,job:o===void 0||o.job===void 0?null:o.job,from:o===void 0?null:q(e,t.gateIndex),lastStoppedMs:s!==void 0&&s.k===`gate.released`?s.stoppedMs:null,stops:t.gateStops},clock:{frozen:t.clockFrozen,why:l!==void 0&&l.k===`clock.frozen`&&(l.why===`gate`||l.why===`breakpoint`)?l.why:null,from:t.clockFrozen?J(e,t.clockIndex):null,lastHiddenMs:c!==void 0&&c.k===`clock.unfrozen`?c.hiddenMs:null,hiddenMs:t.hiddenMs}}}function Ct(e,t,r){let i=/* @__PURE__ */ new Map,a=(e,t)=>{if(e===void 0||e===``)return null;let n=i.get(e);return n===void 0&&(n={at:e,count:0,c:t,waiting:0,poolWaiting:0,poolRunning:0,poolDone:0,queues:[],pool:!1},i.set(e,n)),n.count++,n.c=S(n.c,t),n};for(let i=0;i<7;i++){let o=t.queues[i],s=n[i];for(let t=o.head;t<o.items.length;t++){let n=o.items[t];if(i===4){let t=e.index.items.get(n.id);if(t!==void 0&&v(t.jobIndexes,r)>0)continue}let c=e.events[n.index],l=a(c.at,c.c);l!==null&&(l.waiting++,l.queues.includes(s)||l.queues.push(s))}}for(let n of t.jobs.values()){if(n.atIndex<0)continue;let t=e.events[n.atIndex],r=a(t.at,t.c);r!==null&&(r.pool=!0,n.state===0?r.poolWaiting++:n.state===1?r.poolRunning++:r.poolDone++)}let o=[...i.values()].sort((e,t)=>e.at<t.at?-1:+(e.at>t.at)),s=t.focusIndex>=0?e.events[t.focusIndex]:void 0;return{at:s===void 0||s.at===void 0?null:s.at,from:s===void 0?null:q(e,t.focusIndex),kind:s===void 0?null:s.k,waiting:o}}function wt(e,t,n){if(t.paused&&t.pausedIndex>=0){let n=e.events[t.pausedIndex],r=n.k===`debug.paused`?n.frames[0]:void 0;if(typeof r==`object`&&r&&h(r.loc))return{loc:r.loc,why:`paused`,item:null,from:q(e,t.pausedIndex)}}let r=t.stack.length>0?t.stack[t.stack.length-1]:null;if(r===null&&!(t.mainScript&&t.startIndex>=0))return null;let i=r===null?t.mainSrcIndex:r.srcIndex;if(i>=0){let t=e.events[i];if(t.k===`output`&&t.loc!==void 0)return{loc:t.loc,why:`output`,item:null,from:b(t,i)};if(t.k===`item.new`&&t.loc!==void 0)return{loc:t.loc,why:`created`,item:t.id,from:b(t,i)}}if(r!==null){let t=Y(e,r.id,n);if(t.loc!==null&&t.created!==null)return{loc:t.loc,why:`callback`,item:r.id,from:t.created}}return null}function Tt(e,t,n){let r=Math.max(0,Math.floor(t)),i=Math.min(e.ready,Math.floor(n)),a=[];for(let t=r;t<i;t++)a.push({index:t,event:e.events[t],skipped:!!(e.index.flags[t]&64)});return a}function Et(e,t,n,r){let i=Math.max(0,Math.floor(n)),a=Math.min(t.outputCount,Math.floor(r));return i<a?e.index.output.slice(i,a):[]}function Dt(e,t,n,r,i){let a=e.index.itemsBefore(n),o=Math.max(0,Math.floor(r)),s=Math.min(a,o+Math.max(0,Math.floor(i))),c=[];for(let r=o;r<s;r++)c.push(ut(e,t,e.index.order[r],n));return c}function Ot(e,t,r,i){let a=e.index,o=ht(e,t),s={};for(let a=0;a<7;a++){let o=n[a];s[o]=yt(e,o,t.queues[a],r,i.maxEntries,t.endIndex>=0)}let c=a.itemsBefore(r),l=[];for(let n=Math.max(0,t.noteCount-i.maxNotes);n<t.noteCount;n++){let t=a.notes[n],r=e.events[t];r.k===`note`&&l.push({seq:n,level:r.level,text:r.text,from:b(r,t)})}let u=t.outputCount;return{position:r,length:e.length,ready:e.ready,live:e.live,version:e.version,t:r===0?e.ready>0?a.tMono[0]:0:a.tMono[r-1],endT:e.ready===0?0:a.tMono[e.ready-1],run:o,main:gt(e,t,r),loop:vt(e,t),queues:s,items:{total:c,all:i.items===`all`?Dt(e,t,r,0,c):null},timers:bt(e,t,r,i.maxEntries),pool:xt(e,t,r,i.maxEntries,o.poolSize),output:{total:u,chars:u===0?0:a.outputChars[u-1],chunks:a.output.slice(Math.max(0,u-i.maxOutput),u)},debug:St(e,t),notes:{total:t.noteCount,items:l},focus:Ct(e,t,r),source:wt(e,t,r),log:Tt(e,r-i.maxLog,r),problems:{unknown:t.unknown,malformed:t.malformed,inconsistent:t.inconsistent}}}const kt=e.length;function At(e,t,n,r,i){let a=Math.max(1,Math.min(8192,Math.floor(Number.isFinite(n)?n:1))),o=new Uint32Array(a),s=new Uint32Array(a),c=new Uint8Array(a),l=new Uint8Array(a),u=new Uint8Array(a),d=new Uint8Array(a),f=new Uint32Array(a*kt),p=e.tlState,m=e.tlClass,h=e.tMono,g=t===0?0:h[0],_=t===0?0:h[t-1],v=r===`time`,y=_-g,b=/* @__PURE__ */ new Uint32Array(8),x=0,S=0;for(let e=0;e<a;e++){o[e]=x;let n;if(e===a-1)n=t;else if(!v)n=Math.min(t,Math.ceil((e+1)*t/a));else if(y<=0)n=t;else{let r=g+(e+1)*y/a;for(n=x;n<t&&h[n]<r;)n++}if(n<=x){c[e]=S&7,l[e]=S>>3&3,u[e]=S&32?1:0,d[e]=S&64?1:0;continue}b.fill(0);let r=0,i=0,_=e*kt;for(;x<n;x++){let e=p[x],t=e&7;if(t!==0){b[t]=b[t]+1;let n=e>>3&3;n>r&&(r=n)}i|=e;let n=m[x];n!==0&&(f[_+n-1]=f[_+n-1]+1),S=e}s[e]=n-o[e];let C=0,w=0;for(let e=1;e<8;e++)b[e]>w&&(C=e,w=b[e]);c[e]=C,l[e]=C===0?0:r,u[e]=i&32?1:0,d[e]=i&64?1:0}return{axis:v?`time`:`index`,width:a,version:i,length:t,from:v?g:0,to:v?_:t,start:o,events:s,phase:c,phaseCertainty:l,paused:u,busy:d,counts:f}}function jt(e,t,n){let r=[];for(let n of e.notes){let e=t[n];e.k===`note`&&r.push({index:n,t:e.t,level:e.level,text:e.text})}let i=new Uint32Array(e.output.length),a=new Uint8Array(e.output.length);for(let t=0;t<e.output.length;t++){let n=e.output[t];i[t]=n.index,a[t]=+(n.stream===`stderr`)}return{version:n,pauses:e.pauses.map(e=>({...e})),notes:r,turnIndex:Uint32Array.from(e.turns),turnNumber:Uint32Array.from(e.turnNumbers),outputIndex:i,outputStream:a}}const Mt={observed:1,inferred:2,model:3},Nt=typeof performance<`u`&&typeof performance.now==`function`?()=>performance.now():()=>Date.now();function Pt(e){switch(e){case`step`:return 1;case`callback`:return 2;case`phase`:return 4;case`turn`:return 8;case`output`:return 16;case`pause`:return 32;default:return 255}}var Ft=class{store;#e=new C;#t=0;#n=Re();#r=[];#i=[];#a=0;#o;#s;#c;#l=0;#u=null;#d=0;#f;#p=/* @__PURE__ */ new Set;#m;#h=/* @__PURE__ */ new Map;#g=null;#_=-1;constructor(e,t){this.store=e;let n=t?.keyframeInterval;this.#s=typeof n==`number`&&n>=1?Math.floor(n):512,this.#o=this.#s,this.#c=t?.eager!==!1,this.#f=at(it,t?.view),this.#m=e.subscribe(e=>this.#v(e)),this.#c&&this.#S(1/0)}#v(e){e.rejected===null&&(e.replaced&&(this.#l=0),e.from<this.#t&&this.#y(e.from),this.#l>e.length&&(this.#l=e.length),this.#c&&this.#S(1/0));for(let t of[...this.#p])t(e)}#y(e){for(this.#e.truncate(e);this.#i.length>0&&this.#i[this.#i.length-1]>e;)this.#i.pop(),this.#a-=Be(this.#r.pop());let t=this.#i.length-1,n=t>=0?this.#i[t]:0,r=t>=0?ze(this.#r[t]):Re();this.#x(r,n,e),this.#n=r,this.#t=e,this.#o=n+(t>=0?this.#b(this.#r[t]):this.#s),this.#u!==null&&this.#d>e&&(this.#u=null)}#b(e){return Math.max(this.#s,Be(e)>>2)}#x(e,t,n){let r=this.store.events,i=this.#e,a=i.flags;for(let o=t;o<n;o++)tt(e,r[o],o,a[o],i,r)}#S(e){let t=this.store.events,n=t.length,r=this.#t;if(r>=n)return;let i=this.#e,a=this.#n,o=e===1/0?1/0:Nt()+e;for(;r<n;){let e=t[r],n=i.add(e,r);i.tlClass[r]=tt(a,e,r,n,i,t);let s=a.phase;if(s!==0&&(s|=(Mt[t[a.phaseIndex].c]??0)<<3),(a.paused||a.gateStopped)&&(s|=32),a.stack.length>0&&(s|=64),i.tlState[r]=s,r++,r===this.#o){let e=ze(a);this.#r.push(e),this.#i.push(r),this.#a+=Be(e),this.#o=r+this.#b(e)}if(!(r&255)&&o!==1/0&&Nt()>=o)break}this.#t=r}get ready(){return this.#t}pump(e=4){return this.#S(Math.max(0,e)),this.#t<this.store.length}get position(){return Math.min(this.#l,this.#t)}#C(e){let t=this.#i,n=0,r=t.length;for(;n<r;){let i=n+r>>>1;t[i]<=e?n=i+1:r=i}return n-1}#w(e){let t=this.#C(e),n=t>=0?this.#i[t]:0,r=t>=0?ze(this.#r[t]):Re();return this.#x(r,n,e),r}#T(){let e=this.position;if(e===this.#t)return this.#n;let t=this.#C(e),n=t>=0?this.#i[t]:0;return this.#u!==null&&this.#d<=e&&this.#d>=n?this.#x(this.#u,this.#d,e):this.#u=this.#w(e),this.#d=e,this.#u}seek(e){let t=Number.isFinite(e)?Math.floor(e):e>0?this.store.length:0;return this.#l=Math.max(0,Math.min(this.store.length,t)),this.position}seekTime(e){return this.seek(this.positionAtTime(e))}positionAtTime(e){let t=this.#e.tMono,n=0,r=this.#t;for(;n<r;){let i=n+r>>>1;t[i]<=e?n=i+1:r=i}return n}timeAt(e){if(this.#t===0)return 0;let t=Math.max(1,Math.min(this.#t,Math.floor(e)));return this.#e.tMono[t-1]}find(e,t,n){let r=this.#t,i=n===void 0?this.position:Math.max(0,Math.min(r,Math.floor(n)));if(e===`event`){let e=t>0?i+1:i-1;return e<0||e>r?null:e}let a=Pt(e);if(t>0){let e=this.#e.nextWith(a,i);return e<0||e>=r?null:e+1}let o=this.#e.previousWith(a,i-2);return o>=0?o+1:e===`step`&&i>0?0:null}step(e,t){let n=this.find(e,t);return n===null?null:(this.#l=n,n)}#E(){return{index:this.#e,events:this.store.events,length:this.store.length,ready:this.#t,live:this.store.live,version:this.store.version}}view(e){return Ot(this.#E(),this.#T(),this.position,at(this.#f,e))}viewAt(e,t){let n=Math.max(0,Math.min(this.#t,Math.floor(e))),r=n===this.position?this.#T():this.#w(n);return Ot(this.#E(),r,n,at(this.#f,t))}doing(){let e=this.#T();return e.stack.length>0?`callback`:e.mainScript&&e.startIndex>=0?`main`:`nothing`}item(e){let t=this.position,n=this.#e.items.get(e);return n===void 0||n.firstIndex>=t?null:ut(this.#E(),this.#T(),n,t)}why(e){let t=this.position,n=this.#E(),r=this.#T(),i=[],a=/* @__PURE__ */ new Set,o=e;for(;i.length<1e3&&!a.has(o);){a.add(o);let e=this.#e.items.get(o);if(e===void 0||e.firstIndex>=t)break;let s=ut(n,r,e,t);if(i.push(s),s.created===null)break;o=s.trigger}return i}items(e=0,t=1/0){let n=this.position,r=this.#e.itemsBefore(n);return Dt(this.#E(),this.#T(),n,e,Math.min(t,r))}itemCount(){return this.#e.itemsBefore(this.position)}output(e,t){return Et(this.#E(),this.#T(),e,t)}events(e,t){return Tt(this.#E(),e,t)}timeline(e,t=`index`){let n=t+`:`+e,r=this.#h.get(n),i=this.store.version;if(r!==void 0&&r.version===i&&r.length===this.#t)return r;let a=At(this.#e,this.#t,e,t,i);return this.#h.size>=4&&this.#h.clear(),this.#h.set(n,a),a}markers(){let e=this.store.version,t=this.#g;return t!==null&&t.version===e&&this.#_===this.#t?t:(this.#g=jt(this.#e,this.store.events,e),this.#_=this.#t,this.#g)}query(e){switch(e.what){case`item`:return{what:`item`,item:this.item(e.id)};case`why`:return{what:`why`,chain:this.why(e.id)};case`items`:return{what:`items`,items:this.items(e.from,e.limit),total:this.itemCount()};case`output`:return{what:`output`,chunks:this.output(e.from,e.to)};case`events`:{let t=Math.max(0,Math.floor(e.from));return{what:`events`,entries:this.events(t,Math.min(e.to,t+1e3))}}case`viewAt`:return{what:`viewAt`,view:this.viewAt(e.position)};default:throw TypeError(`unknown query`)}}stats(){return{ready:this.#t,keyframes:this.#r.length,keyframeSlots:this.#a,keyframeInterval:this.#s}}subscribe(e){return this.#p.add(e),()=>{this.#p.delete(e)}}dispose(){this.#m(),this.#p.clear()}};const It=(e,t,n)=>e<t?t:e>n?n:e;var Lt=class{replay;#e=!1;#t=1;#n=`steps`;#r=5;#i=.01;#a=2e3;#o=600;#s=!0;#c=250;#l=null;#u=0;#d=null;#f=!1;#p=!1;#m=null;#h;constructor(e,t){this.replay=e,t!==void 0&&this.setOptions(t),this.#h=e.subscribe(e=>{e.replaced&&(this.#p=!1),e.status===`live`&&this.#s&&(this.#p=!0)})}dispose(){this.#h()}get state(){let e=this.replay,t=e.position,n=e.ready,r=e.store.live;return{playing:this.#e,speed:this.#t,pace:this.#n,follow:this.#s,following:this.#s&&r&&t===n,position:t,length:n,live:r,atEnd:!r&&n>0&&t===n&&e.store.length===n,waiting:this.#f,deadTime:this.#d,t:e.timeAt(t)}}play(){let e=this.replay;!e.store.live&&e.position>=e.store.length&&e.store.length>0&&e.seek(0),this.#e=!0,this.#g()}pause(){this.#e=!1,this.#s=!1,this.#p=!1,this.#g()}toggle(){this.#e?this.pause():this.play()}setSpeed(e){Number.isFinite(e)&&(this.#t=It(e,.05,20))}setPace(e){(e===`steps`||e===`time`||e===`tick`)&&(this.#n=e,this.#g())}setFollow(e){this.#s=e===!0,this.#p=this.#s&&this.replay.store.live}setOptions(e){e.speed!==void 0&&this.setSpeed(e.speed),e.pace!==void 0&&this.setPace(e.pace),typeof e.stepsPerSecond==`number`&&e.stepsPerSecond>0&&(this.#r=e.stepsPerSecond),typeof e.timeScale==`number`&&e.timeScale>0&&(this.#i=e.timeScale),typeof e.deadTimeUs==`number`&&e.deadTimeUs>=0&&(this.#a=e.deadTimeUs),typeof e.deadTimePauseMs==`number`&&e.deadTimePauseMs>=0&&(this.#o=e.deadTimePauseMs),e.follow!==void 0&&this.setFollow(e.follow),typeof e.maxTickMs==`number`&&e.maxTickMs>0&&(this.#c=e.maxTickMs)}seek(e){let t=this.replay,n=t.seek(e);t.store.live&&n>=t.ready||(this.#s=!1,this.#p=!1),this.#g()}seekTime(e){this.seek(this.replay.positionAtTime(e))}step(e,t){return this.#e=!1,this.#s=!1,this.#p=!1,this.#g(),this.replay.step(e,t)!==null}command(e){switch(e.do){case`play`:return this.play();case`pause`:return this.pause();case`toggle`:return this.toggle();case`speed`:return this.setSpeed(e.speed);case`pace`:return this.setPace(e.pace);case`follow`:return this.setFollow(e.on);case`seek`:return this.seek(e.position);case`seekTime`:return this.seekTime(e.t);case`step`:this.step(e.kind,e.direction);return;case`options`:return this.setOptions(e.options);default:return}}#g(){this.#l=null,this.#u=0,this.#d=null,this.#f=!1}tick(e){let t=this.replay,n=t.position,r=t.ready,i=t.store.live;if(this.#s&&(i||this.#p))n!==r&&t.seek(r),this.#p=i||t.store.length>r,this.#l=e,this.#u=0,this.#d=null,this.#f=!1;else if(this.#e){let n=this.#l===null?0:It(e-this.#l,0,this.#c);this.#l=e,this.#n===`tick`?this.#_(r):this.#n===`time`?this.#x(n,r):this.#b(n,r),t.position>=r?(this.#d=null,this.#u=0,i||t.store.length>r?this.#f=!0:(this.#f=!1,this.#e=!1,this.#l=null)):this.#f=!1}let a=this.state,o=this.#m,s=o===null||o.position!==a.position||o.playing!==a.playing||o.speed!==a.speed||o.pace!==a.pace||o.follow!==a.follow||o.following!==a.following||o.length!==a.length||o.live!==a.live||o.atEnd!==a.atEnd||o.waiting!==a.waiting||o.deadTime===null!=(a.deadTime===null)||o.deadTime!==null&&a.deadTime!==null&&o.deadTime.progress!==a.deadTime.progress;return this.#m=a,{moved:a.position!==n,changed:s,state:a}}#_(e){let t=this.replay.position;t<e&&this.replay.seek(t+1)}#v(e,t){if(this.#a<=0||e<=0)return 0;let n=this.replay.timeAt(t)-this.replay.timeAt(e);return n>this.#a?n:0}#y(e,t,n,r){let i=It(r,0,1),a=this.#d;a!==null&&a.afterIndex===t-1&&a.beforeIndex===n-1?a.progress!==i&&(this.#d={...a,progress:i}):this.#d={ms:e/1e3,afterIndex:t-1,beforeIndex:n-1,during:this.replay.doing(),progress:i}}#b(e,t){let n=this.replay,r=1e3/this.#r;this.#u+=e*this.#t;let i=n.position;for(let e=0;e<2e3&&i<t;e++){let e=n.find(`step`,1,i);if(e===null){if(n.store.live||n.store.length>t)e=t;else{i=t;break}}let a=this.#v(i,e),o=a>0?this.#o:0,s=i===0?0:r,c=s+o;if(this.#u<c){a>0&&this.#u>=s?(i!==n.position&&n.seek(i),this.#y(a,i,e,o===0?1:(this.#u-s)/o)):this.#d=null;break}this.#u-=c,this.#d=null,i=e}i!==n.position&&n.seek(i)}#x(e,t){let n=this.replay;this.#u+=e*this.#t;let r=1/(1e3*this.#i),i=n.position;for(this.#d=null;i<t;){let e=i===0?0:n.timeAt(i+1)-n.timeAt(i),t=this.#a>0&&e>this.#a,a=t?Math.min(this.#o,e*r):e*r;if(this.#u<a){t&&(i!==n.position&&n.seek(i),this.#y(e,i,i+1,a===0?1:this.#u/a));break}this.#u-=a,i++}i!==n.position&&n.seek(i)}};const Rt=33554432;function zt(e){return e instanceof Uint8Array?e:new Uint8Array(e)}async function Bt(e,t,n,r){let i=e.writable.getWriter();i.write(t).catch(()=>{}),i.close().catch(()=>{});let a=e.readable.getReader(),o=[],s=0;for(;;){let{done:e,value:t}=await a.read();if(e)break;if(s+=t.byteLength,s>n)throw a.cancel().catch(()=>{}),new E(r);o.push(t)}let c=new Uint8Array(s),l=0;for(let e of o)c.set(e,l),l+=e.byteLength;return c}function Vt(e){return Bt(new CompressionStream(`gzip`),e,1/0,``)}async function Ht(e,t){let n=`the recording is larger than ${Math.round(t/1048576)} MB when unpacked`;try{return await Bt(new DecompressionStream(`gzip`),e,t,n)}catch(e){throw e instanceof E?e:new E(`not a valid gzip file`)}}function Ut(e){return e.length>=2&&e[0]===31&&e[1]===139}function Wt(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{throw new E(`not a text file (invalid UTF-8)`)}}function Gt(e){let t;try{t=Ae(e.charCodeAt(0)===65279?e.slice(1):e)}catch(e){throw e instanceof E?e:new E(`not a nodejs-map recording`)}if(typeof t!=`object`||!t||t.header===void 0||t.header===null||!Array.isArray(t.events))throw new E(`not a nodejs-map recording`);return t}const X=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`,Kt=(/* @__PURE__ */ new Int8Array(128)).fill(-1);for(let e=0;e<64;e++)Kt[X.charCodeAt(e)]=e;function qt(e){let t=[],n=``,r=e.length;for(let i=0;i<r;i+=3){let a=e[i],o=i+1<r?e[i+1]:0,s=i+2<r?e[i+2]:0;n+=X[a>>2],n+=X[(a&3)<<4|o>>4],i+1<r&&(n+=X[(o&15)<<2|s>>6]),i+2<r&&(n+=X[s&63]),n.length>=8192&&(t.push(n),n=``)}return t.push(n),t.join(``)}function Jt(e){let t=e.length;if(t%4==1)throw new E(`the link is damaged (wrong length)`);let n=new Uint8Array(Math.floor(t*3/4)),r=0;for(let i=0;i<t;i+=4){let a=[0,0,0,0];for(let n=0;n<4&&!(i+n>=t);n++){let t=e.charCodeAt(i+n),r=t<128?Kt[t]:-1;if(r<0)throw new E(`the link is damaged (unexpected character)`);a[n]=r}let[o,s,c,l]=a;n[r++]=o<<2|s>>4,i+2<t&&(n[r++]=(s&15)<<4|c>>2),i+3<t&&(n[r++]=(c&3)<<6|l)}return n}async function Yt(e,t){let n=t?.maxBytes!==void 0&&t.maxBytes>0?t.maxBytes:268435456;if(typeof e==`string`){if(e.length>n)throw new E(`the recording is larger than ${Math.round(n/1048576)} MB`);return Gt(e)}if(!(e instanceof Uint8Array)&&!(e instanceof ArrayBuffer))throw new E(`not a recording: expected text or bytes`);let r=zt(e);if(Ut(r))r=await Ht(r,n);else if(r.byteLength>n)throw new E(`the recording is larger than ${Math.round(n/1048576)} MB`);return Gt(Wt(r))}async function Xt(e,t){let n=new TextEncoder().encode(Oe(e));return t?.gzip===!0?Vt(n):n}async function Zt(e,t){let n=t?.maxChars!==void 0&&t.maxChars>0?Math.floor(t.maxChars):24e3,r=await Vt(new TextEncoder().encode(Oe(e))),i=6+Math.ceil(r.byteLength*4/3);if(i>n)return{ok:!1,reason:`too-big`,length:i,limit:n,message:`This recording is too big to share as a link (${i.toLocaleString(`en-US`)} characters; links work up to ${n.toLocaleString(`en-US`)}). Save it and share the file instead.`};let a=`rec=1.`+qt(r);return{ok:!0,fragment:a,length:a.length,fitsEverywhere:a.length<=2e3}}async function Qt(e,t){if(typeof e!=`string`)throw new E(`not a recording link`);if(e.length>2097152)throw new E(`the link is too long to be a recording link`);let n=e.startsWith(`#`)?e.slice(1):e,r;for(let e of n.split(`&`))if(e.startsWith(`rec=`)){r=e.slice(4);break}if(r===void 0)throw new E(`this link does not contain a recording`);let i=r.indexOf(`.`);if(i<0||r.slice(0,i)!==`1`)throw new E(`this link was made by a newer version of nodejs-map`);let a=Jt(r.slice(i+1));if(!Ut(a))throw new E(`the link is damaged`);return Gt(Wt(await Ht(a,t?.maxBytes!==void 0&&t.maxBytes>0?Math.min(t.maxBytes,Rt):Rt)))}const $t=[`nextTick`,`microtask`,`timers`,`immediate`,`pool`,`io`,`close`],en=[`run`,`main`,`loop`,`items`,`timers`,`pool`,`debug`,`notes`,`focus`,`source`,`problems`],tn=[`position`,`length`,`ready`,`live`,`version`,`t`,`endT`];function nn(e,t){if(e===t)return!0;if(typeof e!=`object`||typeof t!=`object`||e===null||t===null)return!1;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!nn(e[n],t[n]))return!1;return!0}if(Array.isArray(t))return!1;let n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let r of n)if(!nn(e[r],t[r]))return!1;return!0}function rn(e,t,n,r){if(!r||e.length===0||t.length===0)return e.length===0&&t.length===0?null:{from:0,to:0,prepend:[],append:t.slice()};let i=n(e[0]),a=n(e[e.length-1]),o=n(t[0]),s=n(t[t.length-1]);if(i===o&&a===s)return null;let c=Math.max(i,o),l=Math.min(a,s)+1;if(c>=l)return{from:0,to:0,prepend:[],append:t.slice()};let u=[],d=[];for(let e of t){let t=n(e);t<c?u.push(e):t>=l&&d.push(e)}return{from:c,to:l,prepend:u,append:d}}const an=e=>e.seq,on=e=>e.index;function sn(e,t){let n={},r={};if(e===null){for(let e of tn)n[e]=t[e];for(let e of en)n[e]=t[e];for(let e of $t)r[e]=t.queues[e];return{full:!0,set:n,queues:r,output:{total:t.output.total,chars:t.output.chars,from:0,to:0,prepend:[],append:t.output.chunks.slice()},log:{from:0,to:0,prepend:[],append:t.log.slice()}}}for(let r of tn)e[r]!==t[r]&&(n[r]=t[r]);for(let r of en)nn(e[r],t[r])||(n[r]=t[r]);for(let n of $t)nn(e.queues[n],t.queues[n])||(r[n]=t.queues[n]);let i=e.version===t.version,a=rn(e.output.chunks,t.output.chunks,an,i);return{full:!1,set:n,queues:r,output:a===null&&e.output.total===t.output.total&&e.output.chars===t.output.chars?null:{total:t.output.total,chars:t.output.chars,...a??{from:0,to:2**53-1,prepend:[],append:[]}},log:rn(e.log,t.log,on,i)}}const cn={maxEntries:60,maxOutput:50,maxLog:30};var ln=class{store;replay;player;#e;#t;#n;#r={...cn};#i=`full`;#a=null;#o=`internal`;#s=null;#c=!1;#l=!0;#u=!0;#d=-1/0;#f=null;#p=null;#m=!1;#h=0;constructor(e,n){this.#e=e,this.#t=n?.now??(typeof performance<`u`?()=>performance.now():()=>Date.now()),this.#n=n?.defer??((e,t)=>{let n=setTimeout(e,t);return()=>clearTimeout(n)}),this.store=new t,this.replay=new Ft(this.store,{eager:!1}),this.player=new Lt(this.replay),this.#g({op:`ready`})}handle(e){if(this.#m)return;let t=typeof e==`object`&&e&&`id`in e&&typeof e.id==`number`?e.id:null;try{this.#_(e)}catch(e){this.#g({op:`error`,re:t,message:un(e)})}this.#x()}dispose(){this.#m=!0,this.#f!==null&&this.#f(),this.#p!==null&&this.#p(),this.#f=null,this.#p=null,this.player.dispose(),this.replay.dispose()}#g(e,t){this.#m||this.#e(e,t)}#_(e){if(typeof e!=`object`||!e)throw TypeError(`not a request`);switch(e.op){case`reset`:this.#h++,this.store.reset(),this.player.pause(),this.player.setFollow(!0),this.#y();break;case`events`:{let t=this.store.apply({base:e.base,events:e.events});if(t.rejected!==null)throw RangeError(t.rejected===`gap`?`events refused: the batch starts at ${e.base} but only ${t.length} events are known`:`events refused: the batch is not of the form { base, events }`);this.#y();break}case`ended`:this.store.end(),this.#y();break;case`open`:this.#v(e.id,Yt(e.data));break;case`openFragment`:this.#v(e.id,Qt(e.fragment));break;case`save`:{let t=e.id;Xt({header:e.header,events:this.store.events},{gzip:e.gzip===!0}).then(e=>this.#g({op:`saved`,re:t,bytes:e},e.buffer instanceof ArrayBuffer?[e.buffer]:void 0),e=>this.#g({op:`error`,re:t,message:un(e)}));break}case`share`:{let t=e.id;Zt({header:e.header,events:this.store.events}).then(e=>this.#g({op:`shared`,re:t,result:e}),e=>this.#g({op:`error`,re:t,message:un(e)}));break}case`player`:this.player.command(e.cmd),this.#l=!0;break;case`tick`:this.#o!==`external`&&(this.#o=`external`,this.#f!==null&&this.#f(),this.#f=null),this.#C(typeof e.now==`number`?e.now:this.#t());break;case`configure`:e.view!==void 0&&(this.#r={...this.#r,...e.view},this.#l=!0),(e.views===`full`||e.views===`patch`)&&(this.#i=e.views,this.#a=null,this.#l=!0),(e.clock===`external`||e.clock===`internal`)&&(this.#o=e.clock),e.timeline!==void 0&&(this.#s=e.timeline===null?null:{width:e.timeline.width,axis:e.timeline.axis===`time`?`time`:`index`},this.#u=!0,this.#d=-1/0),e.markers!==void 0&&(this.#c=e.markers===!0,this.#u=!0,this.#d=-1/0);break;case`query`:this.#g({op:`answer`,re:e.id,answer:this.replay.query(e.q)});break;default:throw TypeError(`unknown request`)}}#v(e,t){let n=++this.#h;t.then(t=>{this.#m||n!==this.#h||(this.store.load(t.events),this.player.pause(),this.#y(),this.#g({op:`opened`,re:e,header:t.header,events:t.events.length}),this.#x())},t=>this.#g({op:`error`,re:e,message:un(t)}))}#y(){this.#l=!0,this.#u=!0,this.#b()}#b(){this.#p!==null||this.#m||this.replay.ready>=this.store.length||(this.#p=this.#n(()=>{this.#p=null;let e=this.replay.pump(6);this.#l=!0,this.#u=!0,e&&this.#b(),this.#x()},0))}#x(){this.#m||this.#o!==`internal`||this.#f!==null||this.#S()&&(this.#f=this.#n(()=>{this.#f=null,this.#C(this.#t()),this.#x()},16))}#S(){if(this.#l||this.#u)return!0;let e=this.player.state;return e.playing||e.follow&&e.live&&e.position<e.length}#C(e){let t=this.player.tick(e);if(t.changed&&(this.#l=!0),this.#l){this.#l=!1;let e=this.replay.view(this.#r);this.#i===`patch`?(this.#g({op:`patch`,patch:sn(this.#a,e),player:t.state}),this.#a=e):this.#g({op:`view`,view:e,player:t.state})}this.#u&&(this.#s!==null||this.#c)?(!this.store.live&&this.replay.ready>=this.store.length||e-this.#d>=100)&&(this.#u=!1,this.#d=e,this.#s!==null&&this.#g({op:`timeline`,summary:this.replay.timeline(this.#s.width,this.#s.axis)}),this.#c&&this.#g({op:`markers`,markers:this.replay.markers()})):this.#s===null&&!this.#c&&(this.#u=!1)}};function un(e){return e instanceof Error?e.message:String(e)}const Z={uvRun:{id:`o:loop.run`,meaning:`uv_run: the event loop. Runs due timers once, then turns: pending, idle, prepare, poll, pending again, check, close, timers.`},phaseTimers:{id:`o:phase.timers`,meaning:`Timers phase: uv__run_timers runs every libuv timer whose time has come (Node uses one for all JS timers).`},phasePending:{id:`o:phase.pending`,meaning:`Pending phase: callbacks deferred from the previous turn; on Windows, completed I/O requests run here.`},phaseIdle:{id:`o:phase.idle`,meaning:`Idle phase: idle handles; Node keeps one active while immediates are queued so poll does not block.`},phasePrepare:{id:`o:phase.prepare`,meaning:`Prepare phase: prepare handles, just before the loop waits for I/O.`},phasePoll:{id:`o:phase.poll`,meaning:`Poll phase: waits for I/O (epoll, kqueue or IOCP) up to the next timer and runs what is ready.`},phaseCheck:{id:`o:phase.check`,meaning:`Check phase: check handles; Node runs setImmediate callbacks here.`},phaseClosing:{id:`o:phase.close`,meaning:`Close phase: close callbacks of handles closed during this turn.`},loopTime:{id:`o:loop.updateTime`,meaning:`The loop clock: libuv reads the time once per turn; timers compare against this cached time.`},spinEventLoop:{id:`o:loop.spin`,meaning:`Node's loop driver: calls uv_run until there is no more work, then emits beforeExit.`},tickEnqueue:{id:`o:tick.nextTick`,meaning:`process.nextTick: pushes a callback onto the nextTick queue.`},tickDrain:{id:`o:tick.drain`,meaning:`processTicksAndRejections: runs the nextTick queue, then microtasks, until both are empty.`},runNextTicks:{id:`o:tick.runNextTicks`,meaning:`runNextTicks: drains nextTicks and microtasks between two timer or immediate callbacks.`},microtaskEnqueue:{id:`o:microtask.queueMicrotask`,meaning:`queueMicrotask: puts a callback on V8's microtask queue.`},microtaskCallback:{id:`o:microtask.runCallback`,meaning:`runMicrotask: the wrapper that runs a queueMicrotask callback with async_hooks before/after.`},microtaskCheckpoint:{id:`o:microtask.checkpoint`,meaning:`MicrotaskQueue::PerformCheckpoint: V8 runs all queued microtasks if it is not already doing so.`},microtaskDrain:{id:`o:microtask.run`,meaning:`MicrotaskQueue::RunMicrotasks: V8 runs every queued microtask (promise reactions, queueMicrotask callbacks).`},runMicrotasksBinding:{id:`o:microtask.binding`,meaning:`runMicrotasks(): the C++ binding processTicksAndRejections calls to make V8 drain the microtask queue.`},promiseThen:{id:`o:v8.promiseThen`,meaning:`Promise.prototype.then (V8 Torque builtin).`},performPromiseThen:{id:`o:v8.performPromiseThen`,meaning:`PerformPromiseThen: stores the reaction, or queues a reaction job at once if the promise is already settled.`},triggerPromiseReactions:{id:`o:v8.triggerReactions`,meaning:`TriggerPromiseReactions: when a promise settles, turns each stored reaction into a queued job.`},promiseReactionEnqueue:{id:`o:v8.enqueueMicrotask`,meaning:`EnqueueMicrotask builtin: where a promise reaction job (or any microtask) is appended to the microtask queue.`},runMicrotasksBuiltin:{id:`o:v8.runMicrotasksBuiltin`,meaning:`RunMicrotasks builtin: the loop inside V8 that takes jobs off the microtask queue.`},runSingleMicrotask:{id:`o:v8.runSingleMicrotask`,meaning:`RunSingleMicrotask: runs one job, dispatching on its kind (callable, promise reaction, ...).`},promiseReactionRun:{id:`o:v8.promiseReactionJob`,meaning:`PromiseReactionJob: runs a .then/.catch handler with the settled value and settles the derived promise.`},timerSet:{id:`o:timers.setTimeout`,meaning:`setTimeout: creates a Timeout and inserts it into the timer lists.`},setInterval:{id:`o:timers.setInterval`,meaning:`setInterval: a Timeout that is re-inserted after each run.`},timerInsert:{id:`o:timers.insert`,meaning:`insert: appends the timer to the list for its duration; a new earliest list reschedules the libuv timer.`},scheduleTimer:{id:`o:timers.scheduleTimer`,meaning:`Environment::ScheduleTimer: starts the single libuv timer for the earliest JS timer.`},timersNative:{id:`o:timers.runTimers`,meaning:`Environment::RunTimers: the libuv timer callback; calls processTimers in JS and reschedules.`},timersProcess:{id:`o:timers.processTimers`,meaning:`processTimers: walks the due timer lists in expiry order.`},listOnTimeout:{id:`o:timers.listOnTimeout`,meaning:`listOnTimeout: runs each due timer of one list; nextTicks and microtasks run between timers.`},uvRunTimers:{id:`o:phase.timers`,meaning:`uv__run_timers: libuv runs timers whose timeout is not later than the loop time.`},immediateSet:{id:`o:immediate.setImmediate`,meaning:`setImmediate: creates an Immediate and appends it to the immediate queue.`},immediateNative:{id:`o:immediate.check`,meaning:`Environment::CheckImmediate: the check-phase callback that calls processImmediate.`},immediateProcess:{id:`o:immediate.process`,meaning:`processImmediate: runs the queued immediates; nextTicks and microtasks run between them.`},toggleImmediateRef:{id:`o:immediate.toggleRef`,meaning:`Environment::ToggleImmediateRef: starts/stops an idle handle so poll does not block while immediates wait.`},poolQueueWork:{id:`o:pool.queue_work`,meaning:`uv_queue_work: the public "run this function on the thread pool" call.`},poolSubmit:{id:`o:pool.submit`,meaning:`uv__work_submit: queues work for the pool (starts the threads on first use).`},poolPost:{id:`o:pool.post`,meaning:`post: appends to the shared work queue and wakes an idle pool thread.`},poolWorker:{id:`o:pool.worker`,meaning:`worker: a pool thread; waits, runs one work item, posts the result back.`},poolDone:{id:`o:pool.done`,meaning:`uv__work_done: on the main thread, runs the after-work callbacks of finished items.`},poolWake:{id:`o:pool.asyncSend`,meaning:`uv_async_send: wakes the loop from another thread (eventfd/pipe on Unix, a completion packet on Windows).`},scheduleWork:{id:`o:cb.ScheduleWork`,meaning:`ThreadPoolWork::ScheduleWork: Node's wrapper around uv_queue_work for fs, crypto and zlib jobs.`},asyncWrapMakeCallback:{id:`o:cb.MakeCallback`,meaning:`AsyncWrap::MakeCallback: calls a JS callback for an async resource (async_hooks before/after).`},makeCallback:{id:`o:cb.InternalMakeCallback`,meaning:`InternalMakeCallback: opens a callback scope, calls the function, closes the scope.`},callbackScopeClose:{id:`o:cb.ScopeClose`,meaning:`InternalCallbackScope::Close: after a callback, runs microtasks or the nextTick drain.`},inspectorPause:{id:`o:inspector.pause`,meaning:`runMessageLoopOnPause: the main thread waits here while a breakpoint holds JavaScript.`},fsReadFile:{id:`o:fs.readFile`,meaning:`fs.readFile: small files in one thread-pool job (ReadFileJob), large ones in chunks.`},fsReadFileJobRun:{id:`o:fs.ReadFileJob.Run`,meaning:`ReadFileJob::Run: schedules the whole read on the thread pool.`},fsReadFileJobWork:{id:`o:fs.ReadFileJob.DoThreadPoolWork`,meaning:`ReadFileJob::DoThreadPoolWork: open, fstat, read, close on a pool thread.`},fsReadFileJobAfter:{id:`o:fs.ReadFileJob.AfterThreadPoolWork`,meaning:`ReadFileJob::AfterThreadPoolWork: builds the Buffer and calls back into JS.`},fsReqCallback:{id:`o:fs.reqCallback`,meaning:`FSReqCallback::Resolve: delivers the result of an async fs request to its JS callback.`},fsReqPromise:{id:`o:fs.reqPromise`,meaning:`FSReqPromise::Resolve: settles the promise of an fs/promises request.`},cryptoPbkdf2:{id:`o:crypto.pbkdf2`,meaning:`crypto.pbkdf2: creates a PBKDF2Job and runs it on the thread pool.`},cryptoRandomBytes:{id:`o:crypto.randomBytes`,meaning:`crypto.randomBytes: creates a RandomBytesJob and runs it on the thread pool.`},cryptoJobRun:{id:`o:crypto.jobRun`,meaning:`CryptoJob::Run: runs a crypto job now (sync) or schedules it on the thread pool (async).`},cryptoDeriveBitsWork:{id:`o:crypto.deriveBitsWork`,meaning:`DeriveBitsJob::DoThreadPoolWork: the pool-thread side of pbkdf2, randomBytes, scrypt, hkdf...`},cryptoPbkdf2DeriveBits:{id:`o:crypto.pbkdf2DeriveBits`,meaning:`PBKDF2Traits::DeriveBits: the PBKDF2 computation (OpenSSL) on a pool thread.`},cryptoRandomBytesDeriveBits:{id:`o:crypto.randomBytesDeriveBits`,meaning:`RandomBytesTraits::DeriveBits: fills the buffer with random bytes on a pool thread.`},cryptoJobAfter:{id:`o:crypto.jobAfter`,meaning:`CryptoJob::AfterThreadPoolWork: back on the main thread, calls job.ondone in JS.`},zlibProcessChunk:{id:`o:zlib.processChunk`,meaning:`processChunk: hands one chunk to the native zlib handle (async write).`},zlibWrite:{id:`o:zlib.write`,meaning:`CompressionStream::Write: queues compression work on the thread pool.`},zlibWork:{id:`o:zlib.work`,meaning:`ZlibContext::DoThreadPoolWork: runs deflate/inflate on a pool thread.`},zlibAfter:{id:`o:zlib.after`,meaning:`CompressionStream::AfterThreadPoolWork: back on the main thread, calls the JS write callback.`},dnsLookup:{id:`o:dns.lookup`,meaning:`dns.lookup: asks the OS resolver (getaddrinfo) on the thread pool, not c-ares.`},dnsGetAddrInfo:{id:`o:dns.getAddrInfo`,meaning:`GetAddrInfo (C++): starts uv_getaddrinfo with AfterGetAddrInfo as callback.`},uvGetaddrinfo:{id:`o:dns.uvGetaddrinfo`,meaning:`uv_getaddrinfo: queues the lookup as slow I/O work on the thread pool.`},getaddrinfoWork:{id:`o:dns.getaddrinfoWork`,meaning:`uv__getaddrinfo_work: calls the OS getaddrinfo on a pool thread.`},dnsAfterGetAddrInfo:{id:`o:dns.afterGetAddrInfo`,meaning:`AfterGetAddrInfo: back on the main thread, converts the addresses and calls oncomplete in JS.`},streamRead:{id:`o:net.streamRead`,meaning:`LibuvStreamWrap::OnUvRead: data arrived on a TCP socket, pipe or TTY; calls onread in JS.`},streamAfterWrite:{id:`o:net.afterWrite`,meaning:`LibuvStreamWrap::AfterUvWrite: a write finished; calls the write callback.`},streamAfterShutdown:{id:`o:net.afterShutdown`,meaning:`LibuvStreamWrap::AfterUvShutdown: the write side was shut down.`},onConnection:{id:`o:net.onConnection`,meaning:`ConnectionWrap::OnConnection: a server accepted a connection.`},afterConnect:{id:`o:net.afterConnect`,meaning:`ConnectionWrap::AfterConnect: an outgoing connect finished.`},udpRecv:{id:`o:net.udpRecv`,meaning:`UDPWrap::OnRecv: a datagram arrived.`},processExit:{id:`o:proc.onExit`,meaning:`ProcessWrap::OnExit: a child process exited.`},fsEvent:{id:`o:fs.watchEvent`,meaning:`FSEventWrap::OnEvent: fs.watch saw a change.`},statWatcher:{id:`o:fs.statWatcher`,meaning:`StatWatcher::Callback: fs.watchFile polled a changed stat.`},httpIncoming:{id:`o:http.incoming`,meaning:`IncomingMessage: a received HTTP request (server) or response (client).`},httpClientRequest:{id:`o:http.clientRequest`,meaning:`ClientRequest: an outgoing HTTP request.`},udpSendDone:{id:`o:net.udpSendDone`,meaning:`UDPWrap::OnSendDone: a datagram send finished; calls oncomplete in JS.`},dnsChannel:{id:`o:dns.channel`,meaning:`ChannelWrap::New: creates the c-ares resolver channel used by dns.resolve* and dns.Resolver.`},dnsQueryResponse:{id:`o:dns.queryResponse`,meaning:`QueryWrap::QueueResponseCallback: defers a c-ares answer with SetImmediate, so its callback runs in the check phase.`},nativeImmediatesRun:{id:`o:immediate.native`,meaning:`Environment::RunAndClearNativeImmediates: runs C++ SetImmediate callbacks (such as c-ares answers) from CheckImmediate.`},streamShutdownQueue:{id:`o:uv.shutdown`,meaning:`uv_shutdown: on Unix, with no writes pending, puts the stream on the pending queue (uv__io_feed); on Windows (TCP), queues a pending request.`},streamShutdownRun:{id:`o:uv.shutdownDone`,meaning:`Where the shutdown callback runs: uv__drain on Unix (from the pending phase), uv__process_tcp_shutdown_req on Windows (TCP).`},uvClose:{id:`o:loop.uvClose`,meaning:`uv_close: starts closing a handle; its close callback always runs later, in the close phase.`},closeCallbacks:{id:`o:loop.finishClose`,meaning:`Where a close callback runs: uv__finish_close (called by uv__run_closing_handles) on Unix, uv__process_endgames on Windows.`},handleOnClose:{id:`o:cb.handleOnClose`,meaning:`HandleWrap::OnClose: Node's close callback for every handle; calls the JS handle's onclose.`},streamFinished:{id:`o:streams.eos`,meaning:`eos (stream.finished): calls back once a stream has ended, finished or errored; used by pipeline.`},messagePortOnMessage:{id:`o:worker.onMessage`,meaning:`MessagePort::OnMessage: delivers queued messages from another thread to the JS listener of the port.`},workerExit:{id:`o:worker.onExit`,meaning:`Worker::JoinThread: after the worker thread stopped, calls onexit in the parent thread.`}};Z.phaseTimers.id,Z.phasePending.id,Z.phaseIdle.id,Z.phasePrepare.id,Z.phasePoll.id,Z.phaseCheck.id,Z.phaseClosing.id;const dn={Timeout:{id:Z.listOnTimeout.id,title:`setTimeout / setInterval timer`,meaning:`setTimeout / setInterval timer; its callback runs from listOnTimeout.`},Immediate:{id:Z.immediateProcess.id,title:`setImmediate`,meaning:`setImmediate; its callback runs from processImmediate in the check phase.`},TickObject:{id:Z.tickDrain.id,title:`process.nextTick`,meaning:`process.nextTick; its callback runs from processTicksAndRejections.`},PROMISE:{id:Z.promiseReactionRun.id,title:`promise`,meaning:`A promise (reported while an async hook is enabled); its reactions run as microtasks.`},Microtask:{id:Z.microtaskCallback.id,title:`queueMicrotask`,meaning:`queueMicrotask callback; runs from the microtask queue via runMicrotask.`},FSREQCALLBACK:{id:Z.fsReqCallback.id,title:`fs request (callback)`,meaning:`Callback-style fs request. fs.readFile's ReadFileJob reports this type too (its callback comes from ReadFileJob::AfterThreadPoolWork).`},FSREQPROMISE:{id:Z.fsReqPromise.id,title:`fs/promises request`,meaning:`fs/promises request.`},PBKDF2REQUEST:{id:Z.cryptoJobAfter.id,title:`pbkdf2 request`,meaning:`crypto.pbkdf2 job; work in PBKDF2Traits::DeriveBits on the pool.`},RANDOMBYTESREQUEST:{id:Z.cryptoJobAfter.id,title:`randomBytes request`,meaning:`crypto.randomBytes / randomFill job; work in RandomBytesTraits::DeriveBits on the pool.`},SCRYPTREQUEST:{id:Z.cryptoJobAfter.id,title:`scrypt request`,meaning:`crypto.scrypt job on the pool.`},GETADDRINFOREQWRAP:{id:Z.dnsAfterGetAddrInfo.id,title:`dns.lookup request`,meaning:`dns.lookup request; getaddrinfo runs on the pool.`},ZLIB:{id:Z.zlibAfter.id,title:`zlib stream`,meaning:`zlib stream; each chunk is compressed on the pool.`},TCPWRAP:{id:Z.streamRead.id,title:`TCP connection`,meaning:`TCP socket handle; reads arrive in the poll phase.`},TCPSERVERWRAP:{id:Z.onConnection.id,title:`TCP server`,meaning:`TCP server handle; new connections arrive in the poll phase.`},TCPCONNECTWRAP:{id:Z.afterConnect.id,title:`TCP connect request`,meaning:`Outgoing TCP connect request.`},PIPEWRAP:{id:Z.streamRead.id,title:`pipe`,meaning:`Pipe handle (also stdio pipes).`},PIPECONNECTWRAP:{id:Z.afterConnect.id,title:`pipe connect request`,meaning:`Outgoing pipe connect request.`},TTYWRAP:{id:Z.streamRead.id,title:`terminal (TTY)`,meaning:`TTY handle (terminal stdio).`},WRITEWRAP:{id:Z.streamAfterWrite.id,title:`stream write`,meaning:`A stream write request.`},SHUTDOWNWRAP:{id:Z.streamAfterShutdown.id,title:`stream shutdown`,meaning:`A stream shutdown request; on Unix uv__drain runs its callback - in the pending phase when no write was waiting, else in poll after the last write.`},UDPWRAP:{id:Z.udpRecv.id,title:`UDP socket`,meaning:`UDP socket handle.`},PROCESSWRAP:{id:Z.processExit.id,title:`child process`,meaning:`Child process handle.`},FSEVENTWRAP:{id:Z.fsEvent.id,title:`fs.watch watcher`,meaning:`fs.watch handle.`},STATWATCHER:{id:Z.statWatcher.id,title:`fs.watchFile watcher`,meaning:`fs.watchFile handle.`},HTTPINCOMINGMESSAGE:{id:Z.httpIncoming.id,title:`HTTP incoming message`,meaning:`HTTP incoming message (server request or client response).`},QUERYWRAP:{id:Z.dnsQueryResponse.id,title:`DNS query (dns.resolve*)`,meaning:`A c-ares query; the answer is deferred with SetImmediate, so the callback runs in the check phase.`},DNSCHANNEL:{id:Z.dnsChannel.id,title:`DNS resolver (c-ares)`,meaning:`The c-ares channel behind dns.resolve* and dns.Resolver; created when the dns module loads.`},PIPESERVERWRAP:{id:Z.onConnection.id,title:`pipe server`,meaning:`Pipe (named pipe / Unix socket) server handle; new connections arrive in the poll phase.`},UDPSENDWRAP:{id:Z.udpSendDone.id,title:`UDP send`,meaning:`A UDP send request.`},STREAM_END_OF_STREAM:{id:Z.streamFinished.id,title:`stream finished callback`,meaning:`stream.finished / pipeline callback, bound to the context where it was registered.`},MESSAGEPORT:{id:Z.messagePortOnMessage.id,title:`MessagePort (worker messages)`,meaning:`A message channel between threads; messages are delivered by MessagePort::OnMessage.`},WORKER:{id:Z.workerExit.id,title:`worker thread`,meaning:`A worker_threads Worker as seen from the parent thread.`},HTTPCLIENTREQUEST:{id:Z.httpClientRequest.id,title:`HTTP client request`,meaning:`HTTP client request.`}};Object.fromEntries(Object.entries(dn).map(([e,t])=>[e,t.id]));const fn={nextTick:`nextTick queue`,microtask:`Microtask queue`,timers:`Timers`,immediate:`Immediates`,pool:`Thread pool requests`,io:`Pending I/O`,close:`Close callbacks`},pn={timers:`timers`,pending:`pending`,idle:`idle`,prepare:`prepare`,poll:`poll`,check:`check`,closing:`close`},mn=new Intl.NumberFormat(`en`,{maximumFractionDigits:1,minimumFractionDigits:1}),hn=new Intl.NumberFormat(`en`,{maximumFractionDigits:3,minimumFractionDigits:3}),gn=new Intl.NumberFormat(`en`,{maximumFractionDigits:0});function _n(e){if(!Number.isFinite(e))return`-`;let t=Math.abs(e);return t<1e3?`${gn.format(e)} µs`:t<1e6?`${hn.format(e/1e3)} ms`:`${hn.format(e/1e6)} s`}function Q(e){return Number.isFinite(e)?Math.abs(e)<1e3?`${mn.format(e)} ms`:`${mn.format(e/1e3)} s`:`-`}function vn(e){let t=e.replace(/[?#].*$/,``).split(/[\\/]/);for(let e=t.length-1;e>=0;e--){let n=t[e];if(n)try{return decodeURIComponent(n)}catch{return n}}return e}function $(e,t=160){let n=``;for(let r of e){if(n.length>=t)return`${n}…`;let e=r.codePointAt(0);n+=r===`
7
+ `?`⏎`:r===` `?` `:e<32||e===127?`�`:r}return n}const yn=[`run`,`output`,`callbacks`,`queues`,`loop`,`timers`,`pool`,`items`,`debug`,`signals`],bn={"run.start":`run`,"run.end":`run`,note:`run`,output:`output`,"item.new":`items`,"item.gone":`items`,"promise.settled":`items`,"callback.start":`callbacks`,"callback.end":`callbacks`,"timer.set":`timers`,"timer.fired":`timers`,"loop.sample":`signals`,scope:`signals`,"pool.thread":`signals`,signal:`signals`,"queue.add":`queues`,"queue.remove":`queues`,"loop.turn":`loop`,"phase.enter":`loop`,"phase.leave":`loop`,"pool.queued":`pool`,"pool.started":`pool`,"pool.finished":`pool`,"pool.posted":`pool`,"pool.delivered":`pool`,"pool.cancelled":`pool`,"pool.size":`pool`,"pool.link":`pool`,"debug.paused":`debug`,"debug.resumed":`debug`,"gate.stopped":`debug`,"gate.released":`debug`,"clock.frozen":`debug`,"clock.unfrozen":`debug`};function xn(e){switch(e.k){case`run.start`:return`Run started: ${$(e.program,60)} on Node ${e.node.version} (${e.mode===`debug`?`debug`:`free run`}, pool size ${e.poolSize})`;case`run.end`:return e.signal?`Run ended by signal ${e.signal}`:`Run ended with exit code ${String(e.code)}`;case`output`:return`${e.stream}: ${$(e.text,120)}`;case`item.new`:return`New ${e.label?`${$(e.label,40)} (${e.type})`:e.type} #${e.id}, created during #${e.trigger}${e.loc?` at ${vn(e.loc.url)}:${e.loc.line}`:``}`;case`callback.start`:return`${e.close===!0?`Close callback`:`Callback`} of ${e.type} #${e.id} started`;case`callback.end`:return`Callback of #${e.id} returned`;case`item.gone`:return`#${e.id} destroyed`;case`promise.settled`:return`Promise #${e.id} settled`;case`timer.set`:return`${e.repeat?`setInterval`:`setTimeout`} #${e.id}: ${Q(e.delayMs)}`;case`loop.sample`:return`Loop counters: turn ${e.loopCount}, ${e.events} events, ${e.eventsWaiting} waiting`;case`scope`:return`Node scope ${$(e.name,40)} lasted ${_n(e.durUs)}`;case`pool.thread`:return`A pool thread ${e.edge===`start`?`started`:`finished`} ${$(e.name,40)}`;case`signal`:return`${$(e.cat,40)} / ${$(e.name,40)} (${$(e.ph,4)})`;case`queue.add`:return`#${e.id} waits in ${fn[e.queue]??e.queue}`;case`queue.remove`:return`#${e.id} left ${fn[e.queue]??e.queue} (${e.why===`cancel`?`cancelled`:`gone`})`;case`loop.turn`:return`Loop turn ${e.n}`;case`phase.enter`:return`Entered the ${pn[e.phase]??e.phase} phase`;case`phase.leave`:return`Left the ${pn[e.phase]??e.phase} phase`;case`timer.fired`:return`Node's timer is due${e.lateMs===void 0?``:`, ${Q(e.lateMs)} late`}`;case`pool.queued`:return`Pool job ${$(e.job,24)} queued (${e.kind}${e.op?` ${$(e.op,30)}`:``})`;case`pool.started`:return`Pool thread ${e.thread} started job ${$(e.job,24)}`;case`pool.finished`:return`Pool thread ${e.thread} finished job ${$(e.job,24)}`;case`pool.posted`:return`Pool thread ${e.thread} posted the result of job ${$(e.job,24)} to the loop`;case`pool.delivered`:return`The loop took the result of pool job ${$(e.job,24)}`;case`pool.cancelled`:return`Pool job ${$(e.job,24)} was cancelled before a thread took it`;case`pool.size`:return`The thread pool has ${e.size} threads (the program changed the size before first use)`;case`pool.link`:return`Pool job ${$(e.job,24)} belongs to #${e.id}`;case`debug.paused`:{let t=e.frames[0];return`Paused (${e.reason})${t?` at ${vn(t.loc.url)}:${t.loc.line}`:``}`}case`debug.resumed`:return`Resumed after ${Q(e.pausedMs)}`;case`gate.stopped`:return`Stopped at the ${e.gate} gate${e.phase?` (${pn[e.phase]??e.phase})`:``}`;case`gate.released`:return`Gate released after ${Q(e.stoppedMs)}`;case`clock.frozen`:return`Loop clock frozen`;case`clock.unfrozen`:return`Loop clock running again; ${Q(e.hiddenMs)} hidden from the program`;case`note`:return`${e.level===`warn`?`Warning from the tool`:`Note from the tool`}: ${$(e.text,220)}`;default:return String(e.k)}}const Sn={groups:yn,certainty:[`observed`,`inferred`,`model`]};function Cn(e){return e.loc!==void 0||e.k===`debug.paused`&&e.frames.length>0}const wn={observed:1,inferred:2,model:4};function Tn(e){return`${[...e.groups].sort().join(`,`)}|${[...e.certainty].sort().join(`,`)}`}function En(e,t){let n;try{n=xn(e)}catch{n=String(e.k)}return{index:t,t:e.t,k:e.k,c:e.c,src:e.src,rule:e.rule??null,at:e.at??null,approx:e.tq!==void 0,text:n}}function Dn(e){switch(e.k){case`run.start`:return`running`;case`run.end`:return`ended`;case`debug.paused`:return`paused`;case`gate.stopped`:return`gated`;case`debug.resumed`:case`gate.released`:return`running`;default:return null}}var On=class{#e=[];#t=/* @__PURE__ */ new Uint32Array(1024);#n=0;#r=0;#i=Tn(Sn);#a=new Set(yn);#o=7;#s=!0;#c=[];#l=null;#u=-1;get length(){return this.#e.length}reset(){this.#e=[],this.#n=0,this.#r=0,this.#c=[],this.#l=null,this.#u=-1}apply(e,t){if(!Number.isInteger(e)||e<0||e>this.#e.length)return!1;if(e<this.#e.length){if(this.#e.length=e,this.#r>e){this.#r=e;let t=this.#n;for(;t>0&&this.#t[t-1]>=e;)t--;this.#n=t}for(;this.#c.length>0&&this.#c[this.#c.length-1][0]>=e;)this.#c.pop();this.#u>=e&&(this.#u=-1)}for(let e=0;e<t.length;e++){let n=t[e],r=this.#e.length;if(this.#e.push(n),typeof n!=`object`||!n)continue;let i=Dn(n);i&&this.#c.push([r,i]),n.k===`run.start`&&(this.#l=n.mode===`debug`?`debug`:`free`),this.#u<0&&Cn(n)&&(this.#u=r)}return!0}steps(){let e=0;for(let t of this.#e)typeof t==`object`&&t&&!l.has(t.k)&&e++;return e}tail(){let e=this.#c[this.#c.length-1],t=0;for(let[,e]of this.#c)(e===`paused`||e===`gated`)&&t++;return{status:e?e[1]:`idle`,mode:this.#l,length:this.#e.length,pauses:t,located:this.#u>=0}}#d(e){if(typeof e!=`object`||!e)return this.#s;if(this.#s)return!0;let t=bn[e.k];return t!==void 0&&!this.#a.has(t)?!1:((wn[e.c]??0)&this.#o)!==0}#f(e){let t=Tn(e);t!==this.#i&&(this.#i=t,this.#a=new Set(e.groups),this.#o=e.certainty.reduce((e,t)=>e|(wn[t]??0),0),this.#s=this.#a.size===yn.length&&this.#o===7,this.#n=0,this.#r=0)}#p(){if(this.#s)this.#r=this.#e.length;else{for(let e=this.#r;e<this.#e.length;e++)if(this.#d(this.#e[e])){if(this.#n===this.#t.length){let e=new Uint32Array(this.#t.length*2);e.set(this.#t),this.#t=e}this.#t[this.#n++]=e}this.#r=this.#e.length}}#m(e){if(this.#s)return Math.min(e,this.#e.length)-1;let t=0,n=this.#n;for(;t<n;){let r=t+n>>1;this.#t[r]<e?t=r+1:n=r}return t-1}window(e,t,n,r){this.#f(e),this.#p();let i=this.#s?this.#e.length:this.#n,a=Math.max(0,Math.min(Math.trunc(t),i)),o=Math.max(a,Math.min(a+Math.max(0,Math.min(Math.trunc(n),500)),i)),s=[];for(let e=a;e<o;e++){let t=this.#s?e:this.#t[e],n=this.#e[t];if(n===void 0)break;s.push(typeof n==`object`&&n?En(n,t):{index:t,t:0,k:`?`,c:`model`,src:`helper`,rule:null,at:null,approx:!1,text:`Malformed event`})}return{total:i,offset:a,rows:s,cursorRow:this.#m(r),length:this.#e.length,all:this.#s,position:r}}eventAt(e){return this.#e[e]??null}};function kn(e){if(typeof e!=`object`||!e)return!1;let t=e;return t.op===`events`&&typeof t.run==`string`&&typeof t.base==`number`&&Array.isArray(t.events)}function An(e){return e instanceof Error?e.message:String(e)}const jn=5e3;var Mn=class{#e;#t;#n=new On;#r=null;#i=!1;#a=/* @__PURE__ */ new Set;#o=``;#s=0;constructor(e,t){this.#e=e,this.#t=new ln((t,n)=>e(t,n),t)}handle(e){try{e.op.startsWith(`app.`)?this.#u(e):(this.#t.handle(e),e.op===`tick`&&this.#e({op:`app.ticked`}))}catch(t){this.#e({op:`app.error`,re:`id`in e&&typeof e.id==`number`?e.id:null,message:An(t)})}}dispose(){this.#t.dispose()}#c(){this.#s++,this.#r!==null&&this.#a.add(this.#r),this.#r=null,this.#i=!1,this.#n.reset(),this.#t.handle({op:`reset`})}#l(){let e=this.#n.tail(),t=`${e.status}|${String(e.mode)}|${String(this.#r)}|${e.pauses}|${String(e.located)}`;t!==this.#o&&(this.#o=t,this.#e({op:`app.tail`,tail:e,run:this.#r}))}#u(e){switch(e.op){case`app.newRun`:this.#c(),this.#i=!0,this.#l();return;case`app.run`:if(this.#a.has(e.run))return;(this.#i||this.#r===null)&&(this.#r=e.run,this.#i=!1,this.#l());return;case`app.eventsText`:{let t;try{t=JSON.parse(e.text)}catch{this.#e({op:`app.error`,re:null,message:`The helper sent an events message that is not valid JSON.`});return}if(!kn(t)||this.#a.has(t.run))return;if(this.#r===null){if(!this.#i)return;this.#r=t.run,this.#i=!1}else if(t.run!==this.#r)return;if(!this.#n.apply(t.base,t.events)){this.#e({op:`app.error`,re:null,message:`Events from the helper arrived with a gap; the view may be incomplete.`});return}this.#t.handle({op:`events`,base:t.base,events:t.events}),this.#l();return}case`app.runEnded`:{let t=e.run===this.#r;t&&this.#t.handle({op:`ended`}),this.#e({op:`app.runFinal`,re:e.id,current:t,length:t?this.#n.length:0,steps:t?this.#n.steps():0,pauses:t?this.#n.tail().pauses:0});return}case`app.open`:this.#d(e.id,()=>Yt(e.data));return;case`app.openFragment`:this.#d(e.id,()=>Qt(e.fragment));return;case`app.close`:this.#c(),this.#l();return;case`app.log`:this.#e({op:`app.log`,re:e.id,window:this.#n.window(e.filter,e.offset,e.limit,e.position)});return}}async#d(e,t){this.#c();let n=this.#s,r;try{r=await t()}catch(t){this.#e({op:`app.error`,re:e,message:An(t)});return}if(n!==this.#s)this.#e({op:`app.error`,re:e,message:`Opening was cancelled: another run or recording was opened meanwhile.`});else try{let t=r.events;this.#t.handle({op:`player`,cmd:{do:`follow`,on:!1}}),this.#t.handle({op:`player`,cmd:{do:`pause`}});for(let e=0;e<t.length||e===0;e+=jn){let n=t.slice(e,e+jn);if(this.#n.apply(e,n),this.#t.handle({op:`events`,base:e,events:n}),t.length===0)break}this.#t.handle({op:`ended`}),this.#t.handle({op:`player`,cmd:{do:`seek`,position:0}}),this.#e({op:`app.opened`,re:e,header:r.header,events:t.length}),this.#l()}catch(t){this.#e({op:`app.error`,re:e,message:An(t)})}}};const Nn=globalThis,Pn=new Mn((e,t)=>Nn.postMessage(e,t??[]));Nn.addEventListener(`message`,e=>Pn.handle(e.data));
8
+ //# sourceMappingURL=app.worker-DZKurLgd.js.map