@p-buddy/parkdown 0.0.10 → 0.0.12

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/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command as t } from "@commander-js/extra-typings";
3
3
  import { populateMarkdownInclusions as l, depopulateMarkdownInclusions as r } from "@p-buddy/parkdown";
4
- const f = "0.0.10", p = new t().version(f).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", (s, o) => (o.push(s), o), new Array()).parse(), { inclusions: c, depopulate: u, file: n, write: i } = p.opts();
4
+ const f = "0.0.12", p = new t().version(f).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", (s, o) => (o.push(s), o), new Array()).parse(), { inclusions: c, depopulate: u, file: n, write: i } = p.opts();
5
5
  n.length === 0 && n.push("README.md");
6
6
  const a = [
7
7
  [l, !c],
package/dist/index.js CHANGED
@@ -1,44 +1,44 @@
1
- var we = Object.defineProperty;
2
- var ve = (e, t, n) => t in e ? we(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var U = (e, t, n) => ve(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { writeFileSync as ee, readFileSync as $e } from "node:fs";
5
- import { basename as Ce, dirname as O, join as S, resolve as te } from "node:path";
6
- import { URLSearchParams as ye } from "node:url";
7
- import { unified as Ee } from "unified";
8
- import xe from "remark-parse";
9
- import { visit as Se } from "unist-util-visit";
10
- import { dedent as A } 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 j = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, be = Ee().use(xe), D = {
14
- md: (e) => be.parse(e)
15
- }, b = (e, t) => {
1
+ var fe = Object.defineProperty;
2
+ var de = (e, t, n) => t in e ? fe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var F = (e, t, n) => de(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { writeFileSync as K, readFileSync as we } from "node:fs";
5
+ import { basename as ve, dirname as A, join as y, resolve as Y } from "node:path";
6
+ import { URLSearchParams as $e } from "node:url";
7
+ import { unified as Ce } 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 h = (e, t) => e.position.start.offset - t.position.start.offset;
12
+ h.reverse = (e, t) => h(t, e);
13
+ const D = (e) => e.position !== void 0 && e.position.start.offset !== void 0 && e.position.end.offset !== void 0, Se = Ce().use(Ee), I = {
14
+ md: (e) => Se.parse(e)
15
+ }, S = (e, t) => {
16
16
  const n = [];
17
- return Se(e, (s, o, r) => {
17
+ return ye(e, (s, o, r) => {
18
18
  if (s.type !== "root") {
19
19
  if (t && s.type !== t) return;
20
- if (j(s)) {
20
+ if (D(s)) {
21
21
  const i = ((r == null ? void 0 : r.children.length) ?? 0) - 1;
22
22
  n.push({ ...s, siblingIndex: o, siblingCount: i });
23
23
  }
24
24
  }
25
25
  }), n;
26
- }, Ne = (e) => e.children.length === 0, ne = (e, t, ...n) => {
26
+ }, xe = (e) => e.children.length === 0, ee = (e, t, ...n) => {
27
27
  if (n.length === 0) throw new Error("No nodes to replace content from");
28
- n.sort(f);
28
+ n.sort(h);
29
29
  const s = n.at(0), o = n.at(-1);
30
30
  return e.slice(0, s.position.start.offset) + t + e.slice(o.position.end.offset);
31
- }, ke = (e, t, n) => {
31
+ }, Ne = (e, t, n) => {
32
32
  const s = Math.min(t.position.end.offset, n.position.end.offset), o = Math.max(t.position.start.offset, n.position.start.offset);
33
33
  return e.slice(s, o);
34
- }, x = (...e) => e.join(" "), Me = (...e) => e.join(`
35
- `), _e = (e) => {
34
+ }, E = (...e) => e.join(" "), be = (...e) => e.join(`
35
+ `), ke = (e) => {
36
36
  const t = e.split("?");
37
37
  return t.length > 1 ? [t.slice(0, -1).join("?"), t.at(-1)] : [e, ""];
38
- }, Re = (e) => _e(e)[0];
39
- class v {
38
+ }, Me = (e) => ke(e)[0];
39
+ class d {
40
40
  constructor(...t) {
41
- U(this, "intervals", []);
41
+ F(this, "intervals", []);
42
42
  for (const [n, s] of t)
43
43
  this.push(n, s);
44
44
  }
@@ -78,7 +78,7 @@ class v {
78
78
  return this.intervals = o;
79
79
  }
80
80
  }
81
- const T = /,\s*(?![^()]*\))/, Q = {
81
+ const U = /,\s*(?![^()]*\))/, H = {
82
82
  reserved: {
83
83
  semi: ";",
84
84
  slash: "/",
@@ -102,9 +102,11 @@ const T = /,\s*(?![^()]*\))/, Q = {
102
102
  tilde: "~",
103
103
  square: "[",
104
104
  unsquare: "]",
105
- tick: "`"
105
+ tick: "`",
106
+ line: `
107
+ `
106
108
  }
107
- }, Pe = "-", G = {
109
+ }, _e = "-", G = {
108
110
  static: [
109
111
  ["'''", '"'],
110
112
  ["''", "'"],
@@ -112,24 +114,24 @@ const T = /,\s*(?![^()]*\))/, Q = {
112
114
  [/p↓:\s+/g, ""]
113
115
  ],
114
116
  url: [
115
- ...Object.entries(Q.unsafe),
116
- ...Object.entries(Q.reserved)
117
+ ...Object.entries(H.unsafe),
118
+ ...Object.entries(H.reserved)
117
119
  ]
118
- }, H = (e, [t, n]) => e.replaceAll(t, n), se = (e, t = Pe) => {
119
- const n = G.static.reduce(H, e);
120
- return G.url.map(([s, o]) => [t + s + t, o]).reduce(H, n).replaceAll(t, " ");
121
- }, Te = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), Oe = ["string", "number", "boolean"], Ae = (e) => Oe.includes(e), je = /^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/, De = (e) => {
122
- const t = e.match(je);
120
+ }, Q = (e, [t, n]) => e.replaceAll(t, n), N = (e, t = _e) => {
121
+ const n = G.static.reduce(Q, e);
122
+ return G.url.map(([s, o]) => [t + s + t, o]).reduce(Q, n).replaceAll(t, " ");
123
+ }, Oe = (e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), Re = ["string", "number", "boolean"], Te = (e) => Re.includes(e), Ae = /^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/, je = (e) => {
124
+ const t = e.match(Ae);
123
125
  if (!t) throw new Error(`Invalid invocation: ${e}`);
124
126
  const [, n, s = ""] = t;
125
127
  if (!s.trim()) return { name: n, parameters: [] };
126
- const o = Le(s);
128
+ const o = Ie(s);
127
129
  return { name: n, parameters: o };
128
- }, Ie = (e, t) => {
130
+ }, De = (e, t) => {
129
131
  for (let n = t + 1; n < e.length; n++)
130
132
  if (e[n] !== void 0) return !1;
131
133
  return !0;
132
- }, Le = (e) => {
134
+ }, Ie = (e) => {
133
135
  const t = [];
134
136
  let n = "", s = !1;
135
137
  for (let o = 0; o < e.length; o++) {
@@ -139,8 +141,8 @@ const T = /,\s*(?![^()]*\))/, Q = {
139
141
  s = !s, n += c ? "'''" : "''", o += c ? 2 : 1;
140
142
  } else i ? (s = !s, n += r) : r === "," && !s ? (t.push(n.trim()), n = "") : n += r;
141
143
  }
142
- return t.push(n.trim()), t.map((o) => o === "" ? void 0 : o ? qe(o) : void 0).filter((o, r, i) => o !== void 0 || !Ie(i, r));
143
- }, qe = (e) => {
144
+ return t.push(n.trim()), t.map((o) => o === "" ? void 0 : o ? Pe(o) : void 0).filter((o, r, i) => o !== void 0 || !De(i, r));
145
+ }, Pe = (e) => {
144
146
  const t = e.length >= 2 && e[0] === "'" && e.at(-1) === "'", n = t && e.length >= 4 && e[1] === "'" && e.at(-2) === "'";
145
147
  return !t || n ? e : e.slice(1, -1);
146
148
  }, We = (e) => {
@@ -151,18 +153,18 @@ const T = /,\s*(?![^()]*\))/, Q = {
151
153
  const r = /(\w+)(\?)?:\s*([^,]+)/g, i = [];
152
154
  let c;
153
155
  for (; (c = r.exec(o)) !== null; ) {
154
- const [, l, a, p] = c, m = p.trim();
155
- if (!Ae(m)) throw new Error(`Unsupported type: ${m}`);
156
- i.push({ name: l, optional: a === "?", type: m });
156
+ const [, l, a, u] = c, p = u.trim();
157
+ if (!Te(p)) throw new Error(`Unsupported type: ${p}`);
158
+ i.push({ name: l, optional: a === "?", type: p });
157
159
  }
158
160
  return { name: s, parameters: i };
159
- }, I = (e) => {
161
+ }, P = (e) => {
160
162
  const t = e.map(We).reduce(
161
163
  (n, { name: s, parameters: o }) => n.set(s, o),
162
164
  /* @__PURE__ */ new Map()
163
165
  );
164
166
  return (n) => {
165
- const { name: s, parameters: o } = De(n);
167
+ const { name: s, parameters: o } = je(n);
166
168
  if (!t.has(s))
167
169
  throw new Error(`Unknown method: ${s}`);
168
170
  const r = t.get(s);
@@ -172,19 +174,19 @@ const T = /,\s*(?![^()]*\))/, Q = {
172
174
  const i = r.filter(({ optional: l }) => !l).length, c = i === r.length ? i.toString() : `${i} - ${r.length}`;
173
175
  throw new Error(`Too many parameters: ${o.length} for method '${s}' (expected: ${c})`);
174
176
  }
175
- return r.reduce((i, { name: c, optional: l, type: a }, p) => {
176
- const m = o[p];
177
- if (m === void 0) {
177
+ return r.reduce((i, { name: c, optional: l, type: a }, u) => {
178
+ const p = o[u];
179
+ if (p === void 0) {
178
180
  if (l) return i;
179
181
  throw new Error(`Missing required parameter: ${c} for method '${s}'`);
180
182
  }
181
183
  switch (a) {
182
184
  case "string":
183
- i[c] = m;
185
+ i[c] = p;
184
186
  break;
185
187
  case "number":
186
188
  case "boolean":
187
- i[c] = JSON.parse(m);
189
+ i[c] = JSON.parse(p);
188
190
  break;
189
191
  }
190
192
  if (typeof i[c] !== a)
@@ -192,7 +194,7 @@ const T = /,\s*(?![^()]*\))/, Q = {
192
194
  return i;
193
195
  }, { name: s });
194
196
  };
195
- }, z = (e) => Object.entries(e).filter(([t]) => t !== "name" && !isNaN(Number(t))).map(([t, n]) => n), Be = [
197
+ }, z = (e) => Object.entries(e).filter(([t]) => t !== "name" && !isNaN(Number(t))).map(([t, n]) => n), Le = [
196
198
  /**
197
199
  * Wraps the content in a markdown-formatted code block.
198
200
  * @param lang The language of the code block (defaults to the file extension).
@@ -222,65 +224,55 @@ const T = /,\s*(?![^()]*\))/, Q = {
222
224
  * @example [](<url>?wrap=dropdown(hello_world,,_))
223
225
  */
224
226
  "dropdown(summary: string, open?: boolean, space?: string)"
225
- ], Fe = I(Be), w = (e, t = 1) => `
227
+ ], qe = P(Le), f = (e, t = 1) => `
226
228
  `.repeat(t) + e + `
227
- `.repeat(t), P = (e, t, n) => `<${t}${n ? ` ${n}` : ""}>${w(e)}</${t}>`, X = (e, t, n) => {
228
- const s = Fe(t);
229
+ `.repeat(t), T = (e, t, n) => `<${t}${n ? ` ${n}` : ""}>${f(e)}</${t}>`, X = (e, t, n) => {
230
+ const s = qe(t);
229
231
  switch (s.name) {
230
232
  case "code":
231
233
  if (!s.lang && !s.meta && (n == null ? void 0 : n.inline) && !e.includes(`
232
234
  `)) return `\`${e}\``;
233
235
  const r = s.lang ?? (n == null ? void 0 : n.extension) ?? "", i = s.meta ? ` ${s.meta}` : "";
234
- return w(`\`\`\`${r}${i}${w(e)}\`\`\``);
236
+ return f(`\`\`\`${r}${i}${f(e)}\`\`\``);
235
237
  case "quote":
236
238
  return n != null && n.inline && !e.includes(`
237
239
 
238
- `) ? `> ${e}` : w(P(w(e), "blockquote"));
240
+ `) ? `> ${e}` : f(T(f(e), "blockquote"));
239
241
  case "dropdown":
240
- const c = P(se(s.summary), "summary");
241
- return w(P([c, e].join(`
242
+ const c = T(N(s.summary), "summary");
243
+ return f(T([c, e].join(`
242
244
  `), "details", s.open ? "open" : void 0));
243
245
  }
244
- }, L = (e) => {
246
+ }, W = (e) => {
245
247
  const t = /(\/\/[^\n]*|\/\*[\s\S]*?\*\/|<!--[\s\S]*?-->)/gm, n = [];
246
248
  let s;
247
249
  for (; (s = t.exec(e)) !== null; ) {
248
- const o = [s.index, s.index + s[0].length], r = Ue(s[0]).trim();
250
+ const o = [s.index, s.index + s[0].length], r = Be(s[0]).trim();
249
251
  n.push({ range: o, value: r });
250
252
  }
251
253
  return n;
252
- }, Ue = (e) => e.startsWith("//") ? e.slice(2) : e.startsWith("/*") ? e.slice(2, -2) : e.startsWith("<!--") ? e.slice(4, -3) : e, oe = [
254
+ }, Be = (e) => e.startsWith("//") ? e.slice(2) : e.startsWith("/*") ? e.slice(2, -2) : e.startsWith("<!--") ? e.slice(4, -3) : e, te = [
253
255
  "p↓:",
254
256
  "pd:",
255
257
  "parkdown:"
256
- ], Qe = [
258
+ ], Fe = [
257
259
  "splice(delete?: number, insert?: string)"
258
- ], V = I(Qe), d = (e, t, n) => (n ?? L(e)).filter(({ value: s }) => s.includes(t)).sort((s, o) => s.range[0] - o.range[0]), J = (e) => ({
260
+ ];
261
+ P(Fe);
262
+ const ne = (e, t) => e.range[0] - t.range[0], se = (e, t, n) => (n ?? W(e)).filter(({ value: s }) => s.includes(t)).sort(ne), V = (e) => ({
259
263
  isSpace: e === " ",
260
264
  isNewline: e === `
261
265
  ` || e === void 0
262
- }), Z = (e) => oe.flatMap((t) => d(e, t)).sort((t, n) => t.range[0] - n.range[0]).reverse().reduce((t, { range: [n, s], value: o }) => {
263
- const r = (a, p) => t.slice(0, a) + t.slice(p), i = J(t[n - 1]), c = J(t[s]), l = s === t.length;
264
- return i.isNewline && c.isNewline ? r(n - (l ? 1 : 0), s + 1) : i.isNewline ? r(n, s + (c.isSpace ? 1 : 0)) : r(n - (i.isSpace ? 1 : 0), s);
265
- }, e), re = oe.map((e) => new RegExp(`^${Te(e)}(\\?[^\\s]+)`)), Ge = (e) => re.map((t) => {
266
- var n;
267
- return (n = t.exec(e)) == null ? void 0 : n[1];
268
- }).filter(Boolean).map((t) => new URLSearchParams(t))[0], q = (e, t) => (Array.isArray(t) ? t.flatMap((n) => d(e, n)) : d(e, t)).filter(({ value: n }) => re.some((s) => s.test(n))).sort((n, s) => n.range[0] - s.range[0]).reverse().reduce((n, { range: [s, o], value: r }) => {
269
- var l, a;
270
- const i = Ge(r), c = ["back", "front"].map((p) => [p, i.get(p)]).filter(([p, m]) => !!m).reduce(
271
- (p, [m, u]) => p.set(m, u.split(T)),
272
- /* @__PURE__ */ new Map()
273
- );
274
- return n = ((l = c.get("back")) == null ? void 0 : l.reduce((p, m) => {
275
- const u = V(m);
276
- if (u.name === "splice")
277
- return p.slice(0, o) + (u.insert ?? "") + p.slice(o + (u.delete ?? 0));
278
- }, n)) ?? n, n = ((a = c.get("front")) == null ? void 0 : a.reduce((p, m) => {
279
- const u = V(m);
280
- if (u.name === "splice")
281
- return p.slice(0, s - (u.delete ?? 0)) + (u.insert ?? "") + p.slice(s);
282
- }, n)) ?? n, n;
283
- }, e), He = [
266
+ }), J = (e) => te.flatMap((t) => se(e, t)).sort((t, n) => t.range[0] - n.range[0]).reverse().reduce((t, { range: [n, s], value: o }) => {
267
+ const r = (p, b) => t.slice(0, p) + t.slice(b), i = V(t[n - 1]), c = V(t[s]), l = s === t.length;
268
+ let a = n;
269
+ for (; a > 0 && t[a - 1] !== `
270
+ `; ) a--;
271
+ const u = t.slice(a, n).trim() === "";
272
+ return i.isNewline && c.isNewline ? r(n - (l ? 1 : 0), s + 1) : i.isNewline || u ? r(a, s + (c.isSpace || c.isNewline ? 1 : 0)) : r(n - (i.isSpace ? 1 : 0), s);
273
+ }, e);
274
+ te.map((e) => new RegExp(`^${Oe(e)}(\\?[^\\s]+)`));
275
+ const Ue = [
284
276
  /**
285
277
  * Extract regions from the retrieved content between comments that INCLUDE the specified ids.
286
278
  * @param id The id of the comment to extract.
@@ -306,106 +298,141 @@ const T = /,\s*(?![^()]*\))/, Q = {
306
298
  * @param id The id of the comment to replace.
307
299
  * @param with The replacement content (if ommitted, the content of the detected comment will be used).
308
300
  * @param space The space character to use between words in the replacement content (defaults to `-`).
309
- * @param expandLeft ADVANCED: The number of characters to expand the left side of the comment.
310
- * @param expandRight ADVANCED: The number of characters to expand the right side of the comment.
311
301
  * @example [](<url>?region=replace(specifier))
312
302
  * @example [](<url>?region=replace(specifier,new-content))
313
303
  * @example [](<url>?region=replace(specifier,new_content,_)
314
304
  */
315
- "replace(id: string, with?: string, space?: string, expandLeft?: number, expandRight?: number)"
316
- ], ze = I(He), Xe = (e, ...t) => {
305
+ "replace(id: string, with?: string, space?: string)",
306
+ /**
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.
326
+ * @param id The id of the comment regions to act on.
327
+ * @param from The content to replace.
328
+ * @param to The content to replace with.
329
+ * @param space The space character to use between words in the content to replace (defaults to `-`).
330
+ * @example [](<url>?region=remap(specifier,hello-world,hello-universe))
331
+ * @example [](<url>?region=remap(specifier,hello_world,hello_universe,_)
332
+ */
333
+ "remap(id: string, from: string, to: string, space?: string)"
334
+ ], He = P(Ue), w = (e, t, n) => {
335
+ const s = se(e, t, n), 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, ...t) => {
317
340
  if (t.length === 0) return e;
318
- e = q(e, t);
319
- const n = L(e), s = ([i, c]) => e.slice(i, c), o = new v(), r = new v();
320
- for (const i of t) {
321
- const c = d(e, i, n);
322
- for (let l = 0; l < c.length - 1; l += 2) {
323
- const a = c[l], p = c[l + 1];
324
- o.push(a.range[1], p.range[0]);
325
- const [m, ...u] = s([a.range[1], p.range[0]]), $ = u[u.length - 1];
326
- r.push(a.range[0], a.range[1] + (m.trim() ? 0 : 1)), r.push(p.range[0], p.range[1] + ($.trim() ? 0 : 1));
341
+ const n = W(e), s = ([i, c]) => e.slice(i, c), o = new d(), r = new d();
342
+ for (const i of t)
343
+ for (const [c, l] of w(e, i, n)) {
344
+ o.push(c.range[1], l.range[0]);
345
+ const [a, ...u] = s([c.range[1], l.range[0]]), p = u[u.length - 1];
346
+ r.push(c.range[0], c.range[1] + (a.trim() ? 0 : 1)), r.push(l.range[0], l.range[1] + (p.trim() ? 0 : 1));
327
347
  }
328
- }
329
- return o.collapse(), r.collapse(), A(
348
+ return o.collapse(), r.collapse(), j(
330
349
  o.subtract(r).map(s).filter(Boolean).join("")
331
350
  ).trim();
332
- }, Ve = (e, ...t) => {
351
+ }, Qe = (e, ...t) => {
333
352
  if (t.length === 0) return e;
334
- e = q(e, t);
335
- const n = L(e), s = ([i, c]) => e.slice(i, c), o = new v();
336
- for (const i of t) {
337
- const c = d(e, i, n);
338
- for (let l = 0; l < c.length - 1; l += 2) {
339
- const a = c[l], p = c[l + 1], m = s([p.range[1], p.range[1] + 1]).at(-1);
340
- o.push(a.range[0], m === `
341
- ` ? p.range[1] + 1 : p.range[1]);
353
+ const n = W(e), s = ([i, c]) => e.slice(i, c), o = new d();
354
+ for (const i of t)
355
+ for (const [c, l] of w(e, i, n)) {
356
+ const a = s([l.range[1], l.range[1] + 1]).at(-1);
357
+ o.push(c.range[0], a === `
358
+ ` ? l.range[1] + 1 : l.range[1]);
342
359
  }
343
- }
344
360
  o.collapse();
345
- const r = new v();
346
- return r.push(0, e.length), r.subtract(o), A(
361
+ const r = new d([0, e.length]);
362
+ return r.subtract(o), j(
347
363
  r.collapse().map(s).filter(Boolean).join("")
348
364
  ).trim();
349
- }, K = (e, t) => {
350
- const n = d(e, t), s = [];
351
- for (let o = 0; o < n.length - 1; o += 2)
352
- s.push([n[o], n[o + 1]]);
353
- return s;
354
- }, Je = (e, t, n) => {
355
- const [s, o] = n;
356
- return e && (s.range[0] -= e), t && (o.range[1] += t), n;
357
- }, Ze = (e, t, n, s, o, r) => {
358
- if (!t || (e = q(e, t), d(e, t).length < 2)) return e;
359
- let c = "", l = 0;
360
- const a = Je.bind(null, o, r);
361
- for (const [m, u] of K(e, t).map(a))
362
- c += e.slice(l, m.range[1]), c += se(n ?? m.value, s), l = u.range[0];
363
- c += e.slice(l);
364
- const p = new v();
365
- return p.push(0, c.length), p.subtract(new v(
366
- ...K(c, t).map(a).flatMap(([m, u]) => [m.range, u.range])
367
- )), A(
368
- p.collapse().map(([m, u]) => c.slice(m, u)).filter(Boolean).join("")
365
+ }, ze = (e, t, n, s) => {
366
+ if (!t) return e;
367
+ let o = "", r = 0;
368
+ for (const [c, l] of w(e, t))
369
+ o += e.slice(r, c.range[1]), o += N(n ?? c.value, s), r = l.range[0];
370
+ o += e.slice(r);
371
+ const i = new d([0, o.length]);
372
+ return i.subtract(new d(
373
+ ...w(o, t).flatMap(([c, l]) => [c.range, l.range])
374
+ )), j(
375
+ i.collapse().map(([c, l]) => o.slice(c, l)).filter(Boolean).join("")
369
376
  ).trim();
370
- }, Ke = (e, t, n) => {
371
- if (!t) return Z(e);
372
- const s = ze(t);
377
+ }, Xe = (e, t, n, s, o) => {
378
+ if (!t) return e;
379
+ const r = n === void 0 ? !1 : n >= 0, i = s ? N(s, o) : "", c = n ?? 0;
380
+ return w(e, t).map((l) => l[r ? 1 : 0]).sort(ne).reverse().reduce(
381
+ (l, { range: a }) => r ? l.slice(0, a[1]) + i + l.slice(Math.min(a[1] + c, l.length)) : l.slice(0, Math.max(a[0] + c, 0)) + i + l.slice(a[0]),
382
+ e
383
+ );
384
+ }, Ve = (e, t, n, s, o) => {
385
+ if (!t) return e;
386
+ let r = "", i = 0;
387
+ const c = [n, s].map((l) => N(l, o));
388
+ console.log(c);
389
+ for (const [l, a] of w(e, t))
390
+ r += e.slice(i, l.range[1]), r += e.slice(l.range[1], a.range[0]).replaceAll(c[0], c[1]), i = a.range[0];
391
+ return r += e.slice(i), r;
392
+ }, Je = (e, t, n) => {
393
+ if (!t) return J(e);
394
+ const s = He(t);
373
395
  switch (s.name) {
374
396
  case "extract":
375
- e = Xe(e, s.id, ...z(s));
397
+ e = Ge(e, s.id, ...z(s));
376
398
  break;
377
399
  case "remove":
378
- e = Ve(e, s.id, ...z(s));
400
+ e = Qe(e, s.id, ...z(s));
379
401
  break;
380
402
  case "replace":
381
- const { with: o, id: r, space: i, expandLeft: c, expandRight: l } = s;
382
- e = Ze(e, r, o, i, c, l);
403
+ e = ze(e, s.id, s.with, s.space);
404
+ break;
405
+ case "splice":
406
+ e = Xe(e, s.id, s.deleteCount, s.insert, s.space);
407
+ break;
408
+ case "remap":
409
+ e = Ve(e, s.id, s.from, s.to, s.space);
383
410
  break;
384
411
  }
385
- return n ? Z(e) : e;
386
- }, Ye = ["http", "./", "../"], et = ({ url: e }) => Ye.some((t) => e.startsWith(t)), tt = (e) => j(e) && Ne(e) && et(e), ie = ({ url: e }, t) => `[](${t ? S(t, e) : e})`, h = {
412
+ return n ? J(e) : e;
413
+ }, Ze = ["http", "./", "../"], Ke = ({ url: e }) => Ze.some((t) => e.startsWith(t)), Ye = (e) => D(e) && xe(e) && Ke(e), oe = ({ url: e }, t) => `[](${t ? y(t, e) : e})`, m = {
387
414
  _open: "<!--",
388
415
  _close: "-->",
389
416
  _flag: "p↓",
390
417
  get begin() {
391
- return x(h._open, h._flag, "BEGIN", h._close);
418
+ return E(m._open, m._flag, "BEGIN", m._close);
392
419
  },
393
420
  get end() {
394
- return x(h._open, h._flag, "END", h._close);
421
+ return E(m._open, m._flag, "END", m._close);
395
422
  },
396
423
  lengthOf(e) {
397
424
  const t = `lines: ${e.split(`
398
425
  `).length}`, n = `chars: ${e.length}`;
399
- return x(h._open, h._flag, "length", t, n, h._close);
426
+ return E(m._open, m._flag, "length", t, n, m._close);
400
427
  }
401
- }, Y = (e) => (t) => j(t) && t.value === h[e], nt = ({ position: e, url: t, siblingCount: n }, s) => ({ position: e, url: t, headingDepth: s, inline: n >= 1 }), st = ({ position: { start: e }, url: t, siblingCount: n }, { position: { end: s } }, o) => ({ position: { start: e, end: s }, url: t, headingDepth: o, inline: n >= 1 }), ot = (e, t, n) => (e.inline ? x : Me)(
402
- ie(e, n),
403
- h.begin,
404
- h.lengthOf(t),
428
+ }, Z = (e) => (t) => D(t) && t.value === m[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 } }, o) => ({ position: { start: e, end: s }, url: t, headingDepth: o, inline: n >= 1 }), nt = (e, t, n) => (e.inline ? E : be)(
429
+ oe(e, n),
430
+ m.begin,
431
+ m.lengthOf(t),
405
432
  t,
406
- h.end
407
- ), rt = (e) => {
408
- const t = b(e, "heading").reduce((n, { position: s, depth: o }) => n.set(s.start.line, o), /* @__PURE__ */ new Map());
433
+ m.end
434
+ ), st = (e) => {
435
+ const t = S(e, "heading").reduce((n, { position: s, depth: o }) => n.set(s.start.line, o), /* @__PURE__ */ new Map());
409
436
  return (n) => {
410
437
  for (let s = n.position.start.line; s >= 1; s--) {
411
438
  const o = t.get(s);
@@ -413,113 +440,113 @@ const T = /,\s*(?![^()]*\))/, Q = {
413
440
  }
414
441
  return 0;
415
442
  };
416
- }, N = {
443
+ }, x = {
417
444
  openingCommentDoesNotFollowLink: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) does not follow link`),
418
445
  closingCommentNotMatchedToOpening: ({ position: { start: e } }) => new Error(`Closing comment (@${e.line}:${e.column}) does not match to opening comment`),
419
446
  openingCommentNotClosed: ({ position: { start: e } }) => new Error(`Opening comment (@${e.line}:${e.column}) is not followed by a closing comment`)
420
- }, it = (e, t) => {
447
+ }, ot = (e, t) => {
421
448
  const n = [], s = [
422
449
  ...e.map((r) => ({ node: r, type: "open" })),
423
450
  ...t.map((r) => ({ node: r, type: "close" }))
424
- ].sort((r, i) => f(r.node, i.node)), o = [];
451
+ ].sort((r, i) => h(r.node, i.node)), o = [];
425
452
  for (const r of s)
426
453
  if (r.type === "open") o.push(r);
427
454
  else {
428
455
  const i = r.node;
429
456
  if (o.length === 0)
430
- throw N.closingCommentNotMatchedToOpening(i);
457
+ throw x.closingCommentNotMatchedToOpening(i);
431
458
  const c = o.pop().node;
432
459
  if (o.length > 0) continue;
433
460
  n.push({ open: c, close: i });
434
461
  }
435
462
  if (o.length > 0)
436
- throw N.openingCommentNotClosed(o[0].node);
463
+ throw x.openingCommentNotClosed(o[0].node);
437
464
  return n;
438
- }, ct = (e, t, n) => {
439
- const s = [...t].sort(f), o = [];
440
- return [...n].sort((r, i) => f.reverse(r.open, i.open)).forEach((r) => {
465
+ }, rt = (e, t, n) => {
466
+ const s = [...t].sort(h), o = [];
467
+ return [...n].sort((r, i) => h.reverse(r.open, i.open)).forEach((r) => {
441
468
  for (; s.length > 0; ) {
442
469
  const i = s.pop();
443
470
  if (i.position.start.offset < r.open.position.start.offset) {
444
- if (ke(e, i, r.open).trim() !== "")
445
- throw N.openingCommentDoesNotFollowLink(r.open);
471
+ if (Ne(e, i, r.open).trim() !== "")
472
+ throw x.openingCommentDoesNotFollowLink(r.open);
446
473
  return o.push([i, r]);
447
474
  }
448
475
  o.push(i);
449
476
  }
450
- throw N.openingCommentDoesNotFollowLink(r.open);
477
+ throw x.openingCommentDoesNotFollowLink(r.open);
451
478
  }), o.push(...s.reverse()), o.reverse();
452
- }, ce = (e, t) => {
453
- t ?? (t = D.md(e));
454
- const n = rt(t), s = b(t, "link").filter(tt), o = b(t, "html").sort(f), r = o.filter(Y("begin")), i = o.filter(Y("end")), c = it(r, i);
455
- return ct(e, s, c).map((a) => Array.isArray(a) ? st(a[0], a[1].close, n(a[0])) : nt(a, n(a)));
456
- }, lt = (e, { url: t }) => (n) => e(S(O(t), n)), le = (...e) => {
479
+ }, re = (e, t) => {
480
+ t ?? (t = I.md(e));
481
+ const n = st(t), s = S(t, "link").filter(Ye), o = S(t, "html").sort(h), r = o.filter(Z("begin")), i = o.filter(Z("end")), c = ot(r, i);
482
+ return rt(e, s, c).map((a) => Array.isArray(a) ? tt(a[0], a[1].close, n(a[0])) : et(a, n(a)));
483
+ }, it = (e, { url: t }) => (n) => e(y(A(t), n)), ie = (...e) => {
457
484
  const t = e.reduce((n, s) => n + s, 0);
458
485
  return Math.min(Math.max(t, 1), 6);
459
- }, at = (e, t, n) => {
486
+ }, ct = (e, t, n) => {
460
487
  if (t === 0) return e;
461
- n ?? (n = D.md(e));
462
- const s = b(n, "heading"), o = e.split(`
488
+ n ?? (n = I.md(e));
489
+ const s = S(n, "heading"), o = e.split(`
463
490
  `);
464
491
  for (const r of s) {
465
- const { depth: i, position: { start: c, end: l } } = r, a = le(i, t), p = o[c.line - 1].slice(i, l.column), m = "#".repeat(a) + p;
466
- o[c.line - 1] = m, r.depth = a;
492
+ const { depth: i, position: { start: c, end: l } } = r, a = ie(i, t), u = o[c.line - 1].slice(i, l.column), p = "#".repeat(a) + u;
493
+ o[c.line - 1] = p, r.depth = a;
467
494
  }
468
495
  return o.join(`
469
496
  `);
470
- }, ae = (e) => ce(e).reverse().sort(f.reverse).reduce((t, n) => ne(t, ie(n), n), e), pe = (e, t, n, s, o) => {
497
+ }, ce = (e) => re(e).reverse().sort(h.reverse).reduce((t, n) => ee(t, oe(n), n), e), le = (e, t, n, s, o) => {
471
498
  try {
472
- e = ae(e), e = at(e, t);
473
- const r = D.md(e);
474
- return ce(e, r).sort(f).reverse().map((i) => {
475
- var B, F;
476
- const { url: c, headingDepth: l } = i, [a, ...p] = Ce(c).split("?"), m = a.split(".").pop() ?? "", u = p.join("?"), $ = O(c), W = S($, a);
499
+ e = ce(e), e = ct(e, t);
500
+ const r = I.md(e);
501
+ return re(e, r).sort(h).reverse().map((i) => {
502
+ var q, B;
503
+ const { url: c, headingDepth: l } = i, [a, ...u] = ve(c).split("?"), p = a.split(".").pop() ?? "", b = u.join("?"), k = A(c), L = y(k, a);
477
504
  if (c.startsWith("./") || c.startsWith("../")) {
478
- let g = n(W);
479
- const C = new ye(u), k = (B = C.get("region")) == null ? void 0 : B.split(T);
480
- g = (k == null ? void 0 : k.reduce(
481
- (y, E, R, { length: de }) => Ke(y, E, R === de - 1),
505
+ let g = n(L);
506
+ const v = new $e(b), M = (q = v.get("region")) == null ? void 0 : q.split(U);
507
+ g = (M == null ? void 0 : M.reduce(
508
+ ($, C, R, { length: he }) => Je($, C, R === he - 1),
482
509
  g
483
510
  )) ?? g;
484
- const he = C.has("skip"), ge = C.get("heading") ?? 0, fe = C.has("inline");
485
- let { inline: M } = i;
486
- if (fe && (M = !0), !he)
487
- if (m === "md") {
488
- const y = lt(n, i), E = o ? S(o, $) : $, R = le(l, Number(ge));
489
- g = pe(
511
+ const me = v.has("skip"), ue = v.get("heading") ?? 0, ge = v.has("inline");
512
+ let { inline: _ } = i;
513
+ if (ge && (_ = !0), !me)
514
+ if (p === "md") {
515
+ const $ = it(n, i), C = o ? y(o, k) : k, R = ie(l, Number(ue));
516
+ g = le(
490
517
  g,
491
518
  /** p↓: ... */
492
519
  R,
493
- y,
494
- W,
495
- E
520
+ $,
521
+ L,
522
+ C
496
523
  /** p↓: ... */
497
524
  );
498
- } else /^(js|ts)x?|svelte$/i.test(m) && (g = X(
525
+ } else /^(js|ts)x?|svelte$/i.test(p) && (g = X(
499
526
  g,
500
527
  "code",
501
528
  /** p↓: ... */
502
- { extension: m, inline: M }
529
+ { extension: p, inline: _ }
503
530
  /** p↓: ... */
504
531
  ));
505
- const _ = (F = C.get("wrap")) == null ? void 0 : F.split(T);
506
- return g = (_ == null ? void 0 : _.reduce((y, E) => X(y, E, { extension: m, inline: M }), g)) ?? g, { target: i, content: ot(i, g, o) };
532
+ const O = (B = v.get("wrap")) == null ? void 0 : B.split(U);
533
+ return g = (O == null ? void 0 : O.reduce(($, C) => X($, C, { extension: p, inline: _ }), g)) ?? g, { target: i, content: nt(i, g, o) };
507
534
  } else throw c.startsWith("http") ? new Error("External web links are not implemented yet") : new Error(`Unsupported link type: ${c}`);
508
- }).reduce((i, { target: c, content: l }) => ne(i, l, c), e);
535
+ }).reduce((i, { target: c, content: l }) => ee(i, l, c), e);
509
536
  } catch (r) {
510
537
  throw new Error(`Error populating inclusions in file ${s ?? "(unknown)"}: ${r}`);
511
538
  }
512
- }, me = (e) => $e(e, "utf-8"), ue = (e) => {
513
- const t = te(e), n = O(t);
514
- return { markdown: me(t), dir: n, path: t };
515
- }, vt = (e, t = !0) => {
516
- const { dir: n, path: s, markdown: o } = ue(e), i = pe(o, 0, (c) => me(te(n, Re(c))), s);
517
- return t && ee(s, i), i;
518
- }, $t = (e, t = !0) => {
519
- const { path: n, markdown: s } = ue(e), o = ae(s);
520
- return t && ee(n, o), o;
539
+ }, ae = (e) => we(e, "utf-8"), pe = (e) => {
540
+ const t = Y(e), n = A(t);
541
+ return { markdown: ae(t), dir: n, path: t };
542
+ }, dt = (e, t = !0) => {
543
+ const { dir: n, path: s, markdown: o } = pe(e), i = le(o, 0, (c) => ae(Y(n, Me(c))), s);
544
+ return t && K(s, i), i;
545
+ }, wt = (e, t = !0) => {
546
+ const { path: n, markdown: s } = pe(e), o = ce(s);
547
+ return t && K(n, o), o;
521
548
  };
522
549
  export {
523
- $t as depopulateMarkdownInclusions,
524
- vt as populateMarkdownInclusions
550
+ wt as depopulateMarkdownInclusions,
551
+ dt as populateMarkdownInclusions
525
552
  };
@@ -1,13 +1,15 @@
1
- (function(m,h){typeof exports=="object"&&typeof module<"u"?h(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"],h):(m=typeof globalThis<"u"?globalThis:m||self,h(m.index={},m.node_fs,m.node_path,m.node_url,m.unified,m.remarkParse,m.unistUtilVisit,m.tsDedent))})(this,function(m,h,g,me,de,he,ge,T){"use strict";var on=Object.defineProperty;var rn=(m,h,g)=>h in m?on(m,h,{enumerable:!0,configurable:!0,writable:!0,value:g}):m[h]=g;var ue=(m,h,g)=>rn(m,typeof h!="symbol"?h+"":h,g);const v=(e,n)=>e.position.start.offset-n.position.start.offset;v.reverse=(e,n)=>v(n,e);const j=e=>e.position!==void 0&&e.position.start.offset!==void 0&&e.position.end.offset!==void 0,fe=de.unified().use(he),q={md:e=>fe.parse(e)},N=(e,n)=>{const t=[];return ge.visit(e,(s,o,r)=>{if(s.type!=="root"){if(n&&s.type!==n)return;if(j(s)){const i=((r==null?void 0:r.children.length)??0)-1;t.push({...s,siblingIndex:o,siblingCount:i})}}}),t},we=e=>e.children.length===0,B=(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)},b=(...e)=>e.join(" "),$e=(...e)=>e.join(`
2
- `),ye=e=>{const n=e.split("?");return n.length>1?[n.slice(0,-1).join("?"),n.at(-1)]:[e,""]},Ce=e=>ye(e)[0];class y{constructor(...n){ue(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,c]=n[r];i<=o?o=Math.max(o,c):(t.push([s,o]),s=i,o=c)}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 c=[];for(const[l,a]of o){if(i<=l||r>=a){c.push([l,a]);continue}r>l&&c.push([l,r]),i<a&&c.push([i,a])}o=c}return this.intervals=o}}const O=/,\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:"`"}},xe="-",U={static:[["'''",'"'],["''","'"],[/parkdown:\s+/g,""],[/p↓:\s+/g,""]],url:[...Object.entries(F.unsafe),...Object.entries(F.reserved)]},Q=(e,[n,t])=>e.replaceAll(n,t),G=(e,n=xe)=>{const t=U.static.reduce(Q,e);return U.url.map(([s,o])=>[n+s+n,o]).reduce(Q,t).replaceAll(n," ")},Ee=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Se=["string","number","boolean"],ke=e=>Se.includes(e),Ne=/^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/,be=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=Te(s);return{name:t,parameters:o}},Me=(e,n)=>{for(let t=n+1;t<e.length;t++)if(e[t]!==void 0)return!1;return!0},Te=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 c=e.at(o+2)==="'";s=!s,t+=c?"'''":"''",o+=c?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?je(o):void 0).filter((o,r,i)=>o!==void 0||!Me(i,r))},je=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)},qe=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 c;for(;(c=r.exec(o))!==null;){const[,l,a,p]=c,u=p.trim();if(!ke(u))throw new Error(`Unsupported type: ${u}`);i.push({name:l,optional:a==="?",type:u})}return{name:s,parameters:i}},P=e=>{const n=e.map(qe).reduce((t,{name:s,parameters:o})=>t.set(s,o),new Map);return t=>{const{name:s,parameters:o}=be(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:l})=>!l).length,c=i===r.length?i.toString():`${i} - ${r.length}`;throw new Error(`Too many parameters: ${o.length} for method '${s}' (expected: ${c})`)}return r.reduce((i,{name:c,optional:l,type:a},p)=>{const u=o[p];if(u===void 0){if(l)return i;throw new Error(`Missing required parameter: ${c} for method '${s}'`)}switch(a){case"string":i[c]=u;break;case"number":case"boolean":i[c]=JSON.parse(u);break}if(typeof i[c]!==a)throw new Error(`Invalid type: ${c} must be ${a}, got ${typeof i[c]} for method '${s}'`);return i},{name:s})}},H=e=>Object.entries(e).filter(([n])=>n!=="name"&&!isNaN(Number(n))).map(([n,t])=>t),Oe=P(["code(lang?: string, meta?: string)","quote()","dropdown(summary: string, open?: boolean, space?: string)"]),C=(e,n=1)=>`
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,pe,ue,me,de,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 ae=(p,m,d)=>sn(p,typeof m!="symbol"?m+"":m,d);const w=(e,n)=>e.position.start.offset-n.position.start.offset;w.reverse=(e,n)=>w(n,e);const T=e=>e.position!==void 0&&e.position.start.offset!==void 0&&e.position.end.offset!==void 0,fe=ue.unified().use(me),j={md:e=>fe.parse(e)},k=(e,n)=>{const t=[];return de.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(w);const s=t.at(0),o=t.at(-1);return e.slice(0,s.position.start.offset)+n+e.slice(o.position.end.offset)},ge=(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)},x=(...e)=>e.join(" "),we=(...e)=>e.join(`
2
+ `),ve=e=>{const n=e.split("?");return n.length>1?[n.slice(0,-1).join("?"),n.at(-1)]:[e,""]},$e=e=>ve(e)[0];class v{constructor(...n){ae(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,c]=n[r];i<=o?o=Math.max(o,c):(t.push([s,o]),s=i,o=c)}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 c=[];for(const[l,a]of o){if(i<=l||r>=a){c.push([l,a]);continue}r>l&&c.push([l,r]),i<a&&c.push([i,a])}o=c}return this.intervals=o}}const F=/,\s*(?![^()]*\))/,B={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
+ `}},Ce="-",U={static:[["'''",'"'],["''","'"],[/parkdown:\s+/g,""],[/p↓:\s+/g,""]],url:[...Object.entries(B.unsafe),...Object.entries(B.reserved)]},H=(e,[n,t])=>e.replaceAll(n,t),N=(e,n=Ce)=>{const t=U.static.reduce(H,e);return U.url.map(([s,o])=>[n+s+n,o]).reduce(H,t).replaceAll(n," ")},ye=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Se=["string","number","boolean"],Ee=e=>Se.includes(e),ke=/^([a-zA-Z0-9_-]+)(?:\(([^)]*)\))?$/,xe=e=>{const n=e.match(ke);if(!n)throw new Error(`Invalid invocation: ${e}`);const[,t,s=""]=n;if(!s.trim())return{name:t,parameters:[]};const o=be(s);return{name:t,parameters:o}},Ne=(e,n)=>{for(let t=n+1;t<e.length;t++)if(e[t]!==void 0)return!1;return!0},be=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 c=e.at(o+2)==="'";s=!s,t+=c?"'''":"''",o+=c?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?Me(o):void 0).filter((o,r,i)=>o!==void 0||!Ne(i,r))},Me=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)},Te=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 c;for(;(c=r.exec(o))!==null;){const[,l,a,h]=c,u=h.trim();if(!Ee(u))throw new Error(`Unsupported type: ${u}`);i.push({name:l,optional:a==="?",type:u})}return{name:s,parameters:i}},O=e=>{const n=e.map(Te).reduce((t,{name:s,parameters:o})=>t.set(s,o),new Map);return t=>{const{name:s,parameters:o}=xe(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:l})=>!l).length,c=i===r.length?i.toString():`${i} - ${r.length}`;throw new Error(`Too many parameters: ${o.length} for method '${s}' (expected: ${c})`)}return r.reduce((i,{name:c,optional:l,type:a},h)=>{const u=o[h];if(u===void 0){if(l)return i;throw new Error(`Missing required parameter: ${c} for method '${s}'`)}switch(a){case"string":i[c]=u;break;case"number":case"boolean":i[c]=JSON.parse(u);break}if(typeof i[c]!==a)throw new Error(`Invalid type: ${c} must be ${a}, got ${typeof i[c]} for method '${s}'`);return i},{name:s})}},G=e=>Object.entries(e).filter(([n])=>n!=="name"&&!isNaN(Number(n))).map(([n,t])=>t),je=O(["code(lang?: string, meta?: string)","quote()","dropdown(summary: string, open?: boolean, space?: string)"]),$=(e,n=1)=>`
3
4
  `.repeat(n)+e+`
4
- `.repeat(n),R=(e,n,t)=>`<${n}${t?` ${t}`:""}>${C(e)}</${n}>`,z=(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(`
5
- `))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(`
5
+ `.repeat(n),R=(e,n,t)=>`<${n}${t?` ${t}`:""}>${$(e)}</${n}>`,Q=(e,n,t)=>{const s=je(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 $(`\`\`\`${r}${i}${$(e)}\`\`\``);case"quote":return t!=null&&t.inline&&!e.includes(`
6
7
 
7
- `)?`> ${e}`:C(R(C(e),"blockquote"));case"dropdown":const c=R(G(s.summary),"summary");return C(R([c,e].join(`
8
- `),"details",s.open?"open":void 0))}},I=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=Pe(s[0]).trim();t.push({range:o,value:r})}return t},Pe=e=>e.startsWith("//")?e.slice(2):e.startsWith("/*")?e.slice(2,-2):e.startsWith("<!--")?e.slice(4,-3):e,V=["p↓:","pd:","parkdown:"],X=P(["splice(delete?: number, insert?: string)"]),$=(e,n,t)=>(t??I(e)).filter(({value:s})=>s.includes(n)).sort((s,o)=>s.range[0]-o.range[0]),J=e=>({isSpace:e===" ",isNewline:e===`
9
- `||e===void 0}),Z=e=>V.flatMap(n=>$(e,n)).sort((n,t)=>n.range[0]-t.range[0]).reverse().reduce((n,{range:[t,s],value:o})=>{const r=(a,p)=>n.slice(0,a)+n.slice(p),i=J(n[t-1]),c=J(n[s]),l=s===n.length;return i.isNewline&&c.isNewline?r(t-(l?1:0),s+1):i.isNewline?r(t,s+(c.isSpace?1:0)):r(t-(i.isSpace?1:0),s)},e),K=V.map(e=>new RegExp(`^${Ee(e)}(\\?[^\\s]+)`)),Re=e=>K.map(n=>{var t;return(t=n.exec(e))==null?void 0:t[1]}).filter(Boolean).map(n=>new URLSearchParams(n))[0],A=(e,n)=>(Array.isArray(n)?n.flatMap(t=>$(e,t)):$(e,n)).filter(({value:t})=>K.some(s=>s.test(t))).sort((t,s)=>t.range[0]-s.range[0]).reverse().reduce((t,{range:[s,o],value:r})=>{var l,a;const i=Re(r),c=["back","front"].map(p=>[p,i.get(p)]).filter(([p,u])=>!!u).reduce((p,[u,d])=>p.set(u,d.split(O)),new Map);return t=((l=c.get("back"))==null?void 0:l.reduce((p,u)=>{const d=X(u);if(d.name==="splice")return p.slice(0,o)+(d.insert??"")+p.slice(o+(d.delete??0))},t))??t,t=((a=c.get("front"))==null?void 0:a.reduce((p,u)=>{const d=X(u);if(d.name==="splice")return p.slice(0,s-(d.delete??0))+(d.insert??"")+p.slice(s)},t))??t,t},e),Ie=P(["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, expandLeft?: number, expandRight?: number)"]),Ae=(e,...n)=>{if(n.length===0)return e;e=A(e,n);const t=I(e),s=([i,c])=>e.slice(i,c),o=new y,r=new y;for(const i of n){const c=$(e,i,t);for(let l=0;l<c.length-1;l+=2){const a=c[l],p=c[l+1];o.push(a.range[1],p.range[0]);const[u,...d]=s([a.range[1],p.range[0]]),x=d[d.length-1];r.push(a.range[0],a.range[1]+(u.trim()?0:1)),r.push(p.range[0],p.range[1]+(x.trim()?0:1))}}return o.collapse(),r.collapse(),T.dedent(o.subtract(r).map(s).filter(Boolean).join("")).trim()},De=(e,...n)=>{if(n.length===0)return e;e=A(e,n);const t=I(e),s=([i,c])=>e.slice(i,c),o=new y;for(const i of n){const c=$(e,i,t);for(let l=0;l<c.length-1;l+=2){const a=c[l],p=c[l+1],u=s([p.range[1],p.range[1]+1]).at(-1);o.push(a.range[0],u===`
10
- `?p.range[1]+1:p.range[1])}}o.collapse();const r=new y;return r.push(0,e.length),r.subtract(o),T.dedent(r.collapse().map(s).filter(Boolean).join("")).trim()},Y=(e,n)=>{const t=$(e,n),s=[];for(let o=0;o<t.length-1;o+=2)s.push([t[o],t[o+1]]);return s},Le=(e,n,t)=>{const[s,o]=t;return e&&(s.range[0]-=e),n&&(o.range[1]+=n),t},We=(e,n,t,s,o,r)=>{if(!n||(e=A(e,n),$(e,n).length<2))return e;let c="",l=0;const a=Le.bind(null,o,r);for(const[u,d]of Y(e,n).map(a))c+=e.slice(l,u.range[1]),c+=G(t??u.value,s),l=d.range[0];c+=e.slice(l);const p=new y;return p.push(0,c.length),p.subtract(new y(...Y(c,n).map(a).flatMap(([u,d])=>[u.range,d.range]))),T.dedent(p.collapse().map(([u,d])=>c.slice(u,d)).filter(Boolean).join("")).trim()},_e=(e,n,t)=>{if(!n)return Z(e);const s=Ie(n);switch(s.name){case"extract":e=Ae(e,s.id,...H(s));break;case"remove":e=De(e,s.id,...H(s));break;case"replace":const{with:o,id:r,space:i,expandLeft:c,expandRight:l}=s;e=We(e,r,o,i,c,l);break}return t?Z(e):e},Be=["http","./","../"],Fe=({url:e})=>Be.some(n=>e.startsWith(n)),Ue=e=>j(e)&&we(e)&&Fe(e),ee=({url:e},n)=>`[](${n?g.join(n,e):e})`,f={_open:"<!--",_close:"-->",_flag:"p↓",get begin(){return b(f._open,f._flag,"BEGIN",f._close)},get end(){return b(f._open,f._flag,"END",f._close)},lengthOf(e){const n=`lines: ${e.split(`
11
- `).length}`,t=`chars: ${e.length}`;return b(f._open,f._flag,"length",n,t,f._close)}},ne=e=>n=>j(n)&&n.value===f[e],Qe=({position:e,url:n,siblingCount:t},s)=>({position:e,url:n,headingDepth:s,inline:t>=1}),Ge=({position:{start:e},url:n,siblingCount:t},{position:{end:s}},o)=>({position:{start:e,end:s},url:n,headingDepth:o,inline:t>=1}),He=(e,n,t)=>(e.inline?b:$e)(ee(e,t),f.begin,f.lengthOf(n),n,f.end),ze=e=>{const n=N(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}},M={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`)},Ve=(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 M.closingCommentNotMatchedToOpening(i);const c=o.pop().node;if(o.length>0)continue;t.push({open:c,close:i})}if(o.length>0)throw M.openingCommentNotClosed(o[0].node);return t},Xe=(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 M.openingCommentDoesNotFollowLink(r.open);return o.push([i,r])}o.push(i)}throw M.openingCommentDoesNotFollowLink(r.open)}),o.push(...s.reverse()),o.reverse()},te=(e,n)=>{n??(n=q.md(e));const t=ze(n),s=N(n,"link").filter(Ue),o=N(n,"html").sort(v),r=o.filter(ne("begin")),i=o.filter(ne("end")),c=Ve(r,i);return Xe(e,s,c).map(a=>Array.isArray(a)?Ge(a[0],a[1].close,t(a[0])):Qe(a,t(a)))},Je=(e,{url:n})=>t=>e(g.join(g.dirname(n),t)),se=(...e)=>{const n=e.reduce((t,s)=>t+s,0);return Math.min(Math.max(n,1),6)},Ze=(e,n,t)=>{if(n===0)return e;t??(t=q.md(e));const s=N(t,"heading"),o=e.split(`
12
- `);for(const r of s){const{depth:i,position:{start:c,end:l}}=r,a=se(i,n),p=o[c.line-1].slice(i,l.column),u="#".repeat(a)+p;o[c.line-1]=u,r.depth=a}return o.join(`
13
- `)},oe=e=>te(e).reverse().sort(v.reverse).reduce((n,t)=>B(n,ee(t),t),e),re=(e,n,t,s,o)=>{try{e=oe(e),e=Ze(e,n);const r=q.md(e);return te(e,r).sort(v).reverse().map(i=>{var ae,pe;const{url:c,headingDepth:l}=i,[a,...p]=g.basename(c).split("?"),u=a.split(".").pop()??"",d=p.join("?"),x=g.dirname(c),le=g.join(x,a);if(c.startsWith("./")||c.startsWith("../")){let w=t(le);const E=new me.URLSearchParams(d),D=(ae=E.get("region"))==null?void 0:ae.split(O);w=(D==null?void 0:D.reduce((S,k,_,{length:sn})=>_e(S,k,_===sn-1),w))??w;const en=E.has("skip"),nn=E.get("heading")??0,tn=E.has("inline");let{inline:L}=i;if(tn&&(L=!0),!en)if(u==="md"){const S=Je(t,i),k=o?g.join(o,x):x,_=se(l,Number(nn));w=re(w,_,S,le,k)}else/^(js|ts)x?|svelte$/i.test(u)&&(w=z(w,"code",{extension:u,inline:L}));const W=(pe=E.get("wrap"))==null?void 0:pe.split(O);return w=(W==null?void 0:W.reduce((S,k)=>z(S,k,{extension:u,inline:L}),w))??w,{target:i,content:He(i,w,o)}}else throw c.startsWith("http")?new Error("External web links are not implemented yet"):new Error(`Unsupported link type: ${c}`)}).reduce((i,{target:c,content:l})=>B(i,l,c),e)}catch(r){throw new Error(`Error populating inclusions in file ${s??"(unknown)"}: ${r}`)}},ie=e=>h.readFileSync(e,"utf-8"),ce=e=>{const n=g.resolve(e),t=g.dirname(n);return{markdown:ie(n),dir:t,path:n}},Ke=(e,n=!0)=>{const{dir:t,path:s,markdown:o}=ce(e),i=re(o,0,c=>ie(g.resolve(t,Ce(c))),s);return n&&h.writeFileSync(s,i),i},Ye=(e,n=!0)=>{const{path:t,markdown:s}=ce(e),o=oe(s);return n&&h.writeFileSync(t,o),o};m.depopulateMarkdownInclusions=Ye,m.populateMarkdownInclusions=Ke,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
8
+ `)?`> ${e}`:$(R($(e),"blockquote"));case"dropdown":const c=R(N(s.summary),"summary");return $(R([c,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=Oe(s[0]).trim();t.push({range:o,value:r})}return t},Oe=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.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]),c=J(n[s]),l=s===n.length;let a=t;for(;a>0&&n[a-1]!==`
11
+ `;)a--;const h=n.slice(a,t).trim()==="";return i.isNewline&&c.isNewline?r(t-(l?1:0),s+1):i.isNewline||h?r(a,s+(c.isSpace||c.isNewline?1:0)):r(t-(i.isSpace?1:0),s)},e);z.map(e=>new RegExp(`^${ye(e)}(\\?[^\\s]+)`));const Re=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)"]),C=(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},qe=(e,...n)=>{if(n.length===0)return e;const t=q(e),s=([i,c])=>e.slice(i,c),o=new v,r=new v;for(const i of n)for(const[c,l]of C(e,i,t)){o.push(c.range[1],l.range[0]);const[a,...h]=s([c.range[1],l.range[0]]),u=h[h.length-1];r.push(c.range[0],c.range[1]+(a.trim()?0:1)),r.push(l.range[0],l.range[1]+(u.trim()?0:1))}return o.collapse(),r.collapse(),M.dedent(o.subtract(r).map(s).filter(Boolean).join("")).trim()},Ie=(e,...n)=>{if(n.length===0)return e;const t=q(e),s=([i,c])=>e.slice(i,c),o=new v;for(const i of n)for(const[c,l]of C(e,i,t)){const a=s([l.range[1],l.range[1]+1]).at(-1);o.push(c.range[0],a===`
12
+ `?l.range[1]+1:l.range[1])}o.collapse();const r=new v([0,e.length]);return r.subtract(o),M.dedent(r.collapse().map(s).filter(Boolean).join("")).trim()},Ae=(e,n,t,s)=>{if(!n)return e;let o="",r=0;for(const[c,l]of C(e,n))o+=e.slice(r,c.range[1]),o+=N(t??c.value,s),r=l.range[0];o+=e.slice(r);const i=new v([0,o.length]);return i.subtract(new v(...C(o,n).flatMap(([c,l])=>[c.range,l.range]))),M.dedent(i.collapse().map(([c,l])=>o.slice(c,l)).filter(Boolean).join("")).trim()},Pe=(e,n,t,s,o)=>{if(!n)return e;const r=t===void 0?!1:t>=0,i=s?N(s,o):"",c=t??0;return C(e,n).map(l=>l[r?1:0]).sort(V).reverse().reduce((l,{range:a})=>r?l.slice(0,a[1])+i+l.slice(Math.min(a[1]+c,l.length)):l.slice(0,Math.max(a[0]+c,0))+i+l.slice(a[0]),e)},De=(e,n,t,s,o)=>{if(!n)return e;let r="",i=0;const c=[t,s].map(l=>N(l,o));console.log(c);for(const[l,a]of C(e,n))r+=e.slice(i,l.range[1]),r+=e.slice(l.range[1],a.range[0]).replaceAll(c[0],c[1]),i=a.range[0];return r+=e.slice(i),r},We=(e,n,t)=>{if(!n)return Z(e);const s=Re(n);switch(s.name){case"extract":e=qe(e,s.id,...G(s));break;case"remove":e=Ie(e,s.id,...G(s));break;case"replace":e=Ae(e,s.id,s.with,s.space);break;case"splice":e=Pe(e,s.id,s.deleteCount,s.insert,s.space);break;case"remap":e=De(e,s.id,s.from,s.to,s.space);break}return t?Z(e):e},_e=["http","./","../"],Le=({url:e})=>_e.some(n=>e.startsWith(n)),Fe=e=>T(e)&&he(e)&&Le(e),K=({url:e},n)=>`[](${n?d.join(n,e):e})`,f={_open:"<!--",_close:"-->",_flag:"p↓",get begin(){return x(f._open,f._flag,"BEGIN",f._close)},get end(){return x(f._open,f._flag,"END",f._close)},lengthOf(e){const n=`lines: ${e.split(`
13
+ `).length}`,t=`chars: ${e.length}`;return x(f._open,f._flag,"length",n,t,f._close)}},Y=e=>n=>T(n)&&n.value===f[e],Be=({position:e,url:n,siblingCount:t},s)=>({position:e,url:n,headingDepth:s,inline:t>=1}),Ue=({position:{start:e},url:n,siblingCount:t},{position:{end:s}},o)=>({position:{start:e,end:s},url:n,headingDepth:o,inline:t>=1}),He=(e,n,t)=>(e.inline?x:we)(K(e,t),f.begin,f.lengthOf(n),n,f.end),Ge=e=>{const n=k(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`)},Qe=(e,n)=>{const t=[],s=[...e.map(r=>({node:r,type:"open"})),...n.map(r=>({node:r,type:"close"}))].sort((r,i)=>w(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 c=o.pop().node;if(o.length>0)continue;t.push({open:c,close:i})}if(o.length>0)throw b.openingCommentNotClosed(o[0].node);return t},ze=(e,n,t)=>{const s=[...n].sort(w),o=[];return[...t].sort((r,i)=>w.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(ge(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=Ge(n),s=k(n,"link").filter(Fe),o=k(n,"html").sort(w),r=o.filter(Y("begin")),i=o.filter(Y("end")),c=Qe(r,i);return ze(e,s,c).map(a=>Array.isArray(a)?Ue(a[0],a[1].close,t(a[0])):Be(a,t(a)))},Ve=(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)},Xe=(e,n,t)=>{if(n===0)return e;t??(t=j.md(e));const s=k(t,"heading"),o=e.split(`
14
+ `);for(const r of s){const{depth:i,position:{start:c,end:l}}=r,a=ne(i,n),h=o[c.line-1].slice(i,l.column),u="#".repeat(a)+h;o[c.line-1]=u,r.depth=a}return o.join(`
15
+ `)},te=e=>ee(e).reverse().sort(w.reverse).reduce((n,t)=>L(n,K(t),t),e),se=(e,n,t,s,o)=>{try{e=te(e),e=Xe(e,n);const r=j.md(e);return ee(e,r).sort(w).reverse().map(i=>{var ce,le;const{url:c,headingDepth:l}=i,[a,...h]=d.basename(c).split("?"),u=a.split(".").pop()??"",I=h.join("?"),A=d.dirname(c),ie=d.join(A,a);if(c.startsWith("./")||c.startsWith("../")){let g=t(ie);const y=new pe.URLSearchParams(I),P=(ce=y.get("region"))==null?void 0:ce.split(F);g=(P==null?void 0:P.reduce((S,E,_,{length:nn})=>We(S,E,_===nn-1),g))??g;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=Ve(t,i),E=o?d.join(o,A):A,_=ne(l,Number(Ye));g=se(g,_,S,ie,E)}else/^(js|ts)x?|svelte$/i.test(u)&&(g=Q(g,"code",{extension:u,inline:D}));const W=(le=y.get("wrap"))==null?void 0:le.split(F);return g=(W==null?void 0:W.reduce((S,E)=>Q(S,E,{extension:u,inline:D}),g))??g,{target:i,content:He(i,g,o)}}else throw c.startsWith("http")?new Error("External web links are not implemented yet"):new Error(`Unsupported link type: ${c}`)}).reduce((i,{target:c,content:l})=>L(i,l,c),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{markdown:oe(n),dir:t,path:n}},Je=(e,n=!0)=>{const{dir:t,path:s,markdown:o}=re(e),i=se(o,0,c=>oe(d.resolve(t,$e(c))),s);return n&&m.writeFileSync(s,i),i},Ze=(e,n=!0)=>{const{path:t,markdown:s}=re(e),o=te(s);return n&&m.writeFileSync(t,o),o};p.depopulateMarkdownInclusions=Ze,p.populateMarkdownInclusions=Je,Object.defineProperty(p,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.10",
5
+ "version": "0.0.12",
6
6
  "main": "./dist/index.js",
7
7
  "bin": "./dist/cli.js",
8
8
  "files": [