@mdream/js 2.0.0-beta.1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +402 -126
  2. package/dist/_chunks/clean.mjs +526 -0
  3. package/dist/_chunks/const.mjs +3 -7
  4. package/dist/_chunks/extraction.d.mts +14 -0
  5. package/dist/_chunks/html.mjs +260 -0
  6. package/dist/_chunks/markdown-processor.mjs +1077 -828
  7. package/dist/_chunks/minimal.mjs +29 -0
  8. package/dist/_chunks/output-runner.mjs +54 -0
  9. package/dist/_chunks/parse.mjs +134 -1501
  10. package/dist/_chunks/plugin.mjs +14 -0
  11. package/dist/_chunks/src.mjs +291 -0
  12. package/dist/_chunks/tag-overrides.mjs +138 -0
  13. package/dist/_chunks/{plugins.mjs → tailwind.mjs} +145 -292
  14. package/dist/_chunks/text.mjs +583 -0
  15. package/dist/_chunks/types.d.mts +136 -126
  16. package/dist/_chunks/url.mjs +82 -0
  17. package/dist/_chunks/utils.mjs +659 -0
  18. package/dist/clean.d.mts +10 -0
  19. package/dist/clean.mjs +2 -0
  20. package/dist/cli.mjs +47 -8
  21. package/dist/html.d.mts +6 -0
  22. package/dist/html.mjs +2 -0
  23. package/dist/index.d.mts +5 -4
  24. package/dist/index.mjs +4 -58
  25. package/dist/parse.d.mts +15 -10
  26. package/dist/plugins.d.mts +13 -28
  27. package/dist/plugins.mjs +52 -2
  28. package/dist/preset/minimal.d.mts +14 -2
  29. package/dist/preset/minimal.mjs +1 -32
  30. package/dist/splitter.d.mts +12 -4
  31. package/dist/splitter.mjs +386 -113
  32. package/dist/text.d.mts +6 -0
  33. package/dist/text.mjs +2 -0
  34. package/package.json +34 -8
  35. package/dist/_chunks/index.d.mts +0 -9
  36. package/dist/_chunks/minimal.d.mts +0 -6
  37. package/dist/_chunks/resolve-plugins.mjs +0 -44
  38. package/dist/_chunks/stream.mjs +0 -37
  39. package/dist/core.d.mts +0 -15
  40. package/dist/core.mjs +0 -28
@@ -0,0 +1,526 @@
1
+ import "./const.mjs";
2
+ import { isInsideHeading } from "./utils.mjs";
3
+ import { resolveUrl } from "./url.mjs";
4
+ const ALL_RULES = {
5
+ urls: true,
6
+ fragments: true,
7
+ emptyLinks: true,
8
+ redundantLinks: true,
9
+ selfLinkHeadings: true,
10
+ emptyImages: true,
11
+ emptyLinkText: true
12
+ };
13
+ function clean(rules = ALL_RULES) {
14
+ const resolved = {
15
+ ...rules,
16
+ apply: (target) => resolved.fragments || resolved.redundantLinks || resolved.selfLinkHeadings ? startPass(resolved, target) : void 0,
17
+ url: rules.urls ? stripTrackingParams : void 0
18
+ };
19
+ return resolved;
20
+ }
21
+ const TRACKING_PARAM_RE = /^(?:utm_|fbclid|gclid|mc_eid|msclkid|oly_)/;
22
+ function stripTrackingParams(url) {
23
+ const queryStart = url.indexOf("?");
24
+ if (queryStart === -1) return url;
25
+ const fragmentStart = url.indexOf("#");
26
+ if (fragmentStart !== -1 && fragmentStart < queryStart) return url;
27
+ const queryEnd = fragmentStart === -1 ? url.length : fragmentStart;
28
+ const query = url.slice(queryStart + 1, queryEnd).split("&").filter((parameter) => !TRACKING_PARAM_RE.test(parameter)).join("&");
29
+ return `${url.slice(0, queryStart)}${query ? `?${query}` : ""}${url.slice(queryEnd)}`;
30
+ }
31
+ function startPass(rules, target) {
32
+ const fragments = rules.fragments === true;
33
+ const selfLinkHeadings = rules.selfLinkHeadings === true;
34
+ const redundantLinks = rules.redundantLinks === true;
35
+ const buffer = target.buffer;
36
+ const depthMap = target.depthMap;
37
+ const links = [];
38
+ const brackets = [];
39
+ const spans = [];
40
+ const spanFragments = [];
41
+ let closing = -1;
42
+ const headings = [];
43
+ let headingStart = -1;
44
+ return {
45
+ holdsOutput: fragments,
46
+ enter(element, outputStart) {
47
+ closing = -1;
48
+ const tagId = element.tagId;
49
+ if (tagId === 26) {
50
+ links.push(element);
51
+ brackets.push(outputStart < buffer.length && buffer[buffer.length - 1] === "[" ? buffer.length - 1 : -1);
52
+ } else if (fragments && headingStart < 0 && tagId >= 7 && tagId <= 12 && !depthMap[26]) headingStart = buffer.length;
53
+ },
54
+ exit(element) {
55
+ closing = -1;
56
+ const tagId = element.tagId;
57
+ if (tagId === 26) {
58
+ for (let index = links.length - 1; index >= 0; index--) if (links[index] === element) {
59
+ closing = brackets[index];
60
+ links.length = index;
61
+ brackets.length = index;
62
+ break;
63
+ }
64
+ } else if (headingStart >= 0 && tagId >= 7 && tagId <= 12 && !depthMap[26]) {
65
+ headings.push(buffer.slice(headingStart).join(""));
66
+ headingStart = -1;
67
+ }
68
+ },
69
+ unwrap(element) {
70
+ const bracket = closing;
71
+ const opener = buffer[bracket];
72
+ const href = element.attributes?.href;
73
+ if (bracket < 0 || element.tagId !== 26 || opener === void 0 || opener.charCodeAt(opener.length - 1) !== 91 || href === void 0 || element.tagHandler?.literalExit) return false;
74
+ let textLength = 0;
75
+ for (let index = bracket + 1; index < buffer.length; index++) textLength += buffer[index].length;
76
+ if (textLength === 0) return false;
77
+ if (!(selfLinkHeadings && href.charCodeAt(0) === 35 && isInsideHeading(depthMap)) && !(redundantLinks && spells(buffer, bracket + 1, textLength, resolveUrl(href, target.options?.origin, rules)))) return false;
78
+ const unwrapped = opener.slice(0, -1) + buffer.slice(bracket + 1).join("");
79
+ target.outputPositions?.replace(bracket, buffer.length, [unwrapped], (offset) => offset > opener.length - 1 ? offset - 1 : offset);
80
+ buffer.length = bracket;
81
+ buffer.push(unwrapped);
82
+ target.lastContentCache = unwrapped;
83
+ closing = -1;
84
+ return true;
85
+ },
86
+ closed(element, outputStart, close) {
87
+ const bracket = closing;
88
+ closing = -1;
89
+ const code = close.charCodeAt(3);
90
+ if (!fragments || bracket < 0 || element.tagHandler?.literalExit || depthMap[23] || close.charCodeAt(0) !== 93 || close.charCodeAt(1) !== 40 || close.charCodeAt(2) !== 35 || code === 41 || code === 32 || Number.isNaN(code)) return;
91
+ const opener = buffer[bracket];
92
+ if (opener === void 0 || opener.charCodeAt(opener.length - 1) !== 91) return;
93
+ let index = outputStart;
94
+ while (index < buffer.length && buffer[index] !== close) index++;
95
+ if (index === buffer.length) return;
96
+ const markedOpener = `${opener.slice(0, -1)}﷐[`;
97
+ target.outputPositions?.replace(bracket, bracket + 1, [markedOpener], (offset) => offset > opener.length - 1 ? offset + 1 : offset);
98
+ buffer[bracket] = markedOpener;
99
+ const marked = `﷑${close}`;
100
+ target.outputPositions?.replace(index, index + 1, [marked], (offset) => offset > 0 ? offset + 1 : offset);
101
+ buffer[index] = marked;
102
+ if (target.lastContentCache === close) target.lastContentCache = marked;
103
+ spans.push(`﷐[${buffer.slice(bracket + 1, index).join("")}${marked}`);
104
+ spanFragments.push(close.slice(3, destinationEnd(close, 3)));
105
+ },
106
+ held() {
107
+ for (let index = 0; index < brackets.length; index++) if (brackets[index] >= 0) return brackets[index];
108
+ return Infinity;
109
+ },
110
+ finish(markdown) {
111
+ return fragments ? applyFragments(markdown, headings, spans, spanFragments) : { markdown };
112
+ }
113
+ };
114
+ }
115
+ function spells(buffer, start, length, value) {
116
+ if (length !== value.length) return false;
117
+ let offset = 0;
118
+ for (let index = start; index < buffer.length; index++) {
119
+ const entry = buffer[index];
120
+ if (!value.startsWith(entry, offset)) return false;
121
+ offset += entry.length;
122
+ }
123
+ return true;
124
+ }
125
+ function isEscaped(md, index) {
126
+ const end = index;
127
+ while (index > 0 && md.charCodeAt(index - 1) === 92) index--;
128
+ return (end - index) % 2 !== 0;
129
+ }
130
+ function htmlTagEnd(md, start, lastGt) {
131
+ if (start >= lastGt || isEscaped(md, start)) return -1;
132
+ let i = start + 1;
133
+ if (md.charCodeAt(i) === 47) i++;
134
+ let code = md.charCodeAt(i);
135
+ if (!(code >= 65 && code <= 90 || code >= 97 && code <= 122)) return -1;
136
+ do {
137
+ i++;
138
+ code = md.charCodeAt(i);
139
+ } while (code >= 65 && code <= 90 || code >= 97 && code <= 122 || code >= 48 && code <= 57 || code === 45);
140
+ if (code !== 32 && code !== 9 && code !== 10 && code !== 13 && code !== 47 && code !== 62) return -1;
141
+ let quote = 0;
142
+ while (i < md.length) {
143
+ code = md.charCodeAt(i);
144
+ if (quote) {
145
+ if (code === quote) quote = 0;
146
+ } else if (code === 34 || code === 39) quote = code;
147
+ else if (code === 62) return i + 1;
148
+ else if (code === 60) return -1;
149
+ i++;
150
+ }
151
+ return -1;
152
+ }
153
+ function slugify(text) {
154
+ let slug = "";
155
+ let lastWasDash = false;
156
+ for (let i = 0; i < text.length; i++) {
157
+ const c = text.charCodeAt(i);
158
+ if (c >= 97 && c <= 122) {
159
+ slug += text[i];
160
+ lastWasDash = false;
161
+ } else if (c >= 65 && c <= 90) {
162
+ slug += String.fromCharCode(c + 32);
163
+ lastWasDash = false;
164
+ } else if (c >= 48 && c <= 57) {
165
+ slug += text[i];
166
+ lastWasDash = false;
167
+ } else if (c === 95) {
168
+ slug += "_";
169
+ lastWasDash = false;
170
+ } else if (c === 32 || c === 9 || c === 45) {
171
+ if (!lastWasDash && slug.length > 0) {
172
+ slug += "-";
173
+ lastWasDash = true;
174
+ }
175
+ }
176
+ }
177
+ if (lastWasDash) slug = slug.slice(0, -1);
178
+ return slug;
179
+ }
180
+ function stripHeadingFormatting(text) {
181
+ let result = "";
182
+ const len = text.length;
183
+ const lastGt = text.lastIndexOf(">");
184
+ let firstTickLength = 0;
185
+ let firstTickLast = 0;
186
+ let otherTickLasts;
187
+ if (text.includes("`")) {
188
+ let scan = 0;
189
+ while (scan < len) {
190
+ let code = text.charCodeAt(scan);
191
+ if (code === 96) {
192
+ const start = scan;
193
+ do {
194
+ scan++;
195
+ code = text.charCodeAt(scan);
196
+ } while (code === 96);
197
+ const ticks = scan - start;
198
+ if (firstTickLength === 0) {
199
+ firstTickLength = ticks;
200
+ firstTickLast = start;
201
+ } else if (ticks === firstTickLength) firstTickLast = start;
202
+ else {
203
+ otherTickLasts ||= /* @__PURE__ */ new Map();
204
+ otherTickLasts.set(ticks, start);
205
+ }
206
+ } else if (code === 60) {
207
+ const tagEnd = htmlTagEnd(text, scan, lastGt);
208
+ scan = tagEnd === -1 ? scan + 1 : tagEnd;
209
+ } else scan++;
210
+ }
211
+ }
212
+ let i = 0;
213
+ let codeTicks = 0;
214
+ while (i < len) {
215
+ const c = text.charCodeAt(i);
216
+ if (c === 96) {
217
+ let end = i + 1;
218
+ while (text.charCodeAt(end) === 96) end++;
219
+ const ticks = end - i;
220
+ if (codeTicks === 0) {
221
+ if ((ticks === firstTickLength ? firstTickLast : otherTickLasts?.get(ticks) ?? i) > i) codeTicks = ticks;
222
+ } else if (codeTicks === ticks) codeTicks = 0;
223
+ i = end;
224
+ continue;
225
+ }
226
+ if (codeTicks !== 0) {
227
+ result += text[i];
228
+ i++;
229
+ continue;
230
+ }
231
+ if (c === 92 && i + 1 < len) {
232
+ result += text[i + 1];
233
+ i += 2;
234
+ continue;
235
+ }
236
+ const tagEnd = c === 60 ? htmlTagEnd(text, i, lastGt) : -1;
237
+ if (tagEnd !== -1) {
238
+ i = tagEnd;
239
+ continue;
240
+ }
241
+ if (c === 91) {
242
+ const close = text.indexOf("]", i + 1);
243
+ if (close !== -1 && text.charCodeAt(close + 1) === 40) {
244
+ const parenClose = text.indexOf(")", close + 2);
245
+ if (parenClose !== -1) {
246
+ result += text.slice(i + 1, close);
247
+ i = parenClose + 1;
248
+ continue;
249
+ }
250
+ }
251
+ i++;
252
+ continue;
253
+ }
254
+ if (c === 42 || c === 95 || c === 126) {
255
+ i++;
256
+ continue;
257
+ }
258
+ result += text[i];
259
+ i++;
260
+ }
261
+ return result.trim();
262
+ }
263
+ function headingSlug(text) {
264
+ if (text.includes("﷐") || text.includes("﷑")) text = text.replaceAll("﷐", "").replaceAll("﷑", "");
265
+ return slugify(stripHeadingFormatting(text));
266
+ }
267
+ const OPEN_CODE = "﷐".charCodeAt(0);
268
+ const CLOSE_CODE = "﷑".charCodeAt(0);
269
+ function destinationEnd(markdown, from) {
270
+ let end = from;
271
+ while (end < markdown.length && markdown.charCodeAt(end) !== 41 && markdown.charCodeAt(end) !== 32) end++;
272
+ return end;
273
+ }
274
+ function linkCloseEnd(markdown, start) {
275
+ if (markdown.charCodeAt(start) !== 93 || markdown.charCodeAt(start + 1) !== 40 || markdown.charCodeAt(start + 2) !== 35) return -1;
276
+ let end = destinationEnd(markdown, start + 3);
277
+ if (markdown.charCodeAt(end) === 32 && markdown.charCodeAt(end + 1) === 34) {
278
+ end += 2;
279
+ while (end < markdown.length && markdown.charCodeAt(end) !== 34) end += markdown.charCodeAt(end) === 92 ? 2 : 1;
280
+ end++;
281
+ }
282
+ return markdown.charCodeAt(end) === 41 ? end + 1 : -1;
283
+ }
284
+ function pairWrittenMarkers(markdown, count, opens, closes) {
285
+ const stack = [];
286
+ let opened = 0;
287
+ let closed = 0;
288
+ let nextOpen = markdown.indexOf("﷐");
289
+ let nextClose = markdown.indexOf("﷑");
290
+ while (nextOpen !== -1 || nextClose !== -1) if (nextOpen !== -1 && (nextClose === -1 || nextOpen < nextClose)) {
291
+ if (opened === count || markdown.charCodeAt(nextOpen + 1) !== 91) return false;
292
+ stack.push(nextOpen);
293
+ opened++;
294
+ nextOpen = markdown.indexOf("﷐", nextOpen + 1);
295
+ } else {
296
+ if (closed === count || stack.length === 0) return false;
297
+ opens[closed] = stack.pop();
298
+ closes[closed] = nextClose;
299
+ closed++;
300
+ nextClose = markdown.indexOf("﷑", nextClose + 1);
301
+ }
302
+ return opened === count && closed === count;
303
+ }
304
+ function isLineStart(markdown, index) {
305
+ return index === 0 || markdown.charCodeAt(index - 1) === 10;
306
+ }
307
+ function fenceOpeningRun(markdown, start, len) {
308
+ let i = start;
309
+ while (i < len && markdown.charCodeAt(i) === 32) i++;
310
+ if (markdown.charCodeAt(i) !== 96) return 0;
311
+ let end = i;
312
+ while (end < len && markdown.charCodeAt(end) === 96) end++;
313
+ return end - i >= 3 ? end - i : 0;
314
+ }
315
+ function fenceCloses(markdown, start, run, len) {
316
+ let i = start;
317
+ while (i < len && markdown.charCodeAt(i) === 32) i++;
318
+ if (markdown.charCodeAt(i) !== 96) return false;
319
+ let end = i;
320
+ while (end < len && markdown.charCodeAt(end) === 96) end++;
321
+ if (end - i < run) return false;
322
+ while (end < len) {
323
+ const code = markdown.charCodeAt(end);
324
+ if (code === 10) return true;
325
+ if (code !== 32 && code !== 9) return false;
326
+ end++;
327
+ }
328
+ return true;
329
+ }
330
+ function inlineCodeEnd(markdown, from, run, len) {
331
+ let search = from;
332
+ while (search < len) {
333
+ if (markdown.charCodeAt(search) !== 96) {
334
+ const next = markdown.indexOf("`", search);
335
+ if (next === -1) return -1;
336
+ search = next;
337
+ }
338
+ let end = search;
339
+ while (end < len && markdown.charCodeAt(end) === 96) end++;
340
+ if (end - search === run) return end;
341
+ search = end;
342
+ }
343
+ return -1;
344
+ }
345
+ function pairSpelledMarkers(markdown, spans, opens, closes) {
346
+ const unpaired = /* @__PURE__ */ new Map();
347
+ for (let index = spans.length - 1; index >= 0; index--) {
348
+ const spelling = stripQuotePrefixes(spans[index]);
349
+ const list = unpaired.get(spelling);
350
+ if (list) list.push(index);
351
+ else unpaired.set(spelling, [index]);
352
+ }
353
+ const len = markdown.length;
354
+ const candidates = [];
355
+ let fenceRun = 0;
356
+ let inDestination = false;
357
+ let i = 0;
358
+ while (i < len) {
359
+ if (fenceRun > 0) {
360
+ const newline = markdown.indexOf("\n", i);
361
+ const lineEnd = newline === -1 ? len : newline + 1;
362
+ if (isLineStart(markdown, i) && fenceCloses(markdown, i, fenceRun, len)) fenceRun = 0;
363
+ i = lineEnd;
364
+ continue;
365
+ }
366
+ const code = markdown.charCodeAt(i);
367
+ if (code === 10) {
368
+ i++;
369
+ continue;
370
+ }
371
+ if (candidates.length === 0 && isLineStart(markdown, i)) {
372
+ const run = fenceOpeningRun(markdown, i, len);
373
+ if (run > 0) {
374
+ fenceRun = run;
375
+ const newline = markdown.indexOf("\n", i);
376
+ i = newline === -1 ? len : newline + 1;
377
+ continue;
378
+ }
379
+ }
380
+ if (candidates.length === 0 && code === 96 && !isEscaped(markdown, i)) {
381
+ let end = i;
382
+ while (end < len && markdown.charCodeAt(end) === 96) end++;
383
+ const closed = inDestination ? -1 : inlineCodeEnd(markdown, end, end - i, len);
384
+ i = closed === -1 ? end : closed;
385
+ continue;
386
+ }
387
+ if (code === 93 && markdown.charCodeAt(i + 1) === 40) {
388
+ inDestination = true;
389
+ i += 2;
390
+ continue;
391
+ }
392
+ if (inDestination && code === 41) {
393
+ inDestination = false;
394
+ i++;
395
+ continue;
396
+ }
397
+ if (code === OPEN_CODE) {
398
+ if (markdown.charCodeAt(i + 1) === 91) candidates.push(i);
399
+ } else if (code === CLOSE_CODE && candidates.length) {
400
+ const end = linkCloseEnd(markdown, i + 1);
401
+ if (end !== -1) {
402
+ let depth = candidates.length;
403
+ while (depth > 0) {
404
+ depth--;
405
+ const list = unpaired.get(stripQuotePrefixes(markdown.slice(candidates[depth], end)));
406
+ if (list?.length) {
407
+ const span = list.pop();
408
+ opens[span] = candidates[depth];
409
+ closes[span] = i;
410
+ candidates.length = depth;
411
+ break;
412
+ }
413
+ }
414
+ }
415
+ }
416
+ i++;
417
+ }
418
+ }
419
+ function stripQuotePrefixes(value) {
420
+ let result = "";
421
+ let copied = 0;
422
+ let newline = value.indexOf("\n");
423
+ while (newline !== -1) {
424
+ let end = newline + 1;
425
+ while (value.charCodeAt(end) === 32) end++;
426
+ while (value.charCodeAt(end) === 62) {
427
+ end++;
428
+ if (value.charCodeAt(end) === 32) end++;
429
+ }
430
+ if (end > newline + 1) {
431
+ result += value.slice(copied, newline + 1);
432
+ copied = end;
433
+ }
434
+ newline = value.indexOf("\n", end);
435
+ }
436
+ return copied ? result + value.slice(copied) : value;
437
+ }
438
+ function applyFragments(markdown, headings, spans, spanFragments) {
439
+ const count = spans.length;
440
+ if (count === 0) return {
441
+ markdown,
442
+ mapPosition: (position) => position
443
+ };
444
+ const slugs = /* @__PURE__ */ new Set();
445
+ for (const heading of headings) {
446
+ const slug = headingSlug(heading);
447
+ if (slug) slugs.add(slug);
448
+ }
449
+ const opens = [];
450
+ const closes = [];
451
+ for (let span = 0; span < count; span++) {
452
+ opens.push(-1);
453
+ closes.push(-1);
454
+ }
455
+ if (!pairWrittenMarkers(markdown, count, opens, closes)) {
456
+ opens.fill(-1);
457
+ closes.fill(-1);
458
+ pairSpelledMarkers(markdown, spans, opens, closes);
459
+ }
460
+ const dropAt = /* @__PURE__ */ new Map();
461
+ for (let span = 0; span < count; span++) {
462
+ const open = opens[span];
463
+ if (open === -1) continue;
464
+ const close = closes[span];
465
+ const closeEnd = linkCloseEnd(markdown, close + 1);
466
+ const broken = closeEnd !== -1 && !slugs.has(spanFragments[span]);
467
+ dropAt.set(open, broken ? 2 : 1);
468
+ dropAt.set(close, broken ? closeEnd - close : 1);
469
+ }
470
+ let result = "";
471
+ let copied = 0;
472
+ let nextOpen = markdown.indexOf("﷐");
473
+ let nextClose = markdown.indexOf("﷑");
474
+ while (nextOpen !== -1 || nextClose !== -1) {
475
+ let next;
476
+ if (nextOpen !== -1 && (nextClose === -1 || nextOpen < nextClose)) {
477
+ next = nextOpen;
478
+ nextOpen = markdown.indexOf("﷐", next + 1);
479
+ } else {
480
+ next = nextClose;
481
+ nextClose = markdown.indexOf("﷑", next + 1);
482
+ }
483
+ const drop = dropAt.get(next);
484
+ if (drop === void 0 || next < copied) continue;
485
+ result += markdown.slice(copied, next);
486
+ copied = next + drop;
487
+ }
488
+ result += markdown.slice(copied);
489
+ let positionMap;
490
+ return {
491
+ markdown: result,
492
+ mapPosition(position) {
493
+ positionMap ??= createPositionMap(dropAt);
494
+ return positionMap(position);
495
+ }
496
+ };
497
+ }
498
+ function createPositionMap(drops) {
499
+ const starts = [];
500
+ const ends = [];
501
+ const totals = [];
502
+ let removed = 0;
503
+ let copied = 0;
504
+ for (const start of [...drops.keys()].sort((a, b) => a - b)) {
505
+ if (start < copied) continue;
506
+ const length = drops.get(start);
507
+ copied = start + length;
508
+ removed += length;
509
+ starts.push(start);
510
+ ends.push(copied);
511
+ totals.push(removed);
512
+ }
513
+ return (position) => {
514
+ let lower = 0;
515
+ let upper = ends.length;
516
+ while (lower < upper) {
517
+ const middle = lower + upper >>> 1;
518
+ if (ends[middle] <= position) lower = middle + 1;
519
+ else upper = middle;
520
+ }
521
+ const completed = lower > 0 ? totals[lower - 1] : 0;
522
+ const partial = lower < starts.length ? Math.max(0, position - starts[lower]) : 0;
523
+ return position - completed - partial;
524
+ };
525
+ }
526
+ export { clean, slugify, stripHeadingFormatting };
@@ -1,9 +1,3 @@
1
- const TAG_H1 = 7;
2
- const TAG_H2 = 8;
3
- const TAG_H3 = 9;
4
- const TAG_H4 = 10;
5
- const TAG_H5 = 11;
6
- const TAG_H6 = 12;
7
1
  const ELEMENT_NODE = 1;
8
2
  const TEXT_NODE = 2;
9
3
  const NodeEventEnter = 0;
@@ -131,4 +125,6 @@ const DEFAULT_BLOCK_SPACING = [2, 2];
131
125
  const BLOCKQUOTE_SPACING = [2, 2];
132
126
  const LIST_ITEM_SPACING = [1, 0];
133
127
  const TABLE_ROW_SPACING = [0, 1];
134
- export { BLOCKQUOTE_SPACING, DEFAULT_BLOCK_SPACING, ELEMENT_NODE, LIST_ITEM_SPACING, NO_SPACING, NodeEventEnter, NodeEventExit, TABLE_ROW_SPACING, TAG_H1, TAG_H2, TAG_H3, TAG_H4, TAG_H5, TAG_H6, TEXT_NODE, TagIdMap, isInsideRawHtmlBlock };
128
+ const FRAGMENT_LINK_OPEN_CODE = 64976;
129
+ const FRAGMENT_LINK_CLOSE_CODE = 64977;
130
+ export { BLOCKQUOTE_SPACING, DEFAULT_BLOCK_SPACING, ELEMENT_NODE, FRAGMENT_LINK_CLOSE_CODE, FRAGMENT_LINK_OPEN_CODE, LIST_ITEM_SPACING, NO_SPACING, NodeEventEnter, NodeEventExit, TABLE_ROW_SPACING, TEXT_NODE, TagIdMap, isInsideRawHtmlBlock };
@@ -0,0 +1,14 @@
1
+ import { ElementNode, PluginSetup, PluginState, TransformPlugin } from "./types.mjs";
2
+ /**
3
+ * Create a plugin with type-safe hook definitions.
4
+ * Pass a setup function when the plugin keeps per-document state: each
5
+ * conversion calls it to create fresh hooks.
6
+ */
7
+ export declare function createPlugin(plugin: TransformPlugin): TransformPlugin;
8
+ export declare function createPlugin(setup: PluginSetup): PluginSetup;
9
+ export interface ExtractedElement extends ElementNode {
10
+ textContent: string;
11
+ }
12
+ type ExtractionCallback = (element: ExtractedElement, state: PluginState) => void;
13
+ /** Extract matching elements through the composable JavaScript plugin interface. */
14
+ export declare function extractionPlugin(selectors: Record<string, ExtractionCallback>): PluginSetup;