@p-buddy/parkdown 0.0.13 → 0.0.14

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.
package/README.md CHANGED
@@ -689,4 +689,14 @@ depopulateMarkdownInclusions(file, writeFile);
689
689
  ```
690
690
 
691
691
  <!-- p↓ END -->
692
- <!-- p↓ END -->
692
+ <!-- p↓ END -->
693
+
694
+ [](?register=recipe(pkg-replace)&region=replace(pkg,'''sweater-vest''',_))
695
+
696
+ [](?register=reciple(pk-replace2)&remap(,'''$lib/index.js''','''sweater-vest'''))
697
+
698
+ [](./src?apply=recipe(pkg-replace))
699
+
700
+ [](?register=recipe(single-line-snippet)&region=single-line(snippet-head),trim(pocket-arg),splice-end(pocket,-2))
701
+
702
+ [](./src?apply=recipe(single-line-snippet))
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { Command as r } from "@commander-js/extra-typings";
3
3
  import { populateMarkdownInclusions as l, depopulateMarkdownInclusions as a } from "@p-buddy/parkdown";
4
4
  import f from "chokidar";
5
- const c = "0.0.13", p = new r().version(c).option("--nw, --no-write", "Do NOT write result to file (defaults to false)", !1).option("--ni, --no-inclusions", "Do NOT process file inclusions (defaults to false)", !1).option("-d, --depopulate", "Remove populated inclusions from the file", !1).option("-f, --file <flag>", "The file(s) to process", (e, o) => (o.push(e), o), new Array()).option("-w, --watch", "Watch the file(s) for changes and update automatically", !1).parse(), { inclusions: u, depopulate: d, file: t, write: n, watch: h } = p.opts();
5
+ const c = "0.0.14", p = new r().version(c).option("--nw, --no-write", "Do NOT write result to file (defaults to false)", !1).option("--ni, --no-inclusions", "Do NOT process file inclusions (defaults to false)", !1).option("-d, --depopulate", "Remove populated inclusions from the file", !1).option("-f, --file <flag>", "The file(s) to process", (e, o) => (o.push(e), o), new Array()).option("-w, --watch", "Watch the file(s) for changes and update automatically", !1).parse(), { inclusions: u, depopulate: d, file: t, write: n, watch: h } = p.opts();
6
6
  t.length === 0 && t.push("README.md");
7
7
  const m = [
8
8
  [l, !u],
package/dist/index.js CHANGED
@@ -1,84 +1,41 @@
1
- var he = Object.defineProperty;
2
- var de = (e, n, t) => n in e ? he(e, n, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[n] = t;
3
- var F = (e, n, t) => de(e, typeof n != "symbol" ? n + "" : n, t);
4
- import { writeFileSync as K, readFileSync as ve } from "node:fs";
5
- import { basename as $e, dirname as A, join as y, resolve as Y } from "node:path";
6
- import { URLSearchParams as Ce } from "node:url";
7
- import { unified as we } from "unified";
8
- import Ee from "remark-parse";
9
- import { visit as ye } from "unist-util-visit";
10
- import { dedent as j } from "ts-dedent";
11
- const f = (e, n) => e.position.start.offset - n.position.start.offset;
12
- f.reverse = (e, n) => f(n, e);
13
- const D = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, Se = we().use(Ee), I = {
14
- md: (e) => Se.parse(e)
15
- }, S = (e, n) => {
16
- const t = [];
17
- return ye(e, (s, o, r) => {
1
+ var ye = Object.defineProperty;
2
+ var Ce = (e, t, n) => t in e ? ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var _ = (e, t, n) => Ce(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { writeFileSync as le, readFileSync as Ee } from "node:fs";
5
+ import { basename as Se, dirname as z, join as T, resolve as ae } from "node:path";
6
+ import { URLSearchParams as Z } from "node:url";
7
+ import { unified as xe } from "unified";
8
+ import ke from "remark-parse";
9
+ import { visit as _e } from "unist-util-visit";
10
+ import { dedent as Ne } from "ts-dedent";
11
+ const f = (e, t) => e.position.start.offset - t.position.start.offset;
12
+ f.reverse = (e, t) => f(t, e);
13
+ const X = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, Re = xe().use(ke), V = {
14
+ md: (e) => Re.parse(e)
15
+ }, I = (e, t) => {
16
+ const n = [];
17
+ return _e(e, (s, r, o) => {
18
18
  if (s.type !== "root") {
19
- if (n && s.type !== n) return;
20
- if (D(s)) {
21
- const i = ((r == null ? void 0 : r.children.length) ?? 0) - 1;
22
- t.push({ ...s, siblingIndex: o, siblingCount: i });
23
- }
24
- }
25
- }), t;
26
- }, xe = (e) => e.children.length === 0, ee = (e, n, ...t) => {
27
- if (t.length === 0) throw new Error("No nodes to replace content from");
28
- t.sort(f);
29
- const s = t.at(0), o = t.at(-1);
30
- return e.slice(0, s.position.start.offset) + n + e.slice(o.position.end.offset);
31
- }, Ne = (e, n, t) => {
32
- const s = Math.min(n.position.end.offset, t.position.end.offset), o = Math.max(n.position.start.offset, t.position.start.offset);
33
- return e.slice(s, o);
34
- }, E = (...e) => e.join(" "), be = (...e) => e.join(`
35
- `), ke = (e) => {
36
- const n = e.split("?");
37
- return n.length > 1 ? [n.slice(0, -1).join("?"), n.at(-1)] : [e, ""];
38
- }, Me = (e) => ke(e)[0];
39
- class d {
40
- constructor(...n) {
41
- F(this, "intervals", []);
42
- for (const [t, s] of n)
43
- this.push(t, s);
44
- }
45
- push(n, t) {
46
- this.intervals.push([Math.min(n, t), Math.max(n, t)]);
47
- }
48
- combine(n) {
49
- this.intervals.push(...n.intervals);
50
- }
51
- collapse() {
52
- const { intervals: n } = this;
53
- if (!n.length) return this.intervals = [];
54
- n.sort((r, i) => r[0] - i[0]);
55
- const t = [];
56
- let [s, o] = n[0];
57
- for (let r = 1; r < n.length; r++) {
58
- const [i, l] = n[r];
59
- i <= o ? o = Math.max(o, l) : (t.push([s, o]), s = i, o = l);
60
- }
61
- return t.push([s, o]), this.intervals = t;
62
- }
63
- subtract(n) {
64
- const { intervals: t } = this, { intervals: s } = n;
65
- if (!t.length || !s.length) return t;
66
- let o = [...t];
67
- for (const [r, i] of s) {
68
- const l = [];
69
- for (const [c, a] of o) {
70
- if (i <= c || r >= a) {
71
- l.push([c, a]);
72
- continue;
73
- }
74
- r > c && l.push([c, r]), i < a && l.push([i, a]);
19
+ if (t && s.type !== t) return;
20
+ if (X(s)) {
21
+ const i = ((o == null ? void 0 : o.children.length) ?? 0) - 1;
22
+ n.push({ ...s, siblingIndex: r, siblingCount: i });
75
23
  }
76
- o = l;
77
24
  }
78
- return this.intervals = o;
79
- }
80
- }
81
- const U = /,\s*(?![^()]*\))/, H = {
25
+ }), n;
26
+ }, Me = (e) => e.children.length === 0, ce = (e, t, ...n) => {
27
+ if (n.length === 0) throw new Error("No nodes to replace content from");
28
+ n.sort(f);
29
+ const s = n.at(0), r = n.at(-1);
30
+ return e.slice(0, s.position.start.offset) + t + e.slice(r.position.end.offset);
31
+ }, Ae = (e, t, n) => {
32
+ const s = Math.min(t.position.end.offset, n.position.end.offset), r = Math.max(t.position.start.offset, n.position.start.offset);
33
+ return e.slice(s, r);
34
+ }, O = (...e) => e.join(" "), Oe = (...e) => e.join(`
35
+ `), Te = (e) => {
36
+ const t = e.split("?");
37
+ return t.length > 1 ? [t.slice(0, -1).join("?"), t.at(-1)] : [e, ""];
38
+ }, Ie = (e) => Te(e)[0], F = /,\s*(?![^()]*\))/, K = {
82
39
  reserved: {
83
40
  semi: ";",
84
41
  slash: "/",
@@ -106,7 +63,7 @@ const U = /,\s*(?![^()]*\))/, H = {
106
63
  line: `
