@hyperbook/markdown 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1640 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b ||= {})
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __commonJS = (cb, mod) => function __require() {
25
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
26
- };
27
- var __copyProps = (to, from, except, desc) => {
28
- if (from && typeof from === "object" || typeof from === "function") {
29
- for (let key of __getOwnPropNames(from))
30
- if (!__hasOwnProp.call(to, key) && key !== except)
31
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
- }
33
- return to;
34
- };
35
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
36
- // If the importer is in node compatibility mode or this is not an ESM
37
- // file that has been converted to a CommonJS file using a Babel-
38
- // compatible transform (i.e. "__esModule" has not been set), then set
39
- // "default" to the CommonJS "module.exports" for node compatibility.
40
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
41
- mod
42
- ));
43
-
44
- // ../../node_modules/.pnpm/is-buffer@2.0.5/node_modules/is-buffer/index.js
45
- var require_is_buffer = __commonJS({
46
- "../../node_modules/.pnpm/is-buffer@2.0.5/node_modules/is-buffer/index.js"(exports, module) {
47
- module.exports = function isBuffer2(obj) {
48
- return obj != null && obj.constructor != null && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
49
- };
50
- }
51
- });
52
-
53
- // ../../node_modules/.pnpm/extend@3.0.2/node_modules/extend/index.js
54
- var require_extend = __commonJS({
55
- "../../node_modules/.pnpm/extend@3.0.2/node_modules/extend/index.js"(exports, module) {
56
- "use strict";
57
- var hasOwn = Object.prototype.hasOwnProperty;
58
- var toStr = Object.prototype.toString;
59
- var defineProperty = Object.defineProperty;
60
- var gOPD = Object.getOwnPropertyDescriptor;
61
- var isArray = function isArray2(arr) {
62
- if (typeof Array.isArray === "function") {
63
- return Array.isArray(arr);
64
- }
65
- return toStr.call(arr) === "[object Array]";
66
- };
67
- var isPlainObject2 = function isPlainObject3(obj) {
68
- if (!obj || toStr.call(obj) !== "[object Object]") {
69
- return false;
70
- }
71
- var hasOwnConstructor = hasOwn.call(obj, "constructor");
72
- var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, "isPrototypeOf");
73
- if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
74
- return false;
75
- }
76
- var key;
77
- for (key in obj) {
78
- }
79
- return typeof key === "undefined" || hasOwn.call(obj, key);
80
- };
81
- var setProperty = function setProperty2(target, options) {
82
- if (defineProperty && options.name === "__proto__") {
83
- defineProperty(target, options.name, {
84
- enumerable: true,
85
- configurable: true,
86
- value: options.newValue,
87
- writable: true
88
- });
89
- } else {
90
- target[options.name] = options.newValue;
91
- }
92
- };
93
- var getProperty = function getProperty2(obj, name) {
94
- if (name === "__proto__") {
95
- if (!hasOwn.call(obj, name)) {
96
- return void 0;
97
- } else if (gOPD) {
98
- return gOPD(obj, name).value;
99
- }
100
- }
101
- return obj[name];
102
- };
103
- module.exports = function extend2() {
104
- var options, name, src, copy, copyIsArray, clone;
105
- var target = arguments[0];
106
- var i = 1;
107
- var length = arguments.length;
108
- var deep = false;
109
- if (typeof target === "boolean") {
110
- deep = target;
111
- target = arguments[1] || {};
112
- i = 2;
113
- }
114
- if (target == null || typeof target !== "object" && typeof target !== "function") {
115
- target = {};
116
- }
117
- for (; i < length; ++i) {
118
- options = arguments[i];
119
- if (options != null) {
120
- for (name in options) {
121
- src = getProperty(target, name);
122
- copy = getProperty(options, name);
123
- if (target !== copy) {
124
- if (deep && copy && (isPlainObject2(copy) || (copyIsArray = isArray(copy)))) {
125
- if (copyIsArray) {
126
- copyIsArray = false;
127
- clone = src && isArray(src) ? src : [];
128
- } else {
129
- clone = src && isPlainObject2(src) ? src : {};
130
- }
131
- setProperty(target, { name, newValue: extend2(deep, clone, copy) });
132
- } else if (typeof copy !== "undefined") {
133
- setProperty(target, { name, newValue: copy });
134
- }
135
- }
136
- }
137
- }
138
- }
139
- return target;
140
- };
141
- }
142
- });
143
-
144
- // src/Markdown.tsx
145
- import remarkDirective from "remark-directive";
146
- import remarkDirectiveRehype from "remark-directive-rehype";
147
- import remarkGfm from "remark-gfm";
148
- import remarkMath from "remark-math";
149
- import remarkGemoji from "remark-gemoji";
150
- import remarkUnwrapImages from "remark-unwrap-images";
151
- import rehypeKatex from "rehype-katex";
152
- import rehypeHighlight from "rehype-highlight";
153
- import { useDirectives as useDirectives2 } from "@hyperbook/provider";
154
- import { Drawer } from "@hyperbook/drawer";
155
-
156
- // src/Code.tsx
157
- import { useDirectives } from "@hyperbook/provider";
158
- import { Fragment, useRef, useState } from "react";
159
- import { jsx, jsxs } from "react/jsx-runtime";
160
- var MdContentCopy = () => {
161
- return /* @__PURE__ */ jsxs(
162
- "svg",
163
- {
164
- xmlns: "http://www.w3.org/2000/svg",
165
- stroke: "currentColor",
166
- fill: "currentColor",
167
- strokeWidth: "0",
168
- height: "1em",
169
- width: "1em",
170
- viewBox: "0 0 24 24",
171
- children: [
172
- /* @__PURE__ */ jsx("path", { d: "M0 0h24v24H0z", fill: "none" }),
173
- /* @__PURE__ */ jsx("path", { d: "M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z" })
174
- ]
175
- }
176
- );
177
- };
178
- var MdDone = () => {
179
- return /* @__PURE__ */ jsxs(
180
- "svg",
181
- {
182
- xmlns: "http://www.w3.org/2000/svg",
183
- stroke: "currentColor",
184
- fill: "currentColor",
185
- strokeWidth: "0",
186
- height: "1em",
187
- width: "1em",
188
- viewBox: "0 0 24 24",
189
- children: [
190
- /* @__PURE__ */ jsx("path", { d: "M0 0h24v24H0z", fill: "none" }),
191
- /* @__PURE__ */ jsx("path", { d: "M9 16.2L4.8 12l-1.4 1.4L9 19 21 7l-1.4-1.4L9 16.2z" })
192
- ]
193
- }
194
- );
195
- };
196
- var copyNoNavigator = (text) => {
197
- const isIos = navigator.userAgent.match(/ipad|iphone/i);
198
- const textarea = document.createElement("textarea");
199
- textarea.value = text;
200
- textarea.style.fontSize = "20px";
201
- document.body.appendChild(textarea);
202
- if (isIos) {
203
- const range = document.createRange();
204
- range.selectNodeContents(textarea);
205
- const selection = window.getSelection();
206
- if (selection) {
207
- selection.removeAllRanges();
208
- selection.addRange(range);
209
- }
210
- textarea.setSelectionRange(0, 999999);
211
- } else {
212
- textarea.select();
213
- }
214
- document.execCommand("copy");
215
- document.body.removeChild(textarea);
216
- };
217
- var Code = ({
218
- children,
219
- className
220
- }) => {
221
- const directives = useDirectives();
222
- if (className === "language-mermaid" && directives["mermaid"]) {
223
- const Mermaid = directives["mermaid"];
224
- return /* @__PURE__ */ jsx(Mermaid, { children });
225
- }
226
- const ref = useRef(null);
227
- const [copied, setCopied] = useState(false);
228
- const copyCode = () => {
229
- if (ref.current) {
230
- const text = ref.current.innerText;
231
- if (navigator.clipboard) {
232
- navigator.clipboard.writeText(text).then(() => {
233
- setCopied(true);
234
- setTimeout(() => setCopied(false), 2e3);
235
- }).catch(() => {
236
- copyNoNavigator(text);
237
- setCopied(true);
238
- setTimeout(() => setCopied(false), 2e3);
239
- });
240
- } else {
241
- copyNoNavigator(text);
242
- setCopied(true);
243
- setTimeout(() => setCopied(false), 2e3);
244
- }
245
- }
246
- };
247
- return !className ? /* @__PURE__ */ jsxs("span", { className: "inline", children: [
248
- /* @__PURE__ */ jsx("code", { ref, className, children }),
249
- /* @__PURE__ */ jsx("button", { className: "copy", onClick: copyCode, "aria-label": "Copy Code", children: copied ? /* @__PURE__ */ jsx(MdDone, {}) : /* @__PURE__ */ jsx(MdContentCopy, {}) })
250
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
251
- /* @__PURE__ */ jsx("code", { ref, className, children }),
252
- /* @__PURE__ */ jsx("button", { className: "copy", onClick: copyCode, "aria-label": "Copy Code", children: copied ? /* @__PURE__ */ jsx(MdDone, {}) : /* @__PURE__ */ jsx(MdContentCopy, {}) })
253
- ] });
254
- };
255
-
256
- // src/Link.tsx
257
- import { useConfig, useLink } from "@hyperbook/provider";
258
- import { useEffect, useState as useState2 } from "react";
259
- import { jsx as jsx2 } from "react/jsx-runtime";
260
- function formatUrl(url) {
261
- if (typeof url !== "string") {
262
- return url;
263
- }
264
- var doubleSlash = url.split("//");
265
- var formatted = doubleSlash.map(
266
- (str) => (
267
- // Insert a word break opportunity after a colon
268
- str.replace(new RegExp("(?<after>:)", "giu"), "$1<wbr>").replace(new RegExp("(?<before>[/~.,\\-_?#%])", "giu"), "<wbr>$1").replace(new RegExp("(?<beforeAndAfter>[=&])", "giu"), "<wbr>$1<wbr>")
269
- )
270
- // Reconnect the strings with word break opportunities after double slashes
271
- ).join("//<wbr>");
272
- return formatted;
273
- }
274
- var Link = ({
275
- href,
276
- title,
277
- children
278
- }) => {
279
- const L = useLink();
280
- const config = useConfig();
281
- const [isExternal, setIsExternal] = useState2(false);
282
- useEffect(() => {
283
- var _a;
284
- if (href) {
285
- const tmp = document.createElement("a");
286
- tmp.href = href;
287
- if (tmp.host !== window.location.host) {
288
- setIsExternal(true);
289
- } else if (config.basePath && !((_a = window.location.pathname) == null ? void 0 : _a.startsWith(config.basePath))) {
290
- setIsExternal(true);
291
- } else {
292
- setIsExternal(false);
293
- }
294
- }
295
- }, [href, config]);
296
- if (isExternal) {
297
- /* @__PURE__ */ jsx2(L, { href, title, target: "_blank", children: formatUrl(children) });
298
- }
299
- return /* @__PURE__ */ jsx2(L, { href, title, children: formatUrl(children) });
300
- };
301
-
302
- // src/Table.tsx
303
- import { jsx as jsx3 } from "react/jsx-runtime";
304
- var tableHeaders = [];
305
- var tdIndex = 0;
306
- var Table = ({
307
- children,
308
- style
309
- }) => {
310
- tableHeaders = [];
311
- return /* @__PURE__ */ jsx3("table", { style, children });
312
- };
313
- var Tr = ({
314
- children,
315
- style
316
- }) => {
317
- tdIndex = 0;
318
- return /* @__PURE__ */ jsx3("tr", { style, children });
319
- };
320
- var Td = ({
321
- children,
322
- style
323
- }) => {
324
- return /* @__PURE__ */ jsx3("td", { "data-label": tableHeaders[tdIndex++], style, children });
325
- };
326
- var Th = ({
327
- children,
328
- style
329
- }) => {
330
- tableHeaders.push(children);
331
- return /* @__PURE__ */ jsx3("th", { style, children });
332
- };
333
-
334
- // src/Headings.tsx
335
- import { useBookmark, useConfig as useConfig2 } from "@hyperbook/provider";
336
- import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
337
- var makeAnchor = (heading) => {
338
- let anchor = heading.toLowerCase();
339
- anchor = anchor.replace(/[^a-zA-Z0-9 ]/g, "");
340
- anchor = anchor.replace(/ /g, "-");
341
- return anchor;
342
- };
343
- var Headings = (level) => ({ children, id }) => {
344
- var _a;
345
- const config = useConfig2();
346
- const bookmarksConfig = (_a = config == null ? void 0 : config.elements) == null ? void 0 : _a.bookmarks;
347
- const heading = (children == null ? void 0 : children[0]) || "";
348
- let anchor = typeof heading === "string" ? makeAnchor(heading) : "";
349
- const label = typeof heading === "string" ? heading : anchor;
350
- const [bookmark, toggleBookmark] = useBookmark(anchor, label);
351
- const container = (children2) => /* @__PURE__ */ jsxs2(Fragment2, { children: [
352
- /* @__PURE__ */ jsx4("a", { className: "heading", id: id != null ? id : anchor, href: `#${id != null ? id : anchor}`, children: /* @__PURE__ */ jsx4("span", { children: children2 }) }),
353
- bookmarksConfig !== false && /* @__PURE__ */ jsx4(
354
- "button",
355
- {
356
- className: bookmark ? "bookmark active" : "bookmark",
357
- onClick: () => toggleBookmark(),
358
- title: "Bookmark",
359
- children: "\u{1F516}"
360
- }
361
- )
362
- ] });
363
- switch (level) {
364
- case 1:
365
- return /* @__PURE__ */ jsx4("h1", { children: container(children) });
366
- case 2:
367
- return /* @__PURE__ */ jsx4("h2", { children: container(children) });
368
- case 3:
369
- return /* @__PURE__ */ jsx4("h3", { children: container(children) });
370
- case 4:
371
- return /* @__PURE__ */ jsx4("h4", { children: container(children) });
372
- case 5:
373
- return /* @__PURE__ */ jsx4("h5", { children: container(children) });
374
- default:
375
- return /* @__PURE__ */ jsx4("h6", { children: container(children) });
376
- }
377
- };
378
-
379
- // src/Image.tsx
380
- import { useMakeUrl } from "@hyperbook/provider";
381
- import { useState as useState3 } from "react";
382
- import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
383
- var Image = ({
384
- src,
385
- title,
386
- alt
387
- }) => {
388
- const makeUrl = useMakeUrl();
389
- const [full, setFull] = useState3(false);
390
- src = makeUrl(src, "public");
391
- return /* @__PURE__ */ jsxs3("figure", { className: full ? "lightbox" : void 0, children: [
392
- /* @__PURE__ */ jsx5("img", { src, alt, onClick: () => setFull((f) => !f) }),
393
- title && /* @__PURE__ */ jsx5("figcaption", { children: title })
394
- ] });
395
- };
396
-
397
- // src/remarkRemoveComments.ts
398
- import { visit, SKIP } from "unist-util-visit";
399
- var remarkRemoveComments = () => (tree) => {
400
- const htmlCommentRegex = /<!--([\s\S]*?)-->/g;
401
- const handler = (node, index2, parent) => {
402
- const isComment = node.value.match(htmlCommentRegex);
403
- if (isComment) {
404
- parent.children.splice(index2, 1);
405
- return [SKIP, index2];
406
- }
407
- };
408
- visit(tree, "html", handler);
409
- visit(tree, "jsx", handler);
410
- };
411
-
412
- // src/remarkCustomHeadingIds.ts
413
- import { visit as visit2 } from "unist-util-visit";
414
- var remarkCustomHeadingIds = () => {
415
- return function(node) {
416
- visit2(node, "heading", (node2) => {
417
- let lastChild = node2.children[node2.children.length - 1];
418
- if (lastChild && lastChild.type === "text") {
419
- let string = lastChild.value.replace(/ +$/, "");
420
- let matched = string.match(/ {#([^]+?)}$/);
421
- if (matched) {
422
- let id = matched[1];
423
- if (!!id.length) {
424
- if (!node2.data) {
425
- node2.data = {};
426
- }
427
- if (!node2.data.hProperties) {
428
- node2.data.hProperties = {};
429
- }
430
- node2.data.id = node2.data.hProperties.id = id;
431
- string = string.substring(0, matched.index);
432
- lastChild.value = string;
433
- }
434
- }
435
- }
436
- });
437
- };
438
- };
439
-
440
- // src/useRemarkSync.ts
441
- import { Fragment as Fragment3, createElement } from "react";
442
-
443
- // ../../node_modules/.pnpm/bail@2.0.2/node_modules/bail/index.js
444
- function bail(error) {
445
- if (error) {
446
- throw error;
447
- }
448
- }
449
-
450
- // ../../node_modules/.pnpm/unified@10.1.2/node_modules/unified/lib/index.js
451
- var import_is_buffer2 = __toESM(require_is_buffer(), 1);
452
- var import_extend = __toESM(require_extend(), 1);
453
-
454
- // ../../node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js
455
- function isPlainObject(value) {
456
- if (typeof value !== "object" || value === null) {
457
- return false;
458
- }
459
- const prototype = Object.getPrototypeOf(value);
460
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
461
- }
462
-
463
- // ../../node_modules/.pnpm/trough@2.1.0/node_modules/trough/index.js
464
- function trough() {
465
- const fns = [];
466
- const pipeline = { run, use };
467
- return pipeline;
468
- function run(...values) {
469
- let middlewareIndex = -1;
470
- const callback = values.pop();
471
- if (typeof callback !== "function") {
472
- throw new TypeError("Expected function as last argument, not " + callback);
473
- }
474
- next(null, ...values);
475
- function next(error, ...output) {
476
- const fn = fns[++middlewareIndex];
477
- let index2 = -1;
478
- if (error) {
479
- callback(error);
480
- return;
481
- }
482
- while (++index2 < values.length) {
483
- if (output[index2] === null || output[index2] === void 0) {
484
- output[index2] = values[index2];
485
- }
486
- }
487
- values = output;
488
- if (fn) {
489
- wrap(fn, next)(...output);
490
- } else {
491
- callback(null, ...output);
492
- }
493
- }
494
- }
495
- function use(middelware) {
496
- if (typeof middelware !== "function") {
497
- throw new TypeError(
498
- "Expected `middelware` to be a function, not " + middelware
499
- );
500
- }
501
- fns.push(middelware);
502
- return pipeline;
503
- }
504
- }
505
- function wrap(middleware, callback) {
506
- let called;
507
- return wrapped;
508
- function wrapped(...parameters) {
509
- const fnExpectsCallback = middleware.length > parameters.length;
510
- let result;
511
- if (fnExpectsCallback) {
512
- parameters.push(done);
513
- }
514
- try {
515
- result = middleware.apply(this, parameters);
516
- } catch (error) {
517
- const exception = (
518
- /** @type {Error} */
519
- error
520
- );
521
- if (fnExpectsCallback && called) {
522
- throw exception;
523
- }
524
- return done(exception);
525
- }
526
- if (!fnExpectsCallback) {
527
- if (result instanceof Promise) {
528
- result.then(then, done);
529
- } else if (result instanceof Error) {
530
- done(result);
531
- } else {
532
- then(result);
533
- }
534
- }
535
- }
536
- function done(error, ...output) {
537
- if (!called) {
538
- called = true;
539
- callback(error, ...output);
540
- }
541
- }
542
- function then(value) {
543
- done(null, value);
544
- }
545
- }
546
-
547
- // ../../node_modules/.pnpm/vfile@5.3.7/node_modules/vfile/lib/index.js
548
- var import_is_buffer = __toESM(require_is_buffer(), 1);
549
-
550
- // ../../node_modules/.pnpm/unist-util-stringify-position@3.0.3/node_modules/unist-util-stringify-position/lib/index.js
551
- function stringifyPosition(value) {
552
- if (!value || typeof value !== "object") {
553
- return "";
554
- }
555
- if ("position" in value || "type" in value) {
556
- return position(value.position);
557
- }
558
- if ("start" in value || "end" in value) {
559
- return position(value);
560
- }
561
- if ("line" in value || "column" in value) {
562
- return point(value);
563
- }
564
- return "";
565
- }
566
- function point(point2) {
567
- return index(point2 && point2.line) + ":" + index(point2 && point2.column);
568
- }
569
- function position(pos) {
570
- return point(pos && pos.start) + "-" + point(pos && pos.end);
571
- }
572
- function index(value) {
573
- return value && typeof value === "number" ? value : 1;
574
- }
575
-
576
- // ../../node_modules/.pnpm/vfile-message@3.1.4/node_modules/vfile-message/lib/index.js
577
- var VFileMessage = class extends Error {
578
- /**
579
- * Create a message for `reason` at `place` from `origin`.
580
- *
581
- * When an error is passed in as `reason`, the `stack` is copied.
582
- *
583
- * @param {string | Error | VFileMessage} reason
584
- * Reason for message, uses the stack and message of the error if given.
585
- *
586
- * > 👉 **Note**: you should use markdown.
587
- * @param {Node | NodeLike | Position | Point | null | undefined} [place]
588
- * Place in file where the message occurred.
589
- * @param {string | null | undefined} [origin]
590
- * Place in code where the message originates (example:
591
- * `'my-package:my-rule'` or `'my-rule'`).
592
- * @returns
593
- * Instance of `VFileMessage`.
594
- */
595
- // To do: next major: expose `undefined` everywhere instead of `null`.
596
- constructor(reason, place, origin) {
597
- const parts = [null, null];
598
- let position2 = {
599
- // @ts-expect-error: we always follows the structure of `position`.
600
- start: { line: null, column: null },
601
- // @ts-expect-error: "
602
- end: { line: null, column: null }
603
- };
604
- super();
605
- if (typeof place === "string") {
606
- origin = place;
607
- place = void 0;
608
- }
609
- if (typeof origin === "string") {
610
- const index2 = origin.indexOf(":");
611
- if (index2 === -1) {
612
- parts[1] = origin;
613
- } else {
614
- parts[0] = origin.slice(0, index2);
615
- parts[1] = origin.slice(index2 + 1);
616
- }
617
- }
618
- if (place) {
619
- if ("type" in place || "position" in place) {
620
- if (place.position) {
621
- position2 = place.position;
622
- }
623
- } else if ("start" in place || "end" in place) {
624
- position2 = place;
625
- } else if ("line" in place || "column" in place) {
626
- position2.start = place;
627
- }
628
- }
629
- this.name = stringifyPosition(place) || "1:1";
630
- this.message = typeof reason === "object" ? reason.message : reason;
631
- this.stack = "";
632
- if (typeof reason === "object" && reason.stack) {
633
- this.stack = reason.stack;
634
- }
635
- this.reason = this.message;
636
- this.fatal;
637
- this.line = position2.start.line;
638
- this.column = position2.start.column;
639
- this.position = position2;
640
- this.source = parts[0];
641
- this.ruleId = parts[1];
642
- this.file;
643
- this.actual;
644
- this.expected;
645
- this.url;
646
- this.note;
647
- }
648
- };
649
- VFileMessage.prototype.file = "";
650
- VFileMessage.prototype.name = "";
651
- VFileMessage.prototype.reason = "";
652
- VFileMessage.prototype.message = "";
653
- VFileMessage.prototype.stack = "";
654
- VFileMessage.prototype.fatal = null;
655
- VFileMessage.prototype.column = null;
656
- VFileMessage.prototype.line = null;
657
- VFileMessage.prototype.source = null;
658
- VFileMessage.prototype.ruleId = null;
659
- VFileMessage.prototype.position = null;
660
-
661
- // ../../node_modules/.pnpm/vfile@5.3.7/node_modules/vfile/lib/minpath.browser.js
662
- var path = { basename, dirname, extname, join, sep: "/" };
663
- function basename(path2, ext) {
664
- if (ext !== void 0 && typeof ext !== "string") {
665
- throw new TypeError('"ext" argument must be a string');
666
- }
667
- assertPath(path2);
668
- let start = 0;
669
- let end = -1;
670
- let index2 = path2.length;
671
- let seenNonSlash;
672
- if (ext === void 0 || ext.length === 0 || ext.length > path2.length) {
673
- while (index2--) {
674
- if (path2.charCodeAt(index2) === 47) {
675
- if (seenNonSlash) {
676
- start = index2 + 1;
677
- break;
678
- }
679
- } else if (end < 0) {
680
- seenNonSlash = true;
681
- end = index2 + 1;
682
- }
683
- }
684
- return end < 0 ? "" : path2.slice(start, end);
685
- }
686
- if (ext === path2) {
687
- return "";
688
- }
689
- let firstNonSlashEnd = -1;
690
- let extIndex = ext.length - 1;
691
- while (index2--) {
692
- if (path2.charCodeAt(index2) === 47) {
693
- if (seenNonSlash) {
694
- start = index2 + 1;
695
- break;
696
- }
697
- } else {
698
- if (firstNonSlashEnd < 0) {
699
- seenNonSlash = true;
700
- firstNonSlashEnd = index2 + 1;
701
- }
702
- if (extIndex > -1) {
703
- if (path2.charCodeAt(index2) === ext.charCodeAt(extIndex--)) {
704
- if (extIndex < 0) {
705
- end = index2;
706
- }
707
- } else {
708
- extIndex = -1;
709
- end = firstNonSlashEnd;
710
- }
711
- }
712
- }
713
- }
714
- if (start === end) {
715
- end = firstNonSlashEnd;
716
- } else if (end < 0) {
717
- end = path2.length;
718
- }
719
- return path2.slice(start, end);
720
- }
721
- function dirname(path2) {
722
- assertPath(path2);
723
- if (path2.length === 0) {
724
- return ".";
725
- }
726
- let end = -1;
727
- let index2 = path2.length;
728
- let unmatchedSlash;
729
- while (--index2) {
730
- if (path2.charCodeAt(index2) === 47) {
731
- if (unmatchedSlash) {
732
- end = index2;
733
- break;
734
- }
735
- } else if (!unmatchedSlash) {
736
- unmatchedSlash = true;
737
- }
738
- }
739
- return end < 0 ? path2.charCodeAt(0) === 47 ? "/" : "." : end === 1 && path2.charCodeAt(0) === 47 ? "//" : path2.slice(0, end);
740
- }
741
- function extname(path2) {
742
- assertPath(path2);
743
- let index2 = path2.length;
744
- let end = -1;
745
- let startPart = 0;
746
- let startDot = -1;
747
- let preDotState = 0;
748
- let unmatchedSlash;
749
- while (index2--) {
750
- const code = path2.charCodeAt(index2);
751
- if (code === 47) {
752
- if (unmatchedSlash) {
753
- startPart = index2 + 1;
754
- break;
755
- }
756
- continue;
757
- }
758
- if (end < 0) {
759
- unmatchedSlash = true;
760
- end = index2 + 1;
761
- }
762
- if (code === 46) {
763
- if (startDot < 0) {
764
- startDot = index2;
765
- } else if (preDotState !== 1) {
766
- preDotState = 1;
767
- }
768
- } else if (startDot > -1) {
769
- preDotState = -1;
770
- }
771
- }
772
- if (startDot < 0 || end < 0 || // We saw a non-dot character immediately before the dot.
773
- preDotState === 0 || // The (right-most) trimmed path component is exactly `..`.
774
- preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
775
- return "";
776
- }
777
- return path2.slice(startDot, end);
778
- }
779
- function join(...segments) {
780
- let index2 = -1;
781
- let joined;
782
- while (++index2 < segments.length) {
783
- assertPath(segments[index2]);
784
- if (segments[index2]) {
785
- joined = joined === void 0 ? segments[index2] : joined + "/" + segments[index2];
786
- }
787
- }
788
- return joined === void 0 ? "." : normalize(joined);
789
- }
790
- function normalize(path2) {
791
- assertPath(path2);
792
- const absolute = path2.charCodeAt(0) === 47;
793
- let value = normalizeString(path2, !absolute);
794
- if (value.length === 0 && !absolute) {
795
- value = ".";
796
- }
797
- if (value.length > 0 && path2.charCodeAt(path2.length - 1) === 47) {
798
- value += "/";
799
- }
800
- return absolute ? "/" + value : value;
801
- }
802
- function normalizeString(path2, allowAboveRoot) {
803
- let result = "";
804
- let lastSegmentLength = 0;
805
- let lastSlash = -1;
806
- let dots = 0;
807
- let index2 = -1;
808
- let code;
809
- let lastSlashIndex;
810
- while (++index2 <= path2.length) {
811
- if (index2 < path2.length) {
812
- code = path2.charCodeAt(index2);
813
- } else if (code === 47) {
814
- break;
815
- } else {
816
- code = 47;
817
- }
818
- if (code === 47) {
819
- if (lastSlash === index2 - 1 || dots === 1) {
820
- } else if (lastSlash !== index2 - 1 && dots === 2) {
821
- if (result.length < 2 || lastSegmentLength !== 2 || result.charCodeAt(result.length - 1) !== 46 || result.charCodeAt(result.length - 2) !== 46) {
822
- if (result.length > 2) {
823
- lastSlashIndex = result.lastIndexOf("/");
824
- if (lastSlashIndex !== result.length - 1) {
825
- if (lastSlashIndex < 0) {
826
- result = "";
827
- lastSegmentLength = 0;
828
- } else {
829
- result = result.slice(0, lastSlashIndex);
830
- lastSegmentLength = result.length - 1 - result.lastIndexOf("/");
831
- }
832
- lastSlash = index2;
833
- dots = 0;
834
- continue;
835
- }
836
- } else if (result.length > 0) {
837
- result = "";
838
- lastSegmentLength = 0;
839
- lastSlash = index2;
840
- dots = 0;
841
- continue;
842
- }
843
- }
844
- if (allowAboveRoot) {
845
- result = result.length > 0 ? result + "/.." : "..";
846
- lastSegmentLength = 2;
847
- }
848
- } else {
849
- if (result.length > 0) {
850
- result += "/" + path2.slice(lastSlash + 1, index2);
851
- } else {
852
- result = path2.slice(lastSlash + 1, index2);
853
- }
854
- lastSegmentLength = index2 - lastSlash - 1;
855
- }
856
- lastSlash = index2;
857
- dots = 0;
858
- } else if (code === 46 && dots > -1) {
859
- dots++;
860
- } else {
861
- dots = -1;
862
- }
863
- }
864
- return result;
865
- }
866
- function assertPath(path2) {
867
- if (typeof path2 !== "string") {
868
- throw new TypeError(
869
- "Path must be a string. Received " + JSON.stringify(path2)
870
- );
871
- }
872
- }
873
-
874
- // ../../node_modules/.pnpm/vfile@5.3.7/node_modules/vfile/lib/minproc.browser.js
875
- var proc = { cwd };
876
- function cwd() {
877
- return "/";
878
- }
879
-
880
- // ../../node_modules/.pnpm/vfile@5.3.7/node_modules/vfile/lib/minurl.shared.js
881
- function isUrl(fileUrlOrPath) {
882
- return fileUrlOrPath !== null && typeof fileUrlOrPath === "object" && // @ts-expect-error: indexable.
883
- fileUrlOrPath.href && // @ts-expect-error: indexable.
884
- fileUrlOrPath.origin;
885
- }
886
-
887
- // ../../node_modules/.pnpm/vfile@5.3.7/node_modules/vfile/lib/minurl.browser.js
888
- function urlToPath(path2) {
889
- if (typeof path2 === "string") {
890
- path2 = new URL(path2);
891
- } else if (!isUrl(path2)) {
892
- const error = new TypeError(
893
- 'The "path" argument must be of type string or an instance of URL. Received `' + path2 + "`"
894
- );
895
- error.code = "ERR_INVALID_ARG_TYPE";
896
- throw error;
897
- }
898
- if (path2.protocol !== "file:") {
899
- const error = new TypeError("The URL must be of scheme file");
900
- error.code = "ERR_INVALID_URL_SCHEME";
901
- throw error;
902
- }
903
- return getPathFromURLPosix(path2);
904
- }
905
- function getPathFromURLPosix(url) {
906
- if (url.hostname !== "") {
907
- const error = new TypeError(
908
- 'File URL host must be "localhost" or empty on darwin'
909
- );
910
- error.code = "ERR_INVALID_FILE_URL_HOST";
911
- throw error;
912
- }
913
- const pathname = url.pathname;
914
- let index2 = -1;
915
- while (++index2 < pathname.length) {
916
- if (pathname.charCodeAt(index2) === 37 && pathname.charCodeAt(index2 + 1) === 50) {
917
- const third = pathname.charCodeAt(index2 + 2);
918
- if (third === 70 || third === 102) {
919
- const error = new TypeError(
920
- "File URL path must not include encoded / characters"
921
- );
922
- error.code = "ERR_INVALID_FILE_URL_PATH";
923
- throw error;
924
- }
925
- }
926
- }
927
- return decodeURIComponent(pathname);
928
- }
929
-
930
- // ../../node_modules/.pnpm/vfile@5.3.7/node_modules/vfile/lib/index.js
931
- var order = ["history", "path", "basename", "stem", "extname", "dirname"];
932
- var VFile = class {
933
- /**
934
- * Create a new virtual file.
935
- *
936
- * `options` is treated as:
937
- *
938
- * * `string` or `Buffer` — `{value: options}`
939
- * * `URL` — `{path: options}`
940
- * * `VFile` — shallow copies its data over to the new file
941
- * * `object` — all fields are shallow copied over to the new file
942
- *
943
- * Path related fields are set in the following order (least specific to
944
- * most specific): `history`, `path`, `basename`, `stem`, `extname`,
945
- * `dirname`.
946
- *
947
- * You cannot set `dirname` or `extname` without setting either `history`,
948
- * `path`, `basename`, or `stem` too.
949
- *
950
- * @param {Compatible | null | undefined} [value]
951
- * File value.
952
- * @returns
953
- * New instance.
954
- */
955
- constructor(value) {
956
- let options;
957
- if (!value) {
958
- options = {};
959
- } else if (typeof value === "string" || buffer(value)) {
960
- options = { value };
961
- } else if (isUrl(value)) {
962
- options = { path: value };
963
- } else {
964
- options = value;
965
- }
966
- this.data = {};
967
- this.messages = [];
968
- this.history = [];
969
- this.cwd = proc.cwd();
970
- this.value;
971
- this.stored;
972
- this.result;
973
- this.map;
974
- let index2 = -1;
975
- while (++index2 < order.length) {
976
- const prop2 = order[index2];
977
- if (prop2 in options && options[prop2] !== void 0 && options[prop2] !== null) {
978
- this[prop2] = prop2 === "history" ? [...options[prop2]] : options[prop2];
979
- }
980
- }
981
- let prop;
982
- for (prop in options) {
983
- if (!order.includes(prop)) {
984
- this[prop] = options[prop];
985
- }
986
- }
987
- }
988
- /**
989
- * Get the full path (example: `'~/index.min.js'`).
990
- *
991
- * @returns {string}
992
- */
993
- get path() {
994
- return this.history[this.history.length - 1];
995
- }
996
- /**
997
- * Set the full path (example: `'~/index.min.js'`).
998
- *
999
- * Cannot be nullified.
1000
- * You can set a file URL (a `URL` object with a `file:` protocol) which will
1001
- * be turned into a path with `url.fileURLToPath`.
1002
- *
1003
- * @param {string | URL} path
1004
- */
1005
- set path(path2) {
1006
- if (isUrl(path2)) {
1007
- path2 = urlToPath(path2);
1008
- }
1009
- assertNonEmpty(path2, "path");
1010
- if (this.path !== path2) {
1011
- this.history.push(path2);
1012
- }
1013
- }
1014
- /**
1015
- * Get the parent path (example: `'~'`).
1016
- */
1017
- get dirname() {
1018
- return typeof this.path === "string" ? path.dirname(this.path) : void 0;
1019
- }
1020
- /**
1021
- * Set the parent path (example: `'~'`).
1022
- *
1023
- * Cannot be set if there’s no `path` yet.
1024
- */
1025
- set dirname(dirname2) {
1026
- assertPath2(this.basename, "dirname");
1027
- this.path = path.join(dirname2 || "", this.basename);
1028
- }
1029
- /**
1030
- * Get the basename (including extname) (example: `'index.min.js'`).
1031
- */
1032
- get basename() {
1033
- return typeof this.path === "string" ? path.basename(this.path) : void 0;
1034
- }
1035
- /**
1036
- * Set basename (including extname) (`'index.min.js'`).
1037
- *
1038
- * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
1039
- * on windows).
1040
- * Cannot be nullified (use `file.path = file.dirname` instead).
1041
- */
1042
- set basename(basename2) {
1043
- assertNonEmpty(basename2, "basename");
1044
- assertPart(basename2, "basename");
1045
- this.path = path.join(this.dirname || "", basename2);
1046
- }
1047
- /**
1048
- * Get the extname (including dot) (example: `'.js'`).
1049
- */
1050
- get extname() {
1051
- return typeof this.path === "string" ? path.extname(this.path) : void 0;
1052
- }
1053
- /**
1054
- * Set the extname (including dot) (example: `'.js'`).
1055
- *
1056
- * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
1057
- * on windows).
1058
- * Cannot be set if there’s no `path` yet.
1059
- */
1060
- set extname(extname2) {
1061
- assertPart(extname2, "extname");
1062
- assertPath2(this.dirname, "extname");
1063
- if (extname2) {
1064
- if (extname2.charCodeAt(0) !== 46) {
1065
- throw new Error("`extname` must start with `.`");
1066
- }
1067
- if (extname2.includes(".", 1)) {
1068
- throw new Error("`extname` cannot contain multiple dots");
1069
- }
1070
- }
1071
- this.path = path.join(this.dirname, this.stem + (extname2 || ""));
1072
- }
1073
- /**
1074
- * Get the stem (basename w/o extname) (example: `'index.min'`).
1075
- */
1076
- get stem() {
1077
- return typeof this.path === "string" ? path.basename(this.path, this.extname) : void 0;
1078
- }
1079
- /**
1080
- * Set the stem (basename w/o extname) (example: `'index.min'`).
1081
- *
1082
- * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
1083
- * on windows).
1084
- * Cannot be nullified (use `file.path = file.dirname` instead).
1085
- */
1086
- set stem(stem) {
1087
- assertNonEmpty(stem, "stem");
1088
- assertPart(stem, "stem");
1089
- this.path = path.join(this.dirname || "", stem + (this.extname || ""));
1090
- }
1091
- /**
1092
- * Serialize the file.
1093
- *
1094
- * @param {BufferEncoding | null | undefined} [encoding='utf8']
1095
- * Character encoding to understand `value` as when it’s a `Buffer`
1096
- * (default: `'utf8'`).
1097
- * @returns {string}
1098
- * Serialized file.
1099
- */
1100
- toString(encoding) {
1101
- return (this.value || "").toString(encoding || void 0);
1102
- }
1103
- /**
1104
- * Create a warning message associated with the file.
1105
- *
1106
- * Its `fatal` is set to `false` and `file` is set to the current file path.
1107
- * Its added to `file.messages`.
1108
- *
1109
- * @param {string | Error | VFileMessage} reason
1110
- * Reason for message, uses the stack and message of the error if given.
1111
- * @param {Node | NodeLike | Position | Point | null | undefined} [place]
1112
- * Place in file where the message occurred.
1113
- * @param {string | null | undefined} [origin]
1114
- * Place in code where the message originates (example:
1115
- * `'my-package:my-rule'` or `'my-rule'`).
1116
- * @returns {VFileMessage}
1117
- * Message.
1118
- */
1119
- message(reason, place, origin) {
1120
- const message = new VFileMessage(reason, place, origin);
1121
- if (this.path) {
1122
- message.name = this.path + ":" + message.name;
1123
- message.file = this.path;
1124
- }
1125
- message.fatal = false;
1126
- this.messages.push(message);
1127
- return message;
1128
- }
1129
- /**
1130
- * Create an info message associated with the file.
1131
- *
1132
- * Its `fatal` is set to `null` and `file` is set to the current file path.
1133
- * Its added to `file.messages`.
1134
- *
1135
- * @param {string | Error | VFileMessage} reason
1136
- * Reason for message, uses the stack and message of the error if given.
1137
- * @param {Node | NodeLike | Position | Point | null | undefined} [place]
1138
- * Place in file where the message occurred.
1139
- * @param {string | null | undefined} [origin]
1140
- * Place in code where the message originates (example:
1141
- * `'my-package:my-rule'` or `'my-rule'`).
1142
- * @returns {VFileMessage}
1143
- * Message.
1144
- */
1145
- info(reason, place, origin) {
1146
- const message = this.message(reason, place, origin);
1147
- message.fatal = null;
1148
- return message;
1149
- }
1150
- /**
1151
- * Create a fatal error associated with the file.
1152
- *
1153
- * Its `fatal` is set to `true` and `file` is set to the current file path.
1154
- * Its added to `file.messages`.
1155
- *
1156
- * > 👉 **Note**: a fatal error means that a file is no longer processable.
1157
- *
1158
- * @param {string | Error | VFileMessage} reason
1159
- * Reason for message, uses the stack and message of the error if given.
1160
- * @param {Node | NodeLike | Position | Point | null | undefined} [place]
1161
- * Place in file where the message occurred.
1162
- * @param {string | null | undefined} [origin]
1163
- * Place in code where the message originates (example:
1164
- * `'my-package:my-rule'` or `'my-rule'`).
1165
- * @returns {never}
1166
- * Message.
1167
- * @throws {VFileMessage}
1168
- * Message.
1169
- */
1170
- fail(reason, place, origin) {
1171
- const message = this.message(reason, place, origin);
1172
- message.fatal = true;
1173
- throw message;
1174
- }
1175
- };
1176
- function assertPart(part, name) {
1177
- if (part && part.includes(path.sep)) {
1178
- throw new Error(
1179
- "`" + name + "` cannot be a path: did not expect `" + path.sep + "`"
1180
- );
1181
- }
1182
- }
1183
- function assertNonEmpty(part, name) {
1184
- if (!part) {
1185
- throw new Error("`" + name + "` cannot be empty");
1186
- }
1187
- }
1188
- function assertPath2(path2, name) {
1189
- if (!path2) {
1190
- throw new Error("Setting `" + name + "` requires `path` to be set too");
1191
- }
1192
- }
1193
- function buffer(value) {
1194
- return (0, import_is_buffer.default)(value);
1195
- }
1196
-
1197
- // ../../node_modules/.pnpm/unified@10.1.2/node_modules/unified/lib/index.js
1198
- var unified = base().freeze();
1199
- var own = {}.hasOwnProperty;
1200
- function base() {
1201
- const transformers = trough();
1202
- const attachers = [];
1203
- let namespace = {};
1204
- let frozen;
1205
- let freezeIndex = -1;
1206
- processor.data = data;
1207
- processor.Parser = void 0;
1208
- processor.Compiler = void 0;
1209
- processor.freeze = freeze;
1210
- processor.attachers = attachers;
1211
- processor.use = use;
1212
- processor.parse = parse;
1213
- processor.stringify = stringify;
1214
- processor.run = run;
1215
- processor.runSync = runSync;
1216
- processor.process = process;
1217
- processor.processSync = processSync;
1218
- return processor;
1219
- function processor() {
1220
- const destination = base();
1221
- let index2 = -1;
1222
- while (++index2 < attachers.length) {
1223
- destination.use(...attachers[index2]);
1224
- }
1225
- destination.data((0, import_extend.default)(true, {}, namespace));
1226
- return destination;
1227
- }
1228
- function data(key, value) {
1229
- if (typeof key === "string") {
1230
- if (arguments.length === 2) {
1231
- assertUnfrozen("data", frozen);
1232
- namespace[key] = value;
1233
- return processor;
1234
- }
1235
- return own.call(namespace, key) && namespace[key] || null;
1236
- }
1237
- if (key) {
1238
- assertUnfrozen("data", frozen);
1239
- namespace = key;
1240
- return processor;
1241
- }
1242
- return namespace;
1243
- }
1244
- function freeze() {
1245
- if (frozen) {
1246
- return processor;
1247
- }
1248
- while (++freezeIndex < attachers.length) {
1249
- const [attacher, ...options] = attachers[freezeIndex];
1250
- if (options[0] === false) {
1251
- continue;
1252
- }
1253
- if (options[0] === true) {
1254
- options[0] = void 0;
1255
- }
1256
- const transformer = attacher.call(processor, ...options);
1257
- if (typeof transformer === "function") {
1258
- transformers.use(transformer);
1259
- }
1260
- }
1261
- frozen = true;
1262
- freezeIndex = Number.POSITIVE_INFINITY;
1263
- return processor;
1264
- }
1265
- function use(value, ...options) {
1266
- let settings;
1267
- assertUnfrozen("use", frozen);
1268
- if (value === null || value === void 0) {
1269
- } else if (typeof value === "function") {
1270
- addPlugin(value, ...options);
1271
- } else if (typeof value === "object") {
1272
- if (Array.isArray(value)) {
1273
- addList(value);
1274
- } else {
1275
- addPreset(value);
1276
- }
1277
- } else {
1278
- throw new TypeError("Expected usable value, not `" + value + "`");
1279
- }
1280
- if (settings) {
1281
- namespace.settings = Object.assign(namespace.settings || {}, settings);
1282
- }
1283
- return processor;
1284
- function add(value2) {
1285
- if (typeof value2 === "function") {
1286
- addPlugin(value2);
1287
- } else if (typeof value2 === "object") {
1288
- if (Array.isArray(value2)) {
1289
- const [plugin, ...options2] = value2;
1290
- addPlugin(plugin, ...options2);
1291
- } else {
1292
- addPreset(value2);
1293
- }
1294
- } else {
1295
- throw new TypeError("Expected usable value, not `" + value2 + "`");
1296
- }
1297
- }
1298
- function addPreset(result) {
1299
- addList(result.plugins);
1300
- if (result.settings) {
1301
- settings = Object.assign(settings || {}, result.settings);
1302
- }
1303
- }
1304
- function addList(plugins) {
1305
- let index2 = -1;
1306
- if (plugins === null || plugins === void 0) {
1307
- } else if (Array.isArray(plugins)) {
1308
- while (++index2 < plugins.length) {
1309
- const thing = plugins[index2];
1310
- add(thing);
1311
- }
1312
- } else {
1313
- throw new TypeError("Expected a list of plugins, not `" + plugins + "`");
1314
- }
1315
- }
1316
- function addPlugin(plugin, value2) {
1317
- let index2 = -1;
1318
- let entry;
1319
- while (++index2 < attachers.length) {
1320
- if (attachers[index2][0] === plugin) {
1321
- entry = attachers[index2];
1322
- break;
1323
- }
1324
- }
1325
- if (entry) {
1326
- if (isPlainObject(entry[1]) && isPlainObject(value2)) {
1327
- value2 = (0, import_extend.default)(true, entry[1], value2);
1328
- }
1329
- entry[1] = value2;
1330
- } else {
1331
- attachers.push([...arguments]);
1332
- }
1333
- }
1334
- }
1335
- function parse(doc) {
1336
- processor.freeze();
1337
- const file = vfile(doc);
1338
- const Parser = processor.Parser;
1339
- assertParser("parse", Parser);
1340
- if (newable(Parser, "parse")) {
1341
- return new Parser(String(file), file).parse();
1342
- }
1343
- return Parser(String(file), file);
1344
- }
1345
- function stringify(node, doc) {
1346
- processor.freeze();
1347
- const file = vfile(doc);
1348
- const Compiler = processor.Compiler;
1349
- assertCompiler("stringify", Compiler);
1350
- assertNode(node);
1351
- if (newable(Compiler, "compile")) {
1352
- return new Compiler(node, file).compile();
1353
- }
1354
- return Compiler(node, file);
1355
- }
1356
- function run(node, doc, callback) {
1357
- assertNode(node);
1358
- processor.freeze();
1359
- if (!callback && typeof doc === "function") {
1360
- callback = doc;
1361
- doc = void 0;
1362
- }
1363
- if (!callback) {
1364
- return new Promise(executor);
1365
- }
1366
- executor(null, callback);
1367
- function executor(resolve, reject) {
1368
- transformers.run(node, vfile(doc), done);
1369
- function done(error, tree, file) {
1370
- tree = tree || node;
1371
- if (error) {
1372
- reject(error);
1373
- } else if (resolve) {
1374
- resolve(tree);
1375
- } else {
1376
- callback(null, tree, file);
1377
- }
1378
- }
1379
- }
1380
- }
1381
- function runSync(node, file) {
1382
- let result;
1383
- let complete;
1384
- processor.run(node, file, done);
1385
- assertDone("runSync", "run", complete);
1386
- return result;
1387
- function done(error, tree) {
1388
- bail(error);
1389
- result = tree;
1390
- complete = true;
1391
- }
1392
- }
1393
- function process(doc, callback) {
1394
- processor.freeze();
1395
- assertParser("process", processor.Parser);
1396
- assertCompiler("process", processor.Compiler);
1397
- if (!callback) {
1398
- return new Promise(executor);
1399
- }
1400
- executor(null, callback);
1401
- function executor(resolve, reject) {
1402
- const file = vfile(doc);
1403
- processor.run(processor.parse(file), file, (error, tree, file2) => {
1404
- if (error || !tree || !file2) {
1405
- done(error);
1406
- } else {
1407
- const result = processor.stringify(tree, file2);
1408
- if (result === void 0 || result === null) {
1409
- } else if (looksLikeAVFileValue(result)) {
1410
- file2.value = result;
1411
- } else {
1412
- file2.result = result;
1413
- }
1414
- done(error, file2);
1415
- }
1416
- });
1417
- function done(error, file2) {
1418
- if (error || !file2) {
1419
- reject(error);
1420
- } else if (resolve) {
1421
- resolve(file2);
1422
- } else {
1423
- callback(null, file2);
1424
- }
1425
- }
1426
- }
1427
- }
1428
- function processSync(doc) {
1429
- let complete;
1430
- processor.freeze();
1431
- assertParser("processSync", processor.Parser);
1432
- assertCompiler("processSync", processor.Compiler);
1433
- const file = vfile(doc);
1434
- processor.process(file, done);
1435
- assertDone("processSync", "process", complete);
1436
- return file;
1437
- function done(error) {
1438
- complete = true;
1439
- bail(error);
1440
- }
1441
- }
1442
- }
1443
- function newable(value, name) {
1444
- return typeof value === "function" && // Prototypes do exist.
1445
- // type-coverage:ignore-next-line
1446
- value.prototype && // A function with keys in its prototype is probably a constructor.
1447
- // Classes’ prototype methods are not enumerable, so we check if some value
1448
- // exists in the prototype.
1449
- // type-coverage:ignore-next-line
1450
- (keys(value.prototype) || name in value.prototype);
1451
- }
1452
- function keys(value) {
1453
- let key;
1454
- for (key in value) {
1455
- if (own.call(value, key)) {
1456
- return true;
1457
- }
1458
- }
1459
- return false;
1460
- }
1461
- function assertParser(name, value) {
1462
- if (typeof value !== "function") {
1463
- throw new TypeError("Cannot `" + name + "` without `Parser`");
1464
- }
1465
- }
1466
- function assertCompiler(name, value) {
1467
- if (typeof value !== "function") {
1468
- throw new TypeError("Cannot `" + name + "` without `Compiler`");
1469
- }
1470
- }
1471
- function assertUnfrozen(name, frozen) {
1472
- if (frozen) {
1473
- throw new Error(
1474
- "Cannot call `" + name + "` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`."
1475
- );
1476
- }
1477
- }
1478
- function assertNode(node) {
1479
- if (!isPlainObject(node) || typeof node.type !== "string") {
1480
- throw new TypeError("Expected node, got `" + node + "`");
1481
- }
1482
- }
1483
- function assertDone(name, asyncName, complete) {
1484
- if (!complete) {
1485
- throw new Error(
1486
- "`" + name + "` finished async. Use `" + asyncName + "` instead"
1487
- );
1488
- }
1489
- }
1490
- function vfile(value) {
1491
- return looksLikeAVFile(value) ? value : new VFile(value);
1492
- }
1493
- function looksLikeAVFile(value) {
1494
- return Boolean(
1495
- value && typeof value === "object" && "message" in value && "messages" in value
1496
- );
1497
- }
1498
- function looksLikeAVFileValue(value) {
1499
- return typeof value === "string" || (0, import_is_buffer2.default)(value);
1500
- }
1501
-
1502
- // src/useRemarkSync.ts
1503
- import remarkParse from "remark-parse";
1504
- import remarkToRehype from "remark-rehype";
1505
- import rehypeReact from "rehype-react";
1506
- var useRemarkSync = (source, {
1507
- remarkToRehypeOptions,
1508
- rehypeReactOptions,
1509
- remarkPlugins = [],
1510
- rehypePlugins = []
1511
- } = {}) => unified().use(remarkParse).use(remarkPlugins).use(remarkToRehype, remarkToRehypeOptions).use(rehypePlugins).use(rehypeReact, __spreadValues({
1512
- createElement,
1513
- Fragment: Fragment3
1514
- }, rehypeReactOptions)).processSync(source).result;
1515
-
1516
- // src/useToc.ts
1517
- import remarkParse2 from "remark-parse";
1518
- import remarkStringify from "remark-stringify";
1519
-
1520
- // src/remarkHeadings.ts
1521
- import { visit as visit3 } from "unist-util-visit";
1522
- import { toString } from "mdast-util-to-string";
1523
- var getAnchor = (heading) => {
1524
- var _a;
1525
- if ((_a = heading == null ? void 0 : heading.data) == null ? void 0 : _a.id) {
1526
- return heading.data.id;
1527
- }
1528
- let anchor = toString(heading, { includeImageAlt: false }).toLowerCase();
1529
- anchor = anchor.replace(/[^a-zA-Z0-9 ]/g, "");
1530
- anchor = anchor.replace(/ /g, "-");
1531
- return anchor;
1532
- };
1533
- var headings = (root) => {
1534
- const headingList = [];
1535
- visit3(root, "heading", (node) => {
1536
- const heading = {
1537
- level: node.depth,
1538
- label: toString(node, { includeImageAlt: false }),
1539
- anchor: getAnchor(node)
1540
- };
1541
- headingList.push(heading);
1542
- });
1543
- return headingList;
1544
- };
1545
- var remarkHeadings = () => {
1546
- return (tree, file) => {
1547
- file.data.headings = headings(tree);
1548
- };
1549
- };
1550
-
1551
- // src/useToc.ts
1552
- var useToc = (markdown) => {
1553
- return unified().use(remarkCustomHeadingIds).use(remarkParse2).use(remarkStringify).use(remarkHeadings).processSync(markdown).data.headings;
1554
- };
1555
-
1556
- // src/Markdown.tsx
1557
- import { Fragment as Fragment4, useState as useState4 } from "react";
1558
- import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
1559
- var Markdown = ({ children, showToc = true }) => {
1560
- const directives = useDirectives2();
1561
- const toc = useToc(children);
1562
- const [isTocOpen, setIsTocOpen] = useState4(false);
1563
- const reactContent = useRemarkSync(children, {
1564
- rehypeReactOptions: {
1565
- passNode: true,
1566
- components: __spreadProps(__spreadValues({}, directives), {
1567
- a: Link,
1568
- code: Code,
1569
- td: Td,
1570
- th: Th,
1571
- table: Table,
1572
- tr: Tr,
1573
- h1: Headings(1),
1574
- h2: Headings(2),
1575
- h3: Headings(3),
1576
- h4: Headings(4),
1577
- h5: Headings(5),
1578
- h6: Headings(6),
1579
- img: Image
1580
- })
1581
- },
1582
- remarkPlugins: [
1583
- remarkRemoveComments,
1584
- remarkCustomHeadingIds,
1585
- remarkGfm,
1586
- remarkDirective,
1587
- remarkDirectiveRehype,
1588
- remarkMath,
1589
- remarkGemoji,
1590
- remarkUnwrapImages
1591
- ],
1592
- rehypePlugins: [
1593
- rehypeKatex,
1594
- [rehypeHighlight, { ignoreMissing: true, plainText: ["mermaid"] }]
1595
- ]
1596
- });
1597
- return /* @__PURE__ */ jsxs4("div", { className: "hyperbook-markdown", children: [
1598
- showToc && /* @__PURE__ */ jsxs4(Fragment4, { children: [
1599
- /* @__PURE__ */ jsxs4(
1600
- "button",
1601
- {
1602
- className: isTocOpen ? "toc-toggle open" : "toc-toggle",
1603
- onClick: () => setIsTocOpen(!isTocOpen),
1604
- title: "Table of Contents",
1605
- children: [
1606
- /* @__PURE__ */ jsx6("div", { className: "bar1" }),
1607
- /* @__PURE__ */ jsx6("div", { className: "bar2" }),
1608
- /* @__PURE__ */ jsx6("div", { className: "bar3" }),
1609
- /* @__PURE__ */ jsx6("div", { className: "bar4" })
1610
- ]
1611
- }
1612
- ),
1613
- /* @__PURE__ */ jsx6(
1614
- Drawer,
1615
- {
1616
- isOpen: isTocOpen,
1617
- onClose: () => setIsTocOpen(false),
1618
- position: "right",
1619
- children: /* @__PURE__ */ jsx6("div", { id: "toc-sidebar", children: /* @__PURE__ */ jsx6("nav", { className: "toc", children: /* @__PURE__ */ jsx6("ul", { children: toc.map((h, i) => /* @__PURE__ */ jsx6("li", { className: `level-${h.level}`, children: /* @__PURE__ */ jsx6("a", { href: `#${h.anchor}`, children: h.label }) }, i)) }) }) })
1620
- }
1621
- )
1622
- ] }),
1623
- reactContent
1624
- ] });
1625
- };
1626
- export {
1627
- Markdown,
1628
- useToc
1629
- };
1630
- /*! Bundled license information:
1631
-
1632
- is-buffer/index.js:
1633
- (*!
1634
- * Determine if an object is a Buffer
1635
- *
1636
- * @author Feross Aboukhadijeh <https://feross.org>
1637
- * @license MIT
1638
- *)
1639
- */
1640
- //# sourceMappingURL=index.esm.mjs.map