synabun 2.0.9 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (679) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/README.md +25 -2
  3. package/THIRD-PARTY-LICENSES.md +68 -4
  4. package/bin/synabun.js +71 -24
  5. package/docs/whatsapp.md +2 -2
  6. package/hooks/claude-code/pre-websearch.mjs +12 -1
  7. package/hooks/claude-code/shared.mjs +5 -0
  8. package/hooks/claude-code/stop.mjs +1 -1
  9. package/launcher.mjs +9 -3
  10. package/lib/claude-hooks.js +172 -18
  11. package/lib/client-config-repair.js +17 -8
  12. package/lib/desktop-app.js +7 -1
  13. package/lib/external-tools.js +1 -1
  14. package/lib/first-launch-protection.js +57 -12
  15. package/lib/mcp-dist.js +176 -0
  16. package/lib/release-npm-ci.mjs +138 -0
  17. package/lib/release-publish.mjs +91 -0
  18. package/lib/release-scan.mjs +50 -0
  19. package/lib/server-crash-record.js +123 -0
  20. package/lib/server-exit.js +318 -0
  21. package/lib/server-supervisor.js +508 -0
  22. package/lib/start-launcher.js +43 -5
  23. package/lib/tools-cli.js +45 -0
  24. package/lib/update-snapshot.js +228 -0
  25. package/lib/virustotal.mjs +192 -0
  26. package/lib/windows-crash-event.js +269 -0
  27. package/mcp-server/dist/http.d.ts +20 -1
  28. package/mcp-server/dist/http.d.ts.map +1 -1
  29. package/mcp-server/dist/http.js +59 -12
  30. package/mcp-server/dist/http.js.map +1 -1
  31. package/mcp-server/dist/index.d.ts +33 -27
  32. package/mcp-server/dist/index.d.ts.map +1 -1
  33. package/mcp-server/dist/index.js +128 -143
  34. package/mcp-server/dist/index.js.map +1 -1
  35. package/mcp-server/dist/preload.js +1 -1
  36. package/mcp-server/dist/preload.js.map +1 -1
  37. package/mcp-server/dist/services/codex-config-heal.d.ts +6 -2
  38. package/mcp-server/dist/services/codex-config-heal.d.ts.map +1 -1
  39. package/mcp-server/dist/services/codex-config-heal.js +81 -28
  40. package/mcp-server/dist/services/codex-config-heal.js.map +1 -1
  41. package/mcp-server/dist/services/memory-judge-backfill.d.ts +6 -0
  42. package/mcp-server/dist/services/memory-judge-backfill.d.ts.map +1 -1
  43. package/mcp-server/dist/services/memory-judge-backfill.js +7 -1
  44. package/mcp-server/dist/services/memory-judge-backfill.js.map +1 -1
  45. package/mcp-server/dist/services/neural-interface.d.ts +16 -10
  46. package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
  47. package/mcp-server/dist/services/neural-interface.js +67 -11
  48. package/mcp-server/dist/services/neural-interface.js.map +1 -1
  49. package/mcp-server/dist/services/server-instructions.d.ts +7 -2
  50. package/mcp-server/dist/services/server-instructions.d.ts.map +1 -1
  51. package/mcp-server/dist/services/server-instructions.js +20 -62
  52. package/mcp-server/dist/services/server-instructions.js.map +1 -1
  53. package/mcp-server/dist/services/tool-catalog.d.ts +120 -0
  54. package/mcp-server/dist/services/tool-catalog.d.ts.map +1 -0
  55. package/mcp-server/dist/services/tool-catalog.js +339 -0
  56. package/mcp-server/dist/services/tool-catalog.js.map +1 -0
  57. package/mcp-server/dist/services/tool-list-refresh-barrier.d.ts +12 -0
  58. package/mcp-server/dist/services/tool-list-refresh-barrier.d.ts.map +1 -0
  59. package/mcp-server/dist/services/tool-list-refresh-barrier.js +40 -0
  60. package/mcp-server/dist/services/tool-list-refresh-barrier.js.map +1 -0
  61. package/mcp-server/dist/services/tool-list.d.ts +108 -0
  62. package/mcp-server/dist/services/tool-list.d.ts.map +1 -0
  63. package/mcp-server/dist/services/tool-list.js +334 -0
  64. package/mcp-server/dist/services/tool-list.js.map +1 -0
  65. package/mcp-server/dist/services/tool-runtime.d.ts +161 -0
  66. package/mcp-server/dist/services/tool-runtime.d.ts.map +1 -0
  67. package/mcp-server/dist/services/tool-runtime.js +400 -0
  68. package/mcp-server/dist/services/tool-runtime.js.map +1 -0
  69. package/mcp-server/dist/services/whiteboard-geometry.d.ts +26 -2
  70. package/mcp-server/dist/services/whiteboard-geometry.d.ts.map +1 -1
  71. package/mcp-server/dist/services/whiteboard-geometry.js +91 -8
  72. package/mcp-server/dist/services/whiteboard-geometry.js.map +1 -1
  73. package/mcp-server/dist/tools/agents.d.ts +10 -10
  74. package/mcp-server/dist/tools/agents.d.ts.map +1 -1
  75. package/mcp-server/dist/tools/agents.js +22 -13
  76. package/mcp-server/dist/tools/agents.js.map +1 -1
  77. package/mcp-server/dist/tools/browser-batch.d.ts +3 -3
  78. package/mcp-server/dist/tools/image-tools.d.ts +1 -1
  79. package/mcp-server/dist/tools/image-tools.js +1 -1
  80. package/mcp-server/dist/tools/skill-tools.d.ts +505 -0
  81. package/mcp-server/dist/tools/skill-tools.d.ts.map +1 -0
  82. package/mcp-server/dist/tools/skill-tools.js +639 -0
  83. package/mcp-server/dist/tools/skill-tools.js.map +1 -0
  84. package/mcp-server/dist/tools/skill.d.ts +7 -0
  85. package/mcp-server/dist/tools/skill.d.ts.map +1 -0
  86. package/mcp-server/dist/tools/skill.js +11 -0
  87. package/mcp-server/dist/tools/skill.js.map +1 -0
  88. package/mcp-server/dist/tools/tool-groups.d.ts +68 -0
  89. package/mcp-server/dist/tools/tool-groups.d.ts.map +1 -0
  90. package/mcp-server/dist/tools/tool-groups.js +147 -0
  91. package/mcp-server/dist/tools/tool-groups.js.map +1 -0
  92. package/mcp-server/dist/tools/whiteboard-format.d.ts.map +1 -1
  93. package/mcp-server/dist/tools/whiteboard-format.js +7 -4
  94. package/mcp-server/dist/tools/whiteboard-format.js.map +1 -1
  95. package/mcp-server/dist/tools/whiteboard-tools.d.ts +64 -13
  96. package/mcp-server/dist/tools/whiteboard-tools.d.ts.map +1 -1
  97. package/mcp-server/dist/tools/whiteboard-tools.js +30 -5
  98. package/mcp-server/dist/tools/whiteboard-tools.js.map +1 -1
  99. package/mcp-server/package-lock.json +2 -2
  100. package/mcp-server/package.json +1 -1
  101. package/mcp-server/src/http.ts +75 -12
  102. package/mcp-server/src/index.ts +147 -154
  103. package/mcp-server/src/preload.ts +12 -12
  104. package/mcp-server/src/services/codex-config-heal.ts +80 -29
  105. package/mcp-server/src/services/memory-judge-backfill.ts +7 -1
  106. package/mcp-server/src/services/neural-interface.ts +79 -20
  107. package/mcp-server/src/services/server-instructions.ts +27 -63
  108. package/mcp-server/src/services/tool-catalog.ts +403 -0
  109. package/mcp-server/src/services/tool-list-refresh-barrier.ts +33 -0
  110. package/mcp-server/src/services/tool-list.ts +410 -0
  111. package/mcp-server/src/services/tool-runtime.ts +457 -0
  112. package/mcp-server/src/services/whiteboard-geometry.ts +94 -9
  113. package/mcp-server/src/tools/agents.ts +22 -14
  114. package/mcp-server/src/tools/image-tools.ts +1 -1
  115. package/mcp-server/src/tools/skill-tools.ts +589 -0
  116. package/mcp-server/src/tools/skill.ts +13 -0
  117. package/mcp-server/src/tools/tool-groups.ts +164 -0
  118. package/mcp-server/src/tools/whiteboard-format.ts +9 -3
  119. package/mcp-server/src/tools/whiteboard-tools.ts +39 -5
  120. package/neural-interface/i18n/en.json +3680 -206
  121. package/neural-interface/i18n/pt-BR.json +3628 -157
  122. package/neural-interface/lib/account-usage.js +5 -3
  123. package/neural-interface/lib/app-controls-api.js +161 -0
  124. package/neural-interface/lib/assistant-api.js +148 -35
  125. package/neural-interface/lib/assistant-brains/claude.js +4 -3
  126. package/neural-interface/lib/assistant-brains/codex-browser-policy-hook.mjs +12 -2
  127. package/neural-interface/lib/assistant-brains/codex-route-gate-hook.mjs +32 -9
  128. package/neural-interface/lib/assistant-brains/codex.js +9 -5
  129. package/neural-interface/lib/assistant-brains/opencode.js +122 -44
  130. package/neural-interface/lib/assistant-brains/opencode2-browser-policy/index.js +59 -0
  131. package/neural-interface/lib/assistant-brains/opencode2-route-gate/index.js +97 -0
  132. package/neural-interface/lib/assistant-catalog.js +23 -9
  133. package/neural-interface/lib/assistant-dispatch.js +874 -156
  134. package/neural-interface/lib/assistant-envelope.js +22 -2
  135. package/neural-interface/lib/assistant-persona.js +80 -11
  136. package/neural-interface/lib/assistant-plan-permissions.js +10 -9
  137. package/neural-interface/lib/assistant-route-gate-codex.js +3 -0
  138. package/neural-interface/lib/assistant-route-gate.js +6 -4
  139. package/neural-interface/lib/assistant-router.js +13 -8
  140. package/neural-interface/lib/assistant-runtime.js +183 -26
  141. package/neural-interface/lib/assistant-task-prompt.js +78 -14
  142. package/neural-interface/lib/assistant-tools.js +51 -0
  143. package/neural-interface/lib/backup-service.js +620 -3
  144. package/neural-interface/lib/backup-zip-reader.js +10 -5
  145. package/neural-interface/lib/backup-zip-writer.js +257 -0
  146. package/neural-interface/lib/browser-execution.js +10 -2
  147. package/neural-interface/lib/browser-guard-cdp.js +83 -0
  148. package/neural-interface/lib/browser-network-guard.js +284 -0
  149. package/neural-interface/lib/browser-policy-roots.js +64 -0
  150. package/neural-interface/lib/browser-tool-policy.js +186 -31
  151. package/neural-interface/lib/claude-agent-bridge.js +4 -2
  152. package/neural-interface/lib/claude-hooks-status.js +103 -0
  153. package/neural-interface/lib/claude-model-catalog.js +64 -14
  154. package/neural-interface/lib/claude-temporary.js +5 -11
  155. package/neural-interface/lib/cli-install.js +18 -138
  156. package/neural-interface/lib/cli-resolver.js +4 -1
  157. package/neural-interface/lib/cli-update-planner.js +32 -31
  158. package/neural-interface/lib/cloudflared/tunnel.js +42 -2
  159. package/neural-interface/lib/codex-mcp-approvals.js +11 -0
  160. package/neural-interface/lib/codex-settings-schema.js +109 -47
  161. package/neural-interface/lib/codex-worker-app-server.js +172 -0
  162. package/neural-interface/lib/confined-fs.js +30 -3
  163. package/neural-interface/lib/crash-notice-api.js +98 -0
  164. package/neural-interface/lib/editor-completion-opencode.js +164 -67
  165. package/neural-interface/lib/exec-loop-command.js +4 -1
  166. package/neural-interface/lib/http-guards.js +8 -2
  167. package/neural-interface/lib/install-details.js +4 -1
  168. package/neural-interface/lib/launch-cache.js +293 -0
  169. package/neural-interface/lib/login-start.js +524 -0
  170. package/neural-interface/lib/mcp-agent-servers.js +67 -0
  171. package/neural-interface/lib/mcp-client-config.js +0 -29
  172. package/neural-interface/lib/mcp-external-servers.js +323 -0
  173. package/neural-interface/lib/{mcp-profile-refresh-coordinator.js → mcp-tools-refresh-coordinator.js} +4 -4
  174. package/neural-interface/lib/morelogin.js +30 -0
  175. package/neural-interface/lib/native-loop-providers.js +565 -50
  176. package/neural-interface/lib/native-loop-runtime.js +287 -41
  177. package/neural-interface/lib/opencode-config.js +557 -0
  178. package/neural-interface/lib/opencode-db-schema.js +58 -0
  179. package/neural-interface/lib/opencode-history.js +49 -204
  180. package/neural-interface/lib/opencode-mcp-ready.js +108 -0
  181. package/neural-interface/lib/opencode-native-boundary.js +44 -0
  182. package/neural-interface/lib/opencode-protocol.js +310 -0
  183. package/neural-interface/lib/opencode-provider-view.js +81 -0
  184. package/neural-interface/lib/opencode-runtime-config.js +32 -15
  185. package/neural-interface/lib/opencode-serve-records.js +624 -0
  186. package/neural-interface/lib/opencode-v2-client.js +53 -131
  187. package/neural-interface/lib/opencode-v2-ws-requests.js +35 -195
  188. package/neural-interface/lib/opencode-worker-activity.js +229 -0
  189. package/neural-interface/lib/opencode-worker-data.js +27 -0
  190. package/neural-interface/lib/opencode2-client.js +796 -0
  191. package/neural-interface/lib/opencode2-proxy.js +76 -0
  192. package/neural-interface/lib/opencode2-translate.js +1057 -0
  193. package/neural-interface/lib/owner-authority.js +249 -0
  194. package/neural-interface/lib/page-session.js +275 -0
  195. package/neural-interface/lib/peer-identity.js +763 -0
  196. package/neural-interface/lib/process-identity.js +361 -0
  197. package/neural-interface/lib/request-gate.js +17 -2
  198. package/neural-interface/lib/rulesets/api.js +1 -1
  199. package/neural-interface/lib/rulesets/fs-safe.js +1 -1
  200. package/neural-interface/lib/rulesets/installer.js +92 -27
  201. package/neural-interface/lib/rulesets/json-edit.js +1 -1
  202. package/neural-interface/lib/session-cache-builder.js +18 -10
  203. package/neural-interface/lib/session-title-generator.js +58 -18
  204. package/neural-interface/lib/skills/api-v2.js +495 -0
  205. package/neural-interface/lib/skills/bundle.js +418 -0
  206. package/neural-interface/lib/skills/catalog.js +294 -0
  207. package/neural-interface/lib/skills/creation-api.js +191 -0
  208. package/neural-interface/lib/skills/creation-brief.js +247 -0
  209. package/neural-interface/lib/skills/creation-sources.js +267 -0
  210. package/neural-interface/lib/skills/creation.js +843 -0
  211. package/neural-interface/lib/skills/deploy.js +564 -0
  212. package/neural-interface/lib/skills/digest.js +119 -0
  213. package/neural-interface/lib/skills/discover.js +111 -0
  214. package/neural-interface/lib/skills/draft-confinement.js +214 -0
  215. package/neural-interface/lib/skills/eval-confinement.js +397 -0
  216. package/neural-interface/lib/skills/eval-sandbox.js +280 -0
  217. package/neural-interface/lib/skills/eval-trace.js +119 -0
  218. package/neural-interface/lib/skills/evals-api.js +212 -0
  219. package/neural-interface/lib/skills/evals.js +1573 -0
  220. package/neural-interface/lib/skills/export.js +200 -0
  221. package/neural-interface/lib/skills/frontmatter.js +64 -0
  222. package/neural-interface/lib/skills/health.js +75 -0
  223. package/neural-interface/lib/skills/json-edit.js +165 -0
  224. package/neural-interface/lib/skills/known-bridge-digests.json +387 -0
  225. package/neural-interface/lib/skills/known-bridges.js +96 -0
  226. package/neural-interface/lib/skills/library.js +823 -0
  227. package/neural-interface/lib/skills/local-store.js +21 -0
  228. package/neural-interface/lib/skills/migration.js +433 -0
  229. package/neural-interface/lib/skills/operations.js +45 -0
  230. package/neural-interface/lib/skills/ownership.js +427 -0
  231. package/neural-interface/lib/skills/packages.js +88 -0
  232. package/neural-interface/lib/skills/reviews.js +212 -0
  233. package/neural-interface/lib/skills/revision.js +80 -0
  234. package/neural-interface/lib/skills/roots.js +262 -0
  235. package/neural-interface/lib/skills/runtime-checks.js +355 -0
  236. package/neural-interface/lib/skills/scan-assets.js +252 -0
  237. package/neural-interface/lib/skills/scan-context.js +26 -0
  238. package/neural-interface/lib/skills/scan-shell.js +324 -0
  239. package/neural-interface/lib/skills/scan.js +364 -0
  240. package/neural-interface/lib/skills/scanners.js +54 -0
  241. package/neural-interface/lib/skills/service.js +522 -0
  242. package/neural-interface/lib/skills/telemetry.js +113 -0
  243. package/neural-interface/lib/sqlite-integrity-worker.js +22 -0
  244. package/neural-interface/lib/style-guide/api.js +4 -3
  245. package/neural-interface/lib/tool-lists.js +124 -0
  246. package/neural-interface/lib/untrusted-file-headers.js +27 -0
  247. package/neural-interface/lib/whatsapp/bridge.js +6 -3
  248. package/neural-interface/lib/worker-confinement.js +1192 -0
  249. package/neural-interface/lib/worker-guard-setting.js +56 -0
  250. package/neural-interface/lib/worker-mcp-channel.js +175 -0
  251. package/neural-interface/lib/worker-relay-ports.js +227 -0
  252. package/neural-interface/lib/worker-resume.js +229 -0
  253. package/neural-interface/lib/worker-sandbox.js +299 -0
  254. package/neural-interface/package-lock.json +1354 -50
  255. package/neural-interface/package.json +6 -2
  256. package/neural-interface/public/index.html +5 -3
  257. package/neural-interface/public/index2d.html +19 -11
  258. package/neural-interface/public/onboarding.html +2 -2
  259. package/neural-interface/public/shared/account-menu.js +8 -5
  260. package/neural-interface/public/shared/agent-runtime-options.js +76 -16
  261. package/neural-interface/public/shared/api.js +1527 -1336
  262. package/neural-interface/public/shared/app-frame.js +192 -0
  263. package/neural-interface/public/shared/assistant/asst-agents-dock.js +205 -19
  264. package/neural-interface/public/shared/assistant/asst-api.js +11 -3
  265. package/neural-interface/public/shared/assistant/asst-ask-styles.js +270 -0
  266. package/neural-interface/public/shared/assistant/asst-ask-tail.js +118 -0
  267. package/neural-interface/public/shared/assistant/asst-ask.js +397 -0
  268. package/neural-interface/public/shared/assistant/asst-brain-picker.js +241 -112
  269. package/neural-interface/public/shared/assistant/asst-composer.js +1 -1
  270. package/neural-interface/public/shared/assistant/asst-control.js +157 -26
  271. package/neural-interface/public/shared/assistant/asst-followups-card.js +383 -0
  272. package/neural-interface/public/shared/assistant/asst-followups.js +417 -0
  273. package/neural-interface/public/shared/assistant/asst-hosts.js +49 -2
  274. package/neural-interface/public/shared/assistant/asst-limit-dock.js +40 -0
  275. package/neural-interface/public/shared/assistant/asst-limit-wait.js +294 -0
  276. package/neural-interface/public/shared/assistant/asst-limit.js +168 -0
  277. package/neural-interface/public/shared/assistant/asst-mascot.js +49 -12
  278. package/neural-interface/public/shared/assistant/asst-menu.js +84 -12
  279. package/neural-interface/public/shared/assistant/asst-panel.js +303 -44
  280. package/neural-interface/public/shared/assistant/asst-rack-styles.js +93 -58
  281. package/neural-interface/public/shared/assistant/asst-redact.js +186 -0
  282. package/neural-interface/public/shared/assistant/asst-render.js +770 -100
  283. package/neural-interface/public/shared/assistant/asst-route.js +83 -12
  284. package/neural-interface/public/shared/assistant/asst-run-stage.js +231 -0
  285. package/neural-interface/public/shared/assistant/asst-sanitize.js +193 -3
  286. package/neural-interface/public/shared/assistant/asst-scene-styles.js +273 -0
  287. package/neural-interface/public/shared/assistant/asst-scenes.js +530 -0
  288. package/neural-interface/public/shared/assistant/asst-sidepanel-styles.js +3 -15
  289. package/neural-interface/public/shared/assistant/asst-sidepanel.js +67 -4
  290. package/neural-interface/public/shared/assistant/asst-slash.js +9 -7
  291. package/neural-interface/public/shared/assistant/asst-state.js +25 -15
  292. package/neural-interface/public/shared/assistant/asst-stop.js +127 -0
  293. package/neural-interface/public/shared/assistant/asst-styles.js +102 -21
  294. package/neural-interface/public/shared/assistant/asst-tool-kinds.js +165 -13
  295. package/neural-interface/public/shared/automation-context.js +5 -2
  296. package/neural-interface/public/shared/cc-dropdown.js +550 -0
  297. package/neural-interface/public/shared/cdx/cdx-context-menu.js +10 -9
  298. package/neural-interface/public/shared/cdx/cdx-copy.js +16 -0
  299. package/neural-interface/public/shared/cdx/cdx-output-model.js +22 -1
  300. package/neural-interface/public/shared/cdx/cdx-output.js +8 -7
  301. package/neural-interface/public/shared/cdx/cdx-panel.js +58 -150
  302. package/neural-interface/public/shared/cdx/cdx-protocol.js +28 -1
  303. package/neural-interface/public/shared/cdx/cdx-render.js +62 -32
  304. package/neural-interface/public/shared/cdx/cdx-requests.js +3 -3
  305. package/neural-interface/public/shared/cdx/cdx-skill-hints.js +54 -0
  306. package/neural-interface/public/shared/cdx/cdx-styles.js +15 -3
  307. package/neural-interface/public/shared/cdx/cdx-tabs.js +201 -74
  308. package/neural-interface/public/shared/cdx/cdx-ws.js +0 -1
  309. package/neural-interface/public/shared/cli-install-view.js +4 -8
  310. package/neural-interface/public/shared/cli-status.js +2 -2
  311. package/neural-interface/public/shared/constants.js +2 -2
  312. package/neural-interface/public/shared/context-menu-areas.js +34 -0
  313. package/neural-interface/public/shared/context-menu-logic.js +243 -0
  314. package/neural-interface/public/shared/context-menu-model.js +366 -0
  315. package/neural-interface/public/shared/context-menu.js +372 -0
  316. package/neural-interface/public/shared/cp/cp-context-menu.js +10 -9
  317. package/neural-interface/public/shared/cp/cp-markdown.js +4 -57
  318. package/neural-interface/public/shared/crash-notice-view.js +168 -0
  319. package/neural-interface/public/shared/data-cache.js +223 -0
  320. package/neural-interface/public/shared/desktop-bridge.js +11 -0
  321. package/neural-interface/public/shared/desktop-titlebar-view.js +78 -1
  322. package/neural-interface/public/shared/desktop-titlebar.js +214 -28
  323. package/neural-interface/public/shared/desktop-update-view.js +35 -5
  324. package/neural-interface/public/shared/editor/editor-panel-logic.js +2 -2
  325. package/neural-interface/public/shared/file-links.js +73 -8
  326. package/neural-interface/public/shared/html-shell.js +78 -86
  327. package/neural-interface/public/shared/i18n.js +2 -0
  328. package/neural-interface/public/shared/launch-prefetch.js +59 -0
  329. package/neural-interface/public/shared/ocp-v2/ocp-v2-approvals.js +7 -7
  330. package/neural-interface/public/shared/ocp-v2/ocp-v2-binding.js +4 -4
  331. package/neural-interface/public/shared/ocp-v2/ocp-v2-caps.js +3 -2
  332. package/neural-interface/public/shared/ocp-v2/ocp-v2-changes-logic.js +3 -101
  333. package/neural-interface/public/shared/ocp-v2/ocp-v2-childpanel.js +9 -2
  334. package/neural-interface/public/shared/ocp-v2/ocp-v2-compact-button.js +1 -3
  335. package/neural-interface/public/shared/ocp-v2/ocp-v2-composer-logic.js +2 -6
  336. package/neural-interface/public/shared/ocp-v2/ocp-v2-context-menu.js +11 -11
  337. package/neural-interface/public/shared/ocp-v2/ocp-v2-context-model.js +0 -3
  338. package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +8 -4
  339. package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +7 -7
  340. package/neural-interface/public/shared/ocp-v2/ocp-v2-modelpicker.js +54 -17
  341. package/neural-interface/public/shared/ocp-v2/ocp-v2-outcome-notifications.js +16 -0
  342. package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +140 -254
  343. package/neural-interface/public/shared/ocp-v2/ocp-v2-plan.js +1 -2
  344. package/neural-interface/public/shared/ocp-v2/ocp-v2-projectbar.js +97 -203
  345. package/neural-interface/public/shared/ocp-v2/ocp-v2-providers.js +11 -9
  346. package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +15 -4
  347. package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +7 -22
  348. package/neural-interface/public/shared/ocp-v2/ocp-v2-send-logic.js +401 -0
  349. package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +20 -13
  350. package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +8 -61
  351. package/neural-interface/public/shared/ocp-v2/ocp-v2-sessions-logic.js +53 -82
  352. package/neural-interface/public/shared/ocp-v2/ocp-v2-slash-hints.js +16 -15
  353. package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +8 -21
  354. package/neural-interface/public/shared/ocp-v2/ocp-v2-status-logic.js +1 -99
  355. package/neural-interface/public/shared/ocp-v2/ocp-v2-status.js +5 -35
  356. package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +48 -40
  357. package/neural-interface/public/shared/ocp-v2/{ocp-v2-profile-inheritance.js → ocp-v2-tools-inheritance.js} +16 -16
  358. package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +205 -62
  359. package/neural-interface/public/shared/opencode-providers.js +39 -0
  360. package/neural-interface/public/shared/page-session.js +96 -0
  361. package/neural-interface/public/shared/registry.js +5 -3
  362. package/neural-interface/public/shared/retired-2d.js +3 -0
  363. package/neural-interface/public/shared/schedules-view.js +452 -0
  364. package/neural-interface/public/shared/settings/settings-app-pane.js +335 -0
  365. package/neural-interface/public/shared/settings/settings-app.js +243 -0
  366. package/neural-interface/public/shared/settings/settings-claude-hooks.js +135 -0
  367. package/neural-interface/public/shared/settings/settings-data.js +90 -0
  368. package/neural-interface/public/shared/settings/settings-ia.js +23 -6
  369. package/neural-interface/public/shared/settings/settings-opencode.js +89 -0
  370. package/neural-interface/public/shared/settings/settings-skill-folders-pane.js +265 -0
  371. package/neural-interface/public/shared/settings/settings-skill-folders.js +130 -0
  372. package/neural-interface/public/shared/settings/settings-worker-guard.js +72 -0
  373. package/neural-interface/public/shared/sidepanel-session-status.js +49 -0
  374. package/neural-interface/public/shared/skills/ss-args.js +96 -0
  375. package/neural-interface/public/shared/skills/ss-creation.js +219 -0
  376. package/neural-interface/public/shared/skills/ss-dialog.js +130 -0
  377. package/neural-interface/public/shared/skills/ss-doc.js +173 -0
  378. package/neural-interface/public/shared/skills/ss-eval-adapters.js +269 -0
  379. package/neural-interface/public/shared/skills/ss-eval-grade.js +359 -0
  380. package/neural-interface/public/shared/skills/ss-eval-optimise.js +153 -0
  381. package/neural-interface/public/shared/skills/ss-eval-plan.js +315 -0
  382. package/neural-interface/public/shared/skills/ss-evals.js +417 -0
  383. package/neural-interface/public/shared/skills/ss-form.js +159 -0
  384. package/neural-interface/public/shared/skills/ss-frontmatter.js +376 -0
  385. package/neural-interface/public/shared/skills/ss-ids.js +32 -0
  386. package/neural-interface/public/shared/skills/ss-lint.js +141 -0
  387. package/neural-interface/public/shared/skills/ss-presets.js +117 -0
  388. package/neural-interface/public/shared/skills/ss-profiles.js +475 -0
  389. package/neural-interface/public/shared/skills/ss-resources.js +165 -0
  390. package/neural-interface/public/shared/skills/ss-review-view.js +190 -0
  391. package/neural-interface/public/shared/skills/ss-tabs.js +79 -0
  392. package/neural-interface/public/shared/skills/ss-unicode.js +135 -0
  393. package/neural-interface/public/shared/skills/studio/sx-actions.js +222 -0
  394. package/neural-interface/public/shared/skills/studio/sx-cm.js +101 -0
  395. package/neural-interface/public/shared/skills/studio/sx-create-ai-view.js +749 -0
  396. package/neural-interface/public/shared/skills/studio/sx-create-ai.js +236 -0
  397. package/neural-interface/public/shared/skills/studio/sx-create-view.js +254 -0
  398. package/neural-interface/public/shared/skills/studio/sx-create.js +126 -0
  399. package/neural-interface/public/shared/skills/studio/sx-diff-view.js +43 -0
  400. package/neural-interface/public/shared/skills/studio/sx-diff.js +133 -0
  401. package/neural-interface/public/shared/skills/studio/sx-docs.js +480 -0
  402. package/neural-interface/public/shared/skills/studio/sx-dom.js +229 -0
  403. package/neural-interface/public/shared/skills/studio/sx-edit-view.js +848 -0
  404. package/neural-interface/public/shared/skills/studio/sx-editor-model.js +193 -0
  405. package/neural-interface/public/shared/skills/studio/sx-errors.js +22 -0
  406. package/neural-interface/public/shared/skills/studio/sx-geometry.js +82 -0
  407. package/neural-interface/public/shared/skills/studio/sx-import.js +262 -0
  408. package/neural-interface/public/shared/skills/studio/sx-inspector.js +308 -0
  409. package/neural-interface/public/shared/skills/studio/sx-install-flow.js +279 -0
  410. package/neural-interface/public/shared/skills/studio/sx-install.js +296 -0
  411. package/neural-interface/public/shared/skills/studio/sx-library-view.js +639 -0
  412. package/neural-interface/public/shared/skills/studio/sx-library.js +475 -0
  413. package/neural-interface/public/shared/skills/studio/sx-main.js +681 -0
  414. package/neural-interface/public/shared/skills/studio/sx-operations-view.js +98 -0
  415. package/neural-interface/public/shared/skills/studio/sx-operations.js +11 -0
  416. package/neural-interface/public/shared/skills/studio/sx-plan.js +158 -0
  417. package/neural-interface/public/shared/skills/studio/sx-publish-view.js +621 -0
  418. package/neural-interface/public/shared/skills/studio/sx-review-view.js +369 -0
  419. package/neural-interface/public/shared/skills/studio/sx-review.js +148 -0
  420. package/neural-interface/public/shared/skills/studio/sx-scan.js +35 -0
  421. package/neural-interface/public/shared/skills/studio/sx-snippets.js +96 -0
  422. package/neural-interface/public/shared/skills/studio/sx-subject.js +248 -0
  423. package/neural-interface/public/shared/skills/studio/sx-test-view.js +994 -0
  424. package/neural-interface/public/shared/skills/studio/sx-test.js +328 -0
  425. package/neural-interface/public/shared/skills/studio/sx-versions-view.js +241 -0
  426. package/neural-interface/public/shared/skills/studio/sx-workspace-view.js +425 -0
  427. package/neural-interface/public/shared/styleguide/sg-panel.js +4 -2
  428. package/neural-interface/public/shared/styles.css +2065 -2150
  429. package/neural-interface/public/shared/synabun-mascot.js +1115 -9
  430. package/neural-interface/public/shared/tool-list-picker.js +55 -0
  431. package/neural-interface/public/shared/tool-list-storage.js +24 -0
  432. package/neural-interface/public/shared/tool-list-view.js +112 -0
  433. package/neural-interface/public/shared/tour/tour-actor.js +268 -0
  434. package/neural-interface/public/shared/tour/tour-beats.js +336 -0
  435. package/neural-interface/public/shared/tour/tour-engine.js +884 -0
  436. package/neural-interface/public/shared/tour/tour-ink.js +390 -0
  437. package/neural-interface/public/shared/tour/tour-stage.js +440 -0
  438. package/neural-interface/public/shared/tour/tour-state.js +40 -0
  439. package/neural-interface/public/shared/tour/tour-tips.js +99 -0
  440. package/neural-interface/public/shared/tour/tour.css +144 -0
  441. package/neural-interface/public/shared/ui-assistant.js +27 -5
  442. package/neural-interface/public/shared/ui-automation-studio.js +155 -152
  443. package/neural-interface/public/shared/ui-bookmarks.js +2 -1
  444. package/neural-interface/public/shared/ui-claude-panel.js +153 -13
  445. package/neural-interface/public/shared/ui-codex-panel.js +1 -0
  446. package/neural-interface/public/shared/ui-command-runner.js +6 -3
  447. package/neural-interface/public/shared/ui-context-menu.js +295 -0
  448. package/neural-interface/public/shared/ui-cost-widget.js +57 -59
  449. package/neural-interface/public/shared/ui-crash-notice.js +187 -0
  450. package/neural-interface/public/shared/ui-detail.js +21 -9
  451. package/neural-interface/public/shared/ui-file-links.js +1 -0
  452. package/neural-interface/public/shared/ui-image-gallery.js +56 -52
  453. package/neural-interface/public/shared/ui-invite.js +18 -2
  454. package/neural-interface/public/shared/ui-keybinds.js +26 -1
  455. package/neural-interface/public/shared/ui-link.js +9 -9
  456. package/neural-interface/public/shared/ui-menubar.js +229 -40
  457. package/neural-interface/public/shared/ui-native-loop-router-state.js +5 -0
  458. package/neural-interface/public/shared/ui-native-loop-router.js +9 -1
  459. package/neural-interface/public/shared/ui-navbar.js +4 -24
  460. package/neural-interface/public/shared/ui-opencode-panel-v2.js +1 -0
  461. package/neural-interface/public/shared/ui-panels.js +96 -65
  462. package/neural-interface/public/shared/ui-schedules-studio.js +2267 -953
  463. package/neural-interface/public/shared/ui-sessions.js +20 -7
  464. package/neural-interface/public/shared/ui-settings.js +679 -496
  465. package/neural-interface/public/shared/ui-sidebar.js +4 -4
  466. package/neural-interface/public/shared/ui-sidepanel-session-entry.js +13 -0
  467. package/neural-interface/public/shared/ui-sidepanel-sessions.js +56 -5
  468. package/neural-interface/public/shared/ui-sidepanel-state.js +23 -12
  469. package/neural-interface/public/shared/ui-sidepanel-tray.js +84 -8
  470. package/neural-interface/public/shared/ui-sidepanel-windows.js +16 -11
  471. package/neural-interface/public/shared/ui-skills.js +42 -2781
  472. package/neural-interface/public/shared/ui-styleguide.js +5 -2
  473. package/neural-interface/public/shared/ui-sync.js +22 -5
  474. package/neural-interface/public/shared/ui-terminal.js +159 -199
  475. package/neural-interface/public/shared/ui-tool-updates.js +3 -1
  476. package/neural-interface/public/shared/ui-tooltip.js +10 -5
  477. package/neural-interface/public/shared/ui-trash.js +14 -5
  478. package/neural-interface/public/shared/ui-tutorial-layout.js +3 -117
  479. package/neural-interface/public/shared/ui-tutorial-preview.js +103 -0
  480. package/neural-interface/public/shared/ui-tutorial-steps.js +3 -61
  481. package/neural-interface/public/shared/ui-tutorial.css +47 -100
  482. package/neural-interface/public/shared/ui-tutorial.js +285 -499
  483. package/neural-interface/public/shared/ui-update.js +121 -16
  484. package/neural-interface/public/shared/ui-whiteboard.js +313 -59
  485. package/neural-interface/public/shared/ui-worker-end.js +4 -0
  486. package/neural-interface/public/shared/ui-workspaces.js +3 -2
  487. package/neural-interface/public/shared/view-variant.js +66 -0
  488. package/neural-interface/public/shared/whatsapp/wa-view.js +1 -1
  489. package/neural-interface/public/shared/whiteboard-list.js +172 -0
  490. package/neural-interface/public/shared/worker-end.js +10 -3
  491. package/neural-interface/public/shared/worker-restart.js +12 -0
  492. package/neural-interface/public/sidepanel-session.html +1 -1
  493. package/neural-interface/public/variant/2d/background.js +2 -1
  494. package/neural-interface/public/variant/2d/context-menu.js +8 -2
  495. package/neural-interface/public/variant/2d/graph.js +42 -20
  496. package/neural-interface/public/variant/2d/hulls.js +14 -9
  497. package/neural-interface/public/variant/2d/lasso.js +11 -7
  498. package/neural-interface/public/variant/2d/main.js +36 -2
  499. package/neural-interface/public/variant/2d/minimap.js +11 -13
  500. package/neural-interface/public/variant/3d/main.js +72 -6
  501. package/neural-interface/public/variant/3d/map-controls.js +24 -9
  502. package/neural-interface/public/vendor/caveat/OFL.txt +93 -0
  503. package/neural-interface/public/vendor/caveat/caveat-latin-400-normal.woff2 +0 -0
  504. package/neural-interface/public/vendor/caveat/caveat-latin-700-normal.woff2 +0 -0
  505. package/neural-interface/public/vendor/caveat/caveat.css +17 -0
  506. package/neural-interface/public/vendor/caveat/manifest.json +12 -0
  507. package/neural-interface/public/vendor/highlight/LICENSE +29 -0
  508. package/neural-interface/public/vendor/highlight/github-dark-dimmed-11.12.0.min.css +9 -0
  509. package/neural-interface/public/vendor/highlight/highlight-11.12.0.min.js +1262 -0
  510. package/neural-interface/public/vendor/highlight/manifest.json +5 -0
  511. package/neural-interface/public/vendor/html2canvas/LICENSE +22 -0
  512. package/neural-interface/public/vendor/html2canvas/html2canvas-1.4.1.min.js +20 -0
  513. package/neural-interface/public/vendor/html2canvas/manifest.json +4 -0
  514. package/neural-interface/public/vendor/marked/LICENSE.md +44 -0
  515. package/neural-interface/public/vendor/marked/manifest.json +4 -0
  516. package/neural-interface/public/vendor/marked/marked-14.1.4.esm.js +2502 -0
  517. package/neural-interface/public/vendor/mermaid/LICENSE +21 -0
  518. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/abnfDiagram-PAR5IXJI.mjs +1 -0
  519. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/architecture-7GRP2DOG-M7G3SWCO.mjs +1 -0
  520. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/architectureDiagram-2PNWDENW.mjs +36 -0
  521. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/blockDiagram-PUWGUBOA.mjs +129 -0
  522. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/c4Diagram-3NLNHZP5.mjs +38 -0
  523. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-2NMSUPJH.mjs +1 -0
  524. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-32MCUW2P.mjs +206 -0
  525. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-3NPNU5GP.mjs +1 -0
  526. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-3SMGFRGC.mjs +1 -0
  527. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-4CAJECRU.mjs +14 -0
  528. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-4OADUZ5Q.mjs +10 -0
  529. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-5IMINLNL.mjs +1 -0
  530. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-5IQCK5RY.mjs +3 -0
  531. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-5MVFYWFU.mjs +1 -0
  532. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-AQ6EADP3.mjs +1 -0
  533. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-AZZRMDJM.mjs +15 -0
  534. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-CLS4B6BI.mjs +168 -0
  535. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-DZP67EKU.mjs +70 -0
  536. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-EICP7K5X.mjs +1 -0
  537. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-GDY2UAB4.mjs +1 -0
  538. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-H7VHZCWX.mjs +1 -0
  539. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-IJBDOHL6.mjs +1 -0
  540. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-JFFVMJIA.mjs +1 -0
  541. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-JQRUD6KW.mjs +1 -0
  542. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-JZGDI5JK.mjs +1 -0
  543. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-KD6SPIPN.mjs +2 -0
  544. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-NF366YI6.mjs +231 -0
  545. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-NUDPKBEF.mjs +32 -0
  546. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-OJINMHTS.mjs +1 -0
  547. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-Q6NGPIAH.mjs +2 -0
  548. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-QJSWEUOL.mjs +132 -0
  549. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-R7JDMUKV.mjs +1 -0
  550. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-RCXAM2GK.mjs +1 -0
  551. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-RT4MAWR3.mjs +1 -0
  552. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-SFMINX4W.mjs +1 -0
  553. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-SLDQ463B.mjs +88 -0
  554. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-STOV2HOB.mjs +1 -0
  555. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-T5OCTHI4.mjs +1 -0
  556. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-TCEHX7R3.mjs +1 -0
  557. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-VQC2EELJ.mjs +1 -0
  558. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-VRZKL3EH.mjs +1 -0
  559. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-VTHDQ7BV.mjs +1 -0
  560. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-VY2OSTJR.mjs +2 -0
  561. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-WUBWJARI.mjs +1 -0
  562. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-YBMQ5JGJ.mjs +2 -0
  563. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-YDMLL4PJ.mjs +1 -0
  564. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-Z6V44ARX.mjs +62 -0
  565. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-ZJJ7VQJP.mjs +339 -0
  566. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-ZNLK7HRR.mjs +1 -0
  567. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-ZQN7UHIL.mjs +1 -0
  568. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-ZS6VBONO.mjs +174 -0
  569. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/chunk-ZUNWM646.mjs +1 -0
  570. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/classDiagram-FGAMPOII.mjs +1 -0
  571. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/classDiagram-v2-AI5RJEK4.mjs +1 -0
  572. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/cose-bilkent-Q72C2OJ3.mjs +1 -0
  573. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/cynefin-OW5HDTMX-6OCTWOGG.mjs +1 -0
  574. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/cynefinDiagram-2OOWUY4M.mjs +62 -0
  575. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/dagre-MPVFI544.mjs +4 -0
  576. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/diagram-AE4NWXFW.mjs +24 -0
  577. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/diagram-BUJID5UG.mjs +41 -0
  578. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/diagram-C44CZ5NI.mjs +24 -0
  579. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/diagram-EYOLEXXS.mjs +30 -0
  580. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/diagram-P7B6PWOJ.mjs +3 -0
  581. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/ebnfDiagram-FTPZ3PV6.mjs +1 -0
  582. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/erDiagram-H3ERR26V.mjs +99 -0
  583. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/eventmodeling-NTZA5JFV-WKSWQHFS.mjs +1 -0
  584. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/flowDiagram-YHGXBVSY.mjs +1 -0
  585. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/ganttDiagram-RWFTB7ED.mjs +292 -0
  586. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/gitGraph-4MIJSDKK-JH2HKYUO.mjs +1 -0
  587. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/gitGraphDiagram-MAR6GKOP.mjs +106 -0
  588. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/info-A6RAGUB7-3TX3OFWW.mjs +1 -0
  589. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/infoDiagram-LV547AFH.mjs +2 -0
  590. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/ishikawaDiagram-PUJQGNDS.mjs +70 -0
  591. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/journeyDiagram-EW5QJT4W.mjs +139 -0
  592. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/kanban-definition-JSQERAZB.mjs +89 -0
  593. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/katex-CZ4GXH2S.mjs +257 -0
  594. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/mindmap-definition-VBJCLQLM.mjs +96 -0
  595. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/packet-AYTQ26CC-MKII6P3Y.mjs +1 -0
  596. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/pegDiagram-7WILOQTJ.mjs +1 -0
  597. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/pie-WAS4IAKB-6B4OPMJ5.mjs +1 -0
  598. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/pieDiagram-EFA7CBSB.mjs +39 -0
  599. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/quadrantDiagram-WARVYA7P.mjs +7 -0
  600. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/radar-RG4KPBEZ-UPTR3XUL.mjs +1 -0
  601. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/railroad-74A4TZTK-MEFUPFMS.mjs +1 -0
  602. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/railroad-abnf-HS5TGJTU-R5YG2S5D.mjs +1 -0
  603. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/railroad-ebnf-LZEXJU2U-G5QEX2L6.mjs +1 -0
  604. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/railroad-peg-WCYAUIDC-H5I2ZRY2.mjs +1 -0
  605. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/railroadDiagram-5NIQVNLQ.mjs +1 -0
  606. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/requirementDiagram-SXREGOKZ.mjs +84 -0
  607. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/sankeyDiagram-VV74M2VP.mjs +40 -0
  608. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/sequenceDiagram-52ZFIFDL.mjs +162 -0
  609. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/sizeCapture-FGA5AGYP.mjs +1 -0
  610. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/stateDiagram-3QAKPIVI.mjs +1 -0
  611. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/stateDiagram-v2-HN2P4RDZ.mjs +1 -0
  612. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/swimlanes-QLVP42QD.mjs +1 -0
  613. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/swimlanesDiagram-JKPDBFCN.mjs +8 -0
  614. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/timeline-definition-GS45XAXW.mjs +120 -0
  615. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/treeView-Q6P3EWNA-ZRJGANNQ.mjs +1 -0
  616. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/treemap-WGGIJYW6-K64VN5AS.mjs +1 -0
  617. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/vennDiagram-QIQU2ZRJ.mjs +34 -0
  618. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/wardley-WFR3VGLG-D67OWCCH.mjs +1 -0
  619. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/wardleyDiagram-U6YNM66N.mjs +78 -0
  620. package/neural-interface/public/vendor/mermaid/chunks/mermaid.esm.min/xychartDiagram-XJAZEDNM.mjs +7 -0
  621. package/neural-interface/public/vendor/mermaid/manifest.json +4 -0
  622. package/neural-interface/public/vendor/mermaid/mermaid-11.17.2.esm.min.mjs +14 -0
  623. package/neural-interface/public/vendor/yaml/LICENSE +13 -0
  624. package/neural-interface/public/vendor/yaml/manifest.json +4 -0
  625. package/neural-interface/public/vendor/yaml/yaml-2.9.1.min.js +137 -0
  626. package/neural-interface/scripts/build-vendor.mjs +116 -3
  627. package/neural-interface/server.js +4834 -2541
  628. package/neural-interface/templates/rulesets/core.md +1 -1
  629. package/neural-interface/templates/rulesets/legacy-hashes.json +18 -0
  630. package/neural-interface/templates/rulesets/manifest.json +8 -8
  631. package/npm-shrinkwrap.json +18 -12
  632. package/package.json +16 -3
  633. package/postinstall.js +9 -4
  634. package/preuninstall.js +1 -1
  635. package/setup.js +97 -322
  636. package/skills/skill-forge/SKILL.md +177 -0
  637. package/skills/skill-forge/evals/evals.json +54 -0
  638. package/skills/skill-forge/references/package.md +105 -0
  639. package/skills/skill-forge/references/review-and-recovery.md +63 -0
  640. package/skills/skill-forge/references/runtime-profiles.md +20 -0
  641. package/skills/skill-forge/references/sources-and-capabilities.md +51 -0
  642. package/skills/synabun/SKILL.md +10 -7
  643. package/skills/synabun/modules/audit.md +1 -5
  644. package/skills/synabun/modules/changelog.md +1 -5
  645. package/skills/synabun/modules/idea.md +1 -1
  646. package/skills/synabun/modules/memorize.md +6 -9
  647. package/skills/synabun/modules/schedule.md +5 -5
  648. package/mcp-server/dist/services/profiles.d.ts +0 -120
  649. package/mcp-server/dist/services/profiles.d.ts.map +0 -1
  650. package/mcp-server/dist/services/profiles.js +0 -387
  651. package/mcp-server/dist/services/profiles.js.map +0 -1
  652. package/mcp-server/dist/tools/leonardo-browser-tools.d.ts +0 -97
  653. package/mcp-server/dist/tools/leonardo-browser-tools.d.ts.map +0 -1
  654. package/mcp-server/dist/tools/leonardo-browser-tools.js +0 -228
  655. package/mcp-server/dist/tools/leonardo-browser-tools.js.map +0 -1
  656. package/mcp-server/dist/tools/leonardo.d.ts +0 -13
  657. package/mcp-server/dist/tools/leonardo.d.ts.map +0 -1
  658. package/mcp-server/dist/tools/leonardo.js +0 -21
  659. package/mcp-server/dist/tools/leonardo.js.map +0 -1
  660. package/mcp-server/dist/tools/profile.d.ts +0 -17
  661. package/mcp-server/dist/tools/profile.d.ts.map +0 -1
  662. package/mcp-server/dist/tools/profile.js +0 -114
  663. package/mcp-server/dist/tools/profile.js.map +0 -1
  664. package/mcp-server/src/services/profiles.ts +0 -428
  665. package/mcp-server/src/tools/leonardo-browser-tools.ts +0 -291
  666. package/mcp-server/src/tools/leonardo.ts +0 -30
  667. package/mcp-server/src/tools/profile.ts +0 -122
  668. package/neural-interface/lib/assistant-brains/opencode-browser-policy.js +0 -47
  669. package/neural-interface/lib/assistant-brains/opencode-route-gate.js +0 -62
  670. package/neural-interface/lib/mcp-profile-servers.js +0 -120
  671. package/neural-interface/public/shared/ui-tutorial-draw.js +0 -311
  672. package/skills/leonardo/SKILL.md +0 -168
  673. package/skills/leonardo/icon.svg +0 -1
  674. package/skills/leonardo/modules/browser-guide.md +0 -378
  675. package/skills/leonardo/modules/image-prompter.md +0 -283
  676. package/skills/leonardo/modules/model-advisor.md +0 -100
  677. package/skills/leonardo/modules/prompt-library.md +0 -110
  678. package/skills/leonardo/modules/style-guide.md +0 -186
  679. package/skills/leonardo/modules/video-prompter.md +0 -317
