volute 0.35.0 → 0.37.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 (167) hide show
  1. package/dist/{accept-ZBDVVCEU.js → accept-AHAOUFBK.js} +4 -4
  2. package/dist/activity-events-N6HCHU4P.js +15 -0
  3. package/dist/{ai-service-LURBEDDB.js → ai-service-C2YNARGH.js} +6 -6
  4. package/dist/{api-client-3A77HMH7.js → api-client-LC5YRA32.js} +1 -1
  5. package/dist/{archive-ESU2FUN4.js → archive-AWIJTVQV.js} +4 -4
  6. package/dist/{auth-WX4TESEI.js → auth-2QOOPMBX.js} +6 -6
  7. package/dist/{bridge-PXIO6PS2.js → bridge-F3ZJEKDN.js} +4 -4
  8. package/dist/{chat-QXAJF3FU.js → chat-5Y4FD77E.js} +9 -9
  9. package/dist/{chunk-BDYXIWA5.js → chunk-2NHRJ3YO.js} +13 -2
  10. package/dist/{chunk-AN2W47GW.js → chunk-3F7XK5Q7.js} +2 -2
  11. package/dist/{chunk-AOB6GVRM.js → chunk-46DYYHN6.js} +8 -3
  12. package/dist/{chunk-WZRZFFCL.js → chunk-5DPRTREW.js} +146 -186
  13. package/dist/{chunk-QWTR6AWZ.js → chunk-7AZQFSOV.js} +2 -2
  14. package/dist/{chunk-BMZQYACC.js → chunk-A6FLW5XD.js} +19 -4
  15. package/dist/{chunk-N5LMGYXX.js → chunk-BIEWHAAM.js} +2 -2
  16. package/dist/{chunk-5N7Y5WAM.js → chunk-CJ26DXZL.js} +29 -13
  17. package/dist/{chunk-ZSR72JB3.js → chunk-CU6OFXMM.js} +1 -1
  18. package/dist/{chunk-N446KRP7.js → chunk-GVVVMZ4J.js} +2 -2
  19. package/dist/chunk-K3NQKI34.js +10 -0
  20. package/dist/{chunk-F7ZNLYKZ.js → chunk-KAB6UGOL.js} +2 -2
  21. package/dist/{chunk-WJPROOU5.js → chunk-KBRGHKVU.js} +681 -3726
  22. package/dist/{chunk-PWQ2ITYG.js → chunk-KXXJYY62.js} +6 -6
  23. package/dist/{chunk-NJK5SDGR.js → chunk-LGNUFVMR.js} +1 -1
  24. package/dist/chunk-LQ6Z4FXN.js +87 -0
  25. package/dist/{chunk-J6CJQDWI.js → chunk-MQRS4J24.js} +2 -2
  26. package/dist/{chunk-CORXD635.js → chunk-N42QMDID.js} +3 -3
  27. package/dist/{chunk-IJHIXLVN.js → chunk-NYP3LBIV.js} +15 -13
  28. package/dist/{chunk-FT5KETXZ.js → chunk-ORNY3MZR.js} +4 -4
  29. package/dist/{chunk-A2ZLHBHG.js → chunk-PMMHVSCR.js} +2 -2
  30. package/dist/chunk-QQQI6ISK.js +853 -0
  31. package/dist/chunk-RG5TOL4O.js +18 -0
  32. package/dist/{chunk-VHJRZM2S.js → chunk-SNW2NPP4.js} +2 -2
  33. package/dist/chunk-SZJWC2GA.js +125 -0
  34. package/dist/{chunk-BKF4WQCY.js → chunk-T2TP6ZC6.js} +20 -8
  35. package/dist/{chunk-2TGZJFAT.js → chunk-TNZ5XQA4.js} +3 -3
  36. package/dist/{chunk-QCH6K235.js → chunk-UI7RPV2B.js} +1 -1
  37. package/dist/{chunk-XRQSAMX2.js → chunk-UIM5NHPP.js} +3 -3
  38. package/dist/{chunk-5XJYUFZH.js → chunk-UQFYNZKT.js} +76 -30
  39. package/dist/{chunk-OTC67N2Z.js → chunk-WC635OPK.js} +1 -1
  40. package/dist/{chunk-BV65KRHM.js → chunk-XLBQYIHH.js} +2 -2
  41. package/dist/{chunk-VY3RB2V7.js → chunk-Z6TIXE77.js} +3 -3
  42. package/dist/cli.js +24 -24
  43. package/dist/{clock-HSEKS5AR.js → clock-BMLJ2TR6.js} +8 -8
  44. package/dist/{cloud-sync-6JL4C24T.js → cloud-sync-OIX576NA.js} +20 -21
  45. package/dist/{config-UTS7QULS.js → config-QB7W3Z7P.js} +4 -4
  46. package/dist/connectors/discord-bridge.js +4 -4
  47. package/dist/connectors/slack-bridge.js +4 -4
  48. package/dist/connectors/telegram-bridge.js +4 -4
  49. package/dist/{conversations-2PW57WO2.js → conversations-G6YRSABR.js} +16 -10
  50. package/dist/{create-5BPOOJAN.js → create-C3BBFYV7.js} +4 -4
  51. package/dist/{create-UVCK2CS6.js → create-PN73742N.js} +4 -4
  52. package/dist/{daemon-client-RVIKXGFQ.js → daemon-client-2MIPKY3E.js} +1 -1
  53. package/dist/{daemon-restart-HSZ3BCX5.js → daemon-restart-L2O6L7NR.js} +9 -9
  54. package/dist/daemon.js +690 -1281
  55. package/dist/db-CBOCDYVA.js +9 -0
  56. package/dist/{db-BDMH4SZ2.js → db-IJL6B26S.js} +1 -1
  57. package/dist/{delete-L5PAVDGQ.js → delete-NLXES2C7.js} +3 -3
  58. package/dist/delivery-manager-4PVBUZJB.js +30 -0
  59. package/dist/{delivery-router-HEJSJAHQ.js → delivery-router-QTFEZ26O.js} +5 -5
  60. package/dist/down-25L2RKCQ.js +17 -0
  61. package/dist/echo-text-T5ZLGMA7.js +31 -0
  62. package/dist/{env-E4XHO2BI.js → env-IQ6Q2333.js} +6 -6
  63. package/dist/exec-ONYZEA5B.js +17 -0
  64. package/dist/{export-OAS6QVBN.js → export-JPDBQESV.js} +6 -6
  65. package/dist/{extension-D74CNM7G.js → extension-LZYHBNLV.js} +26 -7
  66. package/dist/extensions-CLYXNGYB.js +50 -0
  67. package/dist/{files-CWTK6V3H.js → files-LAQ3NXQK.js} +7 -7
  68. package/dist/{import-5A3T7QV4.js → import-EROF27RH.js} +12 -11
  69. package/dist/{isolation-TK5RX2WM.js → isolation-G5J3MTKU.js} +4 -4
  70. package/dist/{join-DF5XSJAC.js → join-6SZCA5FX.js} +3 -3
  71. package/dist/{list-PDMQM7ZV.js → list-KHJZJPEJ.js} +11 -5
  72. package/dist/{login-7TE6CIZF.js → login-F6YMAVLE.js} +6 -6
  73. package/dist/{login-GOTAYLXP.js → login-GYTH67ES.js} +4 -4
  74. package/dist/{logout-T4XS6LRU.js → logout-HHPH52KZ.js} +6 -6
  75. package/dist/{logout-6KIA74EV.js → logout-YHQLOFLR.js} +4 -4
  76. package/dist/message-delivery-N2V5APCS.js +40 -0
  77. package/dist/{mind-5IEYKV7I.js → mind-M57ET546.js} +19 -19
  78. package/dist/mind-activity-tracker-42ENM32S.js +18 -0
  79. package/dist/{mind-history-IE2QH7U5.js → mind-history-WHCNZ6I5.js} +86 -19
  80. package/dist/{mind-list-GEWHWAL4.js → mind-list-H3HC2ZRG.js} +4 -4
  81. package/dist/mind-manager-LS2AIXHQ.js +30 -0
  82. package/dist/{mind-profile-DCBDVF5B.js → mind-profile-7VYRJGFZ.js} +2 -2
  83. package/dist/mind-service-UDXF5WC2.js +36 -0
  84. package/dist/{mind-sleep-ITCF6OQA.js → mind-sleep-ZL5ZXFTM.js} +4 -4
  85. package/dist/{mind-status-X4SX3YUG.js → mind-status-ZWULKOUO.js} +4 -4
  86. package/dist/{mind-wake-KXMKMGWX.js → mind-wake-HK5ORGUK.js} +4 -4
  87. package/dist/{package-D2FSVFAX.js → package-5FGU5QNP.js} +6 -6
  88. package/dist/{read-67VRP2DO.js → read-CP7MYMJQ.js} +8 -8
  89. package/dist/{read-stdin-3X5VYKNS.js → read-stdin-4B5UYPPM.js} +1 -1
  90. package/dist/{register-SB7NXCOE.js → register-XOBFEMI4.js} +4 -4
  91. package/dist/{registry-GBSNW3HG.js → registry-KMELPC3X.js} +3 -3
  92. package/dist/{reject-MUR2KWJ4.js → reject-43AGXB6B.js} +4 -4
  93. package/dist/{restart-5EGG4JXU.js → restart-O5QIYQJT.js} +5 -5
  94. package/dist/{sandbox-R37VIU36.js → sandbox-PQYEICEF.js} +6 -6
  95. package/dist/scheduler-NTC74JYH.js +30 -0
  96. package/dist/{schema-XVZ2CLKW.js → schema-K575EBPE.js} +4 -2
  97. package/dist/{seed-EQORWX77.js → seed-55VC3A57.js} +2 -2
  98. package/dist/{seed-check-KJNTL72M.js → seed-check-HZPVFJKZ.js} +2 -2
  99. package/dist/{seed-cmd-ZM2XGVU2.js → seed-cmd-2KOEQZK6.js} +4 -4
  100. package/dist/{seed-create-DRWGGHEI.js → seed-create-Y2Z5JWBB.js} +6 -6
  101. package/dist/{seed-sprout-JYXGXOP3.js → seed-sprout-OLSIWXZN.js} +15 -15
  102. package/dist/{send-JBJJQ7CA.js → send-7CIP5GLS.js} +8 -8
  103. package/dist/{service-WNPCNHOX.js → service-YMHWPDXW.js} +6 -6
  104. package/dist/{setup-BJ4YAY26.js → setup-6Z34JJEB.js} +32 -37
  105. package/dist/{setup-RHJRFURI.js → setup-PF7JSFMO.js} +6 -4
  106. package/dist/{skill-TAAKEYBV.js → skill-ICN6Y2ZF.js} +6 -6
  107. package/dist/skills/tending/SKILL.md +52 -0
  108. package/dist/{skills-EKMCQ46K.js → skills-FDMLJGZ3.js} +8 -8
  109. package/dist/sleep-manager-TQP5ZJI5.js +34 -0
  110. package/dist/spirit-SM6ARJ2N.js +24 -0
  111. package/dist/{split-AWVOYOPZ.js → split-5YBEQTBF.js} +3 -3
  112. package/dist/{sprout-HE4TITMK.js → sprout-G6G57IOY.js} +2 -2
  113. package/dist/src-LT6ZBYYX.js +2133 -0
  114. package/dist/src-O4PRLMKM.js +425 -0
  115. package/dist/src-OYWRPLC6.js +617 -0
  116. package/dist/{start-3UXOPXQG.js → start-LMXXRR3X.js} +5 -5
  117. package/dist/{status-ZK34WYIM.js → status-MC2P7DBG.js} +7 -7
  118. package/dist/{stop-3XYIBGFM.js → stop-TWDKVEUX.js} +5 -5
  119. package/dist/system-chat-NNXYCSVL.js +34 -0
  120. package/dist/{systems-O43WGQY6.js → systems-Y2WZV2K4.js} +7 -7
  121. package/dist/{tailscale-ZIZ2HWJ5.js → tailscale-LTYNKIPZ.js} +4 -4
  122. package/dist/template-hash-SSIBEEYK.js +9 -0
  123. package/dist/up-5JXV6BZS.js +19 -0
  124. package/dist/{update-ANE5ZM7F.js → update-UOP2INF2.js} +7 -7
  125. package/dist/{update-check-UV55CBEP.js → update-check-IKS7SGK5.js} +4 -4
  126. package/dist/{upgrade-ZMDGC7M2.js → upgrade-RXFZR5FI.js} +3 -3
  127. package/dist/{variant-QWL2WSRI.js → variant-HHDTW74J.js} +1 -1
  128. package/dist/{version-notify-FXSEMXWW.js → version-notify-CSE4NBYM.js} +22 -23
  129. package/dist/{volute-config-D2XVS2YI.js → volute-config-TS62GS6A.js} +2 -2
  130. package/dist/web-assets/assets/index-B3xLeex8.js +75 -0
  131. package/dist/web-assets/assets/index-Dr4A90Lo.css +1 -0
  132. package/dist/web-assets/index.html +2 -2
  133. package/drizzle/0006_channels.sql +17 -0
  134. package/drizzle/0007_drop_conversation_name_title.sql +11 -0
  135. package/drizzle/0008_performance_indexes.sql +6 -0
  136. package/drizzle/meta/0006_snapshot.json +7 -0
  137. package/drizzle/meta/0007_snapshot.json +7 -0
  138. package/drizzle/meta/_journal.json +21 -0
  139. package/package.json +5 -5
  140. package/templates/_base/home/.config/routes.json +2 -2
  141. package/templates/_base/home/VOLUTE.md +1 -2
  142. package/templates/_base/src/lib/context-breakdown.ts +22 -16
  143. package/templates/_base/src/lib/format-prefix.ts +1 -7
  144. package/templates/claude/.init/.config/routes.json +2 -2
  145. package/templates/codex/.init/.config/routes.json +2 -2
  146. package/templates/pi/.init/.config/routes.json +2 -2
  147. package/dist/activity-events-ZW4SDL2C.js +0 -15
  148. package/dist/chunk-7KJOFUNN.js +0 -22
  149. package/dist/chunk-MDJGMOSD.js +0 -207
  150. package/dist/db-BVBJ57TU.js +0 -9
  151. package/dist/delivery-manager-H5ZVBMCQ.js +0 -31
  152. package/dist/down-74VXM45A.js +0 -17
  153. package/dist/exec-PY7THYH4.js +0 -17
  154. package/dist/extensions-XDDFY72A.js +0 -49
  155. package/dist/lib-DYEZMGW7.js +0 -6588
  156. package/dist/message-delivery-GRC4W6P7.js +0 -41
  157. package/dist/mind-activity-tracker-QBLIV7ZJ.js +0 -18
  158. package/dist/mind-manager-HFLB5653.js +0 -31
  159. package/dist/mind-service-X2CAA6W6.js +0 -37
  160. package/dist/scheduler-Y7O4CJXL.js +0 -31
  161. package/dist/sleep-manager-7KFK3USC.js +0 -35
  162. package/dist/spirit-ZFRDXMG7.js +0 -23
  163. package/dist/system-chat-IDPHYHY4.js +0 -35
  164. package/dist/template-hash-A7FNHTB7.js +0 -9
  165. package/dist/up-77ICEDEW.js +0 -19
  166. package/dist/web-assets/assets/index-BhxWKvbB.css +0 -1
  167. package/dist/web-assets/assets/index-CHVKJ9II.js +0 -75
@@ -0,0 +1,2133 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ getAllSites,
4
+ getPublishedPages,
5
+ getRecentPages,
6
+ getSystemPages,
7
+ initDb,
8
+ syncPublishedPages,
9
+ syncSystemPages
10
+ } from "./chunk-QHG4OMZL.js";
11
+ import {
12
+ createExtension
13
+ } from "./chunk-RG5TOL4O.js";
14
+ import "./chunk-K3NQKI34.js";
15
+
16
+ // packages/extensions/pages/src/index.ts
17
+ import { resolve as resolve5 } from "path";
18
+
19
+ // packages/extensions/pages/src/commands.ts
20
+ import { cpSync, existsSync as existsSync2, readdirSync as readdirSync2, readFileSync as readFileSync2, rmSync as rmSync2, statSync as statSync2 } from "fs";
21
+ import { relative as relative2, resolve as resolve2 } from "path";
22
+
23
+ // packages/extensions/pages/src/shared-pages.ts
24
+ import { execFile as execFileCb } from "child_process";
25
+ import {
26
+ chmodSync,
27
+ existsSync,
28
+ mkdirSync,
29
+ readdirSync,
30
+ readFileSync,
31
+ rmSync,
32
+ statSync,
33
+ writeFileSync
34
+ } from "fs";
35
+ import { relative, resolve } from "path";
36
+ function isolationFrom(ctx) {
37
+ return { isIsolationEnabled: ctx.isIsolationEnabled, getMindUser: ctx.getMindUser };
38
+ }
39
+ function execAsync(cmd, args) {
40
+ return new Promise((resolve6, reject) => {
41
+ execFileCb(cmd, args, (err) => {
42
+ if (err) reject(err);
43
+ else resolve6();
44
+ });
45
+ });
46
+ }
47
+ function gitExec(args, opts, isolation) {
48
+ const fullArgs = isolation?.isIsolationEnabled() ? ["-c", "safe.directory=*", ...args] : args;
49
+ return new Promise((resolve6, reject) => {
50
+ execFileCb("git", fullArgs, { cwd: opts.cwd }, (err, stdout, stderr) => {
51
+ if (err) {
52
+ const e = err;
53
+ e.stderr = stderr;
54
+ e.stdout = stdout;
55
+ reject(err);
56
+ } else {
57
+ resolve6(stdout);
58
+ }
59
+ });
60
+ });
61
+ }
62
+ function readWorktreeGitDir(worktreePath2) {
63
+ const dotGit = resolve(worktreePath2, ".git");
64
+ if (!existsSync(dotGit)) return null;
65
+ try {
66
+ const content = readFileSync(dotGit, "utf-8").trim();
67
+ const match = content.match(/^gitdir:\s*(.+)$/);
68
+ return match ? match[1] : null;
69
+ } catch (err) {
70
+ console.warn(`[pages] failed to read .git file at ${dotGit}: ${err.message}`);
71
+ return null;
72
+ }
73
+ }
74
+ function pagesRepoDir(dataDir) {
75
+ return resolve(dataDir, "repo");
76
+ }
77
+ function worktreePath(mindDir) {
78
+ return resolve(mindDir, "home", "pages", "_system");
79
+ }
80
+ async function ensurePagesRepo(dataDir, isolation) {
81
+ const dir = pagesRepoDir(dataDir);
82
+ mkdirSync(dir, { recursive: true });
83
+ if (existsSync(resolve(dir, ".git"))) {
84
+ try {
85
+ await gitExec(["rev-parse", "HEAD"], { cwd: dir }, isolation);
86
+ return;
87
+ } catch (err) {
88
+ const msg = err instanceof Error ? err.message : String(err);
89
+ if (msg.includes("unknown revision") || msg.includes("bad default revision")) {
90
+ console.warn("[pages] repo has no commits, re-initializing");
91
+ rmSync(resolve(dir, ".git"), { recursive: true, force: true });
92
+ } else {
93
+ throw err;
94
+ }
95
+ }
96
+ }
97
+ const isIso = isolation?.isIsolationEnabled() ?? false;
98
+ const initArgs = isIso ? ["init", "--shared=group"] : ["init"];
99
+ await gitExec(initArgs, { cwd: dir }, isolation);
100
+ await gitExec(["checkout", "-b", "main"], { cwd: dir }, isolation);
101
+ writeFileSync(resolve(dir, ".gitkeep"), "");
102
+ await gitExec(["add", "-A"], { cwd: dir }, isolation);
103
+ await gitExec(["commit", "-m", "init pages repo"], { cwd: dir }, isolation);
104
+ if (isIso) {
105
+ try {
106
+ await execAsync("chgrp", ["-R", "volute", dir]);
107
+ } catch {
108
+ console.warn("[pages] failed to chgrp pages repo to volute group");
109
+ }
110
+ chmodSync(dir, 1533);
111
+ }
112
+ }
113
+ async function addPagesWorktree(mindName, mindDir, dataDir, isolation) {
114
+ const dir = pagesRepoDir(dataDir);
115
+ if (!existsSync(resolve(dir, ".git"))) return;
116
+ const wt = worktreePath(mindDir);
117
+ if (existsSync(wt)) return;
118
+ mkdirSync(resolve(mindDir, "home", "pages"), { recursive: true });
119
+ let branchExists = false;
120
+ try {
121
+ await gitExec(["rev-parse", "--verify", mindName], { cwd: dir }, isolation);
122
+ branchExists = true;
123
+ } catch {
124
+ }
125
+ if (branchExists) {
126
+ await gitExec(["worktree", "add", wt, mindName], { cwd: dir }, isolation);
127
+ } else {
128
+ await gitExec(["worktree", "add", "-b", mindName, wt], { cwd: dir }, isolation);
129
+ }
130
+ if (isolation?.isIsolationEnabled()) {
131
+ const user = isolation.getMindUser(mindName);
132
+ try {
133
+ await execAsync("chown", ["-R", `${user}:volute`, wt]);
134
+ } catch {
135
+ console.warn(`[pages] failed to chown worktree for ${mindName}`);
136
+ }
137
+ const wtGitDir = readWorktreeGitDir(wt);
138
+ if (wtGitDir) {
139
+ try {
140
+ await execAsync("chown", ["-R", `${user}:volute`, wtGitDir]);
141
+ } catch {
142
+ console.warn(`[pages] failed to chown worktree git dir for ${mindName}`);
143
+ }
144
+ }
145
+ }
146
+ }
147
+ var pagesLock = Promise.resolve();
148
+ async function withPagesLock(fn) {
149
+ const prev = pagesLock;
150
+ let resolve_;
151
+ pagesLock = new Promise((r) => {
152
+ resolve_ = r;
153
+ });
154
+ await prev;
155
+ try {
156
+ return await fn();
157
+ } finally {
158
+ resolve_();
159
+ }
160
+ }
161
+ async function pagesPull(mindName, mindDir, isolation) {
162
+ return withPagesLock(async () => {
163
+ const wt = worktreePath(mindDir);
164
+ const status = (await gitExec(["status", "--porcelain"], { cwd: wt }, isolation)).trim();
165
+ if (status) {
166
+ await gitExec(["add", "-A"], { cwd: wt }, isolation);
167
+ await gitExec(
168
+ ["commit", "--author", `${mindName} <${mindName}@volute>`, "-m", `wip: ${mindName}`],
169
+ { cwd: wt },
170
+ isolation
171
+ );
172
+ }
173
+ try {
174
+ await gitExec(["rebase", "main"], { cwd: wt }, isolation);
175
+ } catch (err) {
176
+ const errMsg = err instanceof Error ? err.message : String(err);
177
+ const isConflict = errMsg.includes("CONFLICT") || errMsg.includes("could not apply") || errMsg.includes("merge conflict");
178
+ try {
179
+ await gitExec(["rebase", "--abort"], { cwd: wt }, isolation);
180
+ } catch (abortErr) {
181
+ console.error("[pages] rebase abort failed", abortErr);
182
+ }
183
+ if (isConflict) {
184
+ return {
185
+ ok: false,
186
+ conflicts: true,
187
+ message: "Pull conflicts detected \u2014 your changes conflict with main. Reconcile the conflicting files, commit, and pull again."
188
+ };
189
+ }
190
+ console.error("[pages] pull rebase failed", err);
191
+ return { ok: false, message: `Pull failed: ${errMsg}` };
192
+ }
193
+ if (isolation?.isIsolationEnabled()) {
194
+ try {
195
+ await execAsync("chown", ["-R", `${isolation.getMindUser(mindName)}:volute`, wt]);
196
+ } catch {
197
+ }
198
+ }
199
+ return { ok: true, message: "Pulled latest shared changes." };
200
+ });
201
+ }
202
+ async function pagesPullAndMerge(mindName, mindDir, dataDir, message, isolation) {
203
+ return withPagesLock(async () => {
204
+ const wt = worktreePath(mindDir);
205
+ const dir = pagesRepoDir(dataDir);
206
+ const status = (await gitExec(["status", "--porcelain"], { cwd: wt }, isolation)).trim();
207
+ if (status) {
208
+ await gitExec(["add", "-A"], { cwd: wt }, isolation);
209
+ await gitExec(
210
+ ["commit", "--author", `${mindName} <${mindName}@volute>`, "-m", `wip: ${mindName}`],
211
+ { cwd: wt },
212
+ isolation
213
+ );
214
+ }
215
+ try {
216
+ await gitExec(["rebase", "main"], { cwd: wt }, isolation);
217
+ } catch (err) {
218
+ const errMsg = err instanceof Error ? err.message : String(err);
219
+ const isConflict = errMsg.includes("CONFLICT") || errMsg.includes("could not apply") || errMsg.includes("merge conflict");
220
+ try {
221
+ await gitExec(["rebase", "--abort"], { cwd: wt }, isolation);
222
+ } catch (abortErr) {
223
+ console.error("[pages] rebase abort failed", abortErr);
224
+ }
225
+ if (isConflict) {
226
+ return {
227
+ ok: false,
228
+ conflicts: true,
229
+ message: "Pull conflicts detected \u2014 your changes conflict with main. Reconcile the conflicting files, commit, and try again."
230
+ };
231
+ }
232
+ return { ok: false, message: `Pull failed: ${errMsg}` };
233
+ }
234
+ const diff = (await gitExec(["diff", `main...${mindName}`, "--stat"], { cwd: dir }, isolation)).trim();
235
+ if (!diff) {
236
+ return { ok: true, message: "Nothing to publish" };
237
+ }
238
+ try {
239
+ await gitExec(["merge", "--squash", mindName], { cwd: dir }, isolation);
240
+ } catch (err) {
241
+ const errOutput = [
242
+ err.message,
243
+ err.stderr ?? "",
244
+ err.stdout ?? ""
245
+ ].join("\n");
246
+ const isConflict = errOutput.includes("CONFLICT") || errOutput.includes("could not apply");
247
+ try {
248
+ await gitExec(["reset", "--hard", "HEAD"], { cwd: dir }, isolation);
249
+ } catch (resetErr) {
250
+ console.error("[pages] reset after squash conflict failed", resetErr);
251
+ }
252
+ if (isConflict) {
253
+ return { ok: false, conflicts: true, message: "Merge conflicts detected" };
254
+ }
255
+ return { ok: false, message: `Merge failed: ${err.message}` };
256
+ }
257
+ await gitExec(
258
+ ["commit", "--author", `${mindName} <${mindName}@volute>`, "-m", message],
259
+ { cwd: dir },
260
+ isolation
261
+ );
262
+ try {
263
+ await gitExec(["reset", "--hard", "main"], { cwd: wt }, isolation);
264
+ } catch (err) {
265
+ console.error(`[pages] branch reset failed for ${mindName}`, err);
266
+ return {
267
+ ok: true,
268
+ message: "Published to main, but branch reset failed \u2014 run 'volute pages pull' to sync"
269
+ };
270
+ }
271
+ if (isolation?.isIsolationEnabled()) {
272
+ try {
273
+ await execAsync("chown", ["-R", `${isolation.getMindUser(mindName)}:volute`, wt]);
274
+ } catch {
275
+ }
276
+ }
277
+ return { ok: true };
278
+ });
279
+ }
280
+ function collectHtmlFiles(dir) {
281
+ const files = [];
282
+ function walk(d2) {
283
+ let items;
284
+ try {
285
+ items = readdirSync(d2);
286
+ } catch (err) {
287
+ if (err?.code === "ENOENT") return;
288
+ throw err;
289
+ }
290
+ for (const item of items) {
291
+ if (item.startsWith(".")) continue;
292
+ const full = resolve(d2, item);
293
+ try {
294
+ const s = statSync(full);
295
+ if (s.isFile() && item.endsWith(".html")) {
296
+ files.push(relative(dir, full));
297
+ } else if (s.isDirectory()) {
298
+ walk(full);
299
+ }
300
+ } catch (err) {
301
+ if (err?.code === "ENOENT" || err?.code === "EACCES") continue;
302
+ throw err;
303
+ }
304
+ }
305
+ }
306
+ walk(dir);
307
+ return files.sort();
308
+ }
309
+ async function pagesStatus(mindDir, isolation) {
310
+ const wt = worktreePath(mindDir);
311
+ const errors = [];
312
+ const [mainFiles, branchFiles, uncommitted] = await Promise.all([
313
+ gitExec(["ls-tree", "-r", "--name-only", "main"], { cwd: wt }, isolation).then((s) => s.trim().split("\n").filter(Boolean)).catch((err) => {
314
+ errors.push(err);
315
+ return [];
316
+ }),
317
+ gitExec(["ls-tree", "-r", "--name-only", "HEAD"], { cwd: wt }, isolation).then((s) => s.trim().split("\n").filter(Boolean)).catch((err) => {
318
+ errors.push(err);
319
+ return [];
320
+ }),
321
+ gitExec(["status", "--porcelain"], { cwd: wt }, isolation).then((s) => s.trim()).catch((err) => {
322
+ errors.push(err);
323
+ return "";
324
+ })
325
+ ]);
326
+ if (errors.length === 3) {
327
+ throw new Error(`Shared pages git error: ${errors[0].message}`);
328
+ }
329
+ const uncommittedFiles = /* @__PURE__ */ new Set();
330
+ if (uncommitted) {
331
+ for (const line of uncommitted.split("\n")) {
332
+ const match = line.match(/^.{2}\s+(.+)$/);
333
+ if (match) uncommittedFiles.add(match[1]);
334
+ }
335
+ }
336
+ const mainSet = new Set(mainFiles.filter((f) => f.endsWith(".html")));
337
+ const allHtml = /* @__PURE__ */ new Set([
338
+ ...mainFiles.filter((f) => f.endsWith(".html")),
339
+ ...branchFiles.filter((f) => f.endsWith(".html")),
340
+ ...[...uncommittedFiles].filter((f) => f.endsWith(".html"))
341
+ ]);
342
+ if (allHtml.size === 0) return "No shared pages found.";
343
+ const lines = [...allHtml].sort().map((file) => {
344
+ const onMain = mainSet.has(file);
345
+ const isUncommitted = uncommittedFiles.has(file);
346
+ let status;
347
+ if (isUncommitted) {
348
+ status = "uncommitted";
349
+ } else if (onMain) {
350
+ status = "published";
351
+ } else {
352
+ status = "draft";
353
+ }
354
+ return `${status.padEnd(13)} ${file}`;
355
+ });
356
+ return lines.join("\n");
357
+ }
358
+ async function pagesLog(mindDir, limit = 20, isolation) {
359
+ const wt = worktreePath(mindDir);
360
+ const output = (await gitExec(["log", "--oneline", "main", `-${limit}`], { cwd: wt }, isolation)).trim();
361
+ return output || "No history.";
362
+ }
363
+
364
+ // packages/extensions/pages/src/commands.ts
365
+ function createCommands() {
366
+ return {
367
+ publish: {
368
+ description: "Publish all pages (copy to public snapshot)",
369
+ args: [{ name: "message", description: "Commit message for shared publish" }],
370
+ flags: {
371
+ remote: { type: "boolean", description: "Also publish to volute.systems" },
372
+ shared: { type: "boolean", description: "Publish to shared pages repository" }
373
+ },
374
+ handler: async ({ args, flags }, ctx) => {
375
+ const mindName = ctx.mindName;
376
+ if (!mindName) return { error: "No mind specified (use --mind or VOLUTE_MIND)" };
377
+ if (flags.shared) {
378
+ const mindDir2 = ctx.getMindDir(mindName);
379
+ if (!mindDir2) return { error: `Mind not found: ${mindName}` };
380
+ const message = args.message?.trim();
381
+ if (!message)
382
+ return { error: 'Usage: volute pages publish --shared "description of changes"' };
383
+ try {
384
+ const result = await pagesPullAndMerge(
385
+ mindName,
386
+ mindDir2,
387
+ ctx.dataDir,
388
+ message,
389
+ isolationFrom(ctx)
390
+ );
391
+ if (!result.ok) {
392
+ return {
393
+ error: result.message || "Merge conflicts detected \u2014 pull, reconcile, and try again."
394
+ };
395
+ }
396
+ let syncWarning = "";
397
+ if (result.ok && ctx.db) {
398
+ const repoDir = resolve2(ctx.dataDir, "repo");
399
+ try {
400
+ syncSystemPages(ctx.db, collectHtmlFiles(repoDir), mindName);
401
+ } catch (err) {
402
+ console.error("[pages] failed to sync system pages to DB:", err);
403
+ syncWarning = "\nWarning: failed to sync pages to dashboard \u2014 they may not appear in the UI until the next daemon restart.";
404
+ }
405
+ }
406
+ return { output: (result.message || "Published shared pages.") + syncWarning };
407
+ } catch (err) {
408
+ return { error: `Shared publish failed: ${err.message}` };
409
+ }
410
+ }
411
+ const remote = flags.remote;
412
+ const mindDir = ctx.getMindDir(mindName);
413
+ if (!mindDir) return { error: `Mind not found: ${mindName}` };
414
+ const sourceDir = resolve2(mindDir, "home", "pages");
415
+ if (!existsSync2(sourceDir)) return { error: "No pages directory found (home/pages/)" };
416
+ const db = ctx.db;
417
+ if (!db) return { error: "Database not available" };
418
+ const snapshotDir = resolve2(ctx.dataDir, "sites", mindName);
419
+ try {
420
+ if (existsSync2(snapshotDir)) rmSync2(snapshotDir, { recursive: true });
421
+ cpSync(sourceDir, snapshotDir, {
422
+ recursive: true,
423
+ filter: (src) => !src.endsWith("/_system") && !src.includes("/_system/")
424
+ });
425
+ } catch (err) {
426
+ return { error: `Failed to publish snapshot: ${err.message}` };
427
+ }
428
+ const pageFiles = collectFiles(snapshotDir, snapshotDir, [".html", ".md"]);
429
+ let diff;
430
+ try {
431
+ diff = syncPublishedPages(db, mindName, pageFiles);
432
+ } catch (err) {
433
+ return { error: `Failed to update page database: ${err.message}` };
434
+ }
435
+ for (const file of diff.added) {
436
+ ctx.publishActivity({
437
+ type: "page_published",
438
+ mind: mindName,
439
+ summary: `${mindName} published ${file}`,
440
+ metadata: { file, iframeUrl: `/ext/pages/public/${mindName}/${file}` }
441
+ });
442
+ }
443
+ for (const file of diff.removed) {
444
+ ctx.publishActivity({
445
+ type: "page_removed",
446
+ mind: mindName,
447
+ summary: `${mindName} removed ${file}`,
448
+ metadata: { file }
449
+ });
450
+ }
451
+ let output = `Published ${pageFiles.length} files`;
452
+ const parts = [];
453
+ if (diff.added.length > 0) parts.push(`${diff.added.length} new`);
454
+ if (diff.updated.length > 0) parts.push(`${diff.updated.length} updated`);
455
+ if (diff.removed.length > 0) parts.push(`${diff.removed.length} removed`);
456
+ if (parts.length > 0) output += ` (${parts.join(", ")})`;
457
+ if (remote) {
458
+ const config = ctx.getSystemsConfig();
459
+ if (!config)
460
+ return {
461
+ error: "Not connected to volute.systems. Run volute systems register or login first."
462
+ };
463
+ const allFiles = collectFiles(snapshotDir, snapshotDir);
464
+ const files = {};
465
+ for (const f of allFiles) {
466
+ const fp = resolve2(snapshotDir, f);
467
+ files[f] = readFileSync2(fp).toString("base64");
468
+ }
469
+ try {
470
+ const res = await fetch(`${config.apiUrl}/api/pages/publish/${mindName}`, {
471
+ method: "PUT",
472
+ headers: {
473
+ "Content-Type": "application/json",
474
+ Authorization: `Bearer ${config.apiKey}`
475
+ },
476
+ body: JSON.stringify({ files })
477
+ });
478
+ const data = await res.json().catch(() => ({}));
479
+ if (!res.ok) {
480
+ const errMsg = data.error || `HTTP ${res.status}`;
481
+ output += `
482
+ Warning: remote publish failed: ${errMsg}`;
483
+ } else if (data.url) {
484
+ output += `
485
+ Remote: ${data.url}`;
486
+ }
487
+ } catch (err) {
488
+ output += `
489
+ Warning: remote publish failed: ${err.message}`;
490
+ }
491
+ }
492
+ return { output };
493
+ }
494
+ },
495
+ list: {
496
+ description: "List pages with publish status",
497
+ flags: {
498
+ all: { type: "boolean", description: "Show pages from all minds" },
499
+ shared: { type: "boolean", description: "Show shared pages status" }
500
+ },
501
+ handler: async ({ flags }, ctx) => {
502
+ const db = ctx.db;
503
+ if (!db) return { error: "Database not available" };
504
+ const allFlag = flags.all;
505
+ const port = process.env.VOLUTE_DAEMON_PORT || "1618";
506
+ if (allFlag) {
507
+ const { getAllSites: getAllSites2, getSystemPages: getSystemPages2 } = await import("./db-IJL6B26S.js");
508
+ const sites = getAllSites2(db);
509
+ const system = getSystemPages2(db);
510
+ const lines2 = [];
511
+ if (system) {
512
+ for (const f of system.files) {
513
+ const url = `http://localhost:${port}/ext/pages/public/_system/${f.file}`;
514
+ const author = f.author ? ` (${f.author})` : "";
515
+ lines2.push(`_system${author.padStart(10)} ${f.file.padEnd(25)} ${url}`);
516
+ }
517
+ }
518
+ for (const site of sites) {
519
+ for (const f of site.files) {
520
+ const url = `http://localhost:${port}/ext/pages/public/${site.mind}/${f.file}`;
521
+ lines2.push(`${site.mind.padEnd(15)} ${f.file.padEnd(25)} ${url}`);
522
+ }
523
+ }
524
+ return { output: lines2.length > 0 ? lines2.join("\n") : "No published pages found." };
525
+ }
526
+ const mindName = ctx.mindName;
527
+ if (!mindName) return { error: "No mind specified (use --mind or VOLUTE_MIND)" };
528
+ if (flags.shared) {
529
+ const mindDir2 = ctx.getMindDir(mindName);
530
+ if (!mindDir2) return { error: `Mind not found: ${mindName}` };
531
+ try {
532
+ const status = await pagesStatus(mindDir2, isolationFrom(ctx));
533
+ return { output: status };
534
+ } catch (err) {
535
+ return { error: `Failed to check shared status: ${err.message}` };
536
+ }
537
+ }
538
+ const mindDir = ctx.getMindDir(mindName);
539
+ if (!mindDir) return { error: `Mind not found: ${mindName}` };
540
+ const sourceDir = resolve2(mindDir, "home", "pages");
541
+ const published = new Set(getPublishedPages(db, mindName).map((p) => p.file));
542
+ const draftFiles = existsSync2(sourceDir) ? collectFiles(sourceDir, sourceDir, [".html", ".md"]) : [];
543
+ const allFiles = /* @__PURE__ */ new Set([...published, ...draftFiles]);
544
+ if (allFiles.size === 0) return { output: "No pages found." };
545
+ const lines = [...allFiles].sort().map((file) => {
546
+ const isPublished = published.has(file);
547
+ const status = isPublished ? "published" : "draft";
548
+ const url = isPublished ? `http://localhost:${port}/ext/pages/public/${mindName}/${file}` : "";
549
+ return `${status.padEnd(11)} ${file.padEnd(25)} ${url}`;
550
+ });
551
+ return { output: lines.join("\n") };
552
+ }
553
+ },
554
+ pull: {
555
+ description: "Pull latest shared page changes from other minds",
556
+ handler: async (_parsed, ctx) => {
557
+ const mindName = ctx.mindName;
558
+ if (!mindName) return { error: "No mind specified (use --mind or VOLUTE_MIND)" };
559
+ const mindDir = ctx.getMindDir(mindName);
560
+ if (!mindDir) return { error: `Mind not found: ${mindName}` };
561
+ try {
562
+ const result = await pagesPull(mindName, mindDir, isolationFrom(ctx));
563
+ if (!result.ok) {
564
+ return { error: result.message || "Pull failed." };
565
+ }
566
+ return { output: result.message || "Pulled latest shared changes." };
567
+ } catch (err) {
568
+ return { error: `Pull failed: ${err.message}` };
569
+ }
570
+ }
571
+ },
572
+ log: {
573
+ description: "View shared pages commit history",
574
+ flags: {
575
+ limit: { type: "number", description: "Max number of entries to show (default: 20)" }
576
+ },
577
+ handler: async ({ flags }, ctx) => {
578
+ const mindName = ctx.mindName;
579
+ if (!mindName) return { error: "No mind specified (use --mind or VOLUTE_MIND)" };
580
+ const mindDir = ctx.getMindDir(mindName);
581
+ if (!mindDir) return { error: `Mind not found: ${mindName}` };
582
+ const limit = flags.limit ?? 20;
583
+ try {
584
+ const output = await pagesLog(mindDir, limit, isolationFrom(ctx));
585
+ return { output };
586
+ } catch (err) {
587
+ return { error: `Failed to read shared log: ${err.message}` };
588
+ }
589
+ }
590
+ }
591
+ };
592
+ }
593
+ function collectFiles(dir, baseDir, ext) {
594
+ const files = [];
595
+ let items;
596
+ try {
597
+ items = readdirSync2(dir);
598
+ } catch (err) {
599
+ console.error(`[pages] failed to read directory ${dir}: ${err.message}`);
600
+ return files;
601
+ }
602
+ for (const item of items) {
603
+ if (item.startsWith(".")) continue;
604
+ const fullPath = resolve2(dir, item);
605
+ try {
606
+ const s = statSync2(fullPath);
607
+ const matchesExt = !ext || (Array.isArray(ext) ? ext.some((e) => item.endsWith(e)) : item.endsWith(ext));
608
+ if (s.isFile() && matchesExt) {
609
+ files.push(relative2(baseDir, fullPath));
610
+ } else if (s.isDirectory()) {
611
+ files.push(...collectFiles(fullPath, baseDir, ext));
612
+ }
613
+ } catch (err) {
614
+ console.error(`[pages] failed to stat ${fullPath}: ${err.message}`);
615
+ }
616
+ }
617
+ return files.sort();
618
+ }
619
+
620
+ // packages/extensions/pages/src/routes.ts
621
+ import { readFile, stat } from "fs/promises";
622
+ import { extname, resolve as resolve4 } from "path";
623
+ import { Hono } from "hono";
624
+
625
+ // packages/extensions/pages/src/cache.ts
626
+ function mapFiles(mind, files) {
627
+ return files.map((f) => ({
628
+ file: f.file,
629
+ modified: f.updated_at,
630
+ url: `/ext/pages/public/${mind}/${f.file}`,
631
+ author: f.author
632
+ }));
633
+ }
634
+ function getSites(db) {
635
+ const sites = getAllSites(db).map((site) => ({
636
+ name: site.mind,
637
+ label: site.mind,
638
+ pages: mapFiles(site.mind, site.files)
639
+ }));
640
+ const system = getSystemPages(db);
641
+ const systemSite = system ? { name: "_system", label: "Shared Pages", pages: mapFiles("_system", system.files) } : null;
642
+ return { sites, systemSite };
643
+ }
644
+ function getRecentPagesList(db, opts) {
645
+ const rows = getRecentPages(db, opts);
646
+ return rows.map((r) => ({
647
+ mind: r.mind,
648
+ file: r.file,
649
+ modified: r.updated_at,
650
+ url: `/ext/pages/public/${r.mind}/${r.file}`,
651
+ author: r.author
652
+ }));
653
+ }
654
+
655
+ // packages/extensions/pages/src/markdown.ts
656
+ import { existsSync as existsSync3 } from "fs";
657
+ import { dirname, relative as relative3, resolve as resolve3 } from "path";
658
+
659
+ // node_modules/marked/lib/marked.esm.js
660
+ function L() {
661
+ return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
662
+ }
663
+ var T = L();
664
+ function Z(u3) {
665
+ T = u3;
666
+ }
667
+ var C = { exec: () => null };
668
+ function k(u3, e = "") {
669
+ let t = typeof u3 == "string" ? u3 : u3.source, n = { replace: (r, i) => {
670
+ let s = typeof i == "string" ? i : i.source;
671
+ return s = s.replace(m.caret, "$1"), t = t.replace(r, s), n;
672
+ }, getRegex: () => new RegExp(t, e) };
673
+ return n;
674
+ }
675
+ var me = (() => {
676
+ try {
677
+ return !!new RegExp("(?<=1)(?<!1)");
678
+ } catch {
679
+ return false;
680
+ }
681
+ })();
682
+ var m = { codeRemoveIndent: /^(?: {1,4}| {0,3}\t)/gm, outputLinkReplace: /\\([\[\]])/g, indentCodeCompensation: /^(\s+)(?:```)/, beginningSpace: /^\s+/, endingHash: /#$/, startingSpaceChar: /^ /, endingSpaceChar: / $/, nonSpaceChar: /[^ ]/, newLineCharGlobal: /\n/g, tabCharGlobal: /\t/g, multipleSpaceGlobal: /\s+/g, blankLine: /^[ \t]*$/, doubleBlankLine: /\n[ \t]*\n[ \t]*$/, blockquoteStart: /^ {0,3}>/, blockquoteSetextReplace: /\n {0,3}((?:=+|-+) *)(?=\n|$)/g, blockquoteSetextReplace2: /^ {0,3}>[ \t]?/gm, listReplaceTabs: /^\t+/, listReplaceNesting: /^ {1,4}(?=( {4})*[^ ])/g, listIsTask: /^\[[ xX]\] +\S/, listReplaceTask: /^\[[ xX]\] +/, listTaskCheckbox: /\[[ xX]\]/, anyLine: /\n.*\n/, hrefBrackets: /^<(.*)>$/, tableDelimiter: /[:|]/, tableAlignChars: /^\||\| *$/g, tableRowBlankLine: /\n[ \t]*$/, tableAlignRight: /^ *-+: *$/, tableAlignCenter: /^ *:-+: *$/, tableAlignLeft: /^ *:-+ *$/, startATag: /^<a /i, endATag: /^<\/a>/i, startPreScriptTag: /^<(pre|code|kbd|script)(\s|>)/i, endPreScriptTag: /^<\/(pre|code|kbd|script)(\s|>)/i, startAngleBracket: /^</, endAngleBracket: />$/, pedanticHrefTitle: /^([^'"]*[^\s])\s+(['"])(.*)\2/, unicodeAlphaNumeric: /[\p{L}\p{N}]/u, escapeTest: /[&<>"']/, escapeReplace: /[&<>"']/g, escapeTestNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, escapeReplaceNoEncode: /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g, unescapeTest: /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig, caret: /(^|[^\[])\^/g, percentDecode: /%25/g, findPipe: /\|/g, splitPipe: / \|/, slashPipe: /\\\|/g, carriageReturn: /\r\n|\r/g, spaceLine: /^ +$/gm, notSpaceStart: /^\S*/, endingNewline: /\n$/, listItemRegex: (u3) => new RegExp(`^( {0,3}${u3})((?:[ ][^\\n]*)?(?:\\n|$))`), nextBulletRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`), hrRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`), fencesBeginRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}(?:\`\`\`|~~~)`), headingBeginRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}#`), htmlBeginRegex: (u3) => new RegExp(`^ {0,${Math.min(3, u3 - 1)}}<(?:[a-z].*>|!--)`, "i") };
683
+ var xe = /^(?:[ \t]*(?:\n|$))+/;
684
+ var be = /^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/;
685
+ var Re = /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/;
686
+ var I = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
687
+ var Te = /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/;
688
+ var N = /(?:[*+-]|\d{1,9}[.)])/;
689
+ var re = /^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/;
690
+ var se = k(re).replace(/bull/g, N).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/\|table/g, "").getRegex();
691
+ var Oe = k(re).replace(/bull/g, N).replace(/blockCode/g, /(?: {4}| {0,3}\t)/).replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g, / {0,3}>/).replace(/heading/g, / {0,3}#{1,6}/).replace(/html/g, / {0,3}<[^\n>]+>\n/).replace(/table/g, / {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex();
692
+ var Q = /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/;
693
+ var we = /^[^\n]+/;
694
+ var F = /(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/;
695
+ var ye = k(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label", F).replace("title", /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex();
696
+ var Pe = k(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g, N).getRegex();
697
+ var v = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
698
+ var j = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
699
+ var Se = k("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))", "i").replace("comment", j).replace("tag", v).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
700
+ var ie = k(Q).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex();
701
+ var $e = k(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph", ie).getRegex();
702
+ var U = { blockquote: $e, code: be, def: ye, fences: Re, heading: Te, hr: I, html: Se, lheading: se, list: Pe, newline: xe, paragraph: ie, table: C, text: we };
703
+ var te = k("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("blockquote", " {0,3}>").replace("code", "(?: {4}| {0,3} )[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex();
704
+ var _e = { ...U, lheading: Oe, table: te, paragraph: k(Q).replace("hr", I).replace("heading", " {0,3}#{1,6}(?:\\s|$)").replace("|lheading", "").replace("table", te).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", v).getRegex() };
705
+ var Le = { ...U, html: k(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment", j).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(), def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/, heading: /^(#{1,6})(.*)(?:\n+|$)/, fences: C, lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/, paragraph: k(Q).replace("hr", I).replace("heading", ` *#{1,6} *[^
706
+ ]`).replace("lheading", se).replace("|table", "").replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").replace("|tag", "").getRegex() };
707
+ var Me = /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/;
708
+ var ze = /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/;
709
+ var oe = /^( {2,}|\\)\n(?!\s*$)/;
710
+ var Ae = /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/;
711
+ var D = /[\p{P}\p{S}]/u;
712
+ var K = /[\s\p{P}\p{S}]/u;
713
+ var ae = /[^\s\p{P}\p{S}]/u;
714
+ var Ce = k(/^((?![*_])punctSpace)/, "u").replace(/punctSpace/g, K).getRegex();
715
+ var le = /(?!~)[\p{P}\p{S}]/u;
716
+ var Ie = /(?!~)[\s\p{P}\p{S}]/u;
717
+ var Ee = /(?:[^\s\p{P}\p{S}]|~)/u;
718
+ var Be = k(/link|precode-code|html/, "g").replace("link", /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-", me ? "(?<!`)()" : "(^^|[^`])").replace("code", /(?<b>`+)[^`]+\k<b>(?!`)/).replace("html", /<(?! )[^<>]*?>/).getRegex();
719
+ var ue = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
720
+ var qe = k(ue, "u").replace(/punct/g, D).getRegex();
721
+ var ve = k(ue, "u").replace(/punct/g, le).getRegex();
722
+ var pe = "^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)";
723
+ var De = k(pe, "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, K).replace(/punct/g, D).getRegex();
724
+ var He = k(pe, "gu").replace(/notPunctSpace/g, Ee).replace(/punctSpace/g, Ie).replace(/punct/g, le).getRegex();
725
+ var Ze = k("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)", "gu").replace(/notPunctSpace/g, ae).replace(/punctSpace/g, K).replace(/punct/g, D).getRegex();
726
+ var Ge = k(/\\(punct)/, "gu").replace(/punct/g, D).getRegex();
727
+ var Ne = k(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme", /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).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])?)+(?![-_])/).getRegex();
728
+ var Qe = k(j).replace("(?:-->|$)", "-->").getRegex();
729
+ var Fe = k("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment", Qe).replace("attribute", /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex();
730
+ var q = /(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/;
731
+ var je = k(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label", q).replace("href", /<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title", /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex();
732
+ var ce = k(/^!?\[(label)\]\[(ref)\]/).replace("label", q).replace("ref", F).getRegex();
733
+ var he = k(/^!?\[(ref)\](?:\[\])?/).replace("ref", F).getRegex();
734
+ var Ue = k("reflink|nolink(?!\\()", "g").replace("reflink", ce).replace("nolink", he).getRegex();
735
+ var ne = /[hH][tT][tT][pP][sS]?|[fF][tT][pP]/;
736
+ var W = { _backpedal: C, anyPunctuation: Ge, autolink: Ne, blockSkip: Be, br: oe, code: ze, del: C, emStrongLDelim: qe, emStrongRDelimAst: De, emStrongRDelimUnd: Ze, escape: Me, link: je, nolink: he, punctuation: Ce, reflink: ce, reflinkSearch: Ue, tag: Fe, text: Ae, url: C };
737
+ var Ke = { ...W, link: k(/^!?\[(label)\]\((.*?)\)/).replace("label", q).getRegex(), reflink: k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", q).getRegex() };
738
+ var G = { ...W, emStrongRDelimAst: He, emStrongLDelim: ve, url: k(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol", ne).replace("email", /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(), _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/, del: /^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/, text: k(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol", ne).getRegex() };
739
+ var We = { ...G, br: k(oe).replace("{2,}", "*").getRegex(), text: k(G.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex() };
740
+ var E = { normal: U, gfm: _e, pedantic: Le };
741
+ var M = { normal: W, gfm: G, breaks: We, pedantic: Ke };
742
+ var Xe = { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" };
743
+ var ke = (u3) => Xe[u3];
744
+ function w(u3, e) {
745
+ if (e) {
746
+ if (m.escapeTest.test(u3)) return u3.replace(m.escapeReplace, ke);
747
+ } else if (m.escapeTestNoEncode.test(u3)) return u3.replace(m.escapeReplaceNoEncode, ke);
748
+ return u3;
749
+ }
750
+ function X(u3) {
751
+ try {
752
+ u3 = encodeURI(u3).replace(m.percentDecode, "%");
753
+ } catch {
754
+ return null;
755
+ }
756
+ return u3;
757
+ }
758
+ function J(u3, e) {
759
+ let t = u3.replace(m.findPipe, (i, s, a) => {
760
+ let o = false, l = s;
761
+ for (; --l >= 0 && a[l] === "\\"; ) o = !o;
762
+ return o ? "|" : " |";
763
+ }), n = t.split(m.splitPipe), r = 0;
764
+ if (n[0].trim() || n.shift(), n.length > 0 && !n.at(-1)?.trim() && n.pop(), e) if (n.length > e) n.splice(e);
765
+ else for (; n.length < e; ) n.push("");
766
+ for (; r < n.length; r++) n[r] = n[r].trim().replace(m.slashPipe, "|");
767
+ return n;
768
+ }
769
+ function z(u3, e, t) {
770
+ let n = u3.length;
771
+ if (n === 0) return "";
772
+ let r = 0;
773
+ for (; r < n; ) {
774
+ let i = u3.charAt(n - r - 1);
775
+ if (i === e && !t) r++;
776
+ else if (i !== e && t) r++;
777
+ else break;
778
+ }
779
+ return u3.slice(0, n - r);
780
+ }
781
+ function de(u3, e) {
782
+ if (u3.indexOf(e[1]) === -1) return -1;
783
+ let t = 0;
784
+ for (let n = 0; n < u3.length; n++) if (u3[n] === "\\") n++;
785
+ else if (u3[n] === e[0]) t++;
786
+ else if (u3[n] === e[1] && (t--, t < 0)) return n;
787
+ return t > 0 ? -2 : -1;
788
+ }
789
+ function ge(u3, e, t, n, r) {
790
+ let i = e.href, s = e.title || null, a = u3[1].replace(r.other.outputLinkReplace, "$1");
791
+ n.state.inLink = true;
792
+ let o = { type: u3[0].charAt(0) === "!" ? "image" : "link", raw: t, href: i, title: s, text: a, tokens: n.inlineTokens(a) };
793
+ return n.state.inLink = false, o;
794
+ }
795
+ function Je(u3, e, t) {
796
+ let n = u3.match(t.other.indentCodeCompensation);
797
+ if (n === null) return e;
798
+ let r = n[1];
799
+ return e.split(`
800
+ `).map((i) => {
801
+ let s = i.match(t.other.beginningSpace);
802
+ if (s === null) return i;
803
+ let [a] = s;
804
+ return a.length >= r.length ? i.slice(r.length) : i;
805
+ }).join(`
806
+ `);
807
+ }
808
+ var y = class {
809
+ options;
810
+ rules;
811
+ lexer;
812
+ constructor(e) {
813
+ this.options = e || T;
814
+ }
815
+ space(e) {
816
+ let t = this.rules.block.newline.exec(e);
817
+ if (t && t[0].length > 0) return { type: "space", raw: t[0] };
818
+ }
819
+ code(e) {
820
+ let t = this.rules.block.code.exec(e);
821
+ if (t) {
822
+ let n = t[0].replace(this.rules.other.codeRemoveIndent, "");
823
+ return { type: "code", raw: t[0], codeBlockStyle: "indented", text: this.options.pedantic ? n : z(n, `
824
+ `) };
825
+ }
826
+ }
827
+ fences(e) {
828
+ let t = this.rules.block.fences.exec(e);
829
+ if (t) {
830
+ let n = t[0], r = Je(n, t[3] || "", this.rules);
831
+ return { type: "code", raw: n, lang: t[2] ? t[2].trim().replace(this.rules.inline.anyPunctuation, "$1") : t[2], text: r };
832
+ }
833
+ }
834
+ heading(e) {
835
+ let t = this.rules.block.heading.exec(e);
836
+ if (t) {
837
+ let n = t[2].trim();
838
+ if (this.rules.other.endingHash.test(n)) {
839
+ let r = z(n, "#");
840
+ (this.options.pedantic || !r || this.rules.other.endingSpaceChar.test(r)) && (n = r.trim());
841
+ }
842
+ return { type: "heading", raw: t[0], depth: t[1].length, text: n, tokens: this.lexer.inline(n) };
843
+ }
844
+ }
845
+ hr(e) {
846
+ let t = this.rules.block.hr.exec(e);
847
+ if (t) return { type: "hr", raw: z(t[0], `
848
+ `) };
849
+ }
850
+ blockquote(e) {
851
+ let t = this.rules.block.blockquote.exec(e);
852
+ if (t) {
853
+ let n = z(t[0], `
854
+ `).split(`
855
+ `), r = "", i = "", s = [];
856
+ for (; n.length > 0; ) {
857
+ let a = false, o = [], l;
858
+ for (l = 0; l < n.length; l++) if (this.rules.other.blockquoteStart.test(n[l])) o.push(n[l]), a = true;
859
+ else if (!a) o.push(n[l]);
860
+ else break;
861
+ n = n.slice(l);
862
+ let p = o.join(`
863
+ `), c = p.replace(this.rules.other.blockquoteSetextReplace, `
864
+ $1`).replace(this.rules.other.blockquoteSetextReplace2, "");
865
+ r = r ? `${r}
866
+ ${p}` : p, i = i ? `${i}
867
+ ${c}` : c;
868
+ let g = this.lexer.state.top;
869
+ if (this.lexer.state.top = true, this.lexer.blockTokens(c, s, true), this.lexer.state.top = g, n.length === 0) break;
870
+ let h = s.at(-1);
871
+ if (h?.type === "code") break;
872
+ if (h?.type === "blockquote") {
873
+ let R = h, f = R.raw + `
874
+ ` + n.join(`
875
+ `), O = this.blockquote(f);
876
+ s[s.length - 1] = O, r = r.substring(0, r.length - R.raw.length) + O.raw, i = i.substring(0, i.length - R.text.length) + O.text;
877
+ break;
878
+ } else if (h?.type === "list") {
879
+ let R = h, f = R.raw + `
880
+ ` + n.join(`
881
+ `), O = this.list(f);
882
+ s[s.length - 1] = O, r = r.substring(0, r.length - h.raw.length) + O.raw, i = i.substring(0, i.length - R.raw.length) + O.raw, n = f.substring(s.at(-1).raw.length).split(`
883
+ `);
884
+ continue;
885
+ }
886
+ }
887
+ return { type: "blockquote", raw: r, tokens: s, text: i };
888
+ }
889
+ }
890
+ list(e) {
891
+ let t = this.rules.block.list.exec(e);
892
+ if (t) {
893
+ let n = t[1].trim(), r = n.length > 1, i = { type: "list", raw: "", ordered: r, start: r ? +n.slice(0, -1) : "", loose: false, items: [] };
894
+ n = r ? `\\d{1,9}\\${n.slice(-1)}` : `\\${n}`, this.options.pedantic && (n = r ? n : "[*+-]");
895
+ let s = this.rules.other.listItemRegex(n), a = false;
896
+ for (; e; ) {
897
+ let l = false, p = "", c = "";
898
+ if (!(t = s.exec(e)) || this.rules.block.hr.test(e)) break;
899
+ p = t[0], e = e.substring(p.length);
900
+ let g = t[2].split(`
901
+ `, 1)[0].replace(this.rules.other.listReplaceTabs, (O) => " ".repeat(3 * O.length)), h = e.split(`
902
+ `, 1)[0], R = !g.trim(), f = 0;
903
+ if (this.options.pedantic ? (f = 2, c = g.trimStart()) : R ? f = t[1].length + 1 : (f = t[2].search(this.rules.other.nonSpaceChar), f = f > 4 ? 1 : f, c = g.slice(f), f += t[1].length), R && this.rules.other.blankLine.test(h) && (p += h + `
904
+ `, e = e.substring(h.length + 1), l = true), !l) {
905
+ let O = this.rules.other.nextBulletRegex(f), V = this.rules.other.hrRegex(f), Y = this.rules.other.fencesBeginRegex(f), ee = this.rules.other.headingBeginRegex(f), fe = this.rules.other.htmlBeginRegex(f);
906
+ for (; e; ) {
907
+ let H = e.split(`
908
+ `, 1)[0], A;
909
+ if (h = H, this.options.pedantic ? (h = h.replace(this.rules.other.listReplaceNesting, " "), A = h) : A = h.replace(this.rules.other.tabCharGlobal, " "), Y.test(h) || ee.test(h) || fe.test(h) || O.test(h) || V.test(h)) break;
910
+ if (A.search(this.rules.other.nonSpaceChar) >= f || !h.trim()) c += `
911
+ ` + A.slice(f);
912
+ else {
913
+ if (R || g.replace(this.rules.other.tabCharGlobal, " ").search(this.rules.other.nonSpaceChar) >= 4 || Y.test(g) || ee.test(g) || V.test(g)) break;
914
+ c += `
915
+ ` + h;
916
+ }
917
+ !R && !h.trim() && (R = true), p += H + `
918
+ `, e = e.substring(H.length + 1), g = A.slice(f);
919
+ }
920
+ }
921
+ i.loose || (a ? i.loose = true : this.rules.other.doubleBlankLine.test(p) && (a = true)), i.items.push({ type: "list_item", raw: p, task: !!this.options.gfm && this.rules.other.listIsTask.test(c), loose: false, text: c, tokens: [] }), i.raw += p;
922
+ }
923
+ let o = i.items.at(-1);
924
+ if (o) o.raw = o.raw.trimEnd(), o.text = o.text.trimEnd();
925
+ else return;
926
+ i.raw = i.raw.trimEnd();
927
+ for (let l of i.items) {
928
+ if (this.lexer.state.top = false, l.tokens = this.lexer.blockTokens(l.text, []), l.task) {
929
+ if (l.text = l.text.replace(this.rules.other.listReplaceTask, ""), l.tokens[0]?.type === "text" || l.tokens[0]?.type === "paragraph") {
930
+ l.tokens[0].raw = l.tokens[0].raw.replace(this.rules.other.listReplaceTask, ""), l.tokens[0].text = l.tokens[0].text.replace(this.rules.other.listReplaceTask, "");
931
+ for (let c = this.lexer.inlineQueue.length - 1; c >= 0; c--) if (this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)) {
932
+ this.lexer.inlineQueue[c].src = this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask, "");
933
+ break;
934
+ }
935
+ }
936
+ let p = this.rules.other.listTaskCheckbox.exec(l.raw);
937
+ if (p) {
938
+ let c = { type: "checkbox", raw: p[0] + " ", checked: p[0] !== "[ ]" };
939
+ l.checked = c.checked, i.loose ? l.tokens[0] && ["paragraph", "text"].includes(l.tokens[0].type) && "tokens" in l.tokens[0] && l.tokens[0].tokens ? (l.tokens[0].raw = c.raw + l.tokens[0].raw, l.tokens[0].text = c.raw + l.tokens[0].text, l.tokens[0].tokens.unshift(c)) : l.tokens.unshift({ type: "paragraph", raw: c.raw, text: c.raw, tokens: [c] }) : l.tokens.unshift(c);
940
+ }
941
+ }
942
+ if (!i.loose) {
943
+ let p = l.tokens.filter((g) => g.type === "space"), c = p.length > 0 && p.some((g) => this.rules.other.anyLine.test(g.raw));
944
+ i.loose = c;
945
+ }
946
+ }
947
+ if (i.loose) for (let l of i.items) {
948
+ l.loose = true;
949
+ for (let p of l.tokens) p.type === "text" && (p.type = "paragraph");
950
+ }
951
+ return i;
952
+ }
953
+ }
954
+ html(e) {
955
+ let t = this.rules.block.html.exec(e);
956
+ if (t) return { type: "html", block: true, raw: t[0], pre: t[1] === "pre" || t[1] === "script" || t[1] === "style", text: t[0] };
957
+ }
958
+ def(e) {
959
+ let t = this.rules.block.def.exec(e);
960
+ if (t) {
961
+ let n = t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal, " "), r = t[2] ? t[2].replace(this.rules.other.hrefBrackets, "$1").replace(this.rules.inline.anyPunctuation, "$1") : "", i = t[3] ? t[3].substring(1, t[3].length - 1).replace(this.rules.inline.anyPunctuation, "$1") : t[3];
962
+ return { type: "def", tag: n, raw: t[0], href: r, title: i };
963
+ }
964
+ }
965
+ table(e) {
966
+ let t = this.rules.block.table.exec(e);
967
+ if (!t || !this.rules.other.tableDelimiter.test(t[2])) return;
968
+ let n = J(t[1]), r = t[2].replace(this.rules.other.tableAlignChars, "").split("|"), i = t[3]?.trim() ? t[3].replace(this.rules.other.tableRowBlankLine, "").split(`
969
+ `) : [], s = { type: "table", raw: t[0], header: [], align: [], rows: [] };
970
+ if (n.length === r.length) {
971
+ for (let a of r) this.rules.other.tableAlignRight.test(a) ? s.align.push("right") : this.rules.other.tableAlignCenter.test(a) ? s.align.push("center") : this.rules.other.tableAlignLeft.test(a) ? s.align.push("left") : s.align.push(null);
972
+ for (let a = 0; a < n.length; a++) s.header.push({ text: n[a], tokens: this.lexer.inline(n[a]), header: true, align: s.align[a] });
973
+ for (let a of i) s.rows.push(J(a, s.header.length).map((o, l) => ({ text: o, tokens: this.lexer.inline(o), header: false, align: s.align[l] })));
974
+ return s;
975
+ }
976
+ }
977
+ lheading(e) {
978
+ let t = this.rules.block.lheading.exec(e);
979
+ if (t) return { type: "heading", raw: t[0], depth: t[2].charAt(0) === "=" ? 1 : 2, text: t[1], tokens: this.lexer.inline(t[1]) };
980
+ }
981
+ paragraph(e) {
982
+ let t = this.rules.block.paragraph.exec(e);
983
+ if (t) {
984
+ let n = t[1].charAt(t[1].length - 1) === `
985
+ ` ? t[1].slice(0, -1) : t[1];
986
+ return { type: "paragraph", raw: t[0], text: n, tokens: this.lexer.inline(n) };
987
+ }
988
+ }
989
+ text(e) {
990
+ let t = this.rules.block.text.exec(e);
991
+ if (t) return { type: "text", raw: t[0], text: t[0], tokens: this.lexer.inline(t[0]) };
992
+ }
993
+ escape(e) {
994
+ let t = this.rules.inline.escape.exec(e);
995
+ if (t) return { type: "escape", raw: t[0], text: t[1] };
996
+ }
997
+ tag(e) {
998
+ let t = this.rules.inline.tag.exec(e);
999
+ if (t) return !this.lexer.state.inLink && this.rules.other.startATag.test(t[0]) ? this.lexer.state.inLink = true : this.lexer.state.inLink && this.rules.other.endATag.test(t[0]) && (this.lexer.state.inLink = false), !this.lexer.state.inRawBlock && this.rules.other.startPreScriptTag.test(t[0]) ? this.lexer.state.inRawBlock = true : this.lexer.state.inRawBlock && this.rules.other.endPreScriptTag.test(t[0]) && (this.lexer.state.inRawBlock = false), { type: "html", raw: t[0], inLink: this.lexer.state.inLink, inRawBlock: this.lexer.state.inRawBlock, block: false, text: t[0] };
1000
+ }
1001
+ link(e) {
1002
+ let t = this.rules.inline.link.exec(e);
1003
+ if (t) {
1004
+ let n = t[2].trim();
1005
+ if (!this.options.pedantic && this.rules.other.startAngleBracket.test(n)) {
1006
+ if (!this.rules.other.endAngleBracket.test(n)) return;
1007
+ let s = z(n.slice(0, -1), "\\");
1008
+ if ((n.length - s.length) % 2 === 0) return;
1009
+ } else {
1010
+ let s = de(t[2], "()");
1011
+ if (s === -2) return;
1012
+ if (s > -1) {
1013
+ let o = (t[0].indexOf("!") === 0 ? 5 : 4) + t[1].length + s;
1014
+ t[2] = t[2].substring(0, s), t[0] = t[0].substring(0, o).trim(), t[3] = "";
1015
+ }
1016
+ }
1017
+ let r = t[2], i = "";
1018
+ if (this.options.pedantic) {
1019
+ let s = this.rules.other.pedanticHrefTitle.exec(r);
1020
+ s && (r = s[1], i = s[3]);
1021
+ } else i = t[3] ? t[3].slice(1, -1) : "";
1022
+ return r = r.trim(), this.rules.other.startAngleBracket.test(r) && (this.options.pedantic && !this.rules.other.endAngleBracket.test(n) ? r = r.slice(1) : r = r.slice(1, -1)), ge(t, { href: r && r.replace(this.rules.inline.anyPunctuation, "$1"), title: i && i.replace(this.rules.inline.anyPunctuation, "$1") }, t[0], this.lexer, this.rules);
1023
+ }
1024
+ }
1025
+ reflink(e, t) {
1026
+ let n;
1027
+ if ((n = this.rules.inline.reflink.exec(e)) || (n = this.rules.inline.nolink.exec(e))) {
1028
+ let r = (n[2] || n[1]).replace(this.rules.other.multipleSpaceGlobal, " "), i = t[r.toLowerCase()];
1029
+ if (!i) {
1030
+ let s = n[0].charAt(0);
1031
+ return { type: "text", raw: s, text: s };
1032
+ }
1033
+ return ge(n, i, n[0], this.lexer, this.rules);
1034
+ }
1035
+ }
1036
+ emStrong(e, t, n = "") {
1037
+ let r = this.rules.inline.emStrongLDelim.exec(e);
1038
+ if (!r || r[3] && n.match(this.rules.other.unicodeAlphaNumeric)) return;
1039
+ if (!(r[1] || r[2] || "") || !n || this.rules.inline.punctuation.exec(n)) {
1040
+ let s = [...r[0]].length - 1, a, o, l = s, p = 0, c = r[0][0] === "*" ? this.rules.inline.emStrongRDelimAst : this.rules.inline.emStrongRDelimUnd;
1041
+ for (c.lastIndex = 0, t = t.slice(-1 * e.length + s); (r = c.exec(t)) != null; ) {
1042
+ if (a = r[1] || r[2] || r[3] || r[4] || r[5] || r[6], !a) continue;
1043
+ if (o = [...a].length, r[3] || r[4]) {
1044
+ l += o;
1045
+ continue;
1046
+ } else if ((r[5] || r[6]) && s % 3 && !((s + o) % 3)) {
1047
+ p += o;
1048
+ continue;
1049
+ }
1050
+ if (l -= o, l > 0) continue;
1051
+ o = Math.min(o, o + l + p);
1052
+ let g = [...r[0]][0].length, h = e.slice(0, s + r.index + g + o);
1053
+ if (Math.min(s, o) % 2) {
1054
+ let f = h.slice(1, -1);
1055
+ return { type: "em", raw: h, text: f, tokens: this.lexer.inlineTokens(f) };
1056
+ }
1057
+ let R = h.slice(2, -2);
1058
+ return { type: "strong", raw: h, text: R, tokens: this.lexer.inlineTokens(R) };
1059
+ }
1060
+ }
1061
+ }
1062
+ codespan(e) {
1063
+ let t = this.rules.inline.code.exec(e);
1064
+ if (t) {
1065
+ let n = t[2].replace(this.rules.other.newLineCharGlobal, " "), r = this.rules.other.nonSpaceChar.test(n), i = this.rules.other.startingSpaceChar.test(n) && this.rules.other.endingSpaceChar.test(n);
1066
+ return r && i && (n = n.substring(1, n.length - 1)), { type: "codespan", raw: t[0], text: n };
1067
+ }
1068
+ }
1069
+ br(e) {
1070
+ let t = this.rules.inline.br.exec(e);
1071
+ if (t) return { type: "br", raw: t[0] };
1072
+ }
1073
+ del(e) {
1074
+ let t = this.rules.inline.del.exec(e);
1075
+ if (t) return { type: "del", raw: t[0], text: t[2], tokens: this.lexer.inlineTokens(t[2]) };
1076
+ }
1077
+ autolink(e) {
1078
+ let t = this.rules.inline.autolink.exec(e);
1079
+ if (t) {
1080
+ let n, r;
1081
+ return t[2] === "@" ? (n = t[1], r = "mailto:" + n) : (n = t[1], r = n), { type: "link", raw: t[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
1082
+ }
1083
+ }
1084
+ url(e) {
1085
+ let t;
1086
+ if (t = this.rules.inline.url.exec(e)) {
1087
+ let n, r;
1088
+ if (t[2] === "@") n = t[0], r = "mailto:" + n;
1089
+ else {
1090
+ let i;
1091
+ do
1092
+ i = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])?.[0] ?? "";
1093
+ while (i !== t[0]);
1094
+ n = t[0], t[1] === "www." ? r = "http://" + t[0] : r = t[0];
1095
+ }
1096
+ return { type: "link", raw: t[0], text: n, href: r, tokens: [{ type: "text", raw: n, text: n }] };
1097
+ }
1098
+ }
1099
+ inlineText(e) {
1100
+ let t = this.rules.inline.text.exec(e);
1101
+ if (t) {
1102
+ let n = this.lexer.state.inRawBlock;
1103
+ return { type: "text", raw: t[0], text: t[0], escaped: n };
1104
+ }
1105
+ }
1106
+ };
1107
+ var x = class u {
1108
+ tokens;
1109
+ options;
1110
+ state;
1111
+ inlineQueue;
1112
+ tokenizer;
1113
+ constructor(e) {
1114
+ this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = e || T, this.options.tokenizer = this.options.tokenizer || new y(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = { inLink: false, inRawBlock: false, top: true };
1115
+ let t = { other: m, block: E.normal, inline: M.normal };
1116
+ this.options.pedantic ? (t.block = E.pedantic, t.inline = M.pedantic) : this.options.gfm && (t.block = E.gfm, this.options.breaks ? t.inline = M.breaks : t.inline = M.gfm), this.tokenizer.rules = t;
1117
+ }
1118
+ static get rules() {
1119
+ return { block: E, inline: M };
1120
+ }
1121
+ static lex(e, t) {
1122
+ return new u(t).lex(e);
1123
+ }
1124
+ static lexInline(e, t) {
1125
+ return new u(t).inlineTokens(e);
1126
+ }
1127
+ lex(e) {
1128
+ e = e.replace(m.carriageReturn, `
1129
+ `), this.blockTokens(e, this.tokens);
1130
+ for (let t = 0; t < this.inlineQueue.length; t++) {
1131
+ let n = this.inlineQueue[t];
1132
+ this.inlineTokens(n.src, n.tokens);
1133
+ }
1134
+ return this.inlineQueue = [], this.tokens;
1135
+ }
1136
+ blockTokens(e, t = [], n = false) {
1137
+ for (this.options.pedantic && (e = e.replace(m.tabCharGlobal, " ").replace(m.spaceLine, "")); e; ) {
1138
+ let r;
1139
+ if (this.options.extensions?.block?.some((s) => (r = s.call({ lexer: this }, e, t)) ? (e = e.substring(r.raw.length), t.push(r), true) : false)) continue;
1140
+ if (r = this.tokenizer.space(e)) {
1141
+ e = e.substring(r.raw.length);
1142
+ let s = t.at(-1);
1143
+ r.raw.length === 1 && s !== void 0 ? s.raw += `
1144
+ ` : t.push(r);
1145
+ continue;
1146
+ }
1147
+ if (r = this.tokenizer.code(e)) {
1148
+ e = e.substring(r.raw.length);
1149
+ let s = t.at(-1);
1150
+ s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
1151
+ `) ? "" : `
1152
+ `) + r.raw, s.text += `
1153
+ ` + r.text, this.inlineQueue.at(-1).src = s.text) : t.push(r);
1154
+ continue;
1155
+ }
1156
+ if (r = this.tokenizer.fences(e)) {
1157
+ e = e.substring(r.raw.length), t.push(r);
1158
+ continue;
1159
+ }
1160
+ if (r = this.tokenizer.heading(e)) {
1161
+ e = e.substring(r.raw.length), t.push(r);
1162
+ continue;
1163
+ }
1164
+ if (r = this.tokenizer.hr(e)) {
1165
+ e = e.substring(r.raw.length), t.push(r);
1166
+ continue;
1167
+ }
1168
+ if (r = this.tokenizer.blockquote(e)) {
1169
+ e = e.substring(r.raw.length), t.push(r);
1170
+ continue;
1171
+ }
1172
+ if (r = this.tokenizer.list(e)) {
1173
+ e = e.substring(r.raw.length), t.push(r);
1174
+ continue;
1175
+ }
1176
+ if (r = this.tokenizer.html(e)) {
1177
+ e = e.substring(r.raw.length), t.push(r);
1178
+ continue;
1179
+ }
1180
+ if (r = this.tokenizer.def(e)) {
1181
+ e = e.substring(r.raw.length);
1182
+ let s = t.at(-1);
1183
+ s?.type === "paragraph" || s?.type === "text" ? (s.raw += (s.raw.endsWith(`
1184
+ `) ? "" : `
1185
+ `) + r.raw, s.text += `
1186
+ ` + r.raw, this.inlineQueue.at(-1).src = s.text) : this.tokens.links[r.tag] || (this.tokens.links[r.tag] = { href: r.href, title: r.title }, t.push(r));
1187
+ continue;
1188
+ }
1189
+ if (r = this.tokenizer.table(e)) {
1190
+ e = e.substring(r.raw.length), t.push(r);
1191
+ continue;
1192
+ }
1193
+ if (r = this.tokenizer.lheading(e)) {
1194
+ e = e.substring(r.raw.length), t.push(r);
1195
+ continue;
1196
+ }
1197
+ let i = e;
1198
+ if (this.options.extensions?.startBlock) {
1199
+ let s = 1 / 0, a = e.slice(1), o;
1200
+ this.options.extensions.startBlock.forEach((l) => {
1201
+ o = l.call({ lexer: this }, a), typeof o == "number" && o >= 0 && (s = Math.min(s, o));
1202
+ }), s < 1 / 0 && s >= 0 && (i = e.substring(0, s + 1));
1203
+ }
1204
+ if (this.state.top && (r = this.tokenizer.paragraph(i))) {
1205
+ let s = t.at(-1);
1206
+ n && s?.type === "paragraph" ? (s.raw += (s.raw.endsWith(`
1207
+ `) ? "" : `
1208
+ `) + r.raw, s.text += `
1209
+ ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t.push(r), n = i.length !== e.length, e = e.substring(r.raw.length);
1210
+ continue;
1211
+ }
1212
+ if (r = this.tokenizer.text(e)) {
1213
+ e = e.substring(r.raw.length);
1214
+ let s = t.at(-1);
1215
+ s?.type === "text" ? (s.raw += (s.raw.endsWith(`
1216
+ `) ? "" : `
1217
+ `) + r.raw, s.text += `
1218
+ ` + r.text, this.inlineQueue.pop(), this.inlineQueue.at(-1).src = s.text) : t.push(r);
1219
+ continue;
1220
+ }
1221
+ if (e) {
1222
+ let s = "Infinite loop on byte: " + e.charCodeAt(0);
1223
+ if (this.options.silent) {
1224
+ console.error(s);
1225
+ break;
1226
+ } else throw new Error(s);
1227
+ }
1228
+ }
1229
+ return this.state.top = true, t;
1230
+ }
1231
+ inline(e, t = []) {
1232
+ return this.inlineQueue.push({ src: e, tokens: t }), t;
1233
+ }
1234
+ inlineTokens(e, t = []) {
1235
+ let n = e, r = null;
1236
+ if (this.tokens.links) {
1237
+ let o = Object.keys(this.tokens.links);
1238
+ if (o.length > 0) for (; (r = this.tokenizer.rules.inline.reflinkSearch.exec(n)) != null; ) o.includes(r[0].slice(r[0].lastIndexOf("[") + 1, -1)) && (n = n.slice(0, r.index) + "[" + "a".repeat(r[0].length - 2) + "]" + n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
1239
+ }
1240
+ for (; (r = this.tokenizer.rules.inline.anyPunctuation.exec(n)) != null; ) n = n.slice(0, r.index) + "++" + n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);
1241
+ let i;
1242
+ for (; (r = this.tokenizer.rules.inline.blockSkip.exec(n)) != null; ) i = r[2] ? r[2].length : 0, n = n.slice(0, r.index + i) + "[" + "a".repeat(r[0].length - i - 2) + "]" + n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
1243
+ n = this.options.hooks?.emStrongMask?.call({ lexer: this }, n) ?? n;
1244
+ let s = false, a = "";
1245
+ for (; e; ) {
1246
+ s || (a = ""), s = false;
1247
+ let o;
1248
+ if (this.options.extensions?.inline?.some((p) => (o = p.call({ lexer: this }, e, t)) ? (e = e.substring(o.raw.length), t.push(o), true) : false)) continue;
1249
+ if (o = this.tokenizer.escape(e)) {
1250
+ e = e.substring(o.raw.length), t.push(o);
1251
+ continue;
1252
+ }
1253
+ if (o = this.tokenizer.tag(e)) {
1254
+ e = e.substring(o.raw.length), t.push(o);
1255
+ continue;
1256
+ }
1257
+ if (o = this.tokenizer.link(e)) {
1258
+ e = e.substring(o.raw.length), t.push(o);
1259
+ continue;
1260
+ }
1261
+ if (o = this.tokenizer.reflink(e, this.tokens.links)) {
1262
+ e = e.substring(o.raw.length);
1263
+ let p = t.at(-1);
1264
+ o.type === "text" && p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t.push(o);
1265
+ continue;
1266
+ }
1267
+ if (o = this.tokenizer.emStrong(e, n, a)) {
1268
+ e = e.substring(o.raw.length), t.push(o);
1269
+ continue;
1270
+ }
1271
+ if (o = this.tokenizer.codespan(e)) {
1272
+ e = e.substring(o.raw.length), t.push(o);
1273
+ continue;
1274
+ }
1275
+ if (o = this.tokenizer.br(e)) {
1276
+ e = e.substring(o.raw.length), t.push(o);
1277
+ continue;
1278
+ }
1279
+ if (o = this.tokenizer.del(e)) {
1280
+ e = e.substring(o.raw.length), t.push(o);
1281
+ continue;
1282
+ }
1283
+ if (o = this.tokenizer.autolink(e)) {
1284
+ e = e.substring(o.raw.length), t.push(o);
1285
+ continue;
1286
+ }
1287
+ if (!this.state.inLink && (o = this.tokenizer.url(e))) {
1288
+ e = e.substring(o.raw.length), t.push(o);
1289
+ continue;
1290
+ }
1291
+ let l = e;
1292
+ if (this.options.extensions?.startInline) {
1293
+ let p = 1 / 0, c = e.slice(1), g;
1294
+ this.options.extensions.startInline.forEach((h) => {
1295
+ g = h.call({ lexer: this }, c), typeof g == "number" && g >= 0 && (p = Math.min(p, g));
1296
+ }), p < 1 / 0 && p >= 0 && (l = e.substring(0, p + 1));
1297
+ }
1298
+ if (o = this.tokenizer.inlineText(l)) {
1299
+ e = e.substring(o.raw.length), o.raw.slice(-1) !== "_" && (a = o.raw.slice(-1)), s = true;
1300
+ let p = t.at(-1);
1301
+ p?.type === "text" ? (p.raw += o.raw, p.text += o.text) : t.push(o);
1302
+ continue;
1303
+ }
1304
+ if (e) {
1305
+ let p = "Infinite loop on byte: " + e.charCodeAt(0);
1306
+ if (this.options.silent) {
1307
+ console.error(p);
1308
+ break;
1309
+ } else throw new Error(p);
1310
+ }
1311
+ }
1312
+ return t;
1313
+ }
1314
+ };
1315
+ var P = class {
1316
+ options;
1317
+ parser;
1318
+ constructor(e) {
1319
+ this.options = e || T;
1320
+ }
1321
+ space(e) {
1322
+ return "";
1323
+ }
1324
+ code({ text: e, lang: t, escaped: n }) {
1325
+ let r = (t || "").match(m.notSpaceStart)?.[0], i = e.replace(m.endingNewline, "") + `
1326
+ `;
1327
+ return r ? '<pre><code class="language-' + w(r) + '">' + (n ? i : w(i, true)) + `</code></pre>
1328
+ ` : "<pre><code>" + (n ? i : w(i, true)) + `</code></pre>
1329
+ `;
1330
+ }
1331
+ blockquote({ tokens: e }) {
1332
+ return `<blockquote>
1333
+ ${this.parser.parse(e)}</blockquote>
1334
+ `;
1335
+ }
1336
+ html({ text: e }) {
1337
+ return e;
1338
+ }
1339
+ def(e) {
1340
+ return "";
1341
+ }
1342
+ heading({ tokens: e, depth: t }) {
1343
+ return `<h${t}>${this.parser.parseInline(e)}</h${t}>
1344
+ `;
1345
+ }
1346
+ hr(e) {
1347
+ return `<hr>
1348
+ `;
1349
+ }
1350
+ list(e) {
1351
+ let t = e.ordered, n = e.start, r = "";
1352
+ for (let a = 0; a < e.items.length; a++) {
1353
+ let o = e.items[a];
1354
+ r += this.listitem(o);
1355
+ }
1356
+ let i = t ? "ol" : "ul", s = t && n !== 1 ? ' start="' + n + '"' : "";
1357
+ return "<" + i + s + `>
1358
+ ` + r + "</" + i + `>
1359
+ `;
1360
+ }
1361
+ listitem(e) {
1362
+ return `<li>${this.parser.parse(e.tokens)}</li>
1363
+ `;
1364
+ }
1365
+ checkbox({ checked: e }) {
1366
+ return "<input " + (e ? 'checked="" ' : "") + 'disabled="" type="checkbox"> ';
1367
+ }
1368
+ paragraph({ tokens: e }) {
1369
+ return `<p>${this.parser.parseInline(e)}</p>
1370
+ `;
1371
+ }
1372
+ table(e) {
1373
+ let t = "", n = "";
1374
+ for (let i = 0; i < e.header.length; i++) n += this.tablecell(e.header[i]);
1375
+ t += this.tablerow({ text: n });
1376
+ let r = "";
1377
+ for (let i = 0; i < e.rows.length; i++) {
1378
+ let s = e.rows[i];
1379
+ n = "";
1380
+ for (let a = 0; a < s.length; a++) n += this.tablecell(s[a]);
1381
+ r += this.tablerow({ text: n });
1382
+ }
1383
+ return r && (r = `<tbody>${r}</tbody>`), `<table>
1384
+ <thead>
1385
+ ` + t + `</thead>
1386
+ ` + r + `</table>
1387
+ `;
1388
+ }
1389
+ tablerow({ text: e }) {
1390
+ return `<tr>
1391
+ ${e}</tr>
1392
+ `;
1393
+ }
1394
+ tablecell(e) {
1395
+ let t = this.parser.parseInline(e.tokens), n = e.header ? "th" : "td";
1396
+ return (e.align ? `<${n} align="${e.align}">` : `<${n}>`) + t + `</${n}>
1397
+ `;
1398
+ }
1399
+ strong({ tokens: e }) {
1400
+ return `<strong>${this.parser.parseInline(e)}</strong>`;
1401
+ }
1402
+ em({ tokens: e }) {
1403
+ return `<em>${this.parser.parseInline(e)}</em>`;
1404
+ }
1405
+ codespan({ text: e }) {
1406
+ return `<code>${w(e, true)}</code>`;
1407
+ }
1408
+ br(e) {
1409
+ return "<br>";
1410
+ }
1411
+ del({ tokens: e }) {
1412
+ return `<del>${this.parser.parseInline(e)}</del>`;
1413
+ }
1414
+ link({ href: e, title: t, tokens: n }) {
1415
+ let r = this.parser.parseInline(n), i = X(e);
1416
+ if (i === null) return r;
1417
+ e = i;
1418
+ let s = '<a href="' + e + '"';
1419
+ return t && (s += ' title="' + w(t) + '"'), s += ">" + r + "</a>", s;
1420
+ }
1421
+ image({ href: e, title: t, text: n, tokens: r }) {
1422
+ r && (n = this.parser.parseInline(r, this.parser.textRenderer));
1423
+ let i = X(e);
1424
+ if (i === null) return w(n);
1425
+ e = i;
1426
+ let s = `<img src="${e}" alt="${n}"`;
1427
+ return t && (s += ` title="${w(t)}"`), s += ">", s;
1428
+ }
1429
+ text(e) {
1430
+ return "tokens" in e && e.tokens ? this.parser.parseInline(e.tokens) : "escaped" in e && e.escaped ? e.text : w(e.text);
1431
+ }
1432
+ };
1433
+ var $ = class {
1434
+ strong({ text: e }) {
1435
+ return e;
1436
+ }
1437
+ em({ text: e }) {
1438
+ return e;
1439
+ }
1440
+ codespan({ text: e }) {
1441
+ return e;
1442
+ }
1443
+ del({ text: e }) {
1444
+ return e;
1445
+ }
1446
+ html({ text: e }) {
1447
+ return e;
1448
+ }
1449
+ text({ text: e }) {
1450
+ return e;
1451
+ }
1452
+ link({ text: e }) {
1453
+ return "" + e;
1454
+ }
1455
+ image({ text: e }) {
1456
+ return "" + e;
1457
+ }
1458
+ br() {
1459
+ return "";
1460
+ }
1461
+ checkbox({ raw: e }) {
1462
+ return e;
1463
+ }
1464
+ };
1465
+ var b = class u2 {
1466
+ options;
1467
+ renderer;
1468
+ textRenderer;
1469
+ constructor(e) {
1470
+ this.options = e || T, this.options.renderer = this.options.renderer || new P(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.renderer.parser = this, this.textRenderer = new $();
1471
+ }
1472
+ static parse(e, t) {
1473
+ return new u2(t).parse(e);
1474
+ }
1475
+ static parseInline(e, t) {
1476
+ return new u2(t).parseInline(e);
1477
+ }
1478
+ parse(e) {
1479
+ let t = "";
1480
+ for (let n = 0; n < e.length; n++) {
1481
+ let r = e[n];
1482
+ if (this.options.extensions?.renderers?.[r.type]) {
1483
+ let s = r, a = this.options.extensions.renderers[s.type].call({ parser: this }, s);
1484
+ if (a !== false || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "def", "paragraph", "text"].includes(s.type)) {
1485
+ t += a || "";
1486
+ continue;
1487
+ }
1488
+ }
1489
+ let i = r;
1490
+ switch (i.type) {
1491
+ case "space": {
1492
+ t += this.renderer.space(i);
1493
+ break;
1494
+ }
1495
+ case "hr": {
1496
+ t += this.renderer.hr(i);
1497
+ break;
1498
+ }
1499
+ case "heading": {
1500
+ t += this.renderer.heading(i);
1501
+ break;
1502
+ }
1503
+ case "code": {
1504
+ t += this.renderer.code(i);
1505
+ break;
1506
+ }
1507
+ case "table": {
1508
+ t += this.renderer.table(i);
1509
+ break;
1510
+ }
1511
+ case "blockquote": {
1512
+ t += this.renderer.blockquote(i);
1513
+ break;
1514
+ }
1515
+ case "list": {
1516
+ t += this.renderer.list(i);
1517
+ break;
1518
+ }
1519
+ case "checkbox": {
1520
+ t += this.renderer.checkbox(i);
1521
+ break;
1522
+ }
1523
+ case "html": {
1524
+ t += this.renderer.html(i);
1525
+ break;
1526
+ }
1527
+ case "def": {
1528
+ t += this.renderer.def(i);
1529
+ break;
1530
+ }
1531
+ case "paragraph": {
1532
+ t += this.renderer.paragraph(i);
1533
+ break;
1534
+ }
1535
+ case "text": {
1536
+ t += this.renderer.text(i);
1537
+ break;
1538
+ }
1539
+ default: {
1540
+ let s = 'Token with "' + i.type + '" type was not found.';
1541
+ if (this.options.silent) return console.error(s), "";
1542
+ throw new Error(s);
1543
+ }
1544
+ }
1545
+ }
1546
+ return t;
1547
+ }
1548
+ parseInline(e, t = this.renderer) {
1549
+ let n = "";
1550
+ for (let r = 0; r < e.length; r++) {
1551
+ let i = e[r];
1552
+ if (this.options.extensions?.renderers?.[i.type]) {
1553
+ let a = this.options.extensions.renderers[i.type].call({ parser: this }, i);
1554
+ if (a !== false || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(i.type)) {
1555
+ n += a || "";
1556
+ continue;
1557
+ }
1558
+ }
1559
+ let s = i;
1560
+ switch (s.type) {
1561
+ case "escape": {
1562
+ n += t.text(s);
1563
+ break;
1564
+ }
1565
+ case "html": {
1566
+ n += t.html(s);
1567
+ break;
1568
+ }
1569
+ case "link": {
1570
+ n += t.link(s);
1571
+ break;
1572
+ }
1573
+ case "image": {
1574
+ n += t.image(s);
1575
+ break;
1576
+ }
1577
+ case "checkbox": {
1578
+ n += t.checkbox(s);
1579
+ break;
1580
+ }
1581
+ case "strong": {
1582
+ n += t.strong(s);
1583
+ break;
1584
+ }
1585
+ case "em": {
1586
+ n += t.em(s);
1587
+ break;
1588
+ }
1589
+ case "codespan": {
1590
+ n += t.codespan(s);
1591
+ break;
1592
+ }
1593
+ case "br": {
1594
+ n += t.br(s);
1595
+ break;
1596
+ }
1597
+ case "del": {
1598
+ n += t.del(s);
1599
+ break;
1600
+ }
1601
+ case "text": {
1602
+ n += t.text(s);
1603
+ break;
1604
+ }
1605
+ default: {
1606
+ let a = 'Token with "' + s.type + '" type was not found.';
1607
+ if (this.options.silent) return console.error(a), "";
1608
+ throw new Error(a);
1609
+ }
1610
+ }
1611
+ }
1612
+ return n;
1613
+ }
1614
+ };
1615
+ var S = class {
1616
+ options;
1617
+ block;
1618
+ constructor(e) {
1619
+ this.options = e || T;
1620
+ }
1621
+ static passThroughHooks = /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens", "emStrongMask"]);
1622
+ static passThroughHooksRespectAsync = /* @__PURE__ */ new Set(["preprocess", "postprocess", "processAllTokens"]);
1623
+ preprocess(e) {
1624
+ return e;
1625
+ }
1626
+ postprocess(e) {
1627
+ return e;
1628
+ }
1629
+ processAllTokens(e) {
1630
+ return e;
1631
+ }
1632
+ emStrongMask(e) {
1633
+ return e;
1634
+ }
1635
+ provideLexer() {
1636
+ return this.block ? x.lex : x.lexInline;
1637
+ }
1638
+ provideParser() {
1639
+ return this.block ? b.parse : b.parseInline;
1640
+ }
1641
+ };
1642
+ var B = class {
1643
+ defaults = L();
1644
+ options = this.setOptions;
1645
+ parse = this.parseMarkdown(true);
1646
+ parseInline = this.parseMarkdown(false);
1647
+ Parser = b;
1648
+ Renderer = P;
1649
+ TextRenderer = $;
1650
+ Lexer = x;
1651
+ Tokenizer = y;
1652
+ Hooks = S;
1653
+ constructor(...e) {
1654
+ this.use(...e);
1655
+ }
1656
+ walkTokens(e, t) {
1657
+ let n = [];
1658
+ for (let r of e) switch (n = n.concat(t.call(this, r)), r.type) {
1659
+ case "table": {
1660
+ let i = r;
1661
+ for (let s of i.header) n = n.concat(this.walkTokens(s.tokens, t));
1662
+ for (let s of i.rows) for (let a of s) n = n.concat(this.walkTokens(a.tokens, t));
1663
+ break;
1664
+ }
1665
+ case "list": {
1666
+ let i = r;
1667
+ n = n.concat(this.walkTokens(i.items, t));
1668
+ break;
1669
+ }
1670
+ default: {
1671
+ let i = r;
1672
+ this.defaults.extensions?.childTokens?.[i.type] ? this.defaults.extensions.childTokens[i.type].forEach((s) => {
1673
+ let a = i[s].flat(1 / 0);
1674
+ n = n.concat(this.walkTokens(a, t));
1675
+ }) : i.tokens && (n = n.concat(this.walkTokens(i.tokens, t)));
1676
+ }
1677
+ }
1678
+ return n;
1679
+ }
1680
+ use(...e) {
1681
+ let t = this.defaults.extensions || { renderers: {}, childTokens: {} };
1682
+ return e.forEach((n) => {
1683
+ let r = { ...n };
1684
+ if (r.async = this.defaults.async || r.async || false, n.extensions && (n.extensions.forEach((i) => {
1685
+ if (!i.name) throw new Error("extension name required");
1686
+ if ("renderer" in i) {
1687
+ let s = t.renderers[i.name];
1688
+ s ? t.renderers[i.name] = function(...a) {
1689
+ let o = i.renderer.apply(this, a);
1690
+ return o === false && (o = s.apply(this, a)), o;
1691
+ } : t.renderers[i.name] = i.renderer;
1692
+ }
1693
+ if ("tokenizer" in i) {
1694
+ if (!i.level || i.level !== "block" && i.level !== "inline") throw new Error("extension level must be 'block' or 'inline'");
1695
+ let s = t[i.level];
1696
+ s ? s.unshift(i.tokenizer) : t[i.level] = [i.tokenizer], i.start && (i.level === "block" ? t.startBlock ? t.startBlock.push(i.start) : t.startBlock = [i.start] : i.level === "inline" && (t.startInline ? t.startInline.push(i.start) : t.startInline = [i.start]));
1697
+ }
1698
+ "childTokens" in i && i.childTokens && (t.childTokens[i.name] = i.childTokens);
1699
+ }), r.extensions = t), n.renderer) {
1700
+ let i = this.defaults.renderer || new P(this.defaults);
1701
+ for (let s in n.renderer) {
1702
+ if (!(s in i)) throw new Error(`renderer '${s}' does not exist`);
1703
+ if (["options", "parser"].includes(s)) continue;
1704
+ let a = s, o = n.renderer[a], l = i[a];
1705
+ i[a] = (...p) => {
1706
+ let c = o.apply(i, p);
1707
+ return c === false && (c = l.apply(i, p)), c || "";
1708
+ };
1709
+ }
1710
+ r.renderer = i;
1711
+ }
1712
+ if (n.tokenizer) {
1713
+ let i = this.defaults.tokenizer || new y(this.defaults);
1714
+ for (let s in n.tokenizer) {
1715
+ if (!(s in i)) throw new Error(`tokenizer '${s}' does not exist`);
1716
+ if (["options", "rules", "lexer"].includes(s)) continue;
1717
+ let a = s, o = n.tokenizer[a], l = i[a];
1718
+ i[a] = (...p) => {
1719
+ let c = o.apply(i, p);
1720
+ return c === false && (c = l.apply(i, p)), c;
1721
+ };
1722
+ }
1723
+ r.tokenizer = i;
1724
+ }
1725
+ if (n.hooks) {
1726
+ let i = this.defaults.hooks || new S();
1727
+ for (let s in n.hooks) {
1728
+ if (!(s in i)) throw new Error(`hook '${s}' does not exist`);
1729
+ if (["options", "block"].includes(s)) continue;
1730
+ let a = s, o = n.hooks[a], l = i[a];
1731
+ S.passThroughHooks.has(s) ? i[a] = (p) => {
1732
+ if (this.defaults.async && S.passThroughHooksRespectAsync.has(s)) return (async () => {
1733
+ let g = await o.call(i, p);
1734
+ return l.call(i, g);
1735
+ })();
1736
+ let c = o.call(i, p);
1737
+ return l.call(i, c);
1738
+ } : i[a] = (...p) => {
1739
+ if (this.defaults.async) return (async () => {
1740
+ let g = await o.apply(i, p);
1741
+ return g === false && (g = await l.apply(i, p)), g;
1742
+ })();
1743
+ let c = o.apply(i, p);
1744
+ return c === false && (c = l.apply(i, p)), c;
1745
+ };
1746
+ }
1747
+ r.hooks = i;
1748
+ }
1749
+ if (n.walkTokens) {
1750
+ let i = this.defaults.walkTokens, s = n.walkTokens;
1751
+ r.walkTokens = function(a) {
1752
+ let o = [];
1753
+ return o.push(s.call(this, a)), i && (o = o.concat(i.call(this, a))), o;
1754
+ };
1755
+ }
1756
+ this.defaults = { ...this.defaults, ...r };
1757
+ }), this;
1758
+ }
1759
+ setOptions(e) {
1760
+ return this.defaults = { ...this.defaults, ...e }, this;
1761
+ }
1762
+ lexer(e, t) {
1763
+ return x.lex(e, t ?? this.defaults);
1764
+ }
1765
+ parser(e, t) {
1766
+ return b.parse(e, t ?? this.defaults);
1767
+ }
1768
+ parseMarkdown(e) {
1769
+ return (n, r) => {
1770
+ let i = { ...r }, s = { ...this.defaults, ...i }, a = this.onError(!!s.silent, !!s.async);
1771
+ if (this.defaults.async === true && i.async === false) return a(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."));
1772
+ if (typeof n > "u" || n === null) return a(new Error("marked(): input parameter is undefined or null"));
1773
+ if (typeof n != "string") return a(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(n) + ", string expected"));
1774
+ if (s.hooks && (s.hooks.options = s, s.hooks.block = e), s.async) return (async () => {
1775
+ let o = s.hooks ? await s.hooks.preprocess(n) : n, p = await (s.hooks ? await s.hooks.provideLexer() : e ? x.lex : x.lexInline)(o, s), c = s.hooks ? await s.hooks.processAllTokens(p) : p;
1776
+ s.walkTokens && await Promise.all(this.walkTokens(c, s.walkTokens));
1777
+ let h = await (s.hooks ? await s.hooks.provideParser() : e ? b.parse : b.parseInline)(c, s);
1778
+ return s.hooks ? await s.hooks.postprocess(h) : h;
1779
+ })().catch(a);
1780
+ try {
1781
+ s.hooks && (n = s.hooks.preprocess(n));
1782
+ let l = (s.hooks ? s.hooks.provideLexer() : e ? x.lex : x.lexInline)(n, s);
1783
+ s.hooks && (l = s.hooks.processAllTokens(l)), s.walkTokens && this.walkTokens(l, s.walkTokens);
1784
+ let c = (s.hooks ? s.hooks.provideParser() : e ? b.parse : b.parseInline)(l, s);
1785
+ return s.hooks && (c = s.hooks.postprocess(c)), c;
1786
+ } catch (o) {
1787
+ return a(o);
1788
+ }
1789
+ };
1790
+ }
1791
+ onError(e, t) {
1792
+ return (n) => {
1793
+ if (n.message += `
1794
+ Please report this to https://github.com/markedjs/marked.`, e) {
1795
+ let r = "<p>An error occurred:</p><pre>" + w(n.message + "", true) + "</pre>";
1796
+ return t ? Promise.resolve(r) : r;
1797
+ }
1798
+ if (t) return Promise.reject(n);
1799
+ throw n;
1800
+ };
1801
+ }
1802
+ };
1803
+ var _ = new B();
1804
+ function d(u3, e) {
1805
+ return _.parse(u3, e);
1806
+ }
1807
+ d.options = d.setOptions = function(u3) {
1808
+ return _.setOptions(u3), d.defaults = _.defaults, Z(d.defaults), d;
1809
+ };
1810
+ d.getDefaults = L;
1811
+ d.defaults = T;
1812
+ d.use = function(...u3) {
1813
+ return _.use(...u3), d.defaults = _.defaults, Z(d.defaults), d;
1814
+ };
1815
+ d.walkTokens = function(u3, e) {
1816
+ return _.walkTokens(u3, e);
1817
+ };
1818
+ d.parseInline = _.parseInline;
1819
+ d.Parser = b;
1820
+ d.parser = b.parse;
1821
+ d.Renderer = P;
1822
+ d.TextRenderer = $;
1823
+ d.Lexer = x;
1824
+ d.lexer = x.lex;
1825
+ d.Tokenizer = y;
1826
+ d.Hooks = S;
1827
+ d.parse = d;
1828
+ var Dt = d.options;
1829
+ var Ht = d.setOptions;
1830
+ var Zt = d.use;
1831
+ var Gt = d.walkTokens;
1832
+ var Nt = d.parseInline;
1833
+ var Ft = b.parse;
1834
+ var jt = x.lex;
1835
+
1836
+ // packages/extensions/pages/src/markdown.ts
1837
+ var marked = new B({ gfm: true });
1838
+ var BASE_STYLES = `
1839
+ *, *::before, *::after { box-sizing: border-box; }
1840
+ body {
1841
+ max-width: 48rem;
1842
+ margin: 2rem auto;
1843
+ padding: 0 1rem;
1844
+ font-family: system-ui, -apple-system, sans-serif;
1845
+ line-height: 1.6;
1846
+ color: #1a1a1a;
1847
+ }
1848
+ h1, h2, h3, h4, h5, h6 { margin-top: 1.5em; margin-bottom: 0.5em; line-height: 1.3; }
1849
+ h1 { font-size: 2em; }
1850
+ a { color: #2563eb; }
1851
+ code {
1852
+ font-family: ui-monospace, "SFMono-Regular", monospace;
1853
+ font-size: 0.9em;
1854
+ background: #f3f4f6;
1855
+ padding: 0.15em 0.3em;
1856
+ border-radius: 3px;
1857
+ }
1858
+ pre {
1859
+ background: #f3f4f6;
1860
+ padding: 1em;
1861
+ border-radius: 6px;
1862
+ overflow-x: auto;
1863
+ }
1864
+ pre code { background: none; padding: 0; }
1865
+ blockquote {
1866
+ border-left: 3px solid #d1d5db;
1867
+ margin-left: 0;
1868
+ padding-left: 1em;
1869
+ color: #4b5563;
1870
+ }
1871
+ table { border-collapse: collapse; width: 100%; }
1872
+ th, td { border: 1px solid #d1d5db; padding: 0.5em 0.75em; text-align: left; }
1873
+ th { background: #f9fafb; }
1874
+ img { max-width: 100%; height: auto; }
1875
+ hr { border: none; border-top: 1px solid #d1d5db; margin: 2em 0; }
1876
+ `;
1877
+ function escapeHtml(s) {
1878
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
1879
+ }
1880
+ function parseFrontmatter(raw) {
1881
+ const match = raw.match(/^---\n([\s\S]*?)\n---\n?/);
1882
+ if (!match) return { body: raw };
1883
+ const block = match[1];
1884
+ const body = raw.slice(match[0].length);
1885
+ const titleMatch = block.match(/^title:\s*(.+)$/m);
1886
+ const styleMatch = block.match(/^style:\s*(.+)$/m);
1887
+ return {
1888
+ title: titleMatch?.[1].trim(),
1889
+ style: styleMatch?.[1].trim(),
1890
+ body
1891
+ };
1892
+ }
1893
+ function resolveStylesheet(mdFilePath, pagesRoot, frontmatterStyle) {
1894
+ if (frontmatterStyle) {
1895
+ const abs = resolve3(pagesRoot, frontmatterStyle);
1896
+ if (abs.startsWith(pagesRoot + "/") && existsSync3(abs)) return frontmatterStyle;
1897
+ }
1898
+ const dir = dirname(mdFilePath);
1899
+ const localCss = resolve3(dir, "style.css");
1900
+ if (existsSync3(localCss)) return relative3(pagesRoot, localCss);
1901
+ if (dir !== pagesRoot) {
1902
+ const rootCss = resolve3(pagesRoot, "style.css");
1903
+ if (existsSync3(rootCss)) return "style.css";
1904
+ }
1905
+ return null;
1906
+ }
1907
+ async function renderMarkdownPage(body, opts) {
1908
+ const html = await marked.parse(body);
1909
+ const title = escapeHtml(opts.title || "Untitled");
1910
+ const linkTag = opts.stylesheetUrl ? `
1911
+ <link rel="stylesheet" href="${escapeHtml(opts.stylesheetUrl)}">` : "";
1912
+ return `<!DOCTYPE html>
1913
+ <html lang="en">
1914
+ <head>
1915
+ <meta charset="utf-8">
1916
+ <meta name="viewport" content="width=device-width, initial-scale=1">
1917
+ <title>${title}</title>
1918
+ <style>${BASE_STYLES}</style>${linkTag}
1919
+ </head>
1920
+ <body>
1921
+ <article>${html}</article>
1922
+ </body>
1923
+ </html>`;
1924
+ }
1925
+
1926
+ // packages/extensions/pages/src/routes.ts
1927
+ var MIME_TYPES = {
1928
+ ".html": "text/html",
1929
+ ".js": "application/javascript",
1930
+ ".css": "text/css",
1931
+ ".json": "application/json",
1932
+ ".svg": "image/svg+xml",
1933
+ ".png": "image/png",
1934
+ ".jpg": "image/jpeg",
1935
+ ".jpeg": "image/jpeg",
1936
+ ".gif": "image/gif",
1937
+ ".ico": "image/x-icon",
1938
+ ".woff": "font/woff",
1939
+ ".woff2": "font/woff2",
1940
+ ".txt": "text/plain",
1941
+ ".xml": "application/xml"
1942
+ };
1943
+ function createRoutes(ctx) {
1944
+ return new Hono().get("/", async (c) => {
1945
+ if (!ctx.db) return c.json({ error: "Pages database not available" }, 503);
1946
+ const { sites, systemSite } = getSites(ctx.db);
1947
+ const recentPages = getRecentPagesList(ctx.db);
1948
+ return c.json({ sites, systemSite, recentPages });
1949
+ }).get("/feed", async (c) => {
1950
+ if (!ctx.db) return c.json({ error: "Pages database not available" }, 503);
1951
+ const mind = c.req.query("mind");
1952
+ const rawLimit = c.req.query("limit");
1953
+ const limit = rawLimit ? parseInt(rawLimit, 10) || 8 : 8;
1954
+ const recentPages = getRecentPagesList(ctx.db, { mind: mind || void 0, limit });
1955
+ return c.json(
1956
+ recentPages.map((p) => ({
1957
+ id: `page-${p.mind}-${p.file}`,
1958
+ title: `${p.mind}/${p.file}`,
1959
+ url: p.url ?? `/minds/${p.mind}/pages/${p.file}`,
1960
+ date: p.modified,
1961
+ author: p.mind,
1962
+ bodyHtml: `<p>Page updated</p>`,
1963
+ iframeUrl: `/ext/pages/public/${p.mind}/${p.file}`,
1964
+ icon: '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><circle cx="8" cy="8" r="6"/><path d="M2 8h12M8 2c-2 2-2 10 0 12M8 2c2 2 2 10 0 12"/></svg>',
1965
+ color: "purple"
1966
+ }))
1967
+ );
1968
+ }).put("/publish/:name", async (c) => {
1969
+ const user = ctx.resolveUser(c);
1970
+ if (!user) return c.json({ error: "Unauthorized" }, 401);
1971
+ const name = c.req.param("name");
1972
+ if (user.role !== "admin" && user.username !== name) {
1973
+ return c.json({ error: "Forbidden" }, 403);
1974
+ }
1975
+ const config = ctx.getSystemsConfig();
1976
+ if (!config) return c.json({ error: "Not connected to volute.systems" }, 400);
1977
+ const body = await c.req.text();
1978
+ try {
1979
+ const res = await fetch(`${config.apiUrl}/api/pages/publish/${name}`, {
1980
+ method: "PUT",
1981
+ headers: {
1982
+ "Content-Type": "application/json",
1983
+ Authorization: `Bearer ${config.apiKey}`
1984
+ },
1985
+ body
1986
+ });
1987
+ const data = await res.json().catch(() => ({ error: `HTTP ${res.status}` }));
1988
+ return c.json(data, res.status);
1989
+ } catch (err) {
1990
+ return c.json({ error: `Connection failed: ${err.message}` }, 502);
1991
+ }
1992
+ }).get("/status/:name", async (c) => {
1993
+ const user = ctx.resolveUser(c);
1994
+ if (!user) return c.json({ error: "Unauthorized" }, 401);
1995
+ const name = c.req.param("name");
1996
+ if (user.role !== "admin" && user.username !== name) {
1997
+ return c.json({ error: "Forbidden" }, 403);
1998
+ }
1999
+ const config = ctx.getSystemsConfig();
2000
+ if (!config) return c.json({ error: "Not connected to volute.systems" }, 400);
2001
+ try {
2002
+ const res = await fetch(`${config.apiUrl}/api/pages/status/${name}`, {
2003
+ headers: { Authorization: `Bearer ${config.apiKey}` }
2004
+ });
2005
+ const data = await res.json().catch(() => ({ error: `HTTP ${res.status}` }));
2006
+ return c.json(data, res.status);
2007
+ } catch (err) {
2008
+ return c.json({ error: `Connection failed: ${err.message}` }, 502);
2009
+ }
2010
+ });
2011
+ }
2012
+ function createPublicRoutes(ctx) {
2013
+ return new Hono().get("/:name/*", async (c) => {
2014
+ const name = c.req.param("name");
2015
+ if (name.includes("/") || name.includes("\\") || name === "." || name === "..")
2016
+ return c.text("Not found", 404);
2017
+ let pagesRoot;
2018
+ let blockDotfiles = false;
2019
+ if (name === "_system") {
2020
+ pagesRoot = resolve4(ctx.dataDir, "repo");
2021
+ blockDotfiles = true;
2022
+ } else {
2023
+ pagesRoot = resolve4(ctx.dataDir, "sites", name);
2024
+ }
2025
+ const prefix = `/public/${name}`;
2026
+ const idx = c.req.path.indexOf(prefix);
2027
+ const wildcard = idx >= 0 ? c.req.path.slice(idx + prefix.length) : "/";
2028
+ const requestedPath = resolve4(pagesRoot, wildcard.slice(1));
2029
+ if (requestedPath !== pagesRoot && !requestedPath.startsWith(`${pagesRoot}/`))
2030
+ return c.text("Forbidden", 403);
2031
+ if (blockDotfiles) {
2032
+ const relativePath = requestedPath.slice(pagesRoot.length + 1);
2033
+ if (relativePath.split("/").some((seg) => seg.startsWith(".")))
2034
+ return c.text("Not found", 404);
2035
+ }
2036
+ let fileToServe = requestedPath;
2037
+ let fileStat = await stat(requestedPath).catch(() => null);
2038
+ if (fileStat?.isDirectory()) {
2039
+ const indexPath = resolve4(requestedPath, "index.html");
2040
+ fileStat = await stat(indexPath).catch(() => null);
2041
+ if (fileStat?.isFile()) {
2042
+ fileToServe = indexPath;
2043
+ } else {
2044
+ const mdIndexPath = resolve4(requestedPath, "index.md");
2045
+ fileStat = await stat(mdIndexPath).catch(() => null);
2046
+ if (fileStat?.isFile()) {
2047
+ fileToServe = mdIndexPath;
2048
+ } else {
2049
+ return c.text("Not found", 404);
2050
+ }
2051
+ }
2052
+ } else if (!fileStat?.isFile()) {
2053
+ return c.text("Not found", 404);
2054
+ }
2055
+ const ext = extname(fileToServe);
2056
+ try {
2057
+ if (ext === ".md") {
2058
+ const content = await readFile(fileToServe, "utf-8");
2059
+ const { title, style, body: body2 } = parseFrontmatter(content);
2060
+ const cssRelPath = resolveStylesheet(fileToServe, pagesRoot, style);
2061
+ const cssUrl = cssRelPath ? `/ext/pages/public/${name}/${cssRelPath}` : void 0;
2062
+ const html = await renderMarkdownPage(body2, { title, stylesheetUrl: cssUrl });
2063
+ return c.body(html, 200, { "Content-Type": "text/html; charset=utf-8" });
2064
+ }
2065
+ const mime = MIME_TYPES[ext] || "application/octet-stream";
2066
+ const body = await readFile(fileToServe);
2067
+ return c.body(body, 200, { "Content-Type": mime });
2068
+ } catch (err) {
2069
+ const code = err.code;
2070
+ if (code === "EACCES") return c.text("Forbidden", 403);
2071
+ if (code === "ENOENT") return c.text("Not found", 404);
2072
+ console.error(`[pages] error serving ${fileToServe}:`, err.message);
2073
+ return c.text("Internal server error", 500);
2074
+ }
2075
+ });
2076
+ }
2077
+
2078
+ // packages/extensions/pages/src/index.ts
2079
+ var assetsDir = resolve5(import.meta.dirname, "../dist/ui");
2080
+ var skillsDir = resolve5(import.meta.dirname, "../skills");
2081
+ var src_default = createExtension({
2082
+ id: "pages",
2083
+ name: "Pages",
2084
+ version: "0.1.0",
2085
+ description: "Publish and serve web pages from mind directories",
2086
+ initDb,
2087
+ routes: (ctx) => createRoutes(ctx),
2088
+ publicRoutes: (ctx) => createPublicRoutes(ctx),
2089
+ commands: createCommands(),
2090
+ skillsDir,
2091
+ standardSkill: true,
2092
+ icon: '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="1" y="2" width="14" height="12" rx="1.5"/><path d="M1 5h14"/><circle cx="3" cy="3.5" r="0.5" fill="currentColor" stroke="none"/><circle cx="5" cy="3.5" r="0.5" fill="currentColor" stroke="none"/></svg>',
2093
+ color: "purple",
2094
+ ui: {
2095
+ assetsDir,
2096
+ systemSection: {
2097
+ id: "pages",
2098
+ label: "Pages",
2099
+ urlPatterns: ["/pages", "/pages/:site", "/pages/:site/:path"]
2100
+ },
2101
+ mindSections: [{ id: "pages", label: "Pages" }],
2102
+ feedSource: {
2103
+ endpoint: "/api/ext/pages/feed"
2104
+ }
2105
+ },
2106
+ onDaemonStart(ctx) {
2107
+ ensurePagesRepo(ctx.dataDir, isolationFrom(ctx)).then(() => {
2108
+ if (ctx.db) {
2109
+ const repoDir = resolve5(ctx.dataDir, "repo");
2110
+ const htmlFiles = collectHtmlFiles(repoDir);
2111
+ if (htmlFiles.length > 0) {
2112
+ try {
2113
+ syncSystemPages(ctx.db, htmlFiles);
2114
+ } catch (err) {
2115
+ console.error("[pages] failed to sync system pages to DB:", err);
2116
+ }
2117
+ }
2118
+ }
2119
+ }).catch((err) => {
2120
+ console.error("[pages] failed to initialize pages repo:", err);
2121
+ });
2122
+ },
2123
+ onMindStart(mindName, ctx) {
2124
+ const mindDir = ctx.getMindDir(mindName);
2125
+ if (!mindDir) return;
2126
+ addPagesWorktree(mindName, mindDir, ctx.dataDir, isolationFrom(ctx)).catch((err) => {
2127
+ console.error(`[pages] failed to add pages worktree for ${mindName}:`, err);
2128
+ });
2129
+ }
2130
+ });
2131
+ export {
2132
+ src_default as default
2133
+ };