107
64
  `
108
65
  }
109
- }, _e = "-", G = {
66
+ }, je = "-", Y = {
110
67
  static: [
111
68
  ["'''", '"'],
112
69
  ["''", "'"],
@@ -114,73 +71,73 @@ const U = /,\s*(?![^()]*\))/, H = {
114
71
  [/p↓:\s+/g, ""]
115
72
  ],
116
73
  url: [
117
- ...Object.entries(H.unsafe),
118
- ...Object.entries(H.reserved)
74
+ ...Object.entries(K.unsafe),
75
+ ...Object.entries(K.reserved)
119
76
  ]
120
- }, Q = (e, [n, t]) => e.replaceAll(n, t), N = (e, n = _e) => {
121
- const t = G.static.reduce(Q, e);
122
- return G.url.map(([s, o]) => [n + s + n, o]).reduce(Q, t).replaceAll(n, " ");
123
- }, Re = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), Oe = ["string", "number", "boolean"], Te = (e) => Oe.includes(e), Ae = /^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/, je = (e) => {
124
- const n = e.match(Ae);
125
- if (!n) throw new Error(`Invalid invocation: ${e}`);
126
- const [, t, s = ""] = n;
127
- if (!s.trim()) return { name: t, parameters: [] };
128
- const o = Ie(s);
129
- return { name: t, parameters: o };
130
- }, De = (e, n) => {
131
- for (let t = n + 1; t < e.length; t++)
132
- if (e[t] !== void 0) return !1;
77
+ }, ee = (e, [t, n]) => e.replaceAll(t, n), W = (e, t = je) => {
78
+ const n = Y.static.reduce(ee, e);
79
+ return Y.url.map(([s, r]) => [t + s + t, r]).reduce(ee, n).replaceAll(t, " ");
80
+ }, We = ["string", "number", "boolean"], De = (e) => We.includes(e), Pe = /^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/, Le = (e) => {
81
+ const t = e.match(Pe);
82
+ if (!t) throw new Error(`Invalid invocation: ${e}`);
83
+ const [, n, s = ""] = t;
84
+ if (!s.trim()) return { name: n, parameters: [] };
85
+ const r = qe(s);
86
+ return { name: n, parameters: r };
87
+ }, Ue = (e, t) => {
88
+ for (let n = t + 1; n < e.length; n++)
89
+ if (e[n] !== void 0) return !1;
133
90
  return !0;
134
- }, Ie = (e) => {
135
- const n = [];
136
- let t = "", s = !1;
137
- for (let o = 0; o < e.length; o++) {
138
- const r = e[o], i = r === "'";
139
- if (i && e.at(o + 1) === "'") {
140
- const l = e.at(o + 2) === "'";
141
- s = !s, t += l ? "'''" : "''", o += l ? 2 : 1;
142
- } else i ? (s = !s, t += r) : r === "," && !s ? (n.push(t.trim()), t = "") : t += r;
91
+ }, qe = (e) => {
92
+ const t = [];
93
+ let n = "", s = !1;
94
+ for (let r = 0; r < e.length; r++) {
95
+ const o = e[r], i = o === "'";
96
+ if (i && e.at(r + 1) === "'") {
97
+ const l = e.at(r + 2) === "'";
98
+ s = !s, n += l ? "'''" : "''", r += l ? 2 : 1;
99
+ } else i ? (s = !s, n += o) : o === "," && !s ? (t.push(n.trim()), n = "") : n += o;
143
100
  }
144
- return n.push(t.trim()), n.map((o) => o === "" ? void 0 : o ? Pe(o) : void 0).filter((o, r, i) => o !== void 0 || !De(i, r));
145
- }, Pe = (e) => {
146
- const n = e.length >= 2 && e[0] === "'" && e.at(-1) === "'", t = n && e.length >= 4 && e[1] === "'" && e.at(-2) === "'";
147
- return !n || t ? e : e.slice(1, -1);
148
- }, We = (e) => {
149
- const n = /^(\w+)(?:\(([^)]*)\))?/, t = e.match(n);
150
- if (!t) return { name: e };
151
- const [, s, o] = t;
152
- if (!o) return { name: s };
153
- const r = /(\w+)(\?)?:\s*([^,]+)/g, i = [];
101
+ return t.push(n.trim()), t.map((r) => r === "" ? void 0 : r ? Be(r) : void 0).filter((r, o, i) => r !== void 0 || !Ue(i, o));
102
+ }, Be = (e) => {
103
+ const t = e.length >= 2 && e[0] === "'" && e.at(-1) === "'", n = t && e.length >= 4 && e[1] === "'" && e.at(-2) === "'";
104
+ return !t || n ? e : e.slice(1, -1);
105
+ }, Fe = (e) => {
106
+ const t = /^(\w+)(?:\(([^)]*)\))?/, n = e.match(t);
107
+ if (!n) return { name: e };
108
+ const [, s, r] = n;
109
+ if (!r) return { name: s };
110
+ const o = /(\w+)(\?)?:\s*([^,]+)/g, i = [];
154
111
  let l;
155
- for (; (l = r.exec(o)) !== null; ) {
156
- const [, c, a, u] = l, p = u.trim();
157
- if (!Te(p)) throw new Error(`Unsupported type: ${p}`);
158
- i.push({ name: c, optional: a === "?", type: p });
112
+ for (; (l = o.exec(r)) !== null; ) {
113
+ const [, a, c, u] = l, p = u.trim();
114
+ if (!De(p)) throw new Error(`Unsupported type: ${p}`);
115
+ i.push({ name: a, optional: c === "?", type: p });
159
116
  }
160
117
  return { name: s, parameters: i };
161
- }, P = (e) => {
162
- const n = e.map(We).reduce(
163
- (t, { name: s, parameters: o }) => t.set(s, o),
118
+ }, R = (e) => {
119
+ const t = e.map(Fe).reduce(
120
+ (n, { name: s, parameters: r }) => n.set(s, r),
164
121
  /* @__PURE__ */ new Map()
165
122
  );
166
- return (t) => {
167
- const { name: s, parameters: o } = je(t);
168
- if (!n.has(s))
123
+ return (n) => {
124
+ const { name: s, parameters: r } = Le(n);
125
+ if (!t.has(s))
169
126
  throw new Error(`Unknown method: ${s}`);
170
- const r = n.get(s);
171
- if (r === void 0)
127
+ const o = t.get(s);
128
+ if (o === void 0)
172
129
  return { name: s };
173
- if (o.length > r.length) {
174
- const i = r.filter(({ optional: c }) => !c).length, l = i === r.length ? i.toString() : `${i} - ${r.length}`;
175
- throw new Error(`Too many parameters: ${o.length} for method '${s}' (expected: ${l})`);
130
+ if (r.length > o.length) {
131
+ const i = o.filter(({ optional: a }) => !a).length, l = i === o.length ? i.toString() : `${i} - ${o.length}`;
132
+ throw new Error(`Too many parameters: ${r.length} for method '${s}' (expected: ${l})`);
176
133
  }
177
- return r.reduce((i, { name: l, optional: c, type: a }, u) => {
178
- const p = o[u];
134
+ return o.reduce((i, { name: l, optional: a, type: c }, u) => {
135
+ const p = r[u];
179
136
  if (p === void 0) {
180
- if (c) return i;
137
+ if (a) return i;
181
138
  throw new Error(`Missing required parameter: ${l} for method '${s}'`);
182
139
  }
183
- switch (a) {
140
+ switch (c) {
184
141
  case "string":
185
142
  i[l] = p;
186
143
  break;
@@ -189,12 +146,12 @@ const U = /,\s*(?![^()]*\))/, H = {
189
146
  i[l] = JSON.parse(p);
190
147
  break;
191
148
  }
192
- if (typeof i[l] !== a)
193
- throw new Error(`Invalid type: ${l} must be ${a}, got ${typeof i[l]} for method '${s}'`);
149
+ if (typeof i[l] !== c)
150
+ throw new Error(`Invalid type: ${l} must be ${c}, got ${typeof i[l]} for method '${s}'`);
194
151
  return i;
195
152
  }, { name: s });
196
153
  };
197
- }, z = (e) => Object.entries(e).filter(([n]) => n !== "name" && !isNaN(Number(n))).map(([n, t]) => t), Le = [
154
+ }, Q = (e) => Object.entries(e).filter(([t]) => t !== "name" && !isNaN(Number(t))).map(([t, n]) => n), He = [
198
155
  /**
199
156
  * Wraps the content in a markdown-formatted code block.
200
157
  * @param lang The language of the code block (defaults to the file extension).
@@ -224,55 +181,131 @@ const U = /,\s*(?![^()]*\))/, H = {
224
181
  * @example [](<url>?wrap=dropdown(hello_world,,_))
225
182
  */
226
183
  "dropdown(summary: string, open?: boolean, space?: string)"
227
- ], qe = P(Le), h = (e, n = 1) => `
228
- `.repeat(n) + e + `
229
- `.repeat(n), T = (e, n, t) => `<${n}${t ? ` ${t}` : ""}>${h(e)}</${n}>`, X = (e, n, t) => {
230
- const s = qe(n);
184
+ ], Qe = R(He), S = (e, t = 1) => `
185
+ `.repeat(t) + e + `
186
+ `.repeat(t), H = (e, t, n) => `<${t}${n ? ` ${n}` : ""}>${S(e)}</${t}>`, te = (e, t, n) => {
187
+ const s = Qe(t);
231
188
  switch (s.name) {
232
189
  case "code":
233
- if (!s.lang && !s.meta && (t == null ? void 0 : t.inline) && !e.includes(`
190
+ if (!s.lang && !s.meta && (n == null ? void 0 : n.inline) && !e.includes(`
234
191
  `)) return `\`${e}\``;
235
- const r = s.lang ?? (t == null ? void 0 : t.extension) ?? "", i = s.meta ? ` ${s.meta}` : "";
236
- return h(`\`\`\`${r}${i}${h(e)}\`\`\``);
192
+ const o = s.lang ?? (n == null ? void 0 : n.extension) ?? "", i = s.meta ? ` ${s.meta}` : "";
193
+ return S(`\`\`\`${o}${i}${S(e)}\`\`\``);
237
194
  case "quote":
238
- return t != null && t.inline && !e.includes(`
195
+ return n != null && n.inline && !e.includes(`
239
196
 
240
- `) ? `> ${e}` : h(T(h(e), "blockquote"));
197
+ `) ? `> ${e}` : S(H(S(e), "blockquote"));
241
198
  case "dropdown":
242
- const l = T(N(s.summary), "summary");
243
- return h(T([l, e].join(`
199
+ const l = H(W(s.summary), "summary");
200
+ return S(H([l, e].join(`
244
201
  `), "details", s.open ? "open" : void 0));
245
202
  }
246
- }, W = (e) => {
247
- const n = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm, t = [];
203
+ };
204
+ class d {
205
+ constructor(...t) {
206
+ _(this, "_intervals", []);
207
+ _(this, "collapsed", !0);
208
+ for (const [n, s] of t)
209
+ this.push(n, s);
210
+ }
211
+ get intervals() {
212
+ return this._intervals;
213
+ }
214
+ push(t, n) {
215
+ return n ?? (n = t + 1), this._intervals.push([Math.min(t, n), Math.max(t, n)]), this.collapsed = !1, this;
216
+ }
217
+ combine(t) {
218
+ for (const [n, s] of t.intervals)
219
+ this.push(n, s);
220
+ return this;
221
+ }
222
+ collapse(t = !1) {
223
+ const { _intervals: n, collapsed: s } = this;
224
+ if (s && !t || !n.length) return this;
225
+ n.sort((l, a) => l[0] - a[0]);
226
+ const r = [];
227
+ let [o, i] = n[0];
228
+ for (let l = 1; l < n.length; l++) {
229
+ const [a, c] = n[l];
230
+ a <= i ? i = Math.max(i, c) : (r.push([o, i]), o = a, i = c);
231
+ }
232
+ return r.push([o, i]), this._intervals = r, this.collapsed = !0, this;
233
+ }
234
+ subtract(t) {
235
+ this.collapse(), t.collapse();
236
+ const { _intervals: n } = this, { _intervals: s } = t;
237
+ if (!n.length || !s.length) return this;
238
+ let r = [...n];
239
+ for (const [o, i] of s) {
240
+ const l = [];
241
+ for (const [a, c] of r) {
242
+ if (i <= a || o >= c) {
243
+ l.push([a, c]);
244
+ continue;
245
+ }
246
+ o > a && l.push([a, o]), i < c && l.push([i, c]);
247
+ }
248
+ r = l;
249
+ }
250
+ return this._intervals = r, this.collapse(!0), this;
251
+ }
252
+ test(t, n = "head") {
253
+ const { _intervals: s } = this;
254
+ switch (n) {
255
+ case "head":
256
+ return s.some(([r, o]) => t >= r && t < o);
257
+ case "tail":
258
+ return s.some(([r, o]) => t > r && t <= o);
259
+ case "both":
260
+ return s.some(([r, o]) => t >= r && t <= o);
261
+ case "none":
262
+ return s.some(([r, o]) => t > r && t < o);
263
+ }
264
+ }
265
+ slice(t) {
266
+ this.collapse();
267
+ const n = [];
268
+ for (const [s, r] of this._intervals)
269
+ n.push(t.slice(s, r));
270
+ return n.filter(Boolean).join("");
271
+ }
272
+ offset(t) {
273
+ for (const n of this._intervals)
274
+ n[0] += t, n[1] += t;
275
+ return this;
276
+ }
277
+ }
278
+ const D = (e) => {
279
+ const t = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm, n = [];
248
280
  let s;
249
- for (; (s = n.exec(e)) !== null; ) {
250
- const o = [s.index, s.index + s[0].length], r = Be(s[0]).trim();
251
- t.push({ range: o, value: r });
281
+ for (; (s = t.exec(e)) !== null; ) {
282
+ const r = [s.index, s.index + s[0].length], o = Ge(s[0]).trim();
283
+ n.push({ range: r, value: o });
252
284
  }
253
- return t;
254
- }, Be = (e) => e.startsWith("//") ? e.slice(2) : e.startsWith("/*") ? e.slice(2, -2) : e.startsWith("<!--") ? e.slice(4, -3) : e, ne = [
285
+ return n;
286
+ }, Ge = (e) => e.startsWith("//") ? e.slice(2) : e.startsWith("/*") ? e.slice(2, -2) : e.startsWith("<!--") ? e.slice(4, -3) : e, ze = [
255
287
  "p↓:",
256
288
  "pd:",
257
289
  "parkdown:"
258
- ], Fe = [
290
+ ], Xe = [
259
291
  "splice(delete?: number, insert?: string)"
260
292
  ];
261
- P(Fe);
262
- const te = (e, n) => e.range[0] - n.range[0], se = (e, n, t) => (t ?? W(e)).filter(({ value: s }) => s.split(" ").includes(n)).sort(te), V = (e) => ({
293
+ R(Xe);
294
+ const pe = (e, t) => e.range[0] - t.range[0], J = (e, t, n) => (n ?? D(e)).filter(({ value: s }) => s.split(" ").includes(t)).sort(pe), ne = (e) => ({
263
295
  isSpace: e === " ",
264
296
  isNewline: e === `
265
297
  ` || e === void 0
266
- }), J = (e) => ne.flatMap((n) => se(e, n)).sort((n, t) => n.range[0] - t.range[0]).reverse().reduce((n, { range: [t, s], value: o }) => {
267
- const r = (p, b) => n.slice(0, p) + n.slice(b), i = V(n[t - 1]), l = V(n[s]), c = s === n.length;
268
- let a = t;
269
- for (; a > 0 && n[a - 1] !== `
270
- `; ) a--;
271
- const u = n.slice(a, t).trim() === "";
272
- return i.isNewline && l.isNewline ? r(t - (c ? 1 : 0), s + 1) : i.isNewline || u ? r(a, s + (l.isSpace || l.isNewline ? 1 : 0)) : r(t - (i.isSpace ? 1 : 0), s);
273
- }, e);
274
- ne.map((e) => new RegExp(`^${Re(e)}(\\?[^\\s]+)`));
275
- const Ue = [
298
+ }), se = (e) => ze.flatMap((t) => J(e, t)).sort((t, n) => t.range[0] - n.range[0]).reverse().reduce((t, { range: [n, s], value: r }) => {
299
+ const o = (w, $) => t.slice(0, w) + t.slice($), i = ne(t[n - 1]), l = ne(t[s]), a = s === t.length;
300
+ let c = n;
301
+ for (; c > 0 && t[c - 1] !== `
302
+ `; ) c--;
303
+ let u = s;
304
+ for (; u < t.length && t[u] !== `
305
+ `; ) u++;
306
+ const p = t.slice(c, n).trim() === "" && t.slice(s, u).trim() === "";
307
+ return i.isNewline && l.isNewline ? o(n - (a ? 1 : 0), s + 1) : i.isNewline || p ? o(c, s + (l.isSpace || l.isNewline ? 1 : 0)) : o(n - (i.isSpace ? 1 : 0), s);
308
+ }, e), Ve = [
276
309
  /**
277
310
  * Extract regions from the retrieved content between comments that INCLUDE the specified ids.
278
311
  * @param id The id of the comment to extract.
@@ -304,25 +337,7 @@ const Ue = [
304
337
  */
305
338
  "replace(id: string, with?: string, space?: string)",
306
339
  /**
307
- * Splice the retrieved content at the boundary of a comment region (which must INCLUDE the specified id).
308
- *
309
- * **NOTE:** Unlike `extract`, `remove`, and `replace`, `splice` does remove the comment from the content after processing.
310
- * @param id The id of the comment regions to act on.
311
- * @param deleteCount The number of characters to delete at either the beginning or end of the comment region.
312
- * Specifying a number greater than or equal to 0 indicates the action should be taken at the end of the comment region.
313
- * Specifying undefined or a number less than 0 indicates the action should be taken at the beginning of the comment region.
314
- * @param insert The content to insert.
315
- * @param space The space character to use between words in the content to insert (defaults to `-`).
316
- * @example [](<url>?region=splice(specifier,-1)) // Delete one character at the beginning of the comment region.
317
- * @example [](<url>?region=splice(specifier,undefined,new-content)) // Insert at the beginning of the comment region.
318
- * @example [](<url>?region=splice(specifier,0,new-content)) // Insert at the end of the comment region.
319
- * @example [](<url>?region=splice(specifier,1,new-content)) // Delete one character at the end of the comment region and insert.
320
- */
321
- "splice(id: string, deleteCount?: number, insert?: string, space?: string)",
322
- /**
323
- * Remap the content within a comment region (which must INCLUDE the specified id).
324
- *
325
- * **NOTE:** Unlike `extract`, `remove`, and `replace`, `remap` does not remove the comment from the content after processing.
340
+ * Remap the content (similiar to `string.replaceAll`) within a specified comment region.
326
341
  * @param id The id of the comment regions to act on.
327
342
  * @param from The content to replace.
328
343
  * @param to The content to replace with.
@@ -330,230 +345,388 @@ const Ue = [
330
345
  * @example [](<url>?region=remap(specifier,hello-world,hello-universe))
331
346
  * @example [](<url>?region=remap(specifier,hello_world,hello_universe,_)
332
347
  */
333
- "remap(id: string, from: string, to?: string, space?: string)"
334
- ], He = P(Ue), v = (e, n, t) => {
335
- const s = se(e, n, t), o = [];
336
- for (let r = 0; r < s.length - 1; r += 2)
337
- o.push([s[r], s[r + 1]]);
338
- return o;
339
- }, Ge = (e, ...n) => {
340
- if (n.length === 0) return e;
341
- const t = W(e), s = ([i, l]) => e.slice(i, l), o = new d(), r = new d();
342
- for (const i of n)
343
- for (const [l, c] of v(e, i, t)) {
344
- o.push(l.range[1], c.range[0]);
345
- const [a, ...u] = s([l.range[1], c.range[0]]), p = u[u.length - 1];
346
- r.push(l.range[0], l.range[1] + (a.trim() ? 0 : 1)), r.push(c.range[0], c.range[1] + (p.trim() ? 0 : 1));
348
+ "remap(id: string, from: string, to?: string, space?: string)",
349
+ /**
350
+ * Make the content of the region a single line (where all whitespace characters, including newlines, are converted to a single space).
351
+ * @param id The id of the comment regions to act on.
352
+ * @example [](<url>?region=single-line(specifier))
353
+ */
354
+ "single-line(id: string, includeBoundaries?: boolean)",
355
+ /**
356
+ * Trim the whitespace surrounding the comment boundaries of the region.
357
+ * @param id The id of the comment region to act on.
358
+ * @param inside Whether to trim the whitespace within the comment region. Defaults to `true`.
359
+ * @param outside Whether to trim the whitespace outside the comment region. Defaults to `true`.
360
+ * @example [](<url>?region=trim(specifier))
361
+ * @example [](<url>?region=trim(specifier,false))
362
+ * @example [](<url>?region=trim(specifier,,false))
363
+ * @example [](<url>?region=trim(specifier,false,false))
364
+ */
365
+ "trim(id: string, inside?: boolean, outside?: boolean)",
366
+ /**
367
+ * Trim the whitespace surrounding the starting comment boundary of the specified region.
368
+ * @param id The id of the comment region to act on.
369
+ * @param left Whether to trim the whitespace to the left of the comment region. Defaults to `true`.
370
+ * @param right Whether to trim the whitespace to the right of the comment region. Defaults to `true`.
371
+ * @example [](<url>?region=trim-start(specifier))
372
+ * @example [](<url>?region=trim-start(specifier,false))
373
+ */
374
+ "trim-start(id: string, left?: boolean, right?: boolean)",
375
+ /**
376
+ * Trim the whitespace surrounding the ending comment boundary of the specified region.
377
+ * @param id The id of the comment region to act on.
378
+ * @param left Whether to trim the whitespace to the left of the comment region. Defaults to `true`.
379
+ * @param right Whether to trim the whitespace to the right of the comment region. Defaults to `true`.
380
+ * @example [](<url>?region=trim-end(specifier))
381
+ * @example [](<url>?region=trim-end(specifier,false))
382
+ */
383
+ "trim-end(id: string, left?: boolean, right?: boolean)",
384
+ /**
385
+ * Splice the retrieved content at the starting comment boundary of the specified region.
386
+ * @param id The id of the comment region to act on.
387
+ * @param deleteCount The number of characters to delete at either the beginning or end of the comment boundary.
388
+ * Specifying a number greater than or equal to 0 indicates the action should be taken at the end of the comment boundary (i.e to the right of the comment).
389
+ * Specifying undefined or a number less than 0 indicates the action should be taken at the beginning of the comment boundary (i.e to the left of the comment).
390
+ * @param insert The content to insert.
391
+ * @param space The space character to use between words in the content to insert (defaults to `-`).
392
+ *
393
+ * **NOTE:** Content within comments will not be acted upon.
394
+ */
395
+ "splice-start(id: string, deleteCount?: number, insert?: string, space?: string)",
396
+ /**
397
+ * Splice the retrieved content at the ending comment boundary of the specified region.
398
+ * @param id The id of the comment region to act on.
399
+ * @param deleteCount The number of characters to delete at either the beginning or end of the comment boundary.
400
+ * Specifying a number greater than or equal to 0 indicates the action should be taken at the end of the comment boundary (i.e to the right of the comment).
401
+ * Specifying undefined or a number less than 0 indicates the action should be taken at the beginning of the comment boundary (i.e to the left of the comment).
402
+ * @param insert The content to insert.
403
+ * @param space The space character to use between words in the content to insert (defaults to `-`).
404
+ *
405
+ * **NOTE:** Content within comments will not be acted upon.
406
+ */
407
+ "splice-end(id: string, deleteCount?: number, insert?: string, space?: string)",
408
+ /**
409
+ * If included at the end of a query, parkdown comments will not be removed from the content after processing.
410
+ * Helpful when trying to determine fine-grained edits (e.g. trimming, splicing, etc.).
411
+ */
412
+ "debug()"
413
+ ], Je = R(Ve), C = (e, t, n) => {
414
+ const s = J(e, t, n), r = [];
415
+ for (let o = 0; o < s.length - 1; o += 2)
416
+ r.push([s[o], s[o + 1]]);
417
+ return r;
418
+ }, Ze = (e, t, n) => new d(...J(e, t, n).map(({ range: s }) => s)), P = (e) => Ne(e).trim(), Ke = (e, ...t) => {
419
+ if (t.length === 0) return e;
420
+ const n = D(e), s = new d(), r = new d();
421
+ for (const o of t)
422
+ for (const [i, l] of C(e, o, n)) {
423
+ s.push(i.range[1], l.range[0]);
424
+ const [a, ...c] = e.slice(i.range[1], l.range[0]), u = c[c.length - 1];
425
+ r.push(i.range[0], i.range[1] + (a.trim() ? 0 : 1)), r.push(l.range[0], l.range[1] + (u.trim() ? 0 : 1));
347
426
  }
348
- return o.collapse(), r.collapse(), j(
349
- o.subtract(r).map(s).filter(Boolean).join("")
350
- ).trim();
351
- }, Qe = (e, ...n) => {
352
- if (n.length === 0) return e;
353
- const t = W(e), s = ([i, l]) => e.slice(i, l), o = new d();
354
- for (const i of n)
355
- for (const [l, c] of v(e, i, t)) {
356
- const a = s([c.range[1], c.range[1] + 1]).at(-1);
357
- o.push(l.range[0], a === `
358
- ` ? c.range[1] + 1 : c.range[1]);
427
+ return P(s.subtract(r).slice(e));
428
+ }, Ye = (e, ...t) => {
429
+ if (t.length === 0) return e;
430
+ const n = D(e), s = ([o, i]) => e.slice(o, i), r = new d();
431
+ for (const o of t)
432
+ for (const [i, l] of C(e, o, n)) {
433
+ const a = s([l.range[1], l.range[1] + 1]).at(-1);
434
+ r.push(i.range[0], a === `
435
+ ` ? l.range[1] + 1 : l.range[1]);
359
436
  }
360
- o.collapse();
361
- const r = new d([0, e.length]);
362
- return r.subtract(o), j(
363
- r.collapse().map(s).filter(Boolean).join("")
364
- ).trim();
365
- }, ze = (e, n, t, s) => {
366
- if (!n) return e;
367
- let o = "", r = 0;
368
- for (const [l, c] of v(e, n))
369
- o += e.slice(r, l.range[1]), o += N(t ?? l.value, s), r = c.range[0];
370
- o += e.slice(r);
371
- const i = new d([0, o.length]);
372
- return i.subtract(new d(
373
- ...v(o, n).flatMap(([l, c]) => [l.range, c.range])
374
- )), j(
375
- i.collapse().map(([l, c]) => o.slice(l, c)).filter(Boolean).join("")
376
- ).trim();
377
- }, Xe = (e, n, t, s, o) => {
378
- if (!n) return e;
379
- const r = t === void 0 ? !1 : t >= 0, i = s ? N(s, o) : "", l = t ?? 0;
380
- return v(e, n).map((c) => c[r ? 1 : 0]).sort(te).reverse().reduce(
381
- (c, { range: a }) => r ? c.slice(0, a[1]) + i + c.slice(Math.min(a[1] + l, c.length)) : c.slice(0, Math.max(a[0] + l, 0)) + i + c.slice(a[0]),
382
- e
437
+ return P(new d([0, e.length]).subtract(r).slice(e));
438
+ }, et = (e, t, n, s) => {
439
+ if (!t) return e;
440
+ let r = "", o = 0;
441
+ for (const [i, l] of C(e, t))
442
+ r += e.slice(o, i.range[1]), r += W(n ?? i.value, s), o = l.range[0];
443
+ return r += e.slice(o), P(
444
+ new d([0, r.length]).subtract(Ze(r, t)).slice(r)
383
445
  );
384
- }, Ve = (e, n, t, s, o) => {
385
- if (!n) return e;
386
- let r = "", i = 0;
387
- const l = [t, s ?? ""].map((c) => N(c, o));
388
- console.log(l);
389
- for (const [c, a] of v(e, n))
390
- r += e.slice(i, c.range[1]), r += e.slice(c.range[1], a.range[0]).replaceAll(l[0], l[1]), i = a.range[0];
391
- return r += e.slice(i), r;
392
- }, Je = (e, n, t) => {
393
- if (!n) return J(e);
394
- const s = He(n);
446
+ }, tt = (e, t, n, s, r, o) => {
447
+ if (!t) return e;
448
+ const i = !(s === void 0 || s < 0), l = r ? W(r, o) : "", a = s ?? 0, c = D(e), u = new d(...c.map(({ range: p }) => p));
449
+ return C(e, t, c).map((p) => p[n === "start" ? 0 : 1]).sort(pe).reverse().reduce((p, { range: w }) => {
450
+ const $ = new d(), M = i ? 1 : -1;
451
+ let x = Math.abs(a), m = i ? w[1] : w[0];
452
+ for (; x > 0 && m < p.length && m >= 0; )
453
+ u.test(m) || ($.push(m), x--), m += M;
454
+ return m = Math.min(Math.max(0, m), p.length), p = p.slice(0, m) + l + p.slice(m), new d([0, p.length]).subtract($.offset(i ? 0 : l.length)).slice(p);
455
+ }, e);
456
+ }, nt = (e, t, n, s, r) => {
457
+ if (!t) return e;
458
+ let o = "", i = 0;
459
+ [n, s] = [n, s ?? ""].map((l) => W(l, r));
460
+ for (const [l, a] of C(e, t))
461
+ o += e.slice(i, l.range[1]), o += e.slice(l.range[1], a.range[0]).replaceAll(n, s), i = a.range[0];
462
+ return o += e.slice(i), o;
463
+ }, st = (e, t) => {
464
+ if (!t) return e;
465
+ let n = "", s = 0;
466
+ for (const [r, o] of C(e, t))
467
+ n += e.slice(s, r.range[1]), n += e.slice(r.range[1], o.range[0]).replaceAll(/[\s\n]+/g, " "), s = o.range[0];
468
+ return n += e.slice(s), n;
469
+ }, re = (e, t, n) => {
470
+ var o, i, l, a;
471
+ if (!t) return e;
472
+ const s = (c) => /\s/.test(e[c]), r = new d();
473
+ for (const [c, u] of C(e, t)) {
474
+ if ((o = n.start) != null && o.left) {
475
+ let p = c.range[0] - 1;
476
+ for (; s(p); ) r.push(p--);
477
+ }
478
+ if ((i = n.start) != null && i.right) {
479
+ let p = c.range[1];
480
+ for (; s(p); ) r.push(p++);
481
+ }
482
+ if ((l = n.end) != null && l.left) {
483
+ let p = u.range[0] - 1;
484
+ for (; s(p); ) r.push(p--);
485
+ }
486
+ if ((a = n.end) != null && a.right) {
487
+ let p = u.range[1];
488
+ for (; s(p); ) r.push(p++);
489
+ }
490
+ }
491
+ return new d([0, e.length]).subtract(r).slice(e);
492
+ }, rt = (e, t, n) => {
493
+ if (!t) return se(e);
494
+ const s = Je(t);
395
495
  switch (s.name) {
396
496
  case "extract":
397
- e = Ge(e, s.id, ...z(s));
497
+ e = Ke(e, s.id, ...Q(s));
398
498
  break;
399
499
  case "remove":
400
- e = Qe(e, s.id, ...z(s));
500
+ e = Ye(e, s.id, ...Q(s));
401
501
  break;
402
502
  case "replace":
403
- e = ze(e, s.id, s.with, s.space);
503
+ e = et(e, s.id, s.with, s.space);
504
+ break;
505
+ case "splice-start":
506
+ case "splice-end": {
507
+ const { deleteCount: r, insert: o, space: i, id: l } = s, a = s.name === "splice-start" ? "start" : "end";
508
+ e = tt(e, l, a, r, o, i);
404
509
  break;
405
- case "splice":
406
- e = Xe(e, s.id, s.deleteCount, s.insert, s.space);
510
+ }
511
+ case "trim-start":
512
+ case "trim-end": {
513
+ const { left: r, right: o, id: i } = s, l = s.name === "trim-start" ? "start" : "end";
514
+ e = re(e, i, { [l]: { left: r ?? !0, right: o ?? !0 } });
515
+ break;
516
+ }
517
+ case "trim": {
518
+ const { inside: r, outside: o, id: i } = s;
519
+ e = re(e, i, { start: { left: o ?? !0, right: r ?? !0 }, end: { left: r ?? !0, right: o ?? !0 } });
520
+ break;
521
+ }
522
+ case "single-line":
523
+ e = st(e, s.id);
407
524
  break;
408
525
  case "remap":
409
- e = Ve(e, s.id, s.from, s.to, s.space);
526
+ e = nt(e, s.id, s.from, s.to, s.space);
410
527
  break;
411
528
  }
412
- return t ? J(e) : e;
413
- }, Ze = ["http", "./", "../"], Ke = ({ url: e }) => Ze.some((n) => e.startsWith(n)), Ye = (e) => D(e) && xe(e) && Ke(e), oe = ({ url: e }, n) => `[](${n ? y(n, e) : e})`, m = {
529
+ return e = n && s.name !== "debug" ? se(e) : e, n ? P(e) : e;
530
+ }, ot = [
531
+ "recipe(id: string)"
532
+ ], it = [
533
+ "recipe(id: string, 0?: string, 1?: string, 2?: string)"
534
+ ], oe = {
535
+ register: R(ot),
536
+ apply: R(it)
537
+ }, N = class N {
538
+ constructor() {
539
+ _(this, "recipes", /* @__PURE__ */ new Map());
540
+ }
541
+ tryRegister(t) {
542
+ const n = N.Entries(t);
543
+ for (let s = 0; s < n.length; s++) {
544
+ const [r, o] = n[s];
545
+ if (r !== "register") continue;
546
+ const i = oe.register(o);
547
+ switch (i.name) {
548
+ case "recipe":
549
+ const l = n.slice(s + 1).filter(([a]) => a !== "register").map(([a, c]) => `${a}=${c}`).join("&");
550
+ this.recipes.set(i.id, l);
551
+ break;
552
+ default:
553
+ throw new Error(`Unknown registration: ${i.name}`);
554
+ }
555
+ }
556
+ }
557
+ apply(t) {
558
+ const n = N.Entries(t), s = [];
559
+ for (let r = 0; r < n.length; r++) {
560
+ const [o, i] = n[r];
561
+ if (o !== "apply") {
562
+ s.push(`${o}=${i}`);
563
+ continue;
564
+ }
565
+ const l = oe.apply(i);
566
+ switch (l.name) {
567
+ case "recipe":
568
+ s.push(this.recipes.get(l.id)), s.push(...Q(l).map((a) => this.recipes.get(a)));
569
+ break;
570
+ default:
571
+ throw new Error(`Unknown registration: ${l.name}`);
572
+ }
573
+ }
574
+ return s.join("&");
575
+ }
576
+ };
577
+ _(N, "Entries", (t) => Array.from(new URLSearchParams(t).entries()));
578
+ let G = N;
579
+ const lt = ["http", "./", "../", "?"], at = ({ url: e }) => lt.some((t) => e.startsWith(t)), ct = (e) => X(e) && Me(e) && at(e), ue = ({ url: e }, t) => `[](${t ? T(t, e) : e})`, g = {
414
580
  _open: "<!--",
415
581
  _close: "-->",
416
582
  _flag: "p↓",
417
583
  get begin() {
418
- return E(m._open, m._flag, "BEGIN", m._close);
584
+ return O(g._open, g._flag, "BEGIN", g._close);
419
585
  },
420
586
  get end() {
421
- return E(m._open, m._flag, "END", m._close);
587
+ return O(g._open, g._flag, "END", g._close);
422
588
  },
423
589
  lengthOf(e) {
424
- const n = `lines: ${e.split(`
425
- `).length}`, t = `chars: ${e.length}`;
426
- return E(m._open, m._flag, "length", n, t, m._close);
590
+ const t = `lines: ${e.split(`
591
+ `).length}`, n = `chars: ${e.length}`;
592
+ return O(g._open, g._flag, "length", t, n, g._close);
427
593
  }
428
- }, Z = (e) => (n) => D(n) && n.value === m[e], en = ({ position: e, url: n, siblingCount: t }, s) => ({ position: e, url: n, headingDepth: s, inline: t >= 1 }), nn = ({ position: { start: e }, url: n, siblingCount: t }, { position: { end: s } }, o) => ({ position: { start: e, end: s }, url: n, headingDepth: o, inline: t >= 1 }), tn = (e, n, t) => (e.inline ? E : be)(
429
- oe(e, t),
430
- m.begin,
431
- m.lengthOf(n),
432
- n,
433
- m.end
434
- ), sn = (e) => {
435
- const n = S(e, "heading").reduce((t, { position: s, depth: o }) => t.set(s.start.line, o), /* @__PURE__ */ new Map());
436
- return (t) => {
437
- for (let s = t.position.start.line; s >= 1; s--) {
438
- const o = n.get(s);
439
- if (o) return o;
594
+ }, ie = (e) => (t) => X(t) && t.value === g[e], pt = ({ position: e, url: t, siblingCount: n }, s) => ({ position: e, url: t, headingDepth: s, inline: n >= 1 }), ut = ({ position: { start: e }, url: t, siblingCount: n }, { position: { end: s } }, r) => ({ position: { start: e, end: s }, url: t, headingDepth: r, inline: n >= 1 }), mt = (e, t, n) => (e.inline ? O : Oe)(
595
+ ue(e, n),
596
+ g.begin,
597
+ g.lengthOf(t),
598
+ t,
599
+ g.end
600
+ ), gt = (e) => {
601
+ const t = I(e, "heading").reduce((n, { position: s, depth: r }) => n.set(s.start.line, r), /* @__PURE__ */ new Map());
602
+ return (n) => {
603
+ for (let s = n.position.start.line; s >= 1; s--) {
604
+ const r = t.get(s);
605
+ if (r) return r;
440
606
  }
441
607
  return 0;
442
608
  };
443
- }, x = {
609
+ }, j = {
444
610
  openingCommentDoesNotFollowLink: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),
445
611
  closingCommentNotMatchedToOpening: ({ position: { start: e } }) => new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),
446
612
  openingCommentNotClosed: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)
447
- }, on = (e, n) => {
448
- const t = [], s = [
449
- ...e.map((r) => ({ node: r, type: "open" })),
450
- ...n.map((r) => ({ node: r, type: "close" }))
451
- ].sort((r, i) => f(r.node, i.node)), o = [];
452
- for (const r of s)
453
- if (r.type === "open") o.push(r);
613
+ }, ht = (e, t) => {
614
+ const n = [], s = [
615
+ ...e.map((o) => ({ node: o, type: "open" })),
616
+ ...t.map((o) => ({ node: o, type: "close" }))
617
+ ].sort((o, i) => f(o.node, i.node)), r = [];
618
+ for (const o of s)
619
+ if (o.type === "open") r.push(o);
454
620
  else {
455
- const i = r.node;
456
- if (o.length === 0)
457
- throw x.closingCommentNotMatchedToOpening(i);
458
- const l = o.pop().node;
459
- if (o.length > 0) continue;
460
- t.push({ open: l, close: i });
621
+ const i = o.node;
622
+ if (r.length === 0)
623
+ throw j.closingCommentNotMatchedToOpening(i);
624
+ const l = r.pop().node;
625
+ if (r.length > 0) continue;
626
+ n.push({ open: l, close: i });
461
627
  }
462
- if (o.length > 0)
463
- throw x.openingCommentNotClosed(o[0].node);
464
- return t;
465
- }, rn = (e, n, t) => {
466
- const s = [...n].sort(f), o = [];
467
- return [...t].sort((r, i) => f.reverse(r.open, i.open)).forEach((r) => {
628
+ if (r.length > 0)
629
+ throw j.openingCommentNotClosed(r[0].node);
630
+ return n;
631
+ }, dt = (e, t, n) => {
632
+ const s = [...t].sort(f), r = [];
633
+ return [...n].sort((o, i) => f.reverse(o.open, i.open)).forEach((o) => {
468
634
  for (; s.length > 0; ) {
469
635
  const i = s.pop();
470
- if (i.position.start.offset < r.open.position.start.offset) {
471
- if (Ne(e, i, r.open).trim() !== "")
472
- throw x.openingCommentDoesNotFollowLink(r.open);
473
- return o.push([i, r]);
636
+ if (i.position.start.offset < o.open.position.start.offset) {
637
+ if (Ae(e, i, o.open).trim() !== "")
638
+ throw j.openingCommentDoesNotFollowLink(o.open);
639
+ return r.push([i, o]);
474
640
  }
475
- o.push(i);
641
+ r.push(i);
476
642
  }
477
- throw x.openingCommentDoesNotFollowLink(r.open);
478
- }), o.push(...s.reverse()), o.reverse();
479
- }, re = (e, n) => {
480
- n ?? (n = I.md(e));
481
- const t = sn(n), s = S(n, "link").filter(Ye), o = S(n, "html").sort(f), r = o.filter(Z("begin")), i = o.filter(Z("end")), l = on(r, i);
482
- return rn(e, s, l).map((a) => Array.isArray(a) ? nn(a[0], a[1].close, t(a[0])) : en(a, t(a)));
483
- }, ln = (e, { url: n }) => (t) => e(y(A(n), t)), ie = (...e) => {
484
- const n = e.reduce((t, s) => t + s, 0);
485
- return Math.min(Math.max(n, 1), 6);
486
- }, cn = (e, n, t) => {
487
- if (n === 0) return e;
488
- t ?? (t = I.md(e));
489
- const s = S(t, "heading"), o = e.split(`
643
+ throw j.openingCommentDoesNotFollowLink(o.open);
644
+ }), r.push(...s.reverse()), r.reverse();
645
+ }, me = (e, t) => {
646
+ t ?? (t = V.md(e));
647
+ const n = gt(t), s = I(t, "link").filter(ct), r = I(t, "html").sort(f), o = r.filter(ie("begin")), i = r.filter(ie("end")), l = ht(o, i);
648
+ return dt(e, s, l).map((c) => Array.isArray(c) ? ut(c[0], c[1].close, n(c[0])) : pt(c, n(c)));
649
+ }, ft = (e, { url: t }) => (n) => e(T(z(t), n)), ge = (...e) => {
650
+ const t = e.reduce((n, s) => n + s, 0);
651
+ return Math.min(Math.max(t, 1), 6);
652
+ }, vt = (e, t, n) => {
653
+ if (t === 0) return e;
654
+ n ?? (n = V.md(e));
655
+ const s = I(n, "heading"), r = e.split(`
490
656
  `);
491
- for (const r of s) {
492
- const { depth: i, position: { start: l, end: c } } = r, a = ie(i, n), u = o[l.line - 1].slice(i, c.column), p = "#".repeat(a) + u;
493
- o[l.line - 1] = p, r.depth = a;
657
+ for (const o of s) {
658
+ const { depth: i, position: { start: l, end: a } } = o, c = ge(i, t), u = r[l.line - 1].slice(i, a.column), p = "#".repeat(c) + u;
659
+ r[l.line - 1] = p, o.depth = c;
494
660
  }
495
- return o.join(`
661
+ return r.join(`
496
662
  `);
497
- }, le = (e) => re(e).reverse().sort(f.reverse).reduce((n, t) => ee(n, oe(t), t), e), ce = (e, n, t, s, o) => {
663
+ }, he = (e) => me(e).reverse().sort(f.reverse).reduce((t, n) => ce(t, ue(n), n), e), de = (e, t, n, s, r) => {
498
664
  try {
499
- e = le(e), e = cn(e, n);
500
- const r = I.md(e);
501
- return re(e, r).sort(f).reverse().map((i) => {
502
- var q, B;
503
- const { url: l, headingDepth: c } = i, [a, ...u] = $e(l).split("?"), p = a.split(".").pop() ?? "", b = u.join("?"), k = A(l), L = y(k, a);
504
- if (l.startsWith("./") || l.startsWith("../")) {
505
- let g = t(L);
506
- const $ = new Ce(b), M = (q = $.get("region")) == null ? void 0 : q.split(U);
507
- g = (M == null ? void 0 : M.reduce(
508
- (C, w, O, { length: fe }) => Je(C, w, O === fe - 1),
509
- g
510
- )) ?? g;
511
- const me = $.has("skip"), ue = $.get("heading") ?? 0, ge = $.has("inline");
512
- let { inline: _ } = i;
513
- if (ge && (_ = !0), !me)
514
- if (p === "md") {
515
- const C = ln(t, i), w = o ? y(o, k) : k, O = ie(c, Number(ue));
516
- g = ce(
517
- g,
665
+ e = he(e), e = vt(e, t);
666
+ const o = V.md(e), i = new G();
667
+ return me(e, o).sort(f).reverse().map((l) => {
668
+ var $, M, x;
669
+ const { url: a, headingDepth: c } = l, [u, ...p] = Se(a).split("?"), w = i.apply(p.join("?"));
670
+ if (a.startsWith("?")) {
671
+ const b = ($ = new Z(w).get("register")) == null ? void 0 : $.split(F);
672
+ b == null || b.forEach((A) => i.tryRegister(A));
673
+ } else if (a.startsWith("./") || a.startsWith("../")) {
674
+ const m = u.split(".").pop() ?? "", b = z(a), A = T(b, u);
675
+ let h = n(A);
676
+ const k = new Z(w), L = (M = ((y) => {
677
+ const v = Array.from(k.entries()).filter(([E]) => E === y).map(([E, B]) => B);
678
+ return v.length >= 1 ? v.join(",") : void 0;
679
+ })("region")) == null ? void 0 : M.split(F);
680
+ h = (L == null ? void 0 : L.reduce(
681
+ (y, v, E, { length: B }) => rt(y, v, E === B - 1),
682
+ h
683
+ )) ?? h;
684
+ const we = k.has("skip"), $e = k.get("heading") ?? 0, be = k.has("inline");
685
+ let { inline: U } = l;
686
+ if (be && (U = !0), !we)
687
+ if (m === "md") {
688
+ const y = ft(n, l), v = r ? T(r, b) : b, E = ge(c, Number($e));
689
+ h = de(
690
+ h,
518
691
  /** p↓: ... */
519
- O,
520
- C,
521
- L,
522
- w
692
+ E,
693
+ y,
694
+ A,
695
+ v
523
696
  /** p↓: ... */
524
697
  );
525
- } else /^(js|ts)x?|svelte$/i.test(p) && (g = X(
526
- g,
698
+ } else /^(js|ts)x?|svelte$/i.test(m) && (h = te(
699
+ h,
527
700
  "code",
528
701
  /** p↓: ... */
529
- { extension: p, inline: _ }
702
+ { extension: m, inline: U }
530
703
  /** p↓: ... */
531
704
  ));
532
- const R = (B = $.get("wrap")) == null ? void 0 : B.split(U);
533
- return g = (R == null ? void 0 : R.reduce((C, w) => X(C, w, { extension: p, inline: _ }), g)) ?? g, { target: i, content: tn(i, g, o) };
534
- } else throw l.startsWith("http") ? new Error("External web links are not implemented yet") : new Error(`Unsupported link type: ${l}`);
535
- }).reduce((i, { target: l, content: c }) => ee(i, c, l), e);
536
- } catch (r) {
537
- throw new Error(`Error populating inclusions in file ${s ?? "(unknown)"}: ${r}`);
705
+ const q = (x = k.get("wrap")) == null ? void 0 : x.split(F);
706
+ return h = (q == null ? void 0 : q.reduce((y, v) => te(y, v, { extension: m, inline: U }), h)) ?? h, { target: l, content: mt(l, h, r) };
707
+ } else throw a.startsWith("http") ? new Error("External web links are not implemented yet") : new Error(`Unsupported link type: ${a}`);
708
+ }).filter(Boolean).reduce((l, { target: a, content: c }) => ce(l, c, a), e);
709
+ } catch (o) {
710
+ throw new Error(`Error populating inclusions in file ${s ?? "(unknown)"}: ${o}`);
538
711
  }
539
- }, ae = (e) => ve(e, "utf-8"), pe = (e) => {
540
- const n = Y(e), t = A(n);
541
- return { content: ae(n), dir: t, path: n };
542
- }, an = (e, n = !0, t) => {
543
- const { dir: s, path: o, content: r } = pe(e);
544
- t == null || t.unwatch(o), t == null || t.once("change", (c, a) => {
545
- console.log(`Change detected in "${c}". Regenerating "${o}"...`), an(e, n, t);
712
+ }, fe = (e) => Ee(e, "utf-8"), ve = (e) => {
713
+ const t = ae(e), n = z(t);
714
+ return { content: fe(t), dir: n, path: t };
715
+ }, wt = (e, t = !0, n) => {
716
+ const { dir: s, path: r, content: o } = ve(e);
717
+ n == null || n.unwatch(r), n == null || n.once("change", (a, c) => {
718
+ console.log(`Change detected in "${a}". Regenerating "${r}"...`), wt(e, t, n);
546
719
  });
547
- const l = ce(r, 0, (c) => {
548
- const a = Y(s, Me(c));
549
- return t == null || t.add(a), ae(a);
550
- }, o);
551
- return n && K(o, l), t == null || t.add(o), l;
552
- }, $n = (e, n = !0, t) => {
553
- const { path: s, content: o } = pe(e), r = le(o);
554
- return n && K(s, r), r;
720
+ const l = de(o, 0, (a) => {
721
+ const c = ae(s, Ie(a));
722
+ return n == null || n.add(c), fe(c);
723
+ }, r);
724
+ return t && le(r, l), n == null || n.add(r), l;
725
+ }, Nt = (e, t = !0, n) => {
726
+ const { path: s, content: r } = ve(e), o = he(r);
727
+ return t && le(s, o), o;
555
728
  };
556
729
  export {
557
- $n as depopulateMarkdownInclusions,
558
- an as populateMarkdownInclusions
730
+ Nt as depopulateMarkdownInclusions,
731
+ wt as populateMarkdownInclusions
559
732
  };
@@ -1,15 +1,16 @@
1
- (function(p,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("node:fs"),require("node:path"),require("node:url"),require("unified"),require("remark-parse"),require("unist-util-visit"),require("ts-dedent")):typeof define=="function"&&define.amd?define(["exports","node:fs","node:path","node:url","unified","remark-parse","unist-util-visit","ts-dedent"],m):(p=typeof globalThis<"u"?globalThis:p||self,m(p.index={},p.node_fs,p.node_path,p.node_url,p.unified,p.remarkParse,p.unistUtilVisit,p.tsDedent))})(this,function(p,m,d,ue,me,de,ge,M){"use strict";var tn=Object.defineProperty;var sn=(p,m,d)=>m in p?tn(p,m,{enumerable:!0,configurable:!0,writable:!0,value:d}):p[m]=d;var pe=(p,m,d)=>sn(p,typeof m!="symbol"?m+"":m,d);const v=(e,n)=>e.position.start.offset-n.position.start.offset;v.reverse=(e,n)=>v(n,e);const T=e=>e.position!==void 0&&e.position.start.offset!==void 0&&e.position.end.offset!==void 0,fe=me.unified().use(de),j={md:e=>fe.parse(e)},x=(e,n)=>{const t=[];return ge.visit(e,(s,o,r)=>{if(s.type!=="root"){if(n&&s.type!==n)return;if(T(s)){const i=((r==null?void 0:r.children.length)??0)-1;t.push({...s,siblingIndex:o,siblingCount:i})}}}),t},he=e=>e.children.length===0,L=(e,n,...t)=>{if(t.length===0)throw new Error("No nodes to replace content from");t.sort(v);const s=t.at(0),o=t.at(-1);return e.slice(0,s.position.start.offset)+n+e.slice(o.position.end.offset)},ve=(e,n,t)=>{const s=Math.min(n.position.end.offset,t.position.end.offset),o=Math.max(n.position.start.offset,t.position.start.offset);return e.slice(s,o)},N=(...e)=>e.join(" "),$e=(...e)=>e.join(`
2
- `),Ce=e=>{const n=e.split("?");return n.length>1?[n.slice(0,-1).join("?"),n.at(-1)]:[e,""]},we=e=>Ce(e)[0];class ${constructor(...n){pe(this,"intervals",[]);for(const[t,s]of n)this.push(t,s)}push(n,t){this.intervals.push([Math.min(n,t),Math.max(n,t)])}combine(n){this.intervals.push(...n.intervals)}collapse(){const{intervals:n}=this;if(!n.length)return this.intervals=[];n.sort((r,i)=>r[0]-i[0]);const t=[];let[s,o]=n[0];for(let r=1;r<n.length;r++){const[i,l]=n[r];i<=o?o=Math.max(o,l):(t.push([s,o]),s=i,o=l)}return t.push([s,o]),this.intervals=t}subtract(n){const{intervals:t}=this,{intervals:s}=n;if(!t.length||!s.length)return t;let o=[...t];for(const[r,i]of s){const l=[];for(const[c,a]of o){if(i<=c||r>=a){l.push([c,a]);continue}r>c&&l.push([c,r]),i<a&&l.push([i,a])}o=l}return this.intervals=o}}const B=/,\s*(?![^()]*\))/,F={reserved:{semi:";",slash:"/",question:"?",colon:":",at:"@",equal:"=",and:"&"},unsafe:{quote:'"',angle:"<",unangle:">",hash:"#",percent:"%",curly:"{",uncurly:"}",pipe:"|",back:"\\",carrot:"^",tilde:"~",square:"[",unsquare:"]",tick:"`",line:`
3
- `}},ye="-",U={static:[["'''",'"'],["''","'"],[/parkdown:\s+/g,""],[/p↓:\s+/g,""]],url:[...Object.entries(F.unsafe),...Object.entries(F.reserved)]},H=(e,[n,t])=>e.replaceAll(n,t),k=(e,n=ye)=>{const t=U.static.reduce(H,e);return U.url.map(([s,o])=>[n+s+n,o]).reduce(H,t).replaceAll(n," ")},Se=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Ee=["string","number","boolean"],xe=e=>Ee.includes(e),Ne=/^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/,ke=e=>{const n=e.match(Ne);if(!n)throw new Error(`Invalid invocation: ${e}`);const[,t,s=""]=n;if(!s.trim())return{name:t,parameters:[]};const o=Me(s);return{name:t,parameters:o}},be=(e,n)=>{for(let t=n+1;t<e.length;t++)if(e[t]!==void 0)return!1;return!0},Me=e=>{const n=[];let t="",s=!1;for(let o=0;o<e.length;o++){const r=e[o],i=r==="'";if(i&&e.at(o+1)==="'"){const l=e.at(o+2)==="'";s=!s,t+=l?"'''":"''",o+=l?2:1}else i?(s=!s,t+=r):r===","&&!s?(n.push(t.trim()),t=""):t+=r}return n.push(t.trim()),n.map(o=>o===""?void 0:o?Te(o):void 0).filter((o,r,i)=>o!==void 0||!be(i,r))},Te=e=>{const n=e.length>=2&&e[0]==="'"&&e.at(-1)==="'",t=n&&e.length>=4&&e[1]==="'"&&e.at(-2)==="'";return!n||t?e:e.slice(1,-1)},je=e=>{const n=/^(\w+)(?:\(([^)]*)\))?/,t=e.match(n);if(!t)return{name:e};const[,s,o]=t;if(!o)return{name:s};const r=/(\w+)(\?)?:\s*([^,]+)/g,i=[];let l;for(;(l=r.exec(o))!==null;){const[,c,a,f]=l,u=f.trim();if(!xe(u))throw new Error(`Unsupported type: ${u}`);i.push({name:c,optional:a==="?",type:u})}return{name:s,parameters:i}},O=e=>{const n=e.map(je).reduce((t,{name:s,parameters:o})=>t.set(s,o),new Map);return t=>{const{name:s,parameters:o}=ke(t);if(!n.has(s))throw new Error(`Unknown method: ${s}`);const r=n.get(s);if(r===void 0)return{name:s};if(o.length>r.length){const i=r.filter(({optional:c})=>!c).length,l=i===r.length?i.toString():`${i} - ${r.length}`;throw new Error(`Too many parameters: ${o.length} for method '${s}' (expected: ${l})`)}return r.reduce((i,{name:l,optional:c,type:a},f)=>{const u=o[f];if(u===void 0){if(c)return i;throw new Error(`Missing required parameter: ${l} for method '${s}'`)}switch(a){case"string":i[l]=u;break;case"number":case"boolean":i[l]=JSON.parse(u);break}if(typeof i[l]!==a)throw new Error(`Invalid type: ${l} must be ${a}, got ${typeof i[l]} for method '${s}'`);return i},{name:s})}},G=e=>Object.entries(e).filter(([n])=>n!=="name"&&!isNaN(Number(n))).map(([n,t])=>t),Oe=O(["code(lang?: string, meta?: string)","quote()","dropdown(summary: string, open?: boolean, space?: string)"]),C=(e,n=1)=>`
4
- `.repeat(n)+e+`
5
- `.repeat(n),R=(e,n,t)=>`<${n}${t?` ${t}`:""}>${C(e)}</${n}>`,Q=(e,n,t)=>{const s=Oe(n);switch(s.name){case"code":if(!s.lang&&!s.meta&&(t==null?void 0:t.inline)&&!e.includes(`
6
- `))return`\`${e}\``;const r=s.lang??(t==null?void 0:t.extension)??"",i=s.meta?` ${s.meta}`:"";return C(`\`\`\`${r}${i}${C(e)}\`\`\``);case"quote":return t!=null&&t.inline&&!e.includes(`
1
+ (function(u,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("node:fs"),require("node:path"),require("node:url"),require("unified"),require("remark-parse"),require("unist-util-visit"),require("ts-dedent")):typeof define=="function"&&define.amd?define(["exports","node:fs","node:path","node:url","unified","remark-parse","unist-util-visit","ts-dedent"],d):(u=typeof globalThis<"u"?globalThis:u||self,d(u.index={},u.node_fs,u.node_path,u.node_url,u.unified,u.remarkParse,u.unistUtilVisit,u.tsDedent))})(this,function(u,d,g,K,we,$e,ye,Ce){"use strict";var mt=Object.defineProperty;var dt=(u,d,g)=>d in u?mt(u,d,{enumerable:!0,configurable:!0,writable:!0,value:g}):u[d]=g;var _=(u,d,g)=>dt(u,typeof d!="symbol"?d+"":d,g);const $=(e,t)=>e.position.start.offset-t.position.start.offset;$.reverse=(e,t)=>$(t,e);const U=e=>e.position!==void 0&&e.position.start.offset!==void 0&&e.position.end.offset!==void 0,be=we.unified().use($e),B={md:e=>be.parse(e)},A=(e,t)=>{const n=[];return ye.visit(e,(s,r,i)=>{if(s.type!=="root"){if(t&&s.type!==t)return;if(U(s)){const o=((i==null?void 0:i.children.length)??0)-1;n.push({...s,siblingIndex:r,siblingCount:o})}}}),n},Ee=e=>e.children.length===0,Y=(e,t,...n)=>{if(n.length===0)throw new Error("No nodes to replace content from");n.sort($);const s=n.at(0),r=n.at(-1);return e.slice(0,s.position.start.offset)+t+e.slice(r.position.end.offset)},Se=(e,t,n)=>{const s=Math.min(t.position.end.offset,n.position.end.offset),r=Math.max(t.position.start.offset,n.position.start.offset);return e.slice(s,r)},O=(...e)=>e.join(" "),ke=(...e)=>e.join(`
2
+ `),xe=e=>{const t=e.split("?");return t.length>1?[t.slice(0,-1).join("?"),t.at(-1)]:[e,""]},Ne=e=>xe(e)[0],F=/,\s*(?![^()]*\))/,ee={reserved:{semi:";",slash:"/",question:"?",colon:":",at:"@",equal:"=",and:"&"},unsafe:{quote:'"',angle:"<",unangle:">",hash:"#",percent:"%",curly:"{",uncurly:"}",pipe:"|",back:"\\",carrot:"^",tilde:"~",square:"[",unsquare:"]",tick:"`",line:`
3
+ `}},Me="-",te={static:[["'''",'"'],["''","'"],[/parkdown:\s+/g,""],[/p↓:\s+/g,""]],url:[...Object.entries(ee.unsafe),...Object.entries(ee.reserved)]},ne=(e,[t,n])=>e.replaceAll(t,n),I=(e,t=Me)=>{const n=te.static.reduce(ne,e);return te.url.map(([s,r])=>[t+s+t,r]).reduce(ne,n).replaceAll(t," ")},Re=["string","number","boolean"],Te=e=>Re.includes(e),je=/^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/,_e=e=>{const t=e.match(je);if(!t)throw new Error(`Invalid invocation: ${e}`);const[,n,s=""]=t;if(!s.trim())return{name:n,parameters:[]};const r=Oe(s);return{name:n,parameters:r}},Ae=(e,t)=>{for(let n=t+1;n<e.length;n++)if(e[n]!==void 0)return!1;return!0},Oe=e=>{const t=[];let n="",s=!1;for(let r=0;r<e.length;r++){const i=e[r],o=i==="'";if(o&&e.at(r+1)==="'"){const l=e.at(r+2)==="'";s=!s,n+=l?"'''":"''",r+=l?2:1}else o?(s=!s,n+=i):i===","&&!s?(t.push(n.trim()),n=""):n+=i}return t.push(n.trim()),t.map(r=>r===""?void 0:r?Ie(r):void 0).filter((r,i,o)=>r!==void 0||!Ae(o,i))},Ie=e=>{const t=e.length>=2&&e[0]==="'"&&e.at(-1)==="'",n=t&&e.length>=4&&e[1]==="'"&&e.at(-2)==="'";return!t||n?e:e.slice(1,-1)},qe=e=>{const t=/^(\w+)(?:\(([^)]*)\))?/,n=e.match(t);if(!n)return{name:e};const[,s,r]=n;if(!r)return{name:s};const i=/(\w+)(\?)?:\s*([^,]+)/g,o=[];let l;for(;(l=i.exec(r))!==null;){const[,c,a,m]=l,p=m.trim();if(!Te(p))throw new Error(`Unsupported type: ${p}`);o.push({name:c,optional:a==="?",type:p})}return{name:s,parameters:o}},M=e=>{const t=e.map(qe).reduce((n,{name:s,parameters:r})=>n.set(s,r),new Map);return n=>{const{name:s,parameters:r}=_e(n);if(!t.has(s))throw new Error(`Unknown method: ${s}`);const i=t.get(s);if(i===void 0)return{name:s};if(r.length>i.length){const o=i.filter(({optional:c})=>!c).length,l=o===i.length?o.toString():`${o} - ${i.length}`;throw new Error(`Too many parameters: ${r.length} for method '${s}' (expected: ${l})`)}return i.reduce((o,{name:l,optional:c,type:a},m)=>{const p=r[m];if(p===void 0){if(c)return o;throw new Error(`Missing required parameter: ${l} for method '${s}'`)}switch(a){case"string":o[l]=p;break;case"number":case"boolean":o[l]=JSON.parse(p);break}if(typeof o[l]!==a)throw new Error(`Invalid type: ${l} must be ${a}, got ${typeof o[l]} for method '${s}'`);return o},{name:s})}},H=e=>Object.entries(e).filter(([t])=>t!=="name"&&!isNaN(Number(t))).map(([t,n])=>n),De=M(["code(lang?: string, meta?: string)","quote()","dropdown(summary: string, open?: boolean, space?: string)"]),x=(e,t=1)=>`
4
+ `.repeat(t)+e+`
5
+ `.repeat(t),Q=(e,t,n)=>`<${t}${n?` ${n}`:""}>${x(e)}</${t}>`,se=(e,t,n)=>{const s=De(t);switch(s.name){case"code":if(!s.lang&&!s.meta&&(n==null?void 0:n.inline)&&!e.includes(`
6
+ `))return`\`${e}\``;const i=s.lang??(n==null?void 0:n.extension)??"",o=s.meta?` ${s.meta}`:"";return x(`\`\`\`${i}${o}${x(e)}\`\`\``);case"quote":return n!=null&&n.inline&&!e.includes(`
7
7
 
8
- `)?`> ${e}`:C(R(C(e),"blockquote"));case"dropdown":const l=R(k(s.summary),"summary");return C(R([l,e].join(`
9
- `),"details",s.open?"open":void 0))}},q=e=>{const n=/(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm,t=[];let s;for(;(s=n.exec(e))!==null;){const o=[s.index,s.index+s[0].length],r=Re(s[0]).trim();t.push({range:o,value:r})}return t},Re=e=>e.startsWith("//")?e.slice(2):e.startsWith("/*")?e.slice(2,-2):e.startsWith("<!--")?e.slice(4,-3):e,z=["p↓:","pd:","parkdown:"];O(["splice(delete?: number, insert?: string)"]);const V=(e,n)=>e.range[0]-n.range[0],X=(e,n,t)=>(t??q(e)).filter(({value:s})=>s.split(" ").includes(n)).sort(V),J=e=>({isSpace:e===" ",isNewline:e===`
10
- `||e===void 0}),Z=e=>z.flatMap(n=>X(e,n)).sort((n,t)=>n.range[0]-t.range[0]).reverse().reduce((n,{range:[t,s],value:o})=>{const r=(u,I)=>n.slice(0,u)+n.slice(I),i=J(n[t-1]),l=J(n[s]),c=s===n.length;let a=t;for(;a>0&&n[a-1]!==`
11
- `;)a--;const f=n.slice(a,t).trim()==="";return i.isNewline&&l.isNewline?r(t-(c?1:0),s+1):i.isNewline||f?r(a,s+(l.isSpace||l.isNewline?1:0)):r(t-(i.isSpace?1:0),s)},e);z.map(e=>new RegExp(`^${Se(e)}(\\?[^\\s]+)`));const qe=O(["extract(id: string, 0?: string, 1?: string, 2?: string)","remove(id: string, 0?: string, 1?: string, 2?: string)","replace(id: string, with?: string, space?: string)","splice(id: string, deleteCount?: number, insert?: string, space?: string)","remap(id: string, from: string, to?: string, space?: string)"]),w=(e,n,t)=>{const s=X(e,n,t),o=[];for(let r=0;r<s.length-1;r+=2)o.push([s[r],s[r+1]]);return o},Ie=(e,...n)=>{if(n.length===0)return e;const t=q(e),s=([i,l])=>e.slice(i,l),o=new $,r=new $;for(const i of n)for(const[l,c]of w(e,i,t)){o.push(l.range[1],c.range[0]);const[a,...f]=s([l.range[1],c.range[0]]),u=f[f.length-1];r.push(l.range[0],l.range[1]+(a.trim()?0:1)),r.push(c.range[0],c.range[1]+(u.trim()?0:1))}return o.collapse(),r.collapse(),M.dedent(o.subtract(r).map(s).filter(Boolean).join("")).trim()},Ae=(e,...n)=>{if(n.length===0)return e;const t=q(e),s=([i,l])=>e.slice(i,l),o=new $;for(const i of n)for(const[l,c]of w(e,i,t)){const a=s([c.range[1],c.range[1]+1]).at(-1);o.push(l.range[0],a===`
12
- `?c.range[1]+1:c.range[1])}o.collapse();const r=new $([0,e.length]);return r.subtract(o),M.dedent(r.collapse().map(s).filter(Boolean).join("")).trim()},Pe=(e,n,t,s)=>{if(!n)return e;let o="",r=0;for(const[l,c]of w(e,n))o+=e.slice(r,l.range[1]),o+=k(t??l.value,s),r=c.range[0];o+=e.slice(r);const i=new $([0,o.length]);return i.subtract(new $(...w(o,n).flatMap(([l,c])=>[l.range,c.range]))),M.dedent(i.collapse().map(([l,c])=>o.slice(l,c)).filter(Boolean).join("")).trim()},De=(e,n,t,s,o)=>{if(!n)return e;const r=t===void 0?!1:t>=0,i=s?k(s,o):"",l=t??0;return w(e,n).map(c=>c[r?1:0]).sort(V).reverse().reduce((c,{range:a})=>r?c.slice(0,a[1])+i+c.slice(Math.min(a[1]+l,c.length)):c.slice(0,Math.max(a[0]+l,0))+i+c.slice(a[0]),e)},We=(e,n,t,s,o)=>{if(!n)return e;let r="",i=0;const l=[t,s??""].map(c=>k(c,o));console.log(l);for(const[c,a]of w(e,n))r+=e.slice(i,c.range[1]),r+=e.slice(c.range[1],a.range[0]).replaceAll(l[0],l[1]),i=a.range[0];return r+=e.slice(i),r},_e=(e,n,t)=>{if(!n)return Z(e);const s=qe(n);switch(s.name){case"extract":e=Ie(e,s.id,...G(s));break;case"remove":e=Ae(e,s.id,...G(s));break;case"replace":e=Pe(e,s.id,s.with,s.space);break;case"splice":e=De(e,s.id,s.deleteCount,s.insert,s.space);break;case"remap":e=We(e,s.id,s.from,s.to,s.space);break}return t?Z(e):e},Le=["http","./","../"],Be=({url:e})=>Le.some(n=>e.startsWith(n)),Fe=e=>T(e)&&he(e)&&Be(e),K=({url:e},n)=>`[](${n?d.join(n,e):e})`,g={_open:"<!--",_close:"-->",_flag:"p↓",get begin(){return N(g._open,g._flag,"BEGIN",g._close)},get end(){return N(g._open,g._flag,"END",g._close)},lengthOf(e){const n=`lines: ${e.split(`
13
- `).length}`,t=`chars: ${e.length}`;return N(g._open,g._flag,"length",n,t,g._close)}},Y=e=>n=>T(n)&&n.value===g[e],Ue=({position:e,url:n,siblingCount:t},s)=>({position:e,url:n,headingDepth:s,inline:t>=1}),He=({position:{start:e},url:n,siblingCount:t},{position:{end:s}},o)=>({position:{start:e,end:s},url:n,headingDepth:o,inline:t>=1}),Ge=(e,n,t)=>(e.inline?N:$e)(K(e,t),g.begin,g.lengthOf(n),n,g.end),Qe=e=>{const n=x(e,"heading").reduce((t,{position:s,depth:o})=>t.set(s.start.line,o),new Map);return t=>{for(let s=t.position.start.line;s>=1;s--){const o=n.get(s);if(o)return o}return 0}},b={openingCommentDoesNotFollowLink:({position:{start:e}})=>new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),closingCommentNotMatchedToOpening:({position:{start:e}})=>new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),openingCommentNotClosed:({position:{start:e}})=>new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)},ze=(e,n)=>{const t=[],s=[...e.map(r=>({node:r,type:"open"})),...n.map(r=>({node:r,type:"close"}))].sort((r,i)=>v(r.node,i.node)),o=[];for(const r of s)if(r.type==="open")o.push(r);else{const i=r.node;if(o.length===0)throw b.closingCommentNotMatchedToOpening(i);const l=o.pop().node;if(o.length>0)continue;t.push({open:l,close:i})}if(o.length>0)throw b.openingCommentNotClosed(o[0].node);return t},Ve=(e,n,t)=>{const s=[...n].sort(v),o=[];return[...t].sort((r,i)=>v.reverse(r.open,i.open)).forEach(r=>{for(;s.length>0;){const i=s.pop();if(i.position.start.offset<r.open.position.start.offset){if(ve(e,i,r.open).trim()!=="")throw b.openingCommentDoesNotFollowLink(r.open);return o.push([i,r])}o.push(i)}throw b.openingCommentDoesNotFollowLink(r.open)}),o.push(...s.reverse()),o.reverse()},ee=(e,n)=>{n??(n=j.md(e));const t=Qe(n),s=x(n,"link").filter(Fe),o=x(n,"html").sort(v),r=o.filter(Y("begin")),i=o.filter(Y("end")),l=ze(r,i);return Ve(e,s,l).map(a=>Array.isArray(a)?He(a[0],a[1].close,t(a[0])):Ue(a,t(a)))},Xe=(e,{url:n})=>t=>e(d.join(d.dirname(n),t)),ne=(...e)=>{const n=e.reduce((t,s)=>t+s,0);return Math.min(Math.max(n,1),6)},Je=(e,n,t)=>{if(n===0)return e;t??(t=j.md(e));const s=x(t,"heading"),o=e.split(`
14
- `);for(const r of s){const{depth:i,position:{start:l,end:c}}=r,a=ne(i,n),f=o[l.line-1].slice(i,c.column),u="#".repeat(a)+f;o[l.line-1]=u,r.depth=a}return o.join(`
15
- `)},te=e=>ee(e).reverse().sort(v.reverse).reduce((n,t)=>L(n,K(t),t),e),se=(e,n,t,s,o)=>{try{e=te(e),e=Je(e,n);const r=j.md(e);return ee(e,r).sort(v).reverse().map(i=>{var ce,ae;const{url:l,headingDepth:c}=i,[a,...f]=d.basename(l).split("?"),u=a.split(".").pop()??"",I=f.join("?"),A=d.dirname(l),le=d.join(A,a);if(l.startsWith("./")||l.startsWith("../")){let h=t(le);const y=new ue.URLSearchParams(I),P=(ce=y.get("region"))==null?void 0:ce.split(B);h=(P==null?void 0:P.reduce((S,E,_,{length:nn})=>_e(S,E,_===nn-1),h))??h;const Ke=y.has("skip"),Ye=y.get("heading")??0,en=y.has("inline");let{inline:D}=i;if(en&&(D=!0),!Ke)if(u==="md"){const S=Xe(t,i),E=o?d.join(o,A):A,_=ne(c,Number(Ye));h=se(h,_,S,le,E)}else/^(js|ts)x?|svelte$/i.test(u)&&(h=Q(h,"code",{extension:u,inline:D}));const W=(ae=y.get("wrap"))==null?void 0:ae.split(B);return h=(W==null?void 0:W.reduce((S,E)=>Q(S,E,{extension:u,inline:D}),h))??h,{target:i,content:Ge(i,h,o)}}else throw l.startsWith("http")?new Error("External web links are not implemented yet"):new Error(`Unsupported link type: ${l}`)}).reduce((i,{target:l,content:c})=>L(i,c,l),e)}catch(r){throw new Error(`Error populating inclusions in file ${s??"(unknown)"}: ${r}`)}},oe=e=>m.readFileSync(e,"utf-8"),re=e=>{const n=d.resolve(e),t=d.dirname(n);return{content:oe(n),dir:t,path:n}},ie=(e,n=!0,t)=>{const{dir:s,path:o,content:r}=re(e);t==null||t.unwatch(o),t==null||t.once("change",(c,a)=>{console.log(`Change detected in "${c}". Regenerating "${o}"...`),ie(e,n,t)});const l=se(r,0,c=>{const a=d.resolve(s,we(c));return t==null||t.add(a),oe(a)},o);return n&&m.writeFileSync(o,l),t==null||t.add(o),l},Ze=(e,n=!0,t)=>{const{path:s,content:o}=re(e),r=te(o);return n&&m.writeFileSync(s,r),r};p.depopulateMarkdownInclusions=Ze,p.populateMarkdownInclusions=ie,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
8
+ `)?`> ${e}`:x(Q(x(e),"blockquote"));case"dropdown":const l=Q(I(s.summary),"summary");return x(Q([l,e].join(`
9
+ `),"details",s.open?"open":void 0))}};class v{constructor(...t){_(this,"_intervals",[]);_(this,"collapsed",!0);for(const[n,s]of t)this.push(n,s)}get intervals(){return this._intervals}push(t,n){return n??(n=t+1),this._intervals.push([Math.min(t,n),Math.max(t,n)]),this.collapsed=!1,this}combine(t){for(const[n,s]of t.intervals)this.push(n,s);return this}collapse(t=!1){const{_intervals:n,collapsed:s}=this;if(s&&!t||!n.length)return this;n.sort((l,c)=>l[0]-c[0]);const r=[];let[i,o]=n[0];for(let l=1;l<n.length;l++){const[c,a]=n[l];c<=o?o=Math.max(o,a):(r.push([i,o]),i=c,o=a)}return r.push([i,o]),this._intervals=r,this.collapsed=!0,this}subtract(t){this.collapse(),t.collapse();const{_intervals:n}=this,{_intervals:s}=t;if(!n.length||!s.length)return this;let r=[...n];for(const[i,o]of s){const l=[];for(const[c,a]of r){if(o<=c||i>=a){l.push([c,a]);continue}i>c&&l.push([c,i]),o<a&&l.push([o,a])}r=l}return this._intervals=r,this.collapse(!0),this}test(t,n="head"){const{_intervals:s}=this;switch(n){case"head":return s.some(([r,i])=>t>=r&&t<i);case"tail":return s.some(([r,i])=>t>r&&t<=i);case"both":return s.some(([r,i])=>t>=r&&t<=i);case"none":return s.some(([r,i])=>t>r&&t<i)}}slice(t){this.collapse();const n=[];for(const[s,r]of this._intervals)n.push(t.slice(s,r));return n.filter(Boolean).join("")}offset(t){for(const n of this._intervals)n[0]+=t,n[1]+=t;return this}}const q=e=>{const t=/(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm,n=[];let s;for(;(s=t.exec(e))!==null;){const r=[s.index,s.index+s[0].length],i=Pe(s[0]).trim();n.push({range:r,value:i})}return n},Pe=e=>e.startsWith("//")?e.slice(2):e.startsWith("/*")?e.slice(2,-2):e.startsWith("<!--")?e.slice(4,-3):e,We=["p↓:","pd:","parkdown:"];M(["splice(delete?: number, insert?: string)"]);const re=(e,t)=>e.range[0]-t.range[0],G=(e,t,n)=>(n??q(e)).filter(({value:s})=>s.split(" ").includes(t)).sort(re),ie=e=>({isSpace:e===" ",isNewline:e===`
10
+ `||e===void 0}),oe=e=>We.flatMap(t=>G(e,t)).sort((t,n)=>t.range[0]-n.range[0]).reverse().reduce((t,{range:[n,s],value:r})=>{const i=(b,E)=>t.slice(0,b)+t.slice(E),o=ie(t[n-1]),l=ie(t[s]),c=s===t.length;let a=n;for(;a>0&&t[a-1]!==`
11
+ `;)a--;let m=s;for(;m<t.length&&t[m]!==`
12
+ `;)m++;const p=t.slice(a,n).trim()===""&&t.slice(s,m).trim()==="";return o.isNewline&&l.isNewline?i(n-(c?1:0),s+1):o.isNewline||p?i(a,s+(l.isSpace||l.isNewline?1:0)):i(n-(o.isSpace?1:0),s)},e),Le=M(["extract(id: string, 0?: string, 1?: string, 2?: string)","remove(id: string, 0?: string, 1?: string, 2?: string)","replace(id: string, with?: string, space?: string)","remap(id: string, from: string, to?: string, space?: string)","single-line(id: string, includeBoundaries?: boolean)","trim(id: string, inside?: boolean, outside?: boolean)","trim-start(id: string, left?: boolean, right?: boolean)","trim-end(id: string, left?: boolean, right?: boolean)","splice-start(id: string, deleteCount?: number, insert?: string, space?: string)","splice-end(id: string, deleteCount?: number, insert?: string, space?: string)","debug()"]),C=(e,t,n)=>{const s=G(e,t,n),r=[];for(let i=0;i<s.length-1;i+=2)r.push([s[i],s[i+1]]);return r},Ue=(e,t,n)=>new v(...G(e,t,n).map(({range:s})=>s)),D=e=>Ce.dedent(e).trim(),Be=(e,...t)=>{if(t.length===0)return e;const n=q(e),s=new v,r=new v;for(const i of t)for(const[o,l]of C(e,i,n)){s.push(o.range[1],l.range[0]);const[c,...a]=e.slice(o.range[1],l.range[0]),m=a[a.length-1];r.push(o.range[0],o.range[1]+(c.trim()?0:1)),r.push(l.range[0],l.range[1]+(m.trim()?0:1))}return D(s.subtract(r).slice(e))},Fe=(e,...t)=>{if(t.length===0)return e;const n=q(e),s=([i,o])=>e.slice(i,o),r=new v;for(const i of t)for(const[o,l]of C(e,i,n)){const c=s([l.range[1],l.range[1]+1]).at(-1);r.push(o.range[0],c===`
13
+ `?l.range[1]+1:l.range[1])}return D(new v([0,e.length]).subtract(r).slice(e))},He=(e,t,n,s)=>{if(!t)return e;let r="",i=0;for(const[o,l]of C(e,t))r+=e.slice(i,o.range[1]),r+=I(n??o.value,s),i=l.range[0];return r+=e.slice(i),D(new v([0,r.length]).subtract(Ue(r,t)).slice(r))},Qe=(e,t,n,s,r,i)=>{if(!t)return e;const o=!(s===void 0||s<0),l=r?I(r,i):"",c=s??0,a=q(e),m=new v(...a.map(({range:p})=>p));return C(e,t,a).map(p=>p[n==="start"?0:1]).sort(re).reverse().reduce((p,{range:b})=>{const E=new v,W=o?1:-1;let T=Math.abs(c),h=o?b[1]:b[0];for(;T>0&&h<p.length&&h>=0;)m.test(h)||(E.push(h),T--),h+=W;return h=Math.min(Math.max(0,h),p.length),p=p.slice(0,h)+l+p.slice(h),new v([0,p.length]).subtract(E.offset(o?0:l.length)).slice(p)},e)},Ge=(e,t,n,s,r)=>{if(!t)return e;let i="",o=0;[n,s]=[n,s??""].map(l=>I(l,r));for(const[l,c]of C(e,t))i+=e.slice(o,l.range[1]),i+=e.slice(l.range[1],c.range[0]).replaceAll(n,s),o=c.range[0];return i+=e.slice(o),i},ze=(e,t)=>{if(!t)return e;let n="",s=0;for(const[r,i]of C(e,t))n+=e.slice(s,r.range[1]),n+=e.slice(r.range[1],i.range[0]).replaceAll(/[\s\n]+/g," "),s=i.range[0];return n+=e.slice(s),n},le=(e,t,n)=>{var i,o,l,c;if(!t)return e;const s=a=>/\s/.test(e[a]),r=new v;for(const[a,m]of C(e,t)){if((i=n.start)!=null&&i.left){let p=a.range[0]-1;for(;s(p);)r.push(p--)}if((o=n.start)!=null&&o.right){let p=a.range[1];for(;s(p);)r.push(p++)}if((l=n.end)!=null&&l.left){let p=m.range[0]-1;for(;s(p);)r.push(p--)}if((c=n.end)!=null&&c.right){let p=m.range[1];for(;s(p);)r.push(p++)}}return new v([0,e.length]).subtract(r).slice(e)},Ve=(e,t,n)=>{if(!t)return oe(e);const s=Le(t);switch(s.name){case"extract":e=Be(e,s.id,...H(s));break;case"remove":e=Fe(e,s.id,...H(s));break;case"replace":e=He(e,s.id,s.with,s.space);break;case"splice-start":case"splice-end":{const{deleteCount:r,insert:i,space:o,id:l}=s,c=s.name==="splice-start"?"start":"end";e=Qe(e,l,c,r,i,o);break}case"trim-start":case"trim-end":{const{left:r,right:i,id:o}=s,l=s.name==="trim-start"?"start":"end";e=le(e,o,{[l]:{left:r??!0,right:i??!0}});break}case"trim":{const{inside:r,outside:i,id:o}=s;e=le(e,o,{start:{left:i??!0,right:r??!0},end:{left:r??!0,right:i??!0}});break}case"single-line":e=ze(e,s.id);break;case"remap":e=Ge(e,s.id,s.from,s.to,s.space);break}return e=n&&s.name!=="debug"?oe(e):e,n?D(e):e},Xe=["recipe(id: string)"],Je=["recipe(id: string, 0?: string, 1?: string, 2?: string)"],ce={register:M(Xe),apply:M(Je)},R=class R{constructor(){_(this,"recipes",new Map)}tryRegister(t){const n=R.Entries(t);for(let s=0;s<n.length;s++){const[r,i]=n[s];if(r!=="register")continue;const o=ce.register(i);switch(o.name){case"recipe":const l=n.slice(s+1).filter(([c])=>c!=="register").map(([c,a])=>`${c}=${a}`).join("&");this.recipes.set(o.id,l);break;default:throw new Error(`Unknown registration: ${o.name}`)}}}apply(t){const n=R.Entries(t),s=[];for(let r=0;r<n.length;r++){const[i,o]=n[r];if(i!=="apply"){s.push(`${i}=${o}`);continue}const l=ce.apply(o);switch(l.name){case"recipe":s.push(this.recipes.get(l.id)),s.push(...H(l).map(c=>this.recipes.get(c)));break;default:throw new Error(`Unknown registration: ${l.name}`)}}return s.join("&")}};_(R,"Entries",t=>Array.from(new URLSearchParams(t).entries()));let z=R;const Ze=["http","./","../","?"],Ke=({url:e})=>Ze.some(t=>e.startsWith(t)),Ye=e=>U(e)&&Ee(e)&&Ke(e),ae=({url:e},t)=>`[](${t?g.join(t,e):e})`,f={_open:"<!--",_close:"-->",_flag:"p↓",get begin(){return O(f._open,f._flag,"BEGIN",f._close)},get end(){return O(f._open,f._flag,"END",f._close)},lengthOf(e){const t=`lines: ${e.split(`
14
+ `).length}`,n=`chars: ${e.length}`;return O(f._open,f._flag,"length",t,n,f._close)}},pe=e=>t=>U(t)&&t.value===f[e],et=({position:e,url:t,siblingCount:n},s)=>({position:e,url:t,headingDepth:s,inline:n>=1}),tt=({position:{start:e},url:t,siblingCount:n},{position:{end:s}},r)=>({position:{start:e,end:s},url:t,headingDepth:r,inline:n>=1}),nt=(e,t,n)=>(e.inline?O:ke)(ae(e,n),f.begin,f.lengthOf(t),t,f.end),st=e=>{const t=A(e,"heading").reduce((n,{position:s,depth:r})=>n.set(s.start.line,r),new Map);return n=>{for(let s=n.position.start.line;s>=1;s--){const r=t.get(s);if(r)return r}return 0}},P={openingCommentDoesNotFollowLink:({position:{start:e}})=>new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),closingCommentNotMatchedToOpening:({position:{start:e}})=>new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),openingCommentNotClosed:({position:{start:e}})=>new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)},rt=(e,t)=>{const n=[],s=[...e.map(i=>({node:i,type:"open"})),...t.map(i=>({node:i,type:"close"}))].sort((i,o)=>$(i.node,o.node)),r=[];for(const i of s)if(i.type==="open")r.push(i);else{const o=i.node;if(r.length===0)throw P.closingCommentNotMatchedToOpening(o);const l=r.pop().node;if(r.length>0)continue;n.push({open:l,close:o})}if(r.length>0)throw P.openingCommentNotClosed(r[0].node);return n},it=(e,t,n)=>{const s=[...t].sort($),r=[];return[...n].sort((i,o)=>$.reverse(i.open,o.open)).forEach(i=>{for(;s.length>0;){const o=s.pop();if(o.position.start.offset<i.open.position.start.offset){if(Se(e,o,i.open).trim()!=="")throw P.openingCommentDoesNotFollowLink(i.open);return r.push([o,i])}r.push(o)}throw P.openingCommentDoesNotFollowLink(i.open)}),r.push(...s.reverse()),r.reverse()},ue=(e,t)=>{t??(t=B.md(e));const n=st(t),s=A(t,"link").filter(Ye),r=A(t,"html").sort($),i=r.filter(pe("begin")),o=r.filter(pe("end")),l=rt(i,o);return it(e,s,l).map(a=>Array.isArray(a)?tt(a[0],a[1].close,n(a[0])):et(a,n(a)))},ot=(e,{url:t})=>n=>e(g.join(g.dirname(t),n)),me=(...e)=>{const t=e.reduce((n,s)=>n+s,0);return Math.min(Math.max(t,1),6)},lt=(e,t,n)=>{if(t===0)return e;n??(n=B.md(e));const s=A(n,"heading"),r=e.split(`
15
+ `);for(const i of s){const{depth:o,position:{start:l,end:c}}=i,a=me(o,t),m=r[l.line-1].slice(o,c.column),p="#".repeat(a)+m;r[l.line-1]=p,i.depth=a}return r.join(`
16
+ `)},de=e=>ue(e).reverse().sort($.reverse).reduce((t,n)=>Y(t,ae(n),n),e),ge=(e,t,n,s,r)=>{try{e=de(e),e=lt(e,t);const i=B.md(e),o=new z;return ue(e,i).sort($).reverse().map(l=>{var E,W,T;const{url:c,headingDepth:a}=l,[m,...p]=g.basename(c).split("?"),b=o.apply(p.join("?"));if(c.startsWith("?")){const S=(E=new K.URLSearchParams(b).get("register"))==null?void 0:E.split(F);S==null||S.forEach(L=>o.tryRegister(L))}else if(c.startsWith("./")||c.startsWith("../")){const h=m.split(".").pop()??"",S=g.dirname(c),L=g.join(S,m);let w=n(L);const j=new K.URLSearchParams(b),V=(W=(k=>{const y=Array.from(j.entries()).filter(([N])=>N===k).map(([N,Z])=>Z);return y.length>=1?y.join(","):void 0})("region"))==null?void 0:W.split(F);w=(V==null?void 0:V.reduce((k,y,N,{length:Z})=>Ve(k,y,N===Z-1),w))??w;const at=j.has("skip"),pt=j.get("heading")??0,ut=j.has("inline");let{inline:X}=l;if(ut&&(X=!0),!at)if(h==="md"){const k=ot(n,l),y=r?g.join(r,S):S,N=me(a,Number(pt));w=ge(w,N,k,L,y)}else/^(js|ts)x?|svelte$/i.test(h)&&(w=se(w,"code",{extension:h,inline:X}));const J=(T=j.get("wrap"))==null?void 0:T.split(F);return w=(J==null?void 0:J.reduce((k,y)=>se(k,y,{extension:h,inline:X}),w))??w,{target:l,content:nt(l,w,r)}}else throw c.startsWith("http")?new Error("External web links are not implemented yet"):new Error(`Unsupported link type: ${c}`)}).filter(Boolean).reduce((l,{target:c,content:a})=>Y(l,a,c),e)}catch(i){throw new Error(`Error populating inclusions in file ${s??"(unknown)"}: ${i}`)}},he=e=>d.readFileSync(e,"utf-8"),fe=e=>{const t=g.resolve(e),n=g.dirname(t);return{content:he(t),dir:n,path:t}},ve=(e,t=!0,n)=>{const{dir:s,path:r,content:i}=fe(e);n==null||n.unwatch(r),n==null||n.once("change",(c,a)=>{console.log(`Change detected in "${c}". Regenerating "${r}"...`),ve(e,t,n)});const l=ge(i,0,c=>{const a=g.resolve(s,Ne(c));return n==null||n.add(a),he(a)},r);return t&&d.writeFileSync(r,l),n==null||n.add(r),l},ct=(e,t=!0,n)=>{const{path:s,content:r}=fe(e),i=de(r);return t&&d.writeFileSync(s,i),i};u.depopulateMarkdownInclusions=ct,u.populateMarkdownInclusions=ve,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@p-buddy/parkdown",
3
3
  "type": "module",
4
4
  "private": false,
5
- "version": "0.0.13",
5
+ "version": "0.0.14",
6
6
  "main": "./dist/index.js",
7
7
  "bin": "./dist/cli.js",
8
8
  "files": [