@@ -0,0 +1,2502 @@
1
+ /**
2
+ * marked v14.1.4 - a markdown parser
3
+ * Copyright (c) 2011-2024, Christopher Jeffrey. (MIT Licensed)
4
+ * https://github.com/markedjs/marked
5
+ */
6
+
7
+ /**
8
+ * DO NOT EDIT THIS FILE
9
+ * The code in this file is generated from files in ./src/
10
+ */
11
+
12
+ /**
13
+ * Gets the original marked default options.
14
+ */
15
+ function _getDefaults() {
16
+ return {
17
+ async: false,
18
+ breaks: false,
19
+ extensions: null,
20
+ gfm: true,
21
+ hooks: null,
22
+ pedantic: false,
23
+ renderer: null,
24
+ silent: false,
25
+ tokenizer: null,
26
+ walkTokens: null,
27
+ };
28
+ }
29
+ let _defaults = _getDefaults();
30
+ function changeDefaults(newDefaults) {
31
+ _defaults = newDefaults;
32
+ }
33
+
34
+ /**
35
+ * Helpers
36
+ */
37
+ const escapeTest = /[&<>"']/;
38
+ const escapeReplace = new RegExp(escapeTest.source, 'g');
39
+ const escapeTestNoEncode = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/;
40
+ const escapeReplaceNoEncode = new RegExp(escapeTestNoEncode.source, 'g');
41
+ const escapeReplacements = {
42
+ '&': '&amp;',
43
+ '<': '&lt;',
44
+ '>': '&gt;',
45
+ '"': '&quot;',
46
+ "'": '&#39;',
47
+ };
48
+ const getEscapeReplacement = (ch) => escapeReplacements[ch];
49
+ function escape$1(html, encode) {
50
+ if (encode) {
51
+ if (escapeTest.test(html)) {
52
+ return html.replace(escapeReplace, getEscapeReplacement);
53
+ }
54
+ }
55
+ else {
56
+ if (escapeTestNoEncode.test(html)) {
57
+ return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
58
+ }
59
+ }
60
+ return html;
61
+ }
62
+ const caret = /(^|[^\[])\^/g;
63
+ function edit(regex, opt) {
64
+ let source = typeof regex === 'string' ? regex : regex.source;
65
+ opt = opt || '';
66
+ const obj = {
67
+ replace: (name, val) => {
68
+ let valSource = typeof val === 'string' ? val : val.source;
69
+ valSource = valSource.replace(caret, '$1');
70
+ source = source.replace(name, valSource);
71
+ return obj;
72
+ },
73
+ getRegex: () => {
74
+ return new RegExp(source, opt);
75
+ },
76
+ };
77
+ return obj;
78
+ }
79
+ function cleanUrl(href) {
80
+ try {
81
+ href = encodeURI(href).replace(/%25/g, '%');
82
+ }
83
+ catch {
84
+ return null;
85
+ }
86
+ return href;
87
+ }
88
+ const noopTest = { exec: () => null };
89
+ function splitCells(tableRow, count) {
90
+ // ensure that every cell-delimiting pipe has a space
91
+ // before it to distinguish it from an escaped pipe
92
+ const row = tableRow.replace(/\|/g, (match, offset, str) => {
93
+ let escaped = false;
94
+ let curr = offset;
95
+ while (--curr >= 0 && str[curr] === '\\')
96
+ escaped = !escaped;
97
+ if (escaped) {
98
+ // odd number of slashes means | is escaped
99
+ // so we leave it alone
100
+ return '|';
101
+ }
102
+ else {
103
+ // add space before unescaped |
104
+ return ' |';
105
+ }
106
+ }), cells = row.split(/ \|/);
107
+ let i = 0;
108
+ // First/last cell in a row cannot be empty if it has no leading/trailing pipe
109
+ if (!cells[0].trim()) {
110
+ cells.shift();
111
+ }
112
+ if (cells.length > 0 && !cells[cells.length - 1].trim()) {
113
+ cells.pop();
114
+ }
115
+ if (count) {
116
+ if (cells.length > count) {
117
+ cells.splice(count);
118
+ }
119
+ else {
120
+ while (cells.length < count)
121
+ cells.push('');
122
+ }
123
+ }
124
+ for (; i < cells.length; i++) {
125
+ // leading or trailing whitespace is ignored per the gfm spec
126
+ cells[i] = cells[i].trim().replace(/\\\|/g, '|');
127
+ }
128
+ return cells;
129
+ }
130
+ /**
131
+ * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
132
+ * /c*$/ is vulnerable to REDOS.
133
+ *
134
+ * @param str
135
+ * @param c
136
+ * @param invert Remove suffix of non-c chars instead. Default falsey.
137
+ */
138
+ function rtrim(str, c, invert) {
139
+ const l = str.length;
140
+ if (l === 0) {
141
+ return '';
142
+ }
143
+ // Length of suffix matching the invert condition.
144
+ let suffLen = 0;
145
+ // Step left until we fail to match the invert condition.
146
+ while (suffLen < l) {
147
+ const currChar = str.charAt(l - suffLen - 1);
148
+ if (currChar === c && !invert) {
149
+ suffLen++;
150
+ }
151
+ else if (currChar !== c && invert) {
152
+ suffLen++;
153
+ }
154
+ else {
155
+ break;
156
+ }
157
+ }
158
+ return str.slice(0, l - suffLen);
159
+ }
160
+ function findClosingBracket(str, b) {
161
+ if (str.indexOf(b[1]) === -1) {
162
+ return -1;
163
+ }
164
+ let level = 0;
165
+ for (let i = 0; i < str.length; i++) {
166
+ if (str[i] === '\\') {
167
+ i++;
168
+ }
169
+ else if (str[i] === b[0]) {
170
+ level++;
171
+ }
172
+ else if (str[i] === b[1]) {
173
+ level--;
174
+ if (level < 0) {
175
+ return i;
176
+ }
177
+ }
178
+ }
179
+ return -1;
180
+ }
181
+
182
+ function outputLink(cap, link, raw, lexer) {
183
+ const href = link.href;
184
+ const title = link.title ? escape$1(link.title) : null;
185
+ const text = cap[1].replace(/\\([\[\]])/g, '$1');
186
+ if (cap[0].charAt(0) !== '!') {
187
+ lexer.state.inLink = true;
188
+ const token = {
189
+ type: 'link',
190
+ raw,
191
+ href,
192
+ title,
193
+ text,
194
+ tokens: lexer.inlineTokens(text),
195
+ };
196
+ lexer.state.inLink = false;
197
+ return token;
198
+ }
199
+ return {
200
+ type: 'image',
201
+ raw,
202
+ href,
203
+ title,
204
+ text: escape$1(text),
205
+ };
206
+ }
207
+ function indentCodeCompensation(raw, text) {
208
+ const matchIndentToCode = raw.match(/^(\s+)(?:```)/);
209
+ if (matchIndentToCode === null) {
210
+ return text;
211
+ }
212
+ const indentToCode = matchIndentToCode[1];
213
+ return text
214
+ .split('\n')
215
+ .map(node => {
216
+ const matchIndentInNode = node.match(/^\s+/);
217
+ if (matchIndentInNode === null) {
218
+ return node;
219
+ }
220
+ const [indentInNode] = matchIndentInNode;
221
+ if (indentInNode.length >= indentToCode.length) {
222
+ return node.slice(indentToCode.length);
223
+ }
224
+ return node;
225
+ })
226
+ .join('\n');
227
+ }
228
+ /**
229
+ * Tokenizer
230
+ */
231
+ class _Tokenizer {
232
+ options;
233
+ rules; // set by the lexer
234
+ lexer; // set by the lexer
235
+ constructor(options) {
236
+ this.options = options || _defaults;
237
+ }
238
+ space(src) {
239
+ const cap = this.rules.block.newline.exec(src);
240
+ if (cap && cap[0].length > 0) {
241
+ return {
242
+ type: 'space',
243
+ raw: cap[0],
244
+ };
245
+ }
246
+ }
247
+ code(src) {
248
+ const cap = this.rules.block.code.exec(src);
249
+ if (cap) {
250
+ const text = cap[0].replace(/^(?: {1,4}| {0,3}\t)/gm, '');
251
+ return {
252
+ type: 'code',
253
+ raw: cap[0],
254
+ codeBlockStyle: 'indented',
255
+ text: !this.options.pedantic
256
+ ? rtrim(text, '\n')
257
+ : text,
258
+ };
259
+ }
260
+ }
261
+ fences(src) {
262
+ const cap = this.rules.block.fences.exec(src);
263
+ if (cap) {
264
+ const raw = cap[0];
265
+ const text = indentCodeCompensation(raw, cap[3] || '');
266
+ return {
267
+ type: 'code',
268
+ raw,
269
+ lang: cap[2] ? cap[2].trim().replace(this.rules.inline.anyPunctuation, '$1') : cap[2],
270
+ text,
271
+ };
272
+ }
273
+ }
274
+ heading(src) {
275
+ const cap = this.rules.block.heading.exec(src);
276
+ if (cap) {
277
+ let text = cap[2].trim();
278
+ // remove trailing #s
279
+ if (/#$/.test(text)) {
280
+ const trimmed = rtrim(text, '#');
281
+ if (this.options.pedantic) {
282
+ text = trimmed.trim();
283
+ }
284
+ else if (!trimmed || / $/.test(trimmed)) {
285
+ // CommonMark requires space before trailing #s
286
+ text = trimmed.trim();
287
+ }
288
+ }
289
+ return {
290
+ type: 'heading',
291
+ raw: cap[0],
292
+ depth: cap[1].length,
293
+ text,
294
+ tokens: this.lexer.inline(text),
295
+ };
296
+ }
297
+ }
298
+ hr(src) {
299
+ const cap = this.rules.block.hr.exec(src);
300
+ if (cap) {
301
+ return {
302
+ type: 'hr',
303
+ raw: rtrim(cap[0], '\n'),
304
+ };
305
+ }
306
+ }
307
+ blockquote(src) {
308
+ const cap = this.rules.block.blockquote.exec(src);
309
+ if (cap) {
310
+ let lines = rtrim(cap[0], '\n').split('\n');
311
+ let raw = '';
312
+ let text = '';
313
+ const tokens = [];
314
+ while (lines.length > 0) {
315
+ let inBlockquote = false;
316
+ const currentLines = [];
317
+ let i;
318
+ for (i = 0; i < lines.length; i++) {
319
+ // get lines up to a continuation
320
+ if (/^ {0,3}>/.test(lines[i])) {
321
+ currentLines.push(lines[i]);
322
+ inBlockquote = true;
323
+ }
324
+ else if (!inBlockquote) {
325
+ currentLines.push(lines[i]);
326
+ }
327
+ else {
328
+ break;
329
+ }
330
+ }
331
+ lines = lines.slice(i);
332
+ const currentRaw = currentLines.join('\n');
333
+ const currentText = currentRaw
334
+ // precede setext continuation with 4 spaces so it isn't a setext
335
+ .replace(/\n {0,3}((?:=+|-+) *)(?=\n|$)/g, '\n $1')
336
+ .replace(/^ {0,3}>[ \t]?/gm, '');
337
+ raw = raw ? `${raw}\n${currentRaw}` : currentRaw;
338
+ text = text ? `${text}\n${currentText}` : currentText;
339
+ // parse blockquote lines as top level tokens
340
+ // merge paragraphs if this is a continuation
341
+ const top = this.lexer.state.top;
342
+ this.lexer.state.top = true;
343
+ this.lexer.blockTokens(currentText, tokens, true);
344
+ this.lexer.state.top = top;
345
+ // if there is no continuation then we are done
346
+ if (lines.length === 0) {
347
+ break;
348
+ }
349
+ const lastToken = tokens[tokens.length - 1];
350
+ if (lastToken?.type === 'code') {
351
+ // blockquote continuation cannot be preceded by a code block
352
+ break;
353
+ }
354
+ else if (lastToken?.type === 'blockquote') {
355
+ // include continuation in nested blockquote
356
+ const oldToken = lastToken;
357
+ const newText = oldToken.raw + '\n' + lines.join('\n');
358
+ const newToken = this.blockquote(newText);
359
+ tokens[tokens.length - 1] = newToken;
360
+ raw = raw.substring(0, raw.length - oldToken.raw.length) + newToken.raw;
361
+ text = text.substring(0, text.length - oldToken.text.length) + newToken.text;
362
+ break;
363
+ }
364
+ else if (lastToken?.type === 'list') {
365
+ // include continuation in nested list
366
+ const oldToken = lastToken;
367
+ const newText = oldToken.raw + '\n' + lines.join('\n');
368
+ const newToken = this.list(newText);
369
+ tokens[tokens.length - 1] = newToken;
370
+ raw = raw.substring(0, raw.length - lastToken.raw.length) + newToken.raw;
371
+ text = text.substring(0, text.length - oldToken.raw.length) + newToken.raw;
372
+ lines = newText.substring(tokens[tokens.length - 1].raw.length).split('\n');
373
+ continue;
374
+ }
375
+ }
376
+ return {
377
+ type: 'blockquote',
378
+ raw,
379
+ tokens,
380
+ text,
381
+ };
382
+ }
383
+ }
384
+ list(src) {
385
+ let cap = this.rules.block.list.exec(src);
386
+ if (cap) {
387
+ let bull = cap[1].trim();
388
+ const isordered = bull.length > 1;
389
+ const list = {
390
+ type: 'list',
391
+ raw: '',
392
+ ordered: isordered,
393
+ start: isordered ? +bull.slice(0, -1) : '',
394
+ loose: false,
395
+ items: [],
396
+ };
397
+ bull = isordered ? `\\d{1,9}\\${bull.slice(-1)}` : `\\${bull}`;
398
+ if (this.options.pedantic) {
399
+ bull = isordered ? bull : '[*+-]';
400
+ }
401
+ // Get next list item
402
+ const itemRegex = new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`);
403
+ let endsWithBlankLine = false;
404
+ // Check if current bullet point can start a new List Item
405
+ while (src) {
406
+ let endEarly = false;
407
+ let raw = '';
408
+ let itemContents = '';
409
+ if (!(cap = itemRegex.exec(src))) {
410
+ break;
411
+ }
412
+ if (this.rules.block.hr.test(src)) { // End list if bullet was actually HR (possibly move into itemRegex?)
413
+ break;
414
+ }
415
+ raw = cap[0];
416
+ src = src.substring(raw.length);
417
+ let line = cap[2].split('\n', 1)[0].replace(/^\t+/, (t) => ' '.repeat(3 * t.length));
418
+ let nextLine = src.split('\n', 1)[0];
419
+ let blankLine = !line.trim();
420
+ let indent = 0;
421
+ if (this.options.pedantic) {
422
+ indent = 2;
423
+ itemContents = line.trimStart();
424
+ }
425
+ else if (blankLine) {
426
+ indent = cap[1].length + 1;
427
+ }
428
+ else {
429
+ indent = cap[2].search(/[^ ]/); // Find first non-space char
430
+ indent = indent > 4 ? 1 : indent; // Treat indented code blocks (> 4 spaces) as having only 1 indent
431
+ itemContents = line.slice(indent);
432
+ indent += cap[1].length;
433
+ }
434
+ if (blankLine && /^[ \t]*$/.test(nextLine)) { // Items begin with at most one blank line
435
+ raw += nextLine + '\n';
436
+ src = src.substring(nextLine.length + 1);
437
+ endEarly = true;
438
+ }
439
+ if (!endEarly) {
440
+ const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ \t][^\\n]*)?(?:\\n|$))`);
441
+ const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
442
+ const fencesBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:\`\`\`|~~~)`);
443
+ const headingBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}#`);
444
+ const htmlBeginRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}<(?:[a-z].*>|!--)`, 'i');
445
+ // Check if following lines should be included in List Item
446
+ while (src) {
447
+ const rawLine = src.split('\n', 1)[0];
448
+ let nextLineWithoutTabs;
449
+ nextLine = rawLine;
450
+ // Re-align to follow commonmark nesting rules
451
+ if (this.options.pedantic) {
452
+ nextLine = nextLine.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
453
+ nextLineWithoutTabs = nextLine;
454
+ }
455
+ else {
456
+ nextLineWithoutTabs = nextLine.replace(/\t/g, ' ');
457
+ }
458
+ // End list item if found code fences
459
+ if (fencesBeginRegex.test(nextLine)) {
460
+ break;
461
+ }
462
+ // End list item if found start of new heading
463
+ if (headingBeginRegex.test(nextLine)) {
464
+ break;
465
+ }
466
+ // End list item if found start of html block
467
+ if (htmlBeginRegex.test(nextLine)) {
468
+ break;
469
+ }
470
+ // End list item if found start of new bullet
471
+ if (nextBulletRegex.test(nextLine)) {
472
+ break;
473
+ }
474
+ // Horizontal rule found
475
+ if (hrRegex.test(nextLine)) {
476
+ break;
477
+ }
478
+ if (nextLineWithoutTabs.search(/[^ ]/) >= indent || !nextLine.trim()) { // Dedent if possible
479
+ itemContents += '\n' + nextLineWithoutTabs.slice(indent);
480
+ }
481
+ else {
482
+ // not enough indentation
483
+ if (blankLine) {
484
+ break;
485
+ }
486
+ // paragraph continuation unless last line was a different block level element
487
+ if (line.replace(/\t/g, ' ').search(/[^ ]/) >= 4) { // indented code block
488
+ break;
489
+ }
490
+ if (fencesBeginRegex.test(line)) {
491
+ break;
492
+ }
493
+ if (headingBeginRegex.test(line)) {
494
+ break;
495
+ }
496
+ if (hrRegex.test(line)) {
497
+ break;
498
+ }
499
+ itemContents += '\n' + nextLine;
500
+ }
501
+ if (!blankLine && !nextLine.trim()) { // Check if current line is blank
502
+ blankLine = true;
503
+ }
504
+ raw += rawLine + '\n';
505
+ src = src.substring(rawLine.length + 1);
506
+ line = nextLineWithoutTabs.slice(indent);
507
+ }
508
+ }
509
+ if (!list.loose) {
510
+ // If the previous item ended with a blank line, the list is loose
511
+ if (endsWithBlankLine) {
512
+ list.loose = true;
513
+ }
514
+ else if (/\n[ \t]*\n[ \t]*$/.test(raw)) {
515
+ endsWithBlankLine = true;
516
+ }
517
+ }
518
+ let istask = null;
519
+ let ischecked;
520
+ // Check for task list items
521
+ if (this.options.gfm) {
522
+ istask = /^\[[ xX]\] /.exec(itemContents);
523
+ if (istask) {
524
+ ischecked = istask[0] !== '[ ] ';
525
+ itemContents = itemContents.replace(/^\[[ xX]\] +/, '');
526
+ }
527
+ }
528
+ list.items.push({
529
+ type: 'list_item',
530
+ raw,
531
+ task: !!istask,
532
+ checked: ischecked,
533
+ loose: false,
534
+ text: itemContents,
535
+ tokens: [],
536
+ });
537
+ list.raw += raw;
538
+ }
539
+ // Do not consume newlines at end of final item. Alternatively, make itemRegex *start* with any newlines to simplify/speed up endsWithBlankLine logic
540
+ list.items[list.items.length - 1].raw = list.items[list.items.length - 1].raw.trimEnd();
541
+ list.items[list.items.length - 1].text = list.items[list.items.length - 1].text.trimEnd();
542
+ list.raw = list.raw.trimEnd();
543
+ // Item child tokens handled here at end because we needed to have the final item to trim it first
544
+ for (let i = 0; i < list.items.length; i++) {
545
+ this.lexer.state.top = false;
546
+ list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
547
+ if (!list.loose) {
548
+ // Check if list should be loose
549
+ const spacers = list.items[i].tokens.filter(t => t.type === 'space');
550
+ const hasMultipleLineBreaks = spacers.length > 0 && spacers.some(t => /\n.*\n/.test(t.raw));
551
+ list.loose = hasMultipleLineBreaks;
552
+ }
553
+ }
554
+ // Set all items to loose if list is loose
555
+ if (list.loose) {
556
+ for (let i = 0; i < list.items.length; i++) {
557
+ list.items[i].loose = true;
558
+ }
559
+ }
560
+ return list;
561
+ }
562
+ }
563
+ html(src) {
564
+ const cap = this.rules.block.html.exec(src);
565
+ if (cap) {
566
+ const token = {
567
+ type: 'html',
568
+ block: true,
569
+ raw: cap[0],
570
+ pre: cap[1] === 'pre' || cap[1] === 'script' || cap[1] === 'style',
571
+ text: cap[0],
572
+ };
573
+ return token;
574
+ }
575
+ }
576
+ def(src) {
577
+ const cap = this.rules.block.def.exec(src);
578
+ if (cap) {
579
+ const tag = cap[1].toLowerCase().replace(/\s+/g, ' ');
580
+ const href = cap[2] ? cap[2].replace(/^<(.*)>$/, '$1').replace(this.rules.inline.anyPunctuation, '$1') : '';
581
+ const title = cap[3] ? cap[3].substring(1, cap[3].length - 1).replace(this.rules.inline.anyPunctuation, '$1') : cap[3];
582
+ return {
583
+ type: 'def',
584
+ tag,
585
+ raw: cap[0],
586
+ href,
587
+ title,
588
+ };
589
+ }
590
+ }
591
+ table(src) {
592
+ const cap = this.rules.block.table.exec(src);
593
+ if (!cap) {
594
+ return;
595
+ }
596
+ if (!/[:|]/.test(cap[2])) {
597
+ // delimiter row must have a pipe (|) or colon (:) otherwise it is a setext heading
598
+ return;
599
+ }
600
+ const headers = splitCells(cap[1]);
601
+ const aligns = cap[2].replace(/^\||\| *$/g, '').split('|');
602
+ const rows = cap[3] && cap[3].trim() ? cap[3].replace(/\n[ \t]*$/, '').split('\n') : [];
603
+ const item = {
604
+ type: 'table',
605
+ raw: cap[0],
606
+ header: [],
607
+ align: [],
608
+ rows: [],
609
+ };
610
+ if (headers.length !== aligns.length) {
611
+ // header and align columns must be equal, rows can be different.
612
+ return;
613
+ }
614
+ for (const align of aligns) {
615
+ if (/^ *-+: *$/.test(align)) {
616
+ item.align.push('right');
617
+ }
618
+ else if (/^ *:-+: *$/.test(align)) {
619
+ item.align.push('center');
620
+ }
621
+ else if (/^ *:-+ *$/.test(align)) {
622
+ item.align.push('left');
623
+ }
624
+ else {
625
+ item.align.push(null);
626
+ }
627
+ }
628
+ for (let i = 0; i < headers.length; i++) {
629
+ item.header.push({
630
+ text: headers[i],
631
+ tokens: this.lexer.inline(headers[i]),
632
+ header: true,
633
+ align: item.align[i],
634
+ });
635
+ }
636
+ for (const row of rows) {
637
+ item.rows.push(splitCells(row, item.header.length).map((cell, i) => {
638
+ return {
639
+ text: cell,
640
+ tokens: this.lexer.inline(cell),
641
+ header: false,
642
+ align: item.align[i],
643
+ };
644
+ }));
645
+ }
646
+ return item;
647
+ }
648
+ lheading(src) {
649
+ const cap = this.rules.block.lheading.exec(src);
650
+ if (cap) {
651
+ return {
652
+ type: 'heading',
653
+ raw: cap[0],
654
+ depth: cap[2].charAt(0) === '=' ? 1 : 2,
655
+ text: cap[1],
656
+ tokens: this.lexer.inline(cap[1]),
657
+ };
658
+ }
659
+ }
660
+ paragraph(src) {
661
+ const cap = this.rules.block.paragraph.exec(src);
662
+ if (cap) {
663
+ const text = cap[1].charAt(cap[1].length - 1) === '\n'
664
+ ? cap[1].slice(0, -1)
665
+ : cap[1];
666
+ return {
667
+ type: 'paragraph',
668
+ raw: cap[0],
669
+ text,
670
+ tokens: this.lexer.inline(text),
671
+ };
672
+ }
673
+ }
674
+ text(src) {
675
+ const cap = this.rules.block.text.exec(src);
676
+ if (cap) {
677
+ return {
678
+ type: 'text',
679
+ raw: cap[0],
680
+ text: cap[0],
681
+ tokens: this.lexer.inline(cap[0]),
682
+ };
683
+ }
684
+ }
685
+ escape(src) {
686
+ const cap = this.rules.inline.escape.exec(src);
687
+ if (cap) {
688
+ return {
689
+ type: 'escape',
690
+ raw: cap[0],
691
+ text: escape$1(cap[1]),
692
+ };
693
+ }
694
+ }
695
+ tag(src) {
696
+ const cap = this.rules.inline.tag.exec(src);
697
+ if (cap) {
698
+ if (!this.lexer.state.inLink && /^<a /i.test(cap[0])) {
699
+ this.lexer.state.inLink = true;
700
+ }
701
+ else if (this.lexer.state.inLink && /^<\/a>/i.test(cap[0])) {
702
+ this.lexer.state.inLink = false;
703
+ }
704
+ if (!this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
705
+ this.lexer.state.inRawBlock = true;
706
+ }
707
+ else if (this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(cap[0])) {
708
+ this.lexer.state.inRawBlock = false;
709
+ }
710
+ return {
711
+ type: 'html',
712
+ raw: cap[0],
713
+ inLink: this.lexer.state.inLink,
714
+ inRawBlock: this.lexer.state.inRawBlock,
715
+ block: false,
716
+ text: cap[0],
717
+ };
718
+ }
719
+ }
720
+ link(src) {
721
+ const cap = this.rules.inline.link.exec(src);
722
+ if (cap) {
723
+ const trimmedUrl = cap[2].trim();
724
+ if (!this.options.pedantic && /^</.test(trimmedUrl)) {
725
+ // commonmark requires matching angle brackets
726
+ if (!(/>$/.test(trimmedUrl))) {
727
+ return;
728
+ }
729
+ // ending angle bracket cannot be escaped
730
+ const rtrimSlash = rtrim(trimmedUrl.slice(0, -1), '\\');
731
+ if ((trimmedUrl.length - rtrimSlash.length) % 2 === 0) {
732
+ return;
733
+ }
734
+ }
735
+ else {
736
+ // find closing parenthesis
737
+ const lastParenIndex = findClosingBracket(cap[2], '()');
738
+ if (lastParenIndex > -1) {
739
+ const start = cap[0].indexOf('!') === 0 ? 5 : 4;
740
+ const linkLen = start + cap[1].length + lastParenIndex;
741
+ cap[2] = cap[2].substring(0, lastParenIndex);
742
+ cap[0] = cap[0].substring(0, linkLen).trim();
743
+ cap[3] = '';
744
+ }
745
+ }
746
+ let href = cap[2];
747
+ let title = '';
748
+ if (this.options.pedantic) {
749
+ // split pedantic href and title
750
+ const link = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(href);
751
+ if (link) {
752
+ href = link[1];
753
+ title = link[3];
754
+ }
755
+ }
756
+ else {
757
+ title = cap[3] ? cap[3].slice(1, -1) : '';
758
+ }
759
+ href = href.trim();
760
+ if (/^</.test(href)) {
761
+ if (this.options.pedantic && !(/>$/.test(trimmedUrl))) {
762
+ // pedantic allows starting angle bracket without ending angle bracket
763
+ href = href.slice(1);
764
+ }
765
+ else {
766
+ href = href.slice(1, -1);
767
+ }
768
+ }
769
+ return outputLink(cap, {
770
+ href: href ? href.replace(this.rules.inline.anyPunctuation, '$1') : href,
771
+ title: title ? title.replace(this.rules.inline.anyPunctuation, '$1') : title,
772
+ }, cap[0], this.lexer);
773
+ }
774
+ }
775
+ reflink(src, links) {
776
+ let cap;
777
+ if ((cap = this.rules.inline.reflink.exec(src))
778
+ || (cap = this.rules.inline.nolink.exec(src))) {
779
+ const linkString = (cap[2] || cap[1]).replace(/\s+/g, ' ');
780
+ const link = links[linkString.toLowerCase()];
781
+ if (!link) {
782
+ const text = cap[0].charAt(0);
783
+ return {
784
+ type: 'text',
785
+ raw: text,
786
+ text,
787
+ };
788
+ }
789
+ return outputLink(cap, link, cap[0], this.lexer);
790
+ }
791
+ }
792
+ emStrong(src, maskedSrc, prevChar = '') {
793
+ let match = this.rules.inline.emStrongLDelim.exec(src);
794
+ if (!match)
795
+ return;
796
+ // _ can't be between two alphanumerics. \p{L}\p{N} includes non-english alphabet/numbers as well
797
+ if (match[3] && prevChar.match(/[\p{L}\p{N}]/u))
798
+ return;
799
+ const nextChar = match[1] || match[2] || '';
800
+ if (!nextChar || !prevChar || this.rules.inline.punctuation.exec(prevChar)) {
801
+ // unicode Regex counts emoji as 1 char; spread into array for proper count (used multiple times below)
802
+ const lLength = [...match[0]].length - 1;
803
+ let rDelim, rLength, delimTotal = lLength, midDelimTotal = 0;
804
+ const endReg = match[0][0] === '*' ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
805
+ endReg.lastIndex = 0;
806
+ // Clip maskedSrc to same section of string as src (move to lexer?)
807
+ maskedSrc = maskedSrc.slice(-1 * src.length + lLength);
808
+ while ((match = endReg.exec(maskedSrc)) != null) {
809
+ rDelim = match[1] || match[2] || match[3] || match[4] || match[5] || match[6];
810
+ if (!rDelim)
811
+ continue; // skip single * in __abc*abc__
812
+ rLength = [...rDelim].length;
813
+ if (match[3] || match[4]) { // found another Left Delim
814
+ delimTotal += rLength;
815
+ continue;
816
+ }
817
+ else if (match[5] || match[6]) { // either Left or Right Delim
818
+ if (lLength % 3 && !((lLength + rLength) % 3)) {
819
+ midDelimTotal += rLength;
820
+ continue; // CommonMark Emphasis Rules 9-10
821
+ }
822
+ }
823
+ delimTotal -= rLength;
824
+ if (delimTotal > 0)
825
+ continue; // Haven't found enough closing delimiters
826
+ // Remove extra characters. *a*** -> *a*
827
+ rLength = Math.min(rLength, rLength + delimTotal + midDelimTotal);
828
+ // char length can be >1 for unicode characters;
829
+ const lastCharLength = [...match[0]][0].length;
830
+ const raw = src.slice(0, lLength + match.index + lastCharLength + rLength);
831
+ // Create `em` if smallest delimiter has odd char count. *a***
832
+ if (Math.min(lLength, rLength) % 2) {
833
+ const text = raw.slice(1, -1);
834
+ return {
835
+ type: 'em',
836
+ raw,
837
+ text,
838
+ tokens: this.lexer.inlineTokens(text),
839
+ };
840
+ }
841
+ // Create 'strong' if smallest delimiter has even char count. **a***
842
+ const text = raw.slice(2, -2);
843
+ return {
844
+ type: 'strong',
845
+ raw,
846
+ text,
847
+ tokens: this.lexer.inlineTokens(text),
848
+ };
849
+ }
850
+ }
851
+ }
852
+ codespan(src) {
853
+ const cap = this.rules.inline.code.exec(src);
854
+ if (cap) {
855
+ let text = cap[2].replace(/\n/g, ' ');
856
+ const hasNonSpaceChars = /[^ ]/.test(text);
857
+ const hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
858
+ if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
859
+ text = text.substring(1, text.length - 1);
860
+ }
861
+ text = escape$1(text, true);
862
+ return {
863
+ type: 'codespan',
864
+ raw: cap[0],
865
+ text,
866
+ };
867
+ }
868
+ }
869
+ br(src) {
870
+ const cap = this.rules.inline.br.exec(src);
871
+ if (cap) {
872
+ return {
873
+ type: 'br',
874
+ raw: cap[0],
875
+ };
876
+ }
877
+ }
878
+ del(src) {
879
+ const cap = this.rules.inline.del.exec(src);
880
+ if (cap) {
881
+ return {
882
+ type: 'del',
883
+ raw: cap[0],
884
+ text: cap[2],
885
+ tokens: this.lexer.inlineTokens(cap[2]),
886
+ };
887
+ }
888
+ }
889
+ autolink(src) {
890
+ const cap = this.rules.inline.autolink.exec(src);
891
+ if (cap) {
892
+ let text, href;
893
+ if (cap[2] === '@') {
894
+ text = escape$1(cap[1]);
895
+ href = 'mailto:' + text;
896
+ }
897
+ else {
898
+ text = escape$1(cap[1]);
899
+ href = text;
900
+ }
901
+ return {
902
+ type: 'link',
903
+ raw: cap[0],
904
+ text,
905
+ href,
906
+ tokens: [
907
+ {
908
+ type: 'text',
909
+ raw: text,
910
+ text,
911
+ },
912
+ ],
913
+ };
914
+ }
915
+ }
916
+ url(src) {
917
+ let cap;
918
+ if (cap = this.rules.inline.url.exec(src)) {
919
+ let text, href;
920
+ if (cap[2] === '@') {
921
+ text = escape$1(cap[0]);
922
+ href = 'mailto:' + text;
923
+ }
924
+ else {
925
+ // do extended autolink path validation
926
+ let prevCapZero;
927
+ do {
928
+ prevCapZero = cap[0];
929
+ cap[0] = this.rules.inline._backpedal.exec(cap[0])?.[0] ?? '';
930
+ } while (prevCapZero !== cap[0]);
931
+ text = escape$1(cap[0]);
932
+ if (cap[1] === 'www.') {
933
+ href = 'http://' + cap[0];
934
+ }
935
+ else {
936
+ href = cap[0];
937
+ }
938
+ }
939
+ return {
940
+ type: 'link',
941
+ raw: cap[0],
942
+ text,
943
+ href,
944
+ tokens: [
945
+ {
946
+ type: 'text',
947
+ raw: text,
948
+ text,
949
+ },
950
+ ],
951
+ };
952
+ }
953
+ }
954
+ inlineText(src) {
955
+ const cap = this.rules.inline.text.exec(src);
956
+ if (cap) {
957
+ let text;
958
+ if (this.lexer.state.inRawBlock) {
959
+ text = cap[0];
960
+ }
961
+ else {
962
+ text = escape$1(cap[0]);
963
+ }
964
+ return {
965
+ type: 'text',
966
+ raw: cap[0],
967
+ text,
968
+ };
969
+ }
970
+ }
971
+ }
972
+
973
+ /**
974
+ * Block-Level Grammar
975
+ */
976
+ const newline = /^(?:[ \t]*(?:\n|$))+/;
977
+ const blockCode = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
978
+ const fences = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
979
+ const hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
980
+ const heading = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
981
+ const bullet = /(?:[*+-]|\d{1,9}[.)])/;
982
+ const lheading = edit(/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/)
983
+ .replace(/bull/g, bullet) // lists can interrupt
984
+ .replace(/blockCode/g, /(?: {4}| {0,3}\t)/) // indented code blocks can interrupt
985
+ .replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
986
+ .replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
987
+ .replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt
988
+ .replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
989
+ .getRegex();
990
+ const _paragraph = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
991
+ const blockText = /^[^\n]+/;
992
+ const _blockLabel = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
993
+ const def = edit(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/)
994
+ .replace('label', _blockLabel)
995
+ .replace('title', /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/)
996
+ .getRegex();
997
+ const list = edit(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/)
998
+ .replace(/bull/g, bullet)
999
+ .getRegex();
1000
+ const _tag = 'address|article|aside|base|basefont|blockquote|body|caption'
1001
+ + '|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption'
1002
+ + '|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe'
1003
+ + '|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option'
1004
+ + '|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title'
1005
+ + '|tr|track|ul';
1006
+ const _comment = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
1007
+ const html = edit('^ {0,3}(?:' // optional indentation
1008
+ + '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
1009
+ + '|comment[^\\n]*(\\n+|$)' // (2)
1010
+ + '|<\\?[\\s\\S]*?(?:\\?>\\n*|$)' // (3)
1011
+ + '|<![A-Z][\\s\\S]*?(?:>\\n*|$)' // (4)
1012
+ + '|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)' // (5)
1013
+ + '|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (6)
1014
+ + '|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (7) open tag
1015
+ + '|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ \t]*)+\\n|$)' // (7) closing tag
1016
+ + ')', 'i')
1017
+ .replace('comment', _comment)
1018
+ .replace('tag', _tag)
1019
+ .replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/)
1020
+ .getRegex();
1021
+ const paragraph = edit(_paragraph)
1022
+ .replace('hr', hr)
1023
+ .replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
1024
+ .replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs
1025
+ .replace('|table', '')
1026
+ .replace('blockquote', ' {0,3}>')
1027
+ .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1028
+ .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1029
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
1030
+ .replace('tag', _tag) // pars can be interrupted by type (6) html blocks
1031
+ .getRegex();
1032
+ const blockquote = edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/)
1033
+ .replace('paragraph', paragraph)
1034
+ .getRegex();
1035
+ /**
1036
+ * Normal Block Grammar
1037
+ */
1038
+ const blockNormal = {
1039
+ blockquote,
1040
+ code: blockCode,
1041
+ def,
1042
+ fences,
1043
+ heading,
1044
+ hr,
1045
+ html,
1046
+ lheading,
1047
+ list,
1048
+ newline,
1049
+ paragraph,
1050
+ table: noopTest,
1051
+ text: blockText,
1052
+ };
1053
+ /**
1054
+ * GFM Block Grammar
1055
+ */
1056
+ const gfmTable = edit('^ *([^\\n ].*)\\n' // Header
1057
+ + ' {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)' // Align
1058
+ + '(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)') // Cells
1059
+ .replace('hr', hr)
1060
+ .replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
1061
+ .replace('blockquote', ' {0,3}>')
1062
+ .replace('code', '(?: {4}| {0,3}\t)[^\\n]')
1063
+ .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1064
+ .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1065
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
1066
+ .replace('tag', _tag) // tables can be interrupted by type (6) html blocks
1067
+ .getRegex();
1068
+ const blockGfm = {
1069
+ ...blockNormal,
1070
+ table: gfmTable,
1071
+ paragraph: edit(_paragraph)
1072
+ .replace('hr', hr)
1073
+ .replace('heading', ' {0,3}#{1,6}(?:\\s|$)')
1074
+ .replace('|lheading', '') // setext headings don't interrupt commonmark paragraphs
1075
+ .replace('table', gfmTable) // interrupt paragraphs with table
1076
+ .replace('blockquote', ' {0,3}>')
1077
+ .replace('fences', ' {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n')
1078
+ .replace('list', ' {0,3}(?:[*+-]|1[.)]) ') // only lists starting from 1 can interrupt
1079
+ .replace('html', '</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)')
1080
+ .replace('tag', _tag) // pars can be interrupted by type (6) html blocks
1081
+ .getRegex(),
1082
+ };
1083
+ /**
1084
+ * Pedantic grammar (original John Gruber's loose markdown specification)
1085
+ */
1086
+ const blockPedantic = {
1087
+ ...blockNormal,
1088
+ html: edit('^ *(?:comment *(?:\\n|\\s*$)'
1089
+ + '|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)' // closed tag
1090
+ + '|<tag(?:"[^"]*"|\'[^\']*\'|\\s[^\'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))')
1091
+ .replace('comment', _comment)
1092
+ .replace(/tag/g, '(?!(?:'
1093
+ + 'a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub'
1094
+ + '|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)'
1095
+ + '\\b)\\w+(?!:|[^\\w\\s@]*@)\\b')
1096
+ .getRegex(),
1097
+ def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
1098
+ heading: /^(#{1,6})(.*)(?:\n+|$)/,
1099
+ fences: noopTest, // fences not supported
1100
+ lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
1101
+ paragraph: edit(_paragraph)
1102
+ .replace('hr', hr)
1103
+ .replace('heading', ' *#{1,6} *[^\n]')
1104
+ .replace('lheading', lheading)
1105
+ .replace('|table', '')
1106
+ .replace('blockquote', ' {0,3}>')
1107
+ .replace('|fences', '')
1108
+ .replace('|list', '')
1109
+ .replace('|html', '')
1110
+ .replace('|tag', '')
1111
+ .getRegex(),
1112
+ };
1113
+ /**
1114
+ * Inline-Level Grammar
1115
+ */
1116
+ const escape = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
1117
+ const inlineCode = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
1118
+ const br = /^( {2,}|\\)\n(?!\s*$)/;
1119
+ const inlineText = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
1120
+ // list of unicode punctuation marks, plus any missing characters from CommonMark spec
1121
+ const _punctuation = '\\p{P}\\p{S}';
1122
+ const punctuation = edit(/^((?![*_])[\spunctuation])/, 'u')
1123
+ .replace(/punctuation/g, _punctuation).getRegex();
1124
+ // sequences em should skip over [title](link), `code`, <html>
1125
+ const blockSkip = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g;
1126
+ const emStrongLDelim = edit(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/, 'u')
1127
+ .replace(/punct/g, _punctuation)
1128
+ .getRegex();
1129
+ const emStrongRDelimAst = edit('^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong
1130
+ + '|[^*]+(?=[^*])' // Consume to delim
1131
+ + '|(?!\\*)[punct](\\*+)(?=[\\s]|$)' // (1) #*** can only be a Right Delimiter
1132
+ + '|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)' // (2) a***#, a*** can only be a Right Delimiter
1133
+ + '|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])' // (3) #***a, ***a can only be Left Delimiter
1134
+ + '|[\\s](\\*+)(?!\\*)(?=[punct])' // (4) ***# can only be Left Delimiter
1135
+ + '|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])' // (5) #***# can be either Left or Right Delimiter
1136
+ + '|[^punct\\s](\\*+)(?=[^punct\\s])', 'gu') // (6) a***a can be either Left or Right Delimiter
1137
+ .replace(/punct/g, _punctuation)
1138
+ .getRegex();
1139
+ // (6) Not allowed for _
1140
+ const emStrongRDelimUnd = edit('^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)' // Skip orphan inside strong
1141
+ + '|[^_]+(?=[^_])' // Consume to delim
1142
+ + '|(?!_)[punct](_+)(?=[\\s]|$)' // (1) #___ can only be a Right Delimiter
1143
+ + '|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)' // (2) a___#, a___ can only be a Right Delimiter
1144
+ + '|(?!_)[punct\\s](_+)(?=[^punct\\s])' // (3) #___a, ___a can only be Left Delimiter
1145
+ + '|[\\s](_+)(?!_)(?=[punct])' // (4) ___# can only be Left Delimiter
1146
+ + '|(?!_)[punct](_+)(?!_)(?=[punct])', 'gu') // (5) #___# can be either Left or Right Delimiter
1147
+ .replace(/punct/g, _punctuation)
1148
+ .getRegex();
1149
+ const anyPunctuation = edit(/\\([punct])/, 'gu')
1150
+ .replace(/punct/g, _punctuation)
1151
+ .getRegex();
1152
+ const autolink = edit(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/)
1153
+ .replace('scheme', /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/)
1154
+ .replace('email', /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/)
1155
+ .getRegex();
1156
+ const _inlineComment = edit(_comment).replace('(?:-->|$)', '-->').getRegex();
1157
+ const tag = edit('^comment'
1158
+ + '|^</[a-zA-Z][\\w:-]*\\s*>' // self-closing tag
1159
+ + '|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>' // open tag
1160
+ + '|^<\\?[\\s\\S]*?\\?>' // processing instruction, e.g. <?php ?>
1161
+ + '|^<![a-zA-Z]+\\s[\\s\\S]*?>' // declaration, e.g. <!DOCTYPE html>
1162
+ + '|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>') // CDATA section
1163
+ .replace('comment', _inlineComment)
1164
+ .replace('attribute', /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/)
1165
+ .getRegex();
1166
+ const _inlineLabel = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
1167
+ const link = edit(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/)
1168
+ .replace('label', _inlineLabel)
1169
+ .replace('href', /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/)
1170
+ .replace('title', /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/)
1171
+ .getRegex();
1172
+ const reflink = edit(/^!?\[(label)\]\[(ref)\]/)
1173
+ .replace('label', _inlineLabel)
1174
+ .replace('ref', _blockLabel)
1175
+ .getRegex();
1176
+ const nolink = edit(/^!?\[(ref)\](?:\[\])?/)
1177
+ .replace('ref', _blockLabel)
1178
+ .getRegex();
1179
+ const reflinkSearch = edit('reflink|nolink(?!\\()', 'g')
1180
+ .replace('reflink', reflink)
1181
+ .replace('nolink', nolink)
1182
+ .getRegex();
1183
+ /**
1184
+ * Normal Inline Grammar
1185
+ */
1186
+ const inlineNormal = {
1187
+ _backpedal: noopTest, // only used for GFM url
1188
+ anyPunctuation,
1189
+ autolink,
1190
+ blockSkip,
1191
+ br,
1192
+ code: inlineCode,
1193
+ del: noopTest,
1194
+ emStrongLDelim,
1195
+ emStrongRDelimAst,
1196
+ emStrongRDelimUnd,
1197
+ escape,
1198
+ link,
1199
+ nolink,
1200
+ punctuation,
1201
+ reflink,
1202
+ reflinkSearch,
1203
+ tag,
1204
+ text: inlineText,
1205
+ url: noopTest,
1206
+ };
1207
+ /**
1208
+ * Pedantic Inline Grammar
1209
+ */
1210
+ const inlinePedantic = {
1211
+ ...inlineNormal,
1212
+ link: edit(/^!?\[(label)\]\((.*?)\)/)
1213
+ .replace('label', _inlineLabel)
1214
+ .getRegex(),
1215
+ reflink: edit(/^!?\[(label)\]\s*\[([^\]]*)\]/)
1216
+ .replace('label', _inlineLabel)
1217
+ .getRegex(),
1218
+ };
1219
+ /**
1220
+ * GFM Inline Grammar
1221
+ */
1222
+ const inlineGfm = {
1223
+ ...inlineNormal,
1224
+ escape: edit(escape).replace('])', '~|])').getRegex(),
1225
+ url: edit(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, 'i')
1226
+ .replace('email', /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/)
1227
+ .getRegex(),
1228
+ _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
1229
+ del: /^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,
1230
+ text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/,
1231
+ };
1232
+ /**
1233
+ * GFM + Line Breaks Inline Grammar
1234
+ */
1235
+ const inlineBreaks = {
1236
+ ...inlineGfm,
1237
+ br: edit(br).replace('{2,}', '*').getRegex(),
1238
+ text: edit(inlineGfm.text)
1239
+ .replace('\\b_', '\\b_| {2,}\\n')
1240
+ .replace(/\{2,\}/g, '*')
1241
+ .getRegex(),
1242
+ };
1243
+ /**
1244
+ * exports
1245
+ */
1246
+ const block = {
1247
+ normal: blockNormal,
1248
+ gfm: blockGfm,
1249
+ pedantic: blockPedantic,
1250
+ };
1251
+ const inline = {
1252
+ normal: inlineNormal,
1253
+ gfm: inlineGfm,
1254
+ breaks: inlineBreaks,
1255
+ pedantic: inlinePedantic,
1256
+ };
1257
+
1258
+ /**
1259
+ * Block Lexer
1260
+ */
1261
+ class _Lexer {
1262
+ tokens;
1263
+ options;
1264
+ state;
1265
+ tokenizer;
1266
+ inlineQueue;
1267
+ constructor(options) {
1268
+ // TokenList cannot be created in one go
1269
+ this.tokens = [];
1270
+ this.tokens.links = Object.create(null);
1271
+ this.options = options || _defaults;
1272
+ this.options.tokenizer = this.options.tokenizer || new _Tokenizer();
1273
+ this.tokenizer = this.options.tokenizer;
1274
+ this.tokenizer.options = this.options;
1275
+ this.tokenizer.lexer = this;
1276
+ this.inlineQueue = [];
1277
+ this.state = {
1278
+ inLink: false,
1279
+ inRawBlock: false,
1280
+ top: true,
1281
+ };
1282
+ const rules = {
1283
+ block: block.normal,
1284
+ inline: inline.normal,
1285
+ };
1286
+ if (this.options.pedantic) {
1287
+ rules.block = block.pedantic;
1288
+ rules.inline = inline.pedantic;
1289
+ }
1290
+ else if (this.options.gfm) {
1291
+ rules.block = block.gfm;
1292
+ if (this.options.breaks) {
1293
+ rules.inline = inline.breaks;
1294
+ }
1295
+ else {
1296
+ rules.inline = inline.gfm;
1297
+ }
1298
+ }
1299
+ this.tokenizer.rules = rules;
1300
+ }
1301
+ /**
1302
+ * Expose Rules
1303
+ */
1304
+ static get rules() {
1305
+ return {
1306
+ block,
1307
+ inline,
1308
+ };
1309
+ }
1310
+ /**
1311
+ * Static Lex Method
1312
+ */
1313
+ static lex(src, options) {
1314
+ const lexer = new _Lexer(options);
1315
+ return lexer.lex(src);
1316
+ }
1317
+ /**
1318
+ * Static Lex Inline Method
1319
+ */
1320
+ static lexInline(src, options) {
1321
+ const lexer = new _Lexer(options);
1322
+ return lexer.inlineTokens(src);
1323
+ }
1324
+ /**
1325
+ * Preprocessing
1326
+ */
1327
+ lex(src) {
1328
+ src = src
1329
+ .replace(/\r\n|\r/g, '\n');
1330
+ this.blockTokens(src, this.tokens);
1331
+ for (let i = 0; i < this.inlineQueue.length; i++) {
1332
+ const next = this.inlineQueue[i];
1333
+ this.inlineTokens(next.src, next.tokens);
1334
+ }
1335
+ this.inlineQueue = [];
1336
+ return this.tokens;
1337
+ }
1338
+ blockTokens(src, tokens = [], lastParagraphClipped = false) {
1339
+ if (this.options.pedantic) {
1340
+ src = src.replace(/\t/g, ' ').replace(/^ +$/gm, '');
1341
+ }
1342
+ let token;
1343
+ let lastToken;
1344
+ let cutSrc;
1345
+ while (src) {
1346
+ if (this.options.extensions
1347
+ && this.options.extensions.block
1348
+ && this.options.extensions.block.some((extTokenizer) => {
1349
+ if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1350
+ src = src.substring(token.raw.length);
1351
+ tokens.push(token);
1352
+ return true;
1353
+ }
1354
+ return false;
1355
+ })) {
1356
+ continue;
1357
+ }
1358
+ // newline
1359
+ if (token = this.tokenizer.space(src)) {
1360
+ src = src.substring(token.raw.length);
1361
+ if (token.raw.length === 1 && tokens.length > 0) {
1362
+ // if there's a single \n as a spacer, it's terminating the last line,
1363
+ // so move it there so that we don't get unnecessary paragraph tags
1364
+ tokens[tokens.length - 1].raw += '\n';
1365
+ }
1366
+ else {
1367
+ tokens.push(token);
1368
+ }
1369
+ continue;
1370
+ }
1371
+ // code
1372
+ if (token = this.tokenizer.code(src)) {
1373
+ src = src.substring(token.raw.length);
1374
+ lastToken = tokens[tokens.length - 1];
1375
+ // An indented code block cannot interrupt a paragraph.
1376
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1377
+ lastToken.raw += '\n' + token.raw;
1378
+ lastToken.text += '\n' + token.text;
1379
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1380
+ }
1381
+ else {
1382
+ tokens.push(token);
1383
+ }
1384
+ continue;
1385
+ }
1386
+ // fences
1387
+ if (token = this.tokenizer.fences(src)) {
1388
+ src = src.substring(token.raw.length);
1389
+ tokens.push(token);
1390
+ continue;
1391
+ }
1392
+ // heading
1393
+ if (token = this.tokenizer.heading(src)) {
1394
+ src = src.substring(token.raw.length);
1395
+ tokens.push(token);
1396
+ continue;
1397
+ }
1398
+ // hr
1399
+ if (token = this.tokenizer.hr(src)) {
1400
+ src = src.substring(token.raw.length);
1401
+ tokens.push(token);
1402
+ continue;
1403
+ }
1404
+ // blockquote
1405
+ if (token = this.tokenizer.blockquote(src)) {
1406
+ src = src.substring(token.raw.length);
1407
+ tokens.push(token);
1408
+ continue;
1409
+ }
1410
+ // list
1411
+ if (token = this.tokenizer.list(src)) {
1412
+ src = src.substring(token.raw.length);
1413
+ tokens.push(token);
1414
+ continue;
1415
+ }
1416
+ // html
1417
+ if (token = this.tokenizer.html(src)) {
1418
+ src = src.substring(token.raw.length);
1419
+ tokens.push(token);
1420
+ continue;
1421
+ }
1422
+ // def
1423
+ if (token = this.tokenizer.def(src)) {
1424
+ src = src.substring(token.raw.length);
1425
+ lastToken = tokens[tokens.length - 1];
1426
+ if (lastToken && (lastToken.type === 'paragraph' || lastToken.type === 'text')) {
1427
+ lastToken.raw += '\n' + token.raw;
1428
+ lastToken.text += '\n' + token.raw;
1429
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1430
+ }
1431
+ else if (!this.tokens.links[token.tag]) {
1432
+ this.tokens.links[token.tag] = {
1433
+ href: token.href,
1434
+ title: token.title,
1435
+ };
1436
+ }
1437
+ continue;
1438
+ }
1439
+ // table (gfm)
1440
+ if (token = this.tokenizer.table(src)) {
1441
+ src = src.substring(token.raw.length);
1442
+ tokens.push(token);
1443
+ continue;
1444
+ }
1445
+ // lheading
1446
+ if (token = this.tokenizer.lheading(src)) {
1447
+ src = src.substring(token.raw.length);
1448
+ tokens.push(token);
1449
+ continue;
1450
+ }
1451
+ // top-level paragraph
1452
+ // prevent paragraph consuming extensions by clipping 'src' to extension start
1453
+ cutSrc = src;
1454
+ if (this.options.extensions && this.options.extensions.startBlock) {
1455
+ let startIndex = Infinity;
1456
+ const tempSrc = src.slice(1);
1457
+ let tempStart;
1458
+ this.options.extensions.startBlock.forEach((getStartIndex) => {
1459
+ tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1460
+ if (typeof tempStart === 'number' && tempStart >= 0) {
1461
+ startIndex = Math.min(startIndex, tempStart);
1462
+ }
1463
+ });
1464
+ if (startIndex < Infinity && startIndex >= 0) {
1465
+ cutSrc = src.substring(0, startIndex + 1);
1466
+ }
1467
+ }
1468
+ if (this.state.top && (token = this.tokenizer.paragraph(cutSrc))) {
1469
+ lastToken = tokens[tokens.length - 1];
1470
+ if (lastParagraphClipped && lastToken?.type === 'paragraph') {
1471
+ lastToken.raw += '\n' + token.raw;
1472
+ lastToken.text += '\n' + token.text;
1473
+ this.inlineQueue.pop();
1474
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1475
+ }
1476
+ else {
1477
+ tokens.push(token);
1478
+ }
1479
+ lastParagraphClipped = (cutSrc.length !== src.length);
1480
+ src = src.substring(token.raw.length);
1481
+ continue;
1482
+ }
1483
+ // text
1484
+ if (token = this.tokenizer.text(src)) {
1485
+ src = src.substring(token.raw.length);
1486
+ lastToken = tokens[tokens.length - 1];
1487
+ if (lastToken && lastToken.type === 'text') {
1488
+ lastToken.raw += '\n' + token.raw;
1489
+ lastToken.text += '\n' + token.text;
1490
+ this.inlineQueue.pop();
1491
+ this.inlineQueue[this.inlineQueue.length - 1].src = lastToken.text;
1492
+ }
1493
+ else {
1494
+ tokens.push(token);
1495
+ }
1496
+ continue;
1497
+ }
1498
+ if (src) {
1499
+ const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1500
+ if (this.options.silent) {
1501
+ console.error(errMsg);
1502
+ break;
1503
+ }
1504
+ else {
1505
+ throw new Error(errMsg);
1506
+ }
1507
+ }
1508
+ }
1509
+ this.state.top = true;
1510
+ return tokens;
1511
+ }
1512
+ inline(src, tokens = []) {
1513
+ this.inlineQueue.push({ src, tokens });
1514
+ return tokens;
1515
+ }
1516
+ /**
1517
+ * Lexing/Compiling
1518
+ */
1519
+ inlineTokens(src, tokens = []) {
1520
+ let token, lastToken, cutSrc;
1521
+ // String with links masked to avoid interference with em and strong
1522
+ let maskedSrc = src;
1523
+ let match;
1524
+ let keepPrevChar, prevChar;
1525
+ // Mask out reflinks
1526
+ if (this.tokens.links) {
1527
+ const links = Object.keys(this.tokens.links);
1528
+ if (links.length > 0) {
1529
+ while ((match = this.tokenizer.rules.inline.reflinkSearch.exec(maskedSrc)) != null) {
1530
+ if (links.includes(match[0].slice(match[0].lastIndexOf('[') + 1, -1))) {
1531
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex);
1532
+ }
1533
+ }
1534
+ }
1535
+ }
1536
+ // Mask out other blocks
1537
+ while ((match = this.tokenizer.rules.inline.blockSkip.exec(maskedSrc)) != null) {
1538
+ maskedSrc = maskedSrc.slice(0, match.index) + '[' + 'a'.repeat(match[0].length - 2) + ']' + maskedSrc.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
1539
+ }
1540
+ // Mask out escaped characters
1541
+ while ((match = this.tokenizer.rules.inline.anyPunctuation.exec(maskedSrc)) != null) {
1542
+ maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
1543
+ }
1544
+ while (src) {
1545
+ if (!keepPrevChar) {
1546
+ prevChar = '';
1547
+ }
1548
+ keepPrevChar = false;
1549
+ // extensions
1550
+ if (this.options.extensions
1551
+ && this.options.extensions.inline
1552
+ && this.options.extensions.inline.some((extTokenizer) => {
1553
+ if (token = extTokenizer.call({ lexer: this }, src, tokens)) {
1554
+ src = src.substring(token.raw.length);
1555
+ tokens.push(token);
1556
+ return true;
1557
+ }
1558
+ return false;
1559
+ })) {
1560
+ continue;
1561
+ }
1562
+ // escape
1563
+ if (token = this.tokenizer.escape(src)) {
1564
+ src = src.substring(token.raw.length);
1565
+ tokens.push(token);
1566
+ continue;
1567
+ }
1568
+ // tag
1569
+ if (token = this.tokenizer.tag(src)) {
1570
+ src = src.substring(token.raw.length);
1571
+ lastToken = tokens[tokens.length - 1];
1572
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1573
+ lastToken.raw += token.raw;
1574
+ lastToken.text += token.text;
1575
+ }
1576
+ else {
1577
+ tokens.push(token);
1578
+ }
1579
+ continue;
1580
+ }
1581
+ // link
1582
+ if (token = this.tokenizer.link(src)) {
1583
+ src = src.substring(token.raw.length);
1584
+ tokens.push(token);
1585
+ continue;
1586
+ }
1587
+ // reflink, nolink
1588
+ if (token = this.tokenizer.reflink(src, this.tokens.links)) {
1589
+ src = src.substring(token.raw.length);
1590
+ lastToken = tokens[tokens.length - 1];
1591
+ if (lastToken && token.type === 'text' && lastToken.type === 'text') {
1592
+ lastToken.raw += token.raw;
1593
+ lastToken.text += token.text;
1594
+ }
1595
+ else {
1596
+ tokens.push(token);
1597
+ }
1598
+ continue;
1599
+ }
1600
+ // em & strong
1601
+ if (token = this.tokenizer.emStrong(src, maskedSrc, prevChar)) {
1602
+ src = src.substring(token.raw.length);
1603
+ tokens.push(token);
1604
+ continue;
1605
+ }
1606
+ // code
1607
+ if (token = this.tokenizer.codespan(src)) {
1608
+ src = src.substring(token.raw.length);
1609
+ tokens.push(token);
1610
+ continue;
1611
+ }
1612
+ // br
1613
+ if (token = this.tokenizer.br(src)) {
1614
+ src = src.substring(token.raw.length);
1615
+ tokens.push(token);
1616
+ continue;
1617
+ }
1618
+ // del (gfm)
1619
+ if (token = this.tokenizer.del(src)) {
1620
+ src = src.substring(token.raw.length);
1621
+ tokens.push(token);
1622
+ continue;
1623
+ }
1624
+ // autolink
1625
+ if (token = this.tokenizer.autolink(src)) {
1626
+ src = src.substring(token.raw.length);
1627
+ tokens.push(token);
1628
+ continue;
1629
+ }
1630
+ // url (gfm)
1631
+ if (!this.state.inLink && (token = this.tokenizer.url(src))) {
1632
+ src = src.substring(token.raw.length);
1633
+ tokens.push(token);
1634
+ continue;
1635
+ }
1636
+ // text
1637
+ // prevent inlineText consuming extensions by clipping 'src' to extension start
1638
+ cutSrc = src;
1639
+ if (this.options.extensions && this.options.extensions.startInline) {
1640
+ let startIndex = Infinity;
1641
+ const tempSrc = src.slice(1);
1642
+ let tempStart;
1643
+ this.options.extensions.startInline.forEach((getStartIndex) => {
1644
+ tempStart = getStartIndex.call({ lexer: this }, tempSrc);
1645
+ if (typeof tempStart === 'number' && tempStart >= 0) {
1646
+ startIndex = Math.min(startIndex, tempStart);
1647
+ }
1648
+ });
1649
+ if (startIndex < Infinity && startIndex >= 0) {
1650
+ cutSrc = src.substring(0, startIndex + 1);
1651
+ }
1652
+ }
1653
+ if (token = this.tokenizer.inlineText(cutSrc)) {
1654
+ src = src.substring(token.raw.length);
1655
+ if (token.raw.slice(-1) !== '_') { // Track prevChar before string of ____ started
1656
+ prevChar = token.raw.slice(-1);
1657
+ }
1658
+ keepPrevChar = true;
1659
+ lastToken = tokens[tokens.length - 1];
1660
+ if (lastToken && lastToken.type === 'text') {
1661
+ lastToken.raw += token.raw;
1662
+ lastToken.text += token.text;
1663
+ }
1664
+ else {
1665
+ tokens.push(token);
1666
+ }
1667
+ continue;
1668
+ }
1669
+ if (src) {
1670
+ const errMsg = 'Infinite loop on byte: ' + src.charCodeAt(0);
1671
+ if (this.options.silent) {
1672
+ console.error(errMsg);
1673
+ break;
1674
+ }
1675
+ else {
1676
+ throw new Error(errMsg);
1677
+ }
1678
+ }
1679
+ }
1680
+ return tokens;
1681
+ }
1682
+ }
1683
+
1684
+ /**
1685
+ * Renderer
1686
+ */
1687
+ class _Renderer {
1688
+ options;
1689
+ parser; // set by the parser
1690
+ constructor(options) {
1691
+ this.options = options || _defaults;
1692
+ }
1693
+ space(token) {
1694
+ return '';
1695
+ }
1696
+ code({ text, lang, escaped }) {
1697
+ const langString = (lang || '').match(/^\S*/)?.[0];
1698
+ const code = text.replace(/\n$/, '') + '\n';
1699
+ if (!langString) {
1700
+ return '<pre><code>'
1701
+ + (escaped ? code : escape$1(code, true))
1702
+ + '</code></pre>\n';
1703
+ }
1704
+ return '<pre><code class="language-'
1705
+ + escape$1(langString)
1706
+ + '">'
1707
+ + (escaped ? code : escape$1(code, true))
1708
+ + '</code></pre>\n';
1709
+ }
1710
+ blockquote({ tokens }) {
1711
+ const body = this.parser.parse(tokens);
1712
+ return `<blockquote>\n${body}</blockquote>\n`;
1713
+ }
1714
+ html({ text }) {
1715
+ return text;
1716
+ }
1717
+ heading({ tokens, depth }) {
1718
+ return `<h${depth}>${this.parser.parseInline(tokens)}</h${depth}>\n`;
1719
+ }
1720
+ hr(token) {
1721
+ return '<hr>\n';
1722
+ }
1723
+ list(token) {
1724
+ const ordered = token.ordered;
1725
+ const start = token.start;
1726
+ let body = '';
1727
+ for (let j = 0; j < token.items.length; j++) {
1728
+ const item = token.items[j];
1729
+ body += this.listitem(item);
1730
+ }
1731
+ const type = ordered ? 'ol' : 'ul';
1732
+ const startAttr = (ordered && start !== 1) ? (' start="' + start + '"') : '';
1733
+ return '<' + type + startAttr + '>\n' + body + '</' + type + '>\n';
1734
+ }
1735
+ listitem(item) {
1736
+ let itemBody = '';
1737
+ if (item.task) {
1738
+ const checkbox = this.checkbox({ checked: !!item.checked });
1739
+ if (item.loose) {
1740
+ if (item.tokens.length > 0 && item.tokens[0].type === 'paragraph') {
1741
+ item.tokens[0].text = checkbox + ' ' + item.tokens[0].text;
1742
+ if (item.tokens[0].tokens && item.tokens[0].tokens.length > 0 && item.tokens[0].tokens[0].type === 'text') {
1743
+ item.tokens[0].tokens[0].text = checkbox + ' ' + item.tokens[0].tokens[0].text;
1744
+ }
1745
+ }
1746
+ else {
1747
+ item.tokens.unshift({
1748
+ type: 'text',
1749
+ raw: checkbox + ' ',
1750
+ text: checkbox + ' ',
1751
+ });
1752
+ }
1753
+ }
1754
+ else {
1755
+ itemBody += checkbox + ' ';
1756
+ }
1757
+ }
1758
+ itemBody += this.parser.parse(item.tokens, !!item.loose);
1759
+ return `<li>${itemBody}</li>\n`;
1760
+ }
1761
+ checkbox({ checked }) {
1762
+ return '<input '
1763
+ + (checked ? 'checked="" ' : '')
1764
+ + 'disabled="" type="checkbox">';
1765
+ }
1766
+ paragraph({ tokens }) {
1767
+ return `<p>${this.parser.parseInline(tokens)}</p>\n`;
1768
+ }
1769
+ table(token) {
1770
+ let header = '';
1771
+ // header
1772
+ let cell = '';
1773
+ for (let j = 0; j < token.header.length; j++) {
1774
+ cell += this.tablecell(token.header[j]);
1775
+ }
1776
+ header += this.tablerow({ text: cell });
1777
+ let body = '';
1778
+ for (let j = 0; j < token.rows.length; j++) {
1779
+ const row = token.rows[j];
1780
+ cell = '';
1781
+ for (let k = 0; k < row.length; k++) {
1782
+ cell += this.tablecell(row[k]);
1783
+ }
1784
+ body += this.tablerow({ text: cell });
1785
+ }
1786
+ if (body)
1787
+ body = `<tbody>${body}</tbody>`;
1788
+ return '<table>\n'
1789
+ + '<thead>\n'
1790
+ + header
1791
+ + '</thead>\n'
1792
+ + body
1793
+ + '</table>\n';
1794
+ }
1795
+ tablerow({ text }) {
1796
+ return `<tr>\n${text}</tr>\n`;
1797
+ }
1798
+ tablecell(token) {
1799
+ const content = this.parser.parseInline(token.tokens);
1800
+ const type = token.header ? 'th' : 'td';
1801
+ const tag = token.align
1802
+ ? `<${type} align="${token.align}">`
1803
+ : `<${type}>`;
1804
+ return tag + content + `</${type}>\n`;
1805
+ }
1806
+ /**
1807
+ * span level renderer
1808
+ */
1809
+ strong({ tokens }) {
1810
+ return `<strong>${this.parser.parseInline(tokens)}</strong>`;
1811
+ }
1812
+ em({ tokens }) {
1813
+ return `<em>${this.parser.parseInline(tokens)}</em>`;
1814
+ }
1815
+ codespan({ text }) {
1816
+ return `<code>${text}</code>`;
1817
+ }
1818
+ br(token) {
1819
+ return '<br>';
1820
+ }
1821
+ del({ tokens }) {
1822
+ return `<del>${this.parser.parseInline(tokens)}</del>`;
1823
+ }
1824
+ link({ href, title, tokens }) {
1825
+ const text = this.parser.parseInline(tokens);
1826
+ const cleanHref = cleanUrl(href);
1827
+ if (cleanHref === null) {
1828
+ return text;
1829
+ }
1830
+ href = cleanHref;
1831
+ let out = '<a href="' + href + '"';
1832
+ if (title) {
1833
+ out += ' title="' + title + '"';
1834
+ }
1835
+ out += '>' + text + '</a>';
1836
+ return out;
1837
+ }
1838
+ image({ href, title, text }) {
1839
+ const cleanHref = cleanUrl(href);
1840
+ if (cleanHref === null) {
1841
+ return text;
1842
+ }
1843
+ href = cleanHref;
1844
+ let out = `<img src="${href}" alt="${text}"`;
1845
+ if (title) {
1846
+ out += ` title="${title}"`;
1847
+ }
1848
+ out += '>';
1849
+ return out;
1850
+ }
1851
+ text(token) {
1852
+ return 'tokens' in token && token.tokens ? this.parser.parseInline(token.tokens) : token.text;
1853
+ }
1854
+ }
1855
+
1856
+ /**
1857
+ * TextRenderer
1858
+ * returns only the textual part of the token
1859
+ */
1860
+ class _TextRenderer {
1861
+ // no need for block level renderers
1862
+ strong({ text }) {
1863
+ return text;
1864
+ }
1865
+ em({ text }) {
1866
+ return text;
1867
+ }
1868
+ codespan({ text }) {
1869
+ return text;
1870
+ }
1871
+ del({ text }) {
1872
+ return text;
1873
+ }
1874
+ html({ text }) {
1875
+ return text;
1876
+ }
1877
+ text({ text }) {
1878
+ return text;
1879
+ }
1880
+ link({ text }) {
1881
+ return '' + text;
1882
+ }
1883
+ image({ text }) {
1884
+ return '' + text;
1885
+ }
1886
+ br() {
1887
+ return '';
1888
+ }
1889
+ }
1890
+
1891
+ /**
1892
+ * Parsing & Compiling
1893
+ */
1894
+ class _Parser {
1895
+ options;
1896
+ renderer;
1897
+ textRenderer;
1898
+ constructor(options) {
1899
+ this.options = options || _defaults;
1900
+ this.options.renderer = this.options.renderer || new _Renderer();
1901
+ this.renderer = this.options.renderer;
1902
+ this.renderer.options = this.options;
1903
+ this.renderer.parser = this;
1904
+ this.textRenderer = new _TextRenderer();
1905
+ }
1906
+ /**
1907
+ * Static Parse Method
1908
+ */
1909
+ static parse(tokens, options) {
1910
+ const parser = new _Parser(options);
1911
+ return parser.parse(tokens);
1912
+ }
1913
+ /**
1914
+ * Static Parse Inline Method
1915
+ */
1916
+ static parseInline(tokens, options) {
1917
+ const parser = new _Parser(options);
1918
+ return parser.parseInline(tokens);
1919
+ }
1920
+ /**
1921
+ * Parse Loop
1922
+ */
1923
+ parse(tokens, top = true) {
1924
+ let out = '';
1925
+ for (let i = 0; i < tokens.length; i++) {
1926
+ const anyToken = tokens[i];
1927
+ // Run any renderer extensions
1928
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[anyToken.type]) {
1929
+ const genericToken = anyToken;
1930
+ const ret = this.options.extensions.renderers[genericToken.type].call({ parser: this }, genericToken);
1931
+ if (ret !== false || !['space', 'hr', 'heading', 'code', 'table', 'blockquote', 'list', 'html', 'paragraph', 'text'].includes(genericToken.type)) {
1932
+ out += ret || '';
1933
+ continue;
1934
+ }
1935
+ }
1936
+ const token = anyToken;
1937
+ switch (token.type) {
1938
+ case 'space': {
1939
+ out += this.renderer.space(token);
1940
+ continue;
1941
+ }
1942
+ case 'hr': {
1943
+ out += this.renderer.hr(token);
1944
+ continue;
1945
+ }
1946
+ case 'heading': {
1947
+ out += this.renderer.heading(token);
1948
+ continue;
1949
+ }
1950
+ case 'code': {
1951
+ out += this.renderer.code(token);
1952
+ continue;
1953
+ }
1954
+ case 'table': {
1955
+ out += this.renderer.table(token);
1956
+ continue;
1957
+ }
1958
+ case 'blockquote': {
1959
+ out += this.renderer.blockquote(token);
1960
+ continue;
1961
+ }
1962
+ case 'list': {
1963
+ out += this.renderer.list(token);
1964
+ continue;
1965
+ }
1966
+ case 'html': {
1967
+ out += this.renderer.html(token);
1968
+ continue;
1969
+ }
1970
+ case 'paragraph': {
1971
+ out += this.renderer.paragraph(token);
1972
+ continue;
1973
+ }
1974
+ case 'text': {
1975
+ let textToken = token;
1976
+ let body = this.renderer.text(textToken);
1977
+ while (i + 1 < tokens.length && tokens[i + 1].type === 'text') {
1978
+ textToken = tokens[++i];
1979
+ body += '\n' + this.renderer.text(textToken);
1980
+ }
1981
+ if (top) {
1982
+ out += this.renderer.paragraph({
1983
+ type: 'paragraph',
1984
+ raw: body,
1985
+ text: body,
1986
+ tokens: [{ type: 'text', raw: body, text: body }],
1987
+ });
1988
+ }
1989
+ else {
1990
+ out += body;
1991
+ }
1992
+ continue;
1993
+ }
1994
+ default: {
1995
+ const errMsg = 'Token with "' + token.type + '" type was not found.';
1996
+ if (this.options.silent) {
1997
+ console.error(errMsg);
1998
+ return '';
1999
+ }
2000
+ else {
2001
+ throw new Error(errMsg);
2002
+ }
2003
+ }
2004
+ }
2005
+ }
2006
+ return out;
2007
+ }
2008
+ /**
2009
+ * Parse Inline Tokens
2010
+ */
2011
+ parseInline(tokens, renderer) {
2012
+ renderer = renderer || this.renderer;
2013
+ let out = '';
2014
+ for (let i = 0; i < tokens.length; i++) {
2015
+ const anyToken = tokens[i];
2016
+ // Run any renderer extensions
2017
+ if (this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[anyToken.type]) {
2018
+ const ret = this.options.extensions.renderers[anyToken.type].call({ parser: this }, anyToken);
2019
+ if (ret !== false || !['escape', 'html', 'link', 'image', 'strong', 'em', 'codespan', 'br', 'del', 'text'].includes(anyToken.type)) {
2020
+ out += ret || '';
2021
+ continue;
2022
+ }
2023
+ }
2024
+ const token = anyToken;
2025
+ switch (token.type) {
2026
+ case 'escape': {
2027
+ out += renderer.text(token);
2028
+ break;
2029
+ }
2030
+ case 'html': {
2031
+ out += renderer.html(token);
2032
+ break;
2033
+ }
2034
+ case 'link': {
2035
+ out += renderer.link(token);
2036
+ break;
2037
+ }
2038
+ case 'image': {
2039
+ out += renderer.image(token);
2040
+ break;
2041
+ }
2042
+ case 'strong': {
2043
+ out += renderer.strong(token);
2044
+ break;
2045
+ }
2046
+ case 'em': {
2047
+ out += renderer.em(token);
2048
+ break;
2049
+ }
2050
+ case 'codespan': {
2051
+ out += renderer.codespan(token);
2052
+ break;
2053
+ }
2054
+ case 'br': {
2055
+ out += renderer.br(token);
2056
+ break;
2057
+ }
2058
+ case 'del': {
2059
+ out += renderer.del(token);
2060
+ break;
2061
+ }
2062
+ case 'text': {
2063
+ out += renderer.text(token);
2064
+ break;
2065
+ }
2066
+ default: {
2067
+ const errMsg = 'Token with "' + token.type + '" type was not found.';
2068
+ if (this.options.silent) {
2069
+ console.error(errMsg);
2070
+ return '';
2071
+ }
2072
+ else {
2073
+ throw new Error(errMsg);
2074
+ }
2075
+ }
2076
+ }
2077
+ }
2078
+ return out;
2079
+ }
2080
+ }
2081
+
2082
+ class _Hooks {
2083
+ options;
2084
+ block;
2085
+ constructor(options) {
2086
+ this.options = options || _defaults;
2087
+ }
2088
+ static passThroughHooks = new Set([
2089
+ 'preprocess',
2090
+ 'postprocess',
2091
+ 'processAllTokens',
2092
+ ]);
2093
+ /**
2094
+ * Process markdown before marked
2095
+ */
2096
+ preprocess(markdown) {
2097
+ return markdown;
2098
+ }
2099
+ /**
2100
+ * Process HTML after marked is finished
2101
+ */
2102
+ postprocess(html) {
2103
+ return html;
2104
+ }
2105
+ /**
2106
+ * Process all tokens before walk tokens
2107
+ */
2108
+ processAllTokens(tokens) {
2109
+ return tokens;
2110
+ }
2111
+ /**
2112
+ * Provide function to tokenize markdown
2113
+ */
2114
+ provideLexer() {
2115
+ return this.block ? _Lexer.lex : _Lexer.lexInline;
2116
+ }
2117
+ /**
2118
+ * Provide function to parse tokens
2119
+ */
2120
+ provideParser() {
2121
+ return this.block ? _Parser.parse : _Parser.parseInline;
2122
+ }
2123
+ }
2124
+
2125
+ class Marked {
2126
+ defaults = _getDefaults();
2127
+ options = this.setOptions;
2128
+ parse = this.parseMarkdown(true);
2129
+ parseInline = this.parseMarkdown(false);
2130
+ Parser = _Parser;
2131
+ Renderer = _Renderer;
2132
+ TextRenderer = _TextRenderer;
2133
+ Lexer = _Lexer;
2134
+ Tokenizer = _Tokenizer;
2135
+ Hooks = _Hooks;
2136
+ constructor(...args) {
2137
+ this.use(...args);
2138
+ }
2139
+ /**
2140
+ * Run callback for every token
2141
+ */
2142
+ walkTokens(tokens, callback) {
2143
+ let values = [];
2144
+ for (const token of tokens) {
2145
+ values = values.concat(callback.call(this, token));
2146
+ switch (token.type) {
2147
+ case 'table': {
2148
+ const tableToken = token;
2149
+ for (const cell of tableToken.header) {
2150
+ values = values.concat(this.walkTokens(cell.tokens, callback));
2151
+ }
2152
+ for (const row of tableToken.rows) {
2153
+ for (const cell of row) {
2154
+ values = values.concat(this.walkTokens(cell.tokens, callback));
2155
+ }
2156
+ }
2157
+ break;
2158
+ }
2159
+ case 'list': {
2160
+ const listToken = token;
2161
+ values = values.concat(this.walkTokens(listToken.items, callback));
2162
+ break;
2163
+ }
2164
+ default: {
2165
+ const genericToken = token;
2166
+ if (this.defaults.extensions?.childTokens?.[genericToken.type]) {
2167
+ this.defaults.extensions.childTokens[genericToken.type].forEach((childTokens) => {
2168
+ const tokens = genericToken[childTokens].flat(Infinity);
2169
+ values = values.concat(this.walkTokens(tokens, callback));
2170
+ });
2171
+ }
2172
+ else if (genericToken.tokens) {
2173
+ values = values.concat(this.walkTokens(genericToken.tokens, callback));
2174
+ }
2175
+ }
2176
+ }
2177
+ }
2178
+ return values;
2179
+ }
2180
+ use(...args) {
2181
+ const extensions = this.defaults.extensions || { renderers: {}, childTokens: {} };
2182
+ args.forEach((pack) => {
2183
+ // copy options to new object
2184
+ const opts = { ...pack };
2185
+ // set async to true if it was set to true before
2186
+ opts.async = this.defaults.async || opts.async || false;
2187
+ // ==-- Parse "addon" extensions --== //
2188
+ if (pack.extensions) {
2189
+ pack.extensions.forEach((ext) => {
2190
+ if (!ext.name) {
2191
+ throw new Error('extension name required');
2192
+ }
2193
+ if ('renderer' in ext) { // Renderer extensions
2194
+ const prevRenderer = extensions.renderers[ext.name];
2195
+ if (prevRenderer) {
2196
+ // Replace extension with func to run new extension but fall back if false
2197
+ extensions.renderers[ext.name] = function (...args) {
2198
+ let ret = ext.renderer.apply(this, args);
2199
+ if (ret === false) {
2200
+ ret = prevRenderer.apply(this, args);
2201
+ }
2202
+ return ret;
2203
+ };
2204
+ }
2205
+ else {
2206
+ extensions.renderers[ext.name] = ext.renderer;
2207
+ }
2208
+ }
2209
+ if ('tokenizer' in ext) { // Tokenizer Extensions
2210
+ if (!ext.level || (ext.level !== 'block' && ext.level !== 'inline')) {
2211
+ throw new Error("extension level must be 'block' or 'inline'");
2212
+ }
2213
+ const extLevel = extensions[ext.level];
2214
+ if (extLevel) {
2215
+ extLevel.unshift(ext.tokenizer);
2216
+ }
2217
+ else {
2218
+ extensions[ext.level] = [ext.tokenizer];
2219
+ }
2220
+ if (ext.start) { // Function to check for start of token
2221
+ if (ext.level === 'block') {
2222
+ if (extensions.startBlock) {
2223
+ extensions.startBlock.push(ext.start);
2224
+ }
2225
+ else {
2226
+ extensions.startBlock = [ext.start];
2227
+ }
2228
+ }
2229
+ else if (ext.level === 'inline') {
2230
+ if (extensions.startInline) {
2231
+ extensions.startInline.push(ext.start);
2232
+ }
2233
+ else {
2234
+ extensions.startInline = [ext.start];
2235
+ }
2236
+ }
2237
+ }
2238
+ }
2239
+ if ('childTokens' in ext && ext.childTokens) { // Child tokens to be visited by walkTokens
2240
+ extensions.childTokens[ext.name] = ext.childTokens;
2241
+ }
2242
+ });
2243
+ opts.extensions = extensions;
2244
+ }
2245
+ // ==-- Parse "overwrite" extensions --== //
2246
+ if (pack.renderer) {
2247
+ const renderer = this.defaults.renderer || new _Renderer(this.defaults);
2248
+ for (const prop in pack.renderer) {
2249
+ if (!(prop in renderer)) {
2250
+ throw new Error(`renderer '${prop}' does not exist`);
2251
+ }
2252
+ if (['options', 'parser'].includes(prop)) {
2253
+ // ignore options property
2254
+ continue;
2255
+ }
2256
+ const rendererProp = prop;
2257
+ const rendererFunc = pack.renderer[rendererProp];
2258
+ const prevRenderer = renderer[rendererProp];
2259
+ // Replace renderer with func to run extension, but fall back if false
2260
+ renderer[rendererProp] = (...args) => {
2261
+ let ret = rendererFunc.apply(renderer, args);
2262
+ if (ret === false) {
2263
+ ret = prevRenderer.apply(renderer, args);
2264
+ }
2265
+ return ret || '';
2266
+ };
2267
+ }
2268
+ opts.renderer = renderer;
2269
+ }
2270
+ if (pack.tokenizer) {
2271
+ const tokenizer = this.defaults.tokenizer || new _Tokenizer(this.defaults);
2272
+ for (const prop in pack.tokenizer) {
2273
+ if (!(prop in tokenizer)) {
2274
+ throw new Error(`tokenizer '${prop}' does not exist`);
2275
+ }
2276
+ if (['options', 'rules', 'lexer'].includes(prop)) {
2277
+ // ignore options, rules, and lexer properties
2278
+ continue;
2279
+ }
2280
+ const tokenizerProp = prop;
2281
+ const tokenizerFunc = pack.tokenizer[tokenizerProp];
2282
+ const prevTokenizer = tokenizer[tokenizerProp];
2283
+ // Replace tokenizer with func to run extension, but fall back if false
2284
+ // @ts-expect-error cannot type tokenizer function dynamically
2285
+ tokenizer[tokenizerProp] = (...args) => {
2286
+ let ret = tokenizerFunc.apply(tokenizer, args);
2287
+ if (ret === false) {
2288
+ ret = prevTokenizer.apply(tokenizer, args);
2289
+ }
2290
+ return ret;
2291
+ };
2292
+ }
2293
+ opts.tokenizer = tokenizer;
2294
+ }
2295
+ // ==-- Parse Hooks extensions --== //
2296
+ if (pack.hooks) {
2297
+ const hooks = this.defaults.hooks || new _Hooks();
2298
+ for (const prop in pack.hooks) {
2299
+ if (!(prop in hooks)) {
2300
+ throw new Error(`hook '${prop}' does not exist`);
2301
+ }
2302
+ if (['options', 'block'].includes(prop)) {
2303
+ // ignore options and block properties
2304
+ continue;
2305
+ }
2306
+ const hooksProp = prop;
2307
+ const hooksFunc = pack.hooks[hooksProp];
2308
+ const prevHook = hooks[hooksProp];
2309
+ if (_Hooks.passThroughHooks.has(prop)) {
2310
+ // @ts-expect-error cannot type hook function dynamically
2311
+ hooks[hooksProp] = (arg) => {
2312
+ if (this.defaults.async) {
2313
+ return Promise.resolve(hooksFunc.call(hooks, arg)).then(ret => {
2314
+ return prevHook.call(hooks, ret);
2315
+ });
2316
+ }
2317
+ const ret = hooksFunc.call(hooks, arg);
2318
+ return prevHook.call(hooks, ret);
2319
+ };
2320
+ }
2321
+ else {
2322
+ // @ts-expect-error cannot type hook function dynamically
2323
+ hooks[hooksProp] = (...args) => {
2324
+ let ret = hooksFunc.apply(hooks, args);
2325
+ if (ret === false) {
2326
+ ret = prevHook.apply(hooks, args);
2327
+ }
2328
+ return ret;
2329
+ };
2330
+ }
2331
+ }
2332
+ opts.hooks = hooks;
2333
+ }
2334
+ // ==-- Parse WalkTokens extensions --== //
2335
+ if (pack.walkTokens) {
2336
+ const walkTokens = this.defaults.walkTokens;
2337
+ const packWalktokens = pack.walkTokens;
2338
+ opts.walkTokens = function (token) {
2339
+ let values = [];
2340
+ values.push(packWalktokens.call(this, token));
2341
+ if (walkTokens) {
2342
+ values = values.concat(walkTokens.call(this, token));
2343
+ }
2344
+ return values;
2345
+ };
2346
+ }
2347
+ this.defaults = { ...this.defaults, ...opts };
2348
+ });
2349
+ return this;
2350
+ }
2351
+ setOptions(opt) {
2352
+ this.defaults = { ...this.defaults, ...opt };
2353
+ return this;
2354
+ }
2355
+ lexer(src, options) {
2356
+ return _Lexer.lex(src, options ?? this.defaults);
2357
+ }
2358
+ parser(tokens, options) {
2359
+ return _Parser.parse(tokens, options ?? this.defaults);
2360
+ }
2361
+ parseMarkdown(blockType) {
2362
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2363
+ const parse = (src, options) => {
2364
+ const origOpt = { ...options };
2365
+ const opt = { ...this.defaults, ...origOpt };
2366
+ const throwError = this.onError(!!opt.silent, !!opt.async);
2367
+ // throw error if an extension set async to true but parse was called with async: false
2368
+ if (this.defaults.async === true && origOpt.async === false) {
2369
+ return throwError(new Error('marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.'));
2370
+ }
2371
+ // throw error in case of non string input
2372
+ if (typeof src === 'undefined' || src === null) {
2373
+ return throwError(new Error('marked(): input parameter is undefined or null'));
2374
+ }
2375
+ if (typeof src !== 'string') {
2376
+ return throwError(new Error('marked(): input parameter is of type '
2377
+ + Object.prototype.toString.call(src) + ', string expected'));
2378
+ }
2379
+ if (opt.hooks) {
2380
+ opt.hooks.options = opt;
2381
+ opt.hooks.block = blockType;
2382
+ }
2383
+ const lexer = opt.hooks ? opt.hooks.provideLexer() : (blockType ? _Lexer.lex : _Lexer.lexInline);
2384
+ const parser = opt.hooks ? opt.hooks.provideParser() : (blockType ? _Parser.parse : _Parser.parseInline);
2385
+ if (opt.async) {
2386
+ return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src)
2387
+ .then(src => lexer(src, opt))
2388
+ .then(tokens => opt.hooks ? opt.hooks.processAllTokens(tokens) : tokens)
2389
+ .then(tokens => opt.walkTokens ? Promise.all(this.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens)
2390
+ .then(tokens => parser(tokens, opt))
2391
+ .then(html => opt.hooks ? opt.hooks.postprocess(html) : html)
2392
+ .catch(throwError);
2393
+ }
2394
+ try {
2395
+ if (opt.hooks) {
2396
+ src = opt.hooks.preprocess(src);
2397
+ }
2398
+ let tokens = lexer(src, opt);
2399
+ if (opt.hooks) {
2400
+ tokens = opt.hooks.processAllTokens(tokens);
2401
+ }
2402
+ if (opt.walkTokens) {
2403
+ this.walkTokens(tokens, opt.walkTokens);
2404
+ }
2405
+ let html = parser(tokens, opt);
2406
+ if (opt.hooks) {
2407
+ html = opt.hooks.postprocess(html);
2408
+ }
2409
+ return html;
2410
+ }
2411
+ catch (e) {
2412
+ return throwError(e);
2413
+ }
2414
+ };
2415
+ return parse;
2416
+ }
2417
+ onError(silent, async) {
2418
+ return (e) => {
2419
+ e.message += '\nPlease report this to https://github.com/markedjs/marked.';
2420
+ if (silent) {
2421
+ const msg = '<p>An error occurred:</p><pre>'
2422
+ + escape$1(e.message + '', true)
2423
+ + '</pre>';
2424
+ if (async) {
2425
+ return Promise.resolve(msg);
2426
+ }
2427
+ return msg;
2428
+ }
2429
+ if (async) {
2430
+ return Promise.reject(e);
2431
+ }
2432
+ throw e;
2433
+ };
2434
+ }
2435
+ }
2436
+
2437
+ const markedInstance = new Marked();
2438
+ function marked(src, opt) {
2439
+ return markedInstance.parse(src, opt);
2440
+ }
2441
+ /**
2442
+ * Sets the default options.
2443
+ *
2444
+ * @param options Hash of options
2445
+ */
2446
+ marked.options =
2447
+ marked.setOptions = function (options) {
2448
+ markedInstance.setOptions(options);
2449
+ marked.defaults = markedInstance.defaults;
2450
+ changeDefaults(marked.defaults);
2451
+ return marked;
2452
+ };
2453
+ /**
2454
+ * Gets the original marked default options.
2455
+ */
2456
+ marked.getDefaults = _getDefaults;
2457
+ marked.defaults = _defaults;
2458
+ /**
2459
+ * Use Extension
2460
+ */
2461
+ marked.use = function (...args) {
2462
+ markedInstance.use(...args);
2463
+ marked.defaults = markedInstance.defaults;
2464
+ changeDefaults(marked.defaults);
2465
+ return marked;
2466
+ };
2467
+ /**
2468
+ * Run callback for every token
2469
+ */
2470
+ marked.walkTokens = function (tokens, callback) {
2471
+ return markedInstance.walkTokens(tokens, callback);
2472
+ };
2473
+ /**
2474
+ * Compiles markdown to HTML without enclosing `p` tag.
2475
+ *
2476
+ * @param src String of markdown source to be compiled
2477
+ * @param options Hash of options
2478
+ * @return String of compiled HTML
2479
+ */
2480
+ marked.parseInline = markedInstance.parseInline;
2481
+ /**
2482
+ * Expose
2483
+ */
2484
+ marked.Parser = _Parser;
2485
+ marked.parser = _Parser.parse;
2486
+ marked.Renderer = _Renderer;
2487
+ marked.TextRenderer = _TextRenderer;
2488
+ marked.Lexer = _Lexer;
2489
+ marked.lexer = _Lexer.lex;
2490
+ marked.Tokenizer = _Tokenizer;
2491
+ marked.Hooks = _Hooks;
2492
+ marked.parse = marked;
2493
+ const options = marked.options;
2494
+ const setOptions = marked.setOptions;
2495
+ const use = marked.use;
2496
+ const walkTokens = marked.walkTokens;
2497
+ const parseInline = marked.parseInline;
2498
+ const parse = marked;
2499
+ const parser = _Parser.parse;
2500
+ const lexer = _Lexer.lex;
2501
+
2502
+ export { _Hooks as Hooks, _Lexer as Lexer, Marked, _Parser as Parser, _Renderer as Renderer, _TextRenderer as TextRenderer, _Tokenizer as Tokenizer, _defaults as defaults, _getDefaults as getDefaults, lexer, marked, options, parse, parseInline, parser, setOptions, use, walkTokens };