@unified-latex/unified-latex 1.8.3 → 1.8.4

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/index.cjs CHANGED
@@ -1,311 +1,522 @@
1
- "use strict";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const unifiedLatexUtilParse = require("@unified-latex/unified-latex-util-parse");
4
- const unifiedLatexUtilToString = require("@unified-latex/unified-latex-util-to-string");
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
21
+ value: mod,
22
+ enumerable: true
23
+ }) : target, mod));
24
+ //#endregion
25
+ let _unified_latex_unified_latex_util_parse = require("@unified-latex/unified-latex-util-parse");
26
+ let _unified_latex_unified_latex_util_to_string = require("@unified-latex/unified-latex-util-to-string");
27
+ //#region ../../node_modules/bail/index.js
28
+ /**
29
+ * Throw a given error.
30
+ *
31
+ * @param {Error|null|undefined} [error]
32
+ * Maybe error.
33
+ * @returns {asserts error is null|undefined}
34
+ */
5
35
  function bail(error) {
6
- if (error) {
7
- throw error;
8
- }
9
- }
10
- function getDefaultExportFromCjs(x) {
11
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
12
- }
13
- /*!
14
- * Determine if an object is a Buffer
15
- *
16
- * @author Feross Aboukhadijeh <https://feross.org>
17
- * @license MIT
18
- */
19
- var isBuffer$1;
20
- var hasRequiredIsBuffer;
21
- function requireIsBuffer() {
22
- if (hasRequiredIsBuffer) return isBuffer$1;
23
- hasRequiredIsBuffer = 1;
24
- isBuffer$1 = function isBuffer2(obj) {
25
- return obj != null && obj.constructor != null && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
26
- };
27
- return isBuffer$1;
36
+ if (error) throw error;
28
37
  }
29
- var isBufferExports = requireIsBuffer();
30
- const isBuffer = /* @__PURE__ */ getDefaultExportFromCjs(isBufferExports);
31
- var extend$1;
32
- var hasRequiredExtend;
33
- function requireExtend() {
34
- if (hasRequiredExtend) return extend$1;
35
- hasRequiredExtend = 1;
36
- var hasOwn = Object.prototype.hasOwnProperty;
37
- var toStr = Object.prototype.toString;
38
- var defineProperty = Object.defineProperty;
39
- var gOPD = Object.getOwnPropertyDescriptor;
40
- var isArray = function isArray2(arr) {
41
- if (typeof Array.isArray === "function") {
42
- return Array.isArray(arr);
43
- }
44
- return toStr.call(arr) === "[object Array]";
45
- };
46
- var isPlainObject2 = function isPlainObject3(obj) {
47
- if (!obj || toStr.call(obj) !== "[object Object]") {
48
- return false;
49
- }
50
- var hasOwnConstructor = hasOwn.call(obj, "constructor");
51
- var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, "isPrototypeOf");
52
- if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
53
- return false;
54
- }
55
- var key;
56
- for (key in obj) {
57
- }
58
- return typeof key === "undefined" || hasOwn.call(obj, key);
59
- };
60
- var setProperty = function setProperty2(target, options) {
61
- if (defineProperty && options.name === "__proto__") {
62
- defineProperty(target, options.name, {
63
- enumerable: true,
64
- configurable: true,
65
- value: options.newValue,
66
- writable: true
67
- });
68
- } else {
69
- target[options.name] = options.newValue;
70
- }
71
- };
72
- var getProperty = function getProperty2(obj, name) {
73
- if (name === "__proto__") {
74
- if (!hasOwn.call(obj, name)) {
75
- return void 0;
76
- } else if (gOPD) {
77
- return gOPD(obj, name).value;
78
- }
79
- }
80
- return obj[name];
81
- };
82
- extend$1 = function extend2() {
83
- var options, name, src, copy, copyIsArray, clone;
84
- var target = arguments[0];
85
- var i = 1;
86
- var length = arguments.length;
87
- var deep = false;
88
- if (typeof target === "boolean") {
89
- deep = target;
90
- target = arguments[1] || {};
91
- i = 2;
92
- }
93
- if (target == null || typeof target !== "object" && typeof target !== "function") {
94
- target = {};
95
- }
96
- for (; i < length; ++i) {
97
- options = arguments[i];
98
- if (options != null) {
99
- for (name in options) {
100
- src = getProperty(target, name);
101
- copy = getProperty(options, name);
102
- if (target !== copy) {
103
- if (deep && copy && (isPlainObject2(copy) || (copyIsArray = isArray(copy)))) {
104
- if (copyIsArray) {
105
- copyIsArray = false;
106
- clone = src && isArray(src) ? src : [];
107
- } else {
108
- clone = src && isPlainObject2(src) ? src : {};
109
- }
110
- setProperty(target, { name, newValue: extend2(deep, clone, copy) });
111
- } else if (typeof copy !== "undefined") {
112
- setProperty(target, { name, newValue: copy });
113
- }
114
- }
115
- }
116
- }
117
- }
118
- return target;
119
- };
120
- return extend$1;
121
- }
122
- var extendExports = requireExtend();
123
- const extend = /* @__PURE__ */ getDefaultExportFromCjs(extendExports);
38
+ //#endregion
39
+ //#region ../../node_modules/is-buffer/index.js
40
+ var require_is_buffer = /* @__PURE__ */ __commonJSMin(((exports, module) => {
41
+ /*!
42
+ * Determine if an object is a Buffer
43
+ *
44
+ * @author Feross Aboukhadijeh <https://feross.org>
45
+ * @license MIT
46
+ */
47
+ module.exports = function isBuffer(obj) {
48
+ return obj != null && obj.constructor != null && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
49
+ };
50
+ }));
51
+ //#endregion
52
+ //#region ../../node_modules/extend/index.js
53
+ var require_extend = /* @__PURE__ */ __commonJSMin(((exports, module) => {
54
+ var hasOwn = Object.prototype.hasOwnProperty;
55
+ var toStr = Object.prototype.toString;
56
+ var defineProperty = Object.defineProperty;
57
+ var gOPD = Object.getOwnPropertyDescriptor;
58
+ var isArray = function isArray(arr) {
59
+ if (typeof Array.isArray === "function") return Array.isArray(arr);
60
+ return toStr.call(arr) === "[object Array]";
61
+ };
62
+ var isPlainObject = function isPlainObject(obj) {
63
+ if (!obj || toStr.call(obj) !== "[object Object]") return false;
64
+ var hasOwnConstructor = hasOwn.call(obj, "constructor");
65
+ var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, "isPrototypeOf");
66
+ if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) return false;
67
+ var key;
68
+ for (key in obj);
69
+ return typeof key === "undefined" || hasOwn.call(obj, key);
70
+ };
71
+ var setProperty = function setProperty(target, options) {
72
+ if (defineProperty && options.name === "__proto__") defineProperty(target, options.name, {
73
+ enumerable: true,
74
+ configurable: true,
75
+ value: options.newValue,
76
+ writable: true
77
+ });
78
+ else target[options.name] = options.newValue;
79
+ };
80
+ var getProperty = function getProperty(obj, name) {
81
+ if (name === "__proto__") {
82
+ if (!hasOwn.call(obj, name)) return;
83
+ else if (gOPD) return gOPD(obj, name).value;
84
+ }
85
+ return obj[name];
86
+ };
87
+ module.exports = function extend() {
88
+ var options, name, src, copy, copyIsArray, clone;
89
+ var target = arguments[0];
90
+ var i = 1;
91
+ var length = arguments.length;
92
+ var deep = false;
93
+ if (typeof target === "boolean") {
94
+ deep = target;
95
+ target = arguments[1] || {};
96
+ i = 2;
97
+ }
98
+ if (target == null || typeof target !== "object" && typeof target !== "function") target = {};
99
+ for (; i < length; ++i) {
100
+ options = arguments[i];
101
+ if (options != null) for (name in options) {
102
+ src = getProperty(target, name);
103
+ copy = getProperty(options, name);
104
+ if (target !== copy) {
105
+ if (deep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
106
+ if (copyIsArray) {
107
+ copyIsArray = false;
108
+ clone = src && isArray(src) ? src : [];
109
+ } else clone = src && isPlainObject(src) ? src : {};
110
+ setProperty(target, {
111
+ name,
112
+ newValue: extend(deep, clone, copy)
113
+ });
114
+ } else if (typeof copy !== "undefined") setProperty(target, {
115
+ name,
116
+ newValue: copy
117
+ });
118
+ }
119
+ }
120
+ }
121
+ return target;
122
+ };
123
+ }));
124
+ //#endregion
125
+ //#region node_modules/is-plain-obj/index.js
124
126
  function isPlainObject(value) {
125
- if (typeof value !== "object" || value === null) {
126
- return false;
127
- }
128
- const prototype = Object.getPrototypeOf(value);
129
- return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
127
+ if (typeof value !== "object" || value === null) return false;
128
+ const prototype = Object.getPrototypeOf(value);
129
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
130
130
  }
131
+ //#endregion
132
+ //#region ../../node_modules/trough/lib/index.js
133
+ /**
134
+ * @typedef {(error?: Error | null | undefined, ...output: Array<any>) => void} Callback
135
+ * Callback.
136
+ *
137
+ * @typedef {(...input: Array<any>) => any} Middleware
138
+ * Ware.
139
+ *
140
+ * @typedef Pipeline
141
+ * Pipeline.
142
+ * @property {Run} run
143
+ * Run the pipeline.
144
+ * @property {Use} use
145
+ * Add middleware.
146
+ *
147
+ * @typedef {(...input: Array<any>) => void} Run
148
+ * Call all middleware.
149
+ *
150
+ * Calls `done` on completion with either an error or the output of the
151
+ * last middleware.
152
+ *
153
+ * > 👉 **Note**: as the length of input defines whether async functions get a
154
+ * > `next` function,
155
+ * > it’s recommended to keep `input` at one value normally.
156
+
157
+ *
158
+ * @typedef {(fn: Middleware) => Pipeline} Use
159
+ * Add middleware.
160
+ */
161
+ /**
162
+ * Create new middleware.
163
+ *
164
+ * @returns {Pipeline}
165
+ * Pipeline.
166
+ */
131
167
  function trough() {
132
- const fns = [];
133
- const pipeline = { run, use };
134
- return pipeline;
135
- function run(...values) {
136
- let middlewareIndex = -1;
137
- const callback = values.pop();
138
- if (typeof callback !== "function") {
139
- throw new TypeError("Expected function as last argument, not " + callback);
140
- }
141
- next(null, ...values);
142
- function next(error, ...output) {
143
- const fn = fns[++middlewareIndex];
144
- let index2 = -1;
145
- if (error) {
146
- callback(error);
147
- return;
148
- }
149
- while (++index2 < values.length) {
150
- if (output[index2] === null || output[index2] === void 0) {
151
- output[index2] = values[index2];
152
- }
153
- }
154
- values = output;
155
- if (fn) {
156
- wrap(fn, next)(...output);
157
- } else {
158
- callback(null, ...output);
159
- }
160
- }
161
- }
162
- function use(middelware) {
163
- if (typeof middelware !== "function") {
164
- throw new TypeError(
165
- "Expected `middelware` to be a function, not " + middelware
166
- );
167
- }
168
- fns.push(middelware);
169
- return pipeline;
170
- }
168
+ /** @type {Array<Middleware>} */
169
+ const fns = [];
170
+ /** @type {Pipeline} */
171
+ const pipeline = {
172
+ run,
173
+ use
174
+ };
175
+ return pipeline;
176
+ /** @type {Run} */
177
+ function run(...values) {
178
+ let middlewareIndex = -1;
179
+ /** @type {Callback} */
180
+ const callback = values.pop();
181
+ if (typeof callback !== "function") throw new TypeError("Expected function as last argument, not " + callback);
182
+ next(null, ...values);
183
+ /**
184
+ * Run the next `fn`, or we’re done.
185
+ *
186
+ * @param {Error | null | undefined} error
187
+ * @param {Array<any>} output
188
+ */
189
+ function next(error, ...output) {
190
+ const fn = fns[++middlewareIndex];
191
+ let index = -1;
192
+ if (error) {
193
+ callback(error);
194
+ return;
195
+ }
196
+ while (++index < values.length) if (output[index] === null || output[index] === void 0) output[index] = values[index];
197
+ values = output;
198
+ if (fn) wrap(fn, next)(...output);
199
+ else callback(null, ...output);
200
+ }
201
+ }
202
+ /** @type {Use} */
203
+ function use(middelware) {
204
+ if (typeof middelware !== "function") throw new TypeError("Expected `middelware` to be a function, not " + middelware);
205
+ fns.push(middelware);
206
+ return pipeline;
207
+ }
171
208
  }
209
+ /**
210
+ * Wrap `middleware` into a uniform interface.
211
+ *
212
+ * You can pass all input to the resulting function.
213
+ * `callback` is then called with the output of `middleware`.
214
+ *
215
+ * If `middleware` accepts more arguments than the later given in input,
216
+ * an extra `done` function is passed to it after that input,
217
+ * which must be called by `middleware`.
218
+ *
219
+ * The first value in `input` is the main input value.
220
+ * All other input values are the rest input values.
221
+ * The values given to `callback` are the input values,
222
+ * merged with every non-nullish output value.
223
+ *
224
+ * * if `middleware` throws an error,
225
+ * returns a promise that is rejected,
226
+ * or calls the given `done` function with an error,
227
+ * `callback` is called with that error
228
+ * * if `middleware` returns a value or returns a promise that is resolved,
229
+ * that value is the main output value
230
+ * * if `middleware` calls `done`,
231
+ * all non-nullish values except for the first one (the error) overwrite the
232
+ * output values
233
+ *
234
+ * @param {Middleware} middleware
235
+ * Function to wrap.
236
+ * @param {Callback} callback
237
+ * Callback called with the output of `middleware`.
238
+ * @returns {Run}
239
+ * Wrapped middleware.
240
+ */
172
241
  function wrap(middleware, callback) {
173
- let called;
174
- return wrapped;
175
- function wrapped(...parameters) {
176
- const fnExpectsCallback = middleware.length > parameters.length;
177
- let result;
178
- if (fnExpectsCallback) {
179
- parameters.push(done);
180
- }
181
- try {
182
- result = middleware.apply(this, parameters);
183
- } catch (error) {
184
- const exception = (
185
- /** @type {Error} */
186
- error
187
- );
188
- if (fnExpectsCallback && called) {
189
- throw exception;
190
- }
191
- return done(exception);
192
- }
193
- if (!fnExpectsCallback) {
194
- if (result && result.then && typeof result.then === "function") {
195
- result.then(then, done);
196
- } else if (result instanceof Error) {
197
- done(result);
198
- } else {
199
- then(result);
200
- }
201
- }
202
- }
203
- function done(error, ...output) {
204
- if (!called) {
205
- called = true;
206
- callback(error, ...output);
207
- }
208
- }
209
- function then(value) {
210
- done(null, value);
211
- }
242
+ /** @type {boolean} */
243
+ let called;
244
+ return wrapped;
245
+ /**
246
+ * Call `middleware`.
247
+ * @this {any}
248
+ * @param {Array<any>} parameters
249
+ * @returns {void}
250
+ */
251
+ function wrapped(...parameters) {
252
+ const fnExpectsCallback = middleware.length > parameters.length;
253
+ /** @type {any} */
254
+ let result;
255
+ if (fnExpectsCallback) parameters.push(done);
256
+ try {
257
+ result = middleware.apply(this, parameters);
258
+ } catch (error) {
259
+ const exception = error;
260
+ if (fnExpectsCallback && called) throw exception;
261
+ return done(exception);
262
+ }
263
+ if (!fnExpectsCallback) if (result && result.then && typeof result.then === "function") result.then(then, done);
264
+ else if (result instanceof Error) done(result);
265
+ else then(result);
266
+ }
267
+ /**
268
+ * Call `callback`, only once.
269
+ *
270
+ * @type {Callback}
271
+ */
272
+ function done(error, ...output) {
273
+ if (!called) {
274
+ called = true;
275
+ callback(error, ...output);
276
+ }
277
+ }
278
+ /**
279
+ * Call `done` with one value.
280
+ *
281
+ * @param {any} [value]
282
+ */
283
+ function then(value) {
284
+ done(null, value);
285
+ }
212
286
  }
287
+ //#endregion
288
+ //#region node_modules/unist-util-stringify-position/lib/index.js
289
+ /**
290
+ * @typedef {import('unist').Node} Node
291
+ * @typedef {import('unist').Point} Point
292
+ * @typedef {import('unist').Position} Position
293
+ */
294
+ /**
295
+ * @typedef NodeLike
296
+ * @property {string} type
297
+ * @property {PositionLike | null | undefined} [position]
298
+ *
299
+ * @typedef PositionLike
300
+ * @property {PointLike | null | undefined} [start]
301
+ * @property {PointLike | null | undefined} [end]
302
+ *
303
+ * @typedef PointLike
304
+ * @property {number | null | undefined} [line]
305
+ * @property {number | null | undefined} [column]
306
+ * @property {number | null | undefined} [offset]
307
+ */
308
+ /**
309
+ * Serialize the positional info of a point, position (start and end points),
310
+ * or node.
311
+ *
312
+ * @param {Node | NodeLike | Position | PositionLike | Point | PointLike | null | undefined} [value]
313
+ * Node, position, or point.
314
+ * @returns {string}
315
+ * Pretty printed positional info of a node (`string`).
316
+ *
317
+ * In the format of a range `ls:cs-le:ce` (when given `node` or `position`)
318
+ * or a point `l:c` (when given `point`), where `l` stands for line, `c` for
319
+ * column, `s` for `start`, and `e` for end.
320
+ * An empty string (`''`) is returned if the given value is neither `node`,
321
+ * `position`, nor `point`.
322
+ */
213
323
  function stringifyPosition(value) {
214
- if (!value || typeof value !== "object") {
215
- return "";
216
- }
217
- if ("position" in value || "type" in value) {
218
- return position(value.position);
219
- }
220
- if ("start" in value || "end" in value) {
221
- return position(value);
222
- }
223
- if ("line" in value || "column" in value) {
224
- return point(value);
225
- }
226
- return "";
324
+ if (!value || typeof value !== "object") return "";
325
+ if ("position" in value || "type" in value) return position(value.position);
326
+ if ("start" in value || "end" in value) return position(value);
327
+ if ("line" in value || "column" in value) return point(value);
328
+ return "";
227
329
  }
228
- function point(point2) {
229
- return index(point2 && point2.line) + ":" + index(point2 && point2.column);
330
+ /**
331
+ * @param {Point | PointLike | null | undefined} point
332
+ * @returns {string}
333
+ */
334
+ function point(point) {
335
+ return index(point && point.line) + ":" + index(point && point.column);
230
336
  }
337
+ /**
338
+ * @param {Position | PositionLike | null | undefined} pos
339
+ * @returns {string}
340
+ */
231
341
  function position(pos) {
232
- return point(pos && pos.start) + "-" + point(pos && pos.end);
342
+ return point(pos && pos.start) + "-" + point(pos && pos.end);
233
343
  }
344
+ /**
345
+ * @param {number | null | undefined} value
346
+ * @returns {number}
347
+ */
234
348
  function index(value) {
235
- return value && typeof value === "number" ? value : 1;
236
- }
237
- class VFileMessage extends Error {
238
- /**
239
- * Create a message for `reason` at `place` from `origin`.
240
- *
241
- * When an error is passed in as `reason`, the `stack` is copied.
242
- *
243
- * @param {string | Error | VFileMessage} reason
244
- * Reason for message, uses the stack and message of the error if given.
245
- *
246
- * > 👉 **Note**: you should use markdown.
247
- * @param {Node | NodeLike | Position | Point | null | undefined} [place]
248
- * Place in file where the message occurred.
249
- * @param {string | null | undefined} [origin]
250
- * Place in code where the message originates (example:
251
- * `'my-package:my-rule'` or `'my-rule'`).
252
- * @returns
253
- * Instance of `VFileMessage`.
254
- */
255
- // To do: next major: expose `undefined` everywhere instead of `null`.
256
- constructor(reason, place, origin) {
257
- const parts = [null, null];
258
- let position2 = {
259
- // @ts-expect-error: we always follows the structure of `position`.
260
- start: { line: null, column: null },
261
- // @ts-expect-error: "
262
- end: { line: null, column: null }
263
- };
264
- super();
265
- if (typeof place === "string") {
266
- origin = place;
267
- place = void 0;
268
- }
269
- if (typeof origin === "string") {
270
- const index2 = origin.indexOf(":");
271
- if (index2 === -1) {
272
- parts[1] = origin;
273
- } else {
274
- parts[0] = origin.slice(0, index2);
275
- parts[1] = origin.slice(index2 + 1);
276
- }
277
- }
278
- if (place) {
279
- if ("type" in place || "position" in place) {
280
- if (place.position) {
281
- position2 = place.position;
282
- }
283
- } else if ("start" in place || "end" in place) {
284
- position2 = place;
285
- } else if ("line" in place || "column" in place) {
286
- position2.start = place;
287
- }
288
- }
289
- this.name = stringifyPosition(place) || "1:1";
290
- this.message = typeof reason === "object" ? reason.message : reason;
291
- this.stack = "";
292
- if (typeof reason === "object" && reason.stack) {
293
- this.stack = reason.stack;
294
- }
295
- this.reason = this.message;
296
- this.fatal;
297
- this.line = position2.start.line;
298
- this.column = position2.start.column;
299
- this.position = position2;
300
- this.source = parts[0];
301
- this.ruleId = parts[1];
302
- this.file;
303
- this.actual;
304
- this.expected;
305
- this.url;
306
- this.note;
307
- }
349
+ return value && typeof value === "number" ? value : 1;
308
350
  }
351
+ //#endregion
352
+ //#region node_modules/vfile-message/lib/index.js
353
+ /**
354
+ * @typedef {import('unist').Node} Node
355
+ * @typedef {import('unist').Position} Position
356
+ * @typedef {import('unist').Point} Point
357
+ * @typedef {object & {type: string, position?: Position | undefined}} NodeLike
358
+ */
359
+ /**
360
+ * Message.
361
+ */
362
+ var VFileMessage = class extends Error {
363
+ /**
364
+ * Create a message for `reason` at `place` from `origin`.
365
+ *
366
+ * When an error is passed in as `reason`, the `stack` is copied.
367
+ *
368
+ * @param {string | Error | VFileMessage} reason
369
+ * Reason for message, uses the stack and message of the error if given.
370
+ *
371
+ * > 👉 **Note**: you should use markdown.
372
+ * @param {Node | NodeLike | Position | Point | null | undefined} [place]
373
+ * Place in file where the message occurred.
374
+ * @param {string | null | undefined} [origin]
375
+ * Place in code where the message originates (example:
376
+ * `'my-package:my-rule'` or `'my-rule'`).
377
+ * @returns
378
+ * Instance of `VFileMessage`.
379
+ */
380
+ constructor(reason, place, origin) {
381
+ /** @type {[string | null, string | null]} */
382
+ const parts = [null, null];
383
+ /** @type {Position} */
384
+ let position = {
385
+ start: {
386
+ line: null,
387
+ column: null
388
+ },
389
+ end: {
390
+ line: null,
391
+ column: null
392
+ }
393
+ };
394
+ super();
395
+ if (typeof place === "string") {
396
+ origin = place;
397
+ place = void 0;
398
+ }
399
+ if (typeof origin === "string") {
400
+ const index = origin.indexOf(":");
401
+ if (index === -1) parts[1] = origin;
402
+ else {
403
+ parts[0] = origin.slice(0, index);
404
+ parts[1] = origin.slice(index + 1);
405
+ }
406
+ }
407
+ if (place) {
408
+ if ("type" in place || "position" in place) {
409
+ if (place.position) position = place.position;
410
+ } else if ("start" in place || "end" in place) position = place;
411
+ else if ("line" in place || "column" in place) position.start = place;
412
+ }
413
+ /**
414
+ * Serialized positional info of error.
415
+ *
416
+ * On normal errors, this would be something like `ParseError`, buit in
417
+ * `VFile` messages we use this space to show where an error happened.
418
+ */
419
+ this.name = stringifyPosition(place) || "1:1";
420
+ /**
421
+ * Reason for message.
422
+ *
423
+ * @type {string}
424
+ */
425
+ this.message = typeof reason === "object" ? reason.message : reason;
426
+ /**
427
+ * Stack of message.
428
+ *
429
+ * This is used by normal errors to show where something happened in
430
+ * programming code, irrelevant for `VFile` messages,
431
+ *
432
+ * @type {string}
433
+ */
434
+ this.stack = "";
435
+ if (typeof reason === "object" && reason.stack) this.stack = reason.stack;
436
+ /**
437
+ * Reason for message.
438
+ *
439
+ * > 👉 **Note**: you should use markdown.
440
+ *
441
+ * @type {string}
442
+ */
443
+ this.reason = this.message;
444
+ /**
445
+ * State of problem.
446
+ *
447
+ * * `true` — marks associated file as no longer processable (error)
448
+ * * `false` — necessitates a (potential) change (warning)
449
+ * * `null | undefined` — for things that might not need changing (info)
450
+ *
451
+ * @type {boolean | null | undefined}
452
+ */
453
+ this.fatal;
454
+ /**
455
+ * Starting line of error.
456
+ *
457
+ * @type {number | null}
458
+ */
459
+ this.line = position.start.line;
460
+ /**
461
+ * Starting column of error.
462
+ *
463
+ * @type {number | null}
464
+ */
465
+ this.column = position.start.column;
466
+ /**
467
+ * Full unist position.
468
+ *
469
+ * @type {Position | null}
470
+ */
471
+ this.position = position;
472
+ /**
473
+ * Namespace of message (example: `'my-package'`).
474
+ *
475
+ * @type {string | null}
476
+ */
477
+ this.source = parts[0];
478
+ /**
479
+ * Category of message (example: `'my-rule'`).
480
+ *
481
+ * @type {string | null}
482
+ */
483
+ this.ruleId = parts[1];
484
+ /**
485
+ * Path of a file (used throughout the `VFile` ecosystem).
486
+ *
487
+ * @type {string | null}
488
+ */
489
+ this.file;
490
+ /**
491
+ * Specify the source value that’s being reported, which is deemed
492
+ * incorrect.
493
+ *
494
+ * @type {string | null}
495
+ */
496
+ this.actual;
497
+ /**
498
+ * Suggest acceptable values that can be used instead of `actual`.
499
+ *
500
+ * @type {Array<string> | null}
501
+ */
502
+ this.expected;
503
+ /**
504
+ * Link to docs for the message.
505
+ *
506
+ * > 👉 **Note**: this must be an absolute URL that can be passed as `x`
507
+ * > to `new URL(x)`.
508
+ *
509
+ * @type {string | null}
510
+ */
511
+ this.url;
512
+ /**
513
+ * Long form description of the message (you should use markdown).
514
+ *
515
+ * @type {string | null}
516
+ */
517
+ this.note;
518
+ }
519
+ };
309
520
  VFileMessage.prototype.file = "";
310
521
  VFileMessage.prototype.name = "";
311
522
  VFileMessage.prototype.reason = "";
@@ -317,844 +528,1093 @@ VFileMessage.prototype.line = null;
317
528
  VFileMessage.prototype.source = null;
318
529
  VFileMessage.prototype.ruleId = null;
319
530
  VFileMessage.prototype.position = null;
320
- const path = { basename, dirname, extname, join, sep: "/" };
321
- function basename(path2, ext) {
322
- if (ext !== void 0 && typeof ext !== "string") {
323
- throw new TypeError('"ext" argument must be a string');
324
- }
325
- assertPath$1(path2);
326
- let start = 0;
327
- let end = -1;
328
- let index2 = path2.length;
329
- let seenNonSlash;
330
- if (ext === void 0 || ext.length === 0 || ext.length > path2.length) {
331
- while (index2--) {
332
- if (path2.charCodeAt(index2) === 47) {
333
- if (seenNonSlash) {
334
- start = index2 + 1;
335
- break;
336
- }
337
- } else if (end < 0) {
338
- seenNonSlash = true;
339
- end = index2 + 1;
340
- }
341
- }
342
- return end < 0 ? "" : path2.slice(start, end);
343
- }
344
- if (ext === path2) {
345
- return "";
346
- }
347
- let firstNonSlashEnd = -1;
348
- let extIndex = ext.length - 1;
349
- while (index2--) {
350
- if (path2.charCodeAt(index2) === 47) {
351
- if (seenNonSlash) {
352
- start = index2 + 1;
353
- break;
354
- }
355
- } else {
356
- if (firstNonSlashEnd < 0) {
357
- seenNonSlash = true;
358
- firstNonSlashEnd = index2 + 1;
359
- }
360
- if (extIndex > -1) {
361
- if (path2.charCodeAt(index2) === ext.charCodeAt(extIndex--)) {
362
- if (extIndex < 0) {
363
- end = index2;
364
- }
365
- } else {
366
- extIndex = -1;
367
- end = firstNonSlashEnd;
368
- }
369
- }
370
- }
371
- }
372
- if (start === end) {
373
- end = firstNonSlashEnd;
374
- } else if (end < 0) {
375
- end = path2.length;
376
- }
377
- return path2.slice(start, end);
531
+ //#endregion
532
+ //#region node_modules/vfile/lib/minpath.browser.js
533
+ var path = {
534
+ basename,
535
+ dirname,
536
+ extname,
537
+ join,
538
+ sep: "/"
539
+ };
540
+ /**
541
+ * Get the basename from a path.
542
+ *
543
+ * @param {string} path
544
+ * File path.
545
+ * @param {string | undefined} [ext]
546
+ * Extension to strip.
547
+ * @returns {string}
548
+ * Stem or basename.
549
+ */
550
+ function basename(path, ext) {
551
+ if (ext !== void 0 && typeof ext !== "string") throw new TypeError("\"ext\" argument must be a string");
552
+ assertPath$1(path);
553
+ let start = 0;
554
+ let end = -1;
555
+ let index = path.length;
556
+ /** @type {boolean | undefined} */
557
+ let seenNonSlash;
558
+ if (ext === void 0 || ext.length === 0 || ext.length > path.length) {
559
+ while (index--) if (path.charCodeAt(index) === 47) {
560
+ if (seenNonSlash) {
561
+ start = index + 1;
562
+ break;
563
+ }
564
+ } else if (end < 0) {
565
+ seenNonSlash = true;
566
+ end = index + 1;
567
+ }
568
+ return end < 0 ? "" : path.slice(start, end);
569
+ }
570
+ if (ext === path) return "";
571
+ let firstNonSlashEnd = -1;
572
+ let extIndex = ext.length - 1;
573
+ while (index--) if (path.charCodeAt(index) === 47) {
574
+ if (seenNonSlash) {
575
+ start = index + 1;
576
+ break;
577
+ }
578
+ } else {
579
+ if (firstNonSlashEnd < 0) {
580
+ seenNonSlash = true;
581
+ firstNonSlashEnd = index + 1;
582
+ }
583
+ if (extIndex > -1) if (path.charCodeAt(index) === ext.charCodeAt(extIndex--)) {
584
+ if (extIndex < 0) end = index;
585
+ } else {
586
+ extIndex = -1;
587
+ end = firstNonSlashEnd;
588
+ }
589
+ }
590
+ if (start === end) end = firstNonSlashEnd;
591
+ else if (end < 0) end = path.length;
592
+ return path.slice(start, end);
378
593
  }
379
- function dirname(path2) {
380
- assertPath$1(path2);
381
- if (path2.length === 0) {
382
- return ".";
383
- }
384
- let end = -1;
385
- let index2 = path2.length;
386
- let unmatchedSlash;
387
- while (--index2) {
388
- if (path2.charCodeAt(index2) === 47) {
389
- if (unmatchedSlash) {
390
- end = index2;
391
- break;
392
- }
393
- } else if (!unmatchedSlash) {
394
- unmatchedSlash = true;
395
- }
396
- }
397
- return end < 0 ? path2.charCodeAt(0) === 47 ? "/" : "." : end === 1 && path2.charCodeAt(0) === 47 ? "//" : path2.slice(0, end);
594
+ /**
595
+ * Get the dirname from a path.
596
+ *
597
+ * @param {string} path
598
+ * File path.
599
+ * @returns {string}
600
+ * File path.
601
+ */
602
+ function dirname(path) {
603
+ assertPath$1(path);
604
+ if (path.length === 0) return ".";
605
+ let end = -1;
606
+ let index = path.length;
607
+ /** @type {boolean | undefined} */
608
+ let unmatchedSlash;
609
+ while (--index) if (path.charCodeAt(index) === 47) {
610
+ if (unmatchedSlash) {
611
+ end = index;
612
+ break;
613
+ }
614
+ } else if (!unmatchedSlash) unmatchedSlash = true;
615
+ return end < 0 ? path.charCodeAt(0) === 47 ? "/" : "." : end === 1 && path.charCodeAt(0) === 47 ? "//" : path.slice(0, end);
398
616
  }
399
- function extname(path2) {
400
- assertPath$1(path2);
401
- let index2 = path2.length;
402
- let end = -1;
403
- let startPart = 0;
404
- let startDot = -1;
405
- let preDotState = 0;
406
- let unmatchedSlash;
407
- while (index2--) {
408
- const code = path2.charCodeAt(index2);
409
- if (code === 47) {
410
- if (unmatchedSlash) {
411
- startPart = index2 + 1;
412
- break;
413
- }
414
- continue;
415
- }
416
- if (end < 0) {
417
- unmatchedSlash = true;
418
- end = index2 + 1;
419
- }
420
- if (code === 46) {
421
- if (startDot < 0) {
422
- startDot = index2;
423
- } else if (preDotState !== 1) {
424
- preDotState = 1;
425
- }
426
- } else if (startDot > -1) {
427
- preDotState = -1;
428
- }
429
- }
430
- if (startDot < 0 || end < 0 || // We saw a non-dot character immediately before the dot.
431
- preDotState === 0 || // The (right-most) trimmed path component is exactly `..`.
432
- preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
433
- return "";
434
- }
435
- return path2.slice(startDot, end);
617
+ /**
618
+ * Get an extname from a path.
619
+ *
620
+ * @param {string} path
621
+ * File path.
622
+ * @returns {string}
623
+ * Extname.
624
+ */
625
+ function extname(path) {
626
+ assertPath$1(path);
627
+ let index = path.length;
628
+ let end = -1;
629
+ let startPart = 0;
630
+ let startDot = -1;
631
+ let preDotState = 0;
632
+ /** @type {boolean | undefined} */
633
+ let unmatchedSlash;
634
+ while (index--) {
635
+ const code = path.charCodeAt(index);
636
+ if (code === 47) {
637
+ if (unmatchedSlash) {
638
+ startPart = index + 1;
639
+ break;
640
+ }
641
+ continue;
642
+ }
643
+ if (end < 0) {
644
+ unmatchedSlash = true;
645
+ end = index + 1;
646
+ }
647
+ if (code === 46) {
648
+ if (startDot < 0) startDot = index;
649
+ else if (preDotState !== 1) preDotState = 1;
650
+ } else if (startDot > -1) preDotState = -1;
651
+ }
652
+ if (startDot < 0 || end < 0 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) return "";
653
+ return path.slice(startDot, end);
436
654
  }
655
+ /**
656
+ * Join segments from a path.
657
+ *
658
+ * @param {Array<string>} segments
659
+ * Path segments.
660
+ * @returns {string}
661
+ * File path.
662
+ */
437
663
  function join(...segments) {
438
- let index2 = -1;
439
- let joined;
440
- while (++index2 < segments.length) {
441
- assertPath$1(segments[index2]);
442
- if (segments[index2]) {
443
- joined = joined === void 0 ? segments[index2] : joined + "/" + segments[index2];
444
- }
445
- }
446
- return joined === void 0 ? "." : normalize(joined);
664
+ let index = -1;
665
+ /** @type {string | undefined} */
666
+ let joined;
667
+ while (++index < segments.length) {
668
+ assertPath$1(segments[index]);
669
+ if (segments[index]) joined = joined === void 0 ? segments[index] : joined + "/" + segments[index];
670
+ }
671
+ return joined === void 0 ? "." : normalize(joined);
447
672
  }
448
- function normalize(path2) {
449
- assertPath$1(path2);
450
- const absolute = path2.charCodeAt(0) === 47;
451
- let value = normalizeString(path2, !absolute);
452
- if (value.length === 0 && !absolute) {
453
- value = ".";
454
- }
455
- if (value.length > 0 && path2.charCodeAt(path2.length - 1) === 47) {
456
- value += "/";
457
- }
458
- return absolute ? "/" + value : value;
673
+ /**
674
+ * Normalize a basic file path.
675
+ *
676
+ * @param {string} path
677
+ * File path.
678
+ * @returns {string}
679
+ * File path.
680
+ */
681
+ function normalize(path) {
682
+ assertPath$1(path);
683
+ const absolute = path.charCodeAt(0) === 47;
684
+ let value = normalizeString(path, !absolute);
685
+ if (value.length === 0 && !absolute) value = ".";
686
+ if (value.length > 0 && path.charCodeAt(path.length - 1) === 47) value += "/";
687
+ return absolute ? "/" + value : value;
459
688
  }
460
- function normalizeString(path2, allowAboveRoot) {
461
- let result = "";
462
- let lastSegmentLength = 0;
463
- let lastSlash = -1;
464
- let dots = 0;
465
- let index2 = -1;
466
- let code;
467
- let lastSlashIndex;
468
- while (++index2 <= path2.length) {
469
- if (index2 < path2.length) {
470
- code = path2.charCodeAt(index2);
471
- } else if (code === 47) {
472
- break;
473
- } else {
474
- code = 47;
475
- }
476
- if (code === 47) {
477
- if (lastSlash === index2 - 1 || dots === 1) ;
478
- else if (lastSlash !== index2 - 1 && dots === 2) {
479
- if (result.length < 2 || lastSegmentLength !== 2 || result.charCodeAt(result.length - 1) !== 46 || result.charCodeAt(result.length - 2) !== 46) {
480
- if (result.length > 2) {
481
- lastSlashIndex = result.lastIndexOf("/");
482
- if (lastSlashIndex !== result.length - 1) {
483
- if (lastSlashIndex < 0) {
484
- result = "";
485
- lastSegmentLength = 0;
486
- } else {
487
- result = result.slice(0, lastSlashIndex);
488
- lastSegmentLength = result.length - 1 - result.lastIndexOf("/");
489
- }
490
- lastSlash = index2;
491
- dots = 0;
492
- continue;
493
- }
494
- } else if (result.length > 0) {
495
- result = "";
496
- lastSegmentLength = 0;
497
- lastSlash = index2;
498
- dots = 0;
499
- continue;
500
- }
501
- }
502
- if (allowAboveRoot) {
503
- result = result.length > 0 ? result + "/.." : "..";
504
- lastSegmentLength = 2;
505
- }
506
- } else {
507
- if (result.length > 0) {
508
- result += "/" + path2.slice(lastSlash + 1, index2);
509
- } else {
510
- result = path2.slice(lastSlash + 1, index2);
511
- }
512
- lastSegmentLength = index2 - lastSlash - 1;
513
- }
514
- lastSlash = index2;
515
- dots = 0;
516
- } else if (code === 46 && dots > -1) {
517
- dots++;
518
- } else {
519
- dots = -1;
520
- }
521
- }
522
- return result;
689
+ /**
690
+ * Resolve `.` and `..` elements in a path with directory names.
691
+ *
692
+ * @param {string} path
693
+ * File path.
694
+ * @param {boolean} allowAboveRoot
695
+ * Whether `..` can move above root.
696
+ * @returns {string}
697
+ * File path.
698
+ */
699
+ function normalizeString(path, allowAboveRoot) {
700
+ let result = "";
701
+ let lastSegmentLength = 0;
702
+ let lastSlash = -1;
703
+ let dots = 0;
704
+ let index = -1;
705
+ /** @type {number | undefined} */
706
+ let code;
707
+ /** @type {number} */
708
+ let lastSlashIndex;
709
+ while (++index <= path.length) {
710
+ if (index < path.length) code = path.charCodeAt(index);
711
+ else if (code === 47) break;
712
+ else code = 47;
713
+ if (code === 47) {
714
+ if (lastSlash === index - 1 || dots === 1) {} else if (lastSlash !== index - 1 && dots === 2) {
715
+ if (result.length < 2 || lastSegmentLength !== 2 || result.charCodeAt(result.length - 1) !== 46 || result.charCodeAt(result.length - 2) !== 46) {
716
+ if (result.length > 2) {
717
+ lastSlashIndex = result.lastIndexOf("/");
718
+ if (lastSlashIndex !== result.length - 1) {
719
+ if (lastSlashIndex < 0) {
720
+ result = "";
721
+ lastSegmentLength = 0;
722
+ } else {
723
+ result = result.slice(0, lastSlashIndex);
724
+ lastSegmentLength = result.length - 1 - result.lastIndexOf("/");
725
+ }
726
+ lastSlash = index;
727
+ dots = 0;
728
+ continue;
729
+ }
730
+ } else if (result.length > 0) {
731
+ result = "";
732
+ lastSegmentLength = 0;
733
+ lastSlash = index;
734
+ dots = 0;
735
+ continue;
736
+ }
737
+ }
738
+ if (allowAboveRoot) {
739
+ result = result.length > 0 ? result + "/.." : "..";
740
+ lastSegmentLength = 2;
741
+ }
742
+ } else {
743
+ if (result.length > 0) result += "/" + path.slice(lastSlash + 1, index);
744
+ else result = path.slice(lastSlash + 1, index);
745
+ lastSegmentLength = index - lastSlash - 1;
746
+ }
747
+ lastSlash = index;
748
+ dots = 0;
749
+ } else if (code === 46 && dots > -1) dots++;
750
+ else dots = -1;
751
+ }
752
+ return result;
523
753
  }
524
- function assertPath$1(path2) {
525
- if (typeof path2 !== "string") {
526
- throw new TypeError(
527
- "Path must be a string. Received " + JSON.stringify(path2)
528
- );
529
- }
754
+ /**
755
+ * Make sure `path` is a string.
756
+ *
757
+ * @param {string} path
758
+ * File path.
759
+ * @returns {asserts path is string}
760
+ * Nothing.
761
+ */
762
+ function assertPath$1(path) {
763
+ if (typeof path !== "string") throw new TypeError("Path must be a string. Received " + JSON.stringify(path));
530
764
  }
531
- const proc = { cwd };
765
+ //#endregion
766
+ //#region node_modules/vfile/lib/minproc.browser.js
767
+ var proc = { cwd };
532
768
  function cwd() {
533
- return "/";
769
+ return "/";
534
770
  }
771
+ //#endregion
772
+ //#region node_modules/vfile/lib/minurl.shared.js
773
+ /**
774
+ * @typedef URL
775
+ * @property {string} hash
776
+ * @property {string} host
777
+ * @property {string} hostname
778
+ * @property {string} href
779
+ * @property {string} origin
780
+ * @property {string} password
781
+ * @property {string} pathname
782
+ * @property {string} port
783
+ * @property {string} protocol
784
+ * @property {string} search
785
+ * @property {any} searchParams
786
+ * @property {string} username
787
+ * @property {() => string} toString
788
+ * @property {() => string} toJSON
789
+ */
790
+ /**
791
+ * Check if `fileUrlOrPath` looks like a URL.
792
+ *
793
+ * @param {unknown} fileUrlOrPath
794
+ * File path or URL.
795
+ * @returns {fileUrlOrPath is URL}
796
+ * Whether it’s a URL.
797
+ */
535
798
  function isUrl(fileUrlOrPath) {
536
- return fileUrlOrPath !== null && typeof fileUrlOrPath === "object" && // @ts-expect-error: indexable.
537
- fileUrlOrPath.href && // @ts-expect-error: indexable.
538
- fileUrlOrPath.origin;
799
+ return fileUrlOrPath !== null && typeof fileUrlOrPath === "object" && fileUrlOrPath.href && fileUrlOrPath.origin;
539
800
  }
540
- function urlToPath(path2) {
541
- if (typeof path2 === "string") {
542
- path2 = new URL(path2);
543
- } else if (!isUrl(path2)) {
544
- const error = new TypeError(
545
- 'The "path" argument must be of type string or an instance of URL. Received `' + path2 + "`"
546
- );
547
- error.code = "ERR_INVALID_ARG_TYPE";
548
- throw error;
549
- }
550
- if (path2.protocol !== "file:") {
551
- const error = new TypeError("The URL must be of scheme file");
552
- error.code = "ERR_INVALID_URL_SCHEME";
553
- throw error;
554
- }
555
- return getPathFromURLPosix(path2);
801
+ //#endregion
802
+ //#region node_modules/vfile/lib/minurl.browser.js
803
+ /**
804
+ * @param {string | URL} path
805
+ * File URL.
806
+ * @returns {string}
807
+ * File URL.
808
+ */
809
+ function urlToPath(path) {
810
+ if (typeof path === "string") path = new URL(path);
811
+ else if (!isUrl(path)) {
812
+ /** @type {NodeJS.ErrnoException} */
813
+ const error = /* @__PURE__ */ new TypeError("The \"path\" argument must be of type string or an instance of URL. Received `" + path + "`");
814
+ error.code = "ERR_INVALID_ARG_TYPE";
815
+ throw error;
816
+ }
817
+ if (path.protocol !== "file:") {
818
+ /** @type {NodeJS.ErrnoException} */
819
+ const error = /* @__PURE__ */ new TypeError("The URL must be of scheme file");
820
+ error.code = "ERR_INVALID_URL_SCHEME";
821
+ throw error;
822
+ }
823
+ return getPathFromURLPosix(path);
556
824
  }
825
+ /**
826
+ * Get a path from a POSIX URL.
827
+ *
828
+ * @param {URL} url
829
+ * URL.
830
+ * @returns {string}
831
+ * File path.
832
+ */
557
833
  function getPathFromURLPosix(url) {
558
- if (url.hostname !== "") {
559
- const error = new TypeError(
560
- 'File URL host must be "localhost" or empty on darwin'
561
- );
562
- error.code = "ERR_INVALID_FILE_URL_HOST";
563
- throw error;
564
- }
565
- const pathname = url.pathname;
566
- let index2 = -1;
567
- while (++index2 < pathname.length) {
568
- if (pathname.charCodeAt(index2) === 37 && pathname.charCodeAt(index2 + 1) === 50) {
569
- const third = pathname.charCodeAt(index2 + 2);
570
- if (third === 70 || third === 102) {
571
- const error = new TypeError(
572
- "File URL path must not include encoded / characters"
573
- );
574
- error.code = "ERR_INVALID_FILE_URL_PATH";
575
- throw error;
576
- }
577
- }
578
- }
579
- return decodeURIComponent(pathname);
580
- }
581
- const order = ["history", "path", "basename", "stem", "extname", "dirname"];
582
- class VFile {
583
- /**
584
- * Create a new virtual file.
585
- *
586
- * `options` is treated as:
587
- *
588
- * * `string` or `Buffer` — `{value: options}`
589
- * * `URL` — `{path: options}`
590
- * * `VFile` — shallow copies its data over to the new file
591
- * * `object` — all fields are shallow copied over to the new file
592
- *
593
- * Path related fields are set in the following order (least specific to
594
- * most specific): `history`, `path`, `basename`, `stem`, `extname`,
595
- * `dirname`.
596
- *
597
- * You cannot set `dirname` or `extname` without setting either `history`,
598
- * `path`, `basename`, or `stem` too.
599
- *
600
- * @param {Compatible | null | undefined} [value]
601
- * File value.
602
- * @returns
603
- * New instance.
604
- */
605
- constructor(value) {
606
- let options;
607
- if (!value) {
608
- options = {};
609
- } else if (typeof value === "string" || buffer(value)) {
610
- options = { value };
611
- } else if (isUrl(value)) {
612
- options = { path: value };
613
- } else {
614
- options = value;
615
- }
616
- this.data = {};
617
- this.messages = [];
618
- this.history = [];
619
- this.cwd = proc.cwd();
620
- this.value;
621
- this.stored;
622
- this.result;
623
- this.map;
624
- let index2 = -1;
625
- while (++index2 < order.length) {
626
- const prop2 = order[index2];
627
- if (prop2 in options && options[prop2] !== void 0 && options[prop2] !== null) {
628
- this[prop2] = prop2 === "history" ? [...options[prop2]] : options[prop2];
629
- }
630
- }
631
- let prop;
632
- for (prop in options) {
633
- if (!order.includes(prop)) {
634
- this[prop] = options[prop];
635
- }
636
- }
637
- }
638
- /**
639
- * Get the full path (example: `'~/index.min.js'`).
640
- *
641
- * @returns {string}
642
- */
643
- get path() {
644
- return this.history[this.history.length - 1];
645
- }
646
- /**
647
- * Set the full path (example: `'~/index.min.js'`).
648
- *
649
- * Cannot be nullified.
650
- * You can set a file URL (a `URL` object with a `file:` protocol) which will
651
- * be turned into a path with `url.fileURLToPath`.
652
- *
653
- * @param {string | URL} path
654
- */
655
- set path(path2) {
656
- if (isUrl(path2)) {
657
- path2 = urlToPath(path2);
658
- }
659
- assertNonEmpty(path2, "path");
660
- if (this.path !== path2) {
661
- this.history.push(path2);
662
- }
663
- }
664
- /**
665
- * Get the parent path (example: `'~'`).
666
- */
667
- get dirname() {
668
- return typeof this.path === "string" ? path.dirname(this.path) : void 0;
669
- }
670
- /**
671
- * Set the parent path (example: `'~'`).
672
- *
673
- * Cannot be set if there’s no `path` yet.
674
- */
675
- set dirname(dirname2) {
676
- assertPath(this.basename, "dirname");
677
- this.path = path.join(dirname2 || "", this.basename);
678
- }
679
- /**
680
- * Get the basename (including extname) (example: `'index.min.js'`).
681
- */
682
- get basename() {
683
- return typeof this.path === "string" ? path.basename(this.path) : void 0;
684
- }
685
- /**
686
- * Set basename (including extname) (`'index.min.js'`).
687
- *
688
- * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
689
- * on windows).
690
- * Cannot be nullified (use `file.path = file.dirname` instead).
691
- */
692
- set basename(basename2) {
693
- assertNonEmpty(basename2, "basename");
694
- assertPart(basename2, "basename");
695
- this.path = path.join(this.dirname || "", basename2);
696
- }
697
- /**
698
- * Get the extname (including dot) (example: `'.js'`).
699
- */
700
- get extname() {
701
- return typeof this.path === "string" ? path.extname(this.path) : void 0;
702
- }
703
- /**
704
- * Set the extname (including dot) (example: `'.js'`).
705
- *
706
- * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
707
- * on windows).
708
- * Cannot be set if there’s no `path` yet.
709
- */
710
- set extname(extname2) {
711
- assertPart(extname2, "extname");
712
- assertPath(this.dirname, "extname");
713
- if (extname2) {
714
- if (extname2.charCodeAt(0) !== 46) {
715
- throw new Error("`extname` must start with `.`");
716
- }
717
- if (extname2.includes(".", 1)) {
718
- throw new Error("`extname` cannot contain multiple dots");
719
- }
720
- }
721
- this.path = path.join(this.dirname, this.stem + (extname2 || ""));
722
- }
723
- /**
724
- * Get the stem (basename w/o extname) (example: `'index.min'`).
725
- */
726
- get stem() {
727
- return typeof this.path === "string" ? path.basename(this.path, this.extname) : void 0;
728
- }
729
- /**
730
- * Set the stem (basename w/o extname) (example: `'index.min'`).
731
- *
732
- * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
733
- * on windows).
734
- * Cannot be nullified (use `file.path = file.dirname` instead).
735
- */
736
- set stem(stem) {
737
- assertNonEmpty(stem, "stem");
738
- assertPart(stem, "stem");
739
- this.path = path.join(this.dirname || "", stem + (this.extname || ""));
740
- }
741
- /**
742
- * Serialize the file.
743
- *
744
- * @param {BufferEncoding | null | undefined} [encoding='utf8']
745
- * Character encoding to understand `value` as when it’s a `Buffer`
746
- * (default: `'utf8'`).
747
- * @returns {string}
748
- * Serialized file.
749
- */
750
- toString(encoding) {
751
- return (this.value || "").toString(encoding || void 0);
752
- }
753
- /**
754
- * Create a warning message associated with the file.
755
- *
756
- * Its `fatal` is set to `false` and `file` is set to the current file path.
757
- * Its added to `file.messages`.
758
- *
759
- * @param {string | Error | VFileMessage} reason
760
- * Reason for message, uses the stack and message of the error if given.
761
- * @param {Node | NodeLike | Position | Point | null | undefined} [place]
762
- * Place in file where the message occurred.
763
- * @param {string | null | undefined} [origin]
764
- * Place in code where the message originates (example:
765
- * `'my-package:my-rule'` or `'my-rule'`).
766
- * @returns {VFileMessage}
767
- * Message.
768
- */
769
- message(reason, place, origin) {
770
- const message = new VFileMessage(reason, place, origin);
771
- if (this.path) {
772
- message.name = this.path + ":" + message.name;
773
- message.file = this.path;
774
- }
775
- message.fatal = false;
776
- this.messages.push(message);
777
- return message;
778
- }
779
- /**
780
- * Create an info message associated with the file.
781
- *
782
- * Its `fatal` is set to `null` and `file` is set to the current file path.
783
- * Its added to `file.messages`.
784
- *
785
- * @param {string | Error | VFileMessage} reason
786
- * Reason for message, uses the stack and message of the error if given.
787
- * @param {Node | NodeLike | Position | Point | null | undefined} [place]
788
- * Place in file where the message occurred.
789
- * @param {string | null | undefined} [origin]
790
- * Place in code where the message originates (example:
791
- * `'my-package:my-rule'` or `'my-rule'`).
792
- * @returns {VFileMessage}
793
- * Message.
794
- */
795
- info(reason, place, origin) {
796
- const message = this.message(reason, place, origin);
797
- message.fatal = null;
798
- return message;
799
- }
800
- /**
801
- * Create a fatal error associated with the file.
802
- *
803
- * Its `fatal` is set to `true` and `file` is set to the current file path.
804
- * Its added to `file.messages`.
805
- *
806
- * > 👉 **Note**: a fatal error means that a file is no longer processable.
807
- *
808
- * @param {string | Error | VFileMessage} reason
809
- * Reason for message, uses the stack and message of the error if given.
810
- * @param {Node | NodeLike | Position | Point | null | undefined} [place]
811
- * Place in file where the message occurred.
812
- * @param {string | null | undefined} [origin]
813
- * Place in code where the message originates (example:
814
- * `'my-package:my-rule'` or `'my-rule'`).
815
- * @returns {never}
816
- * Message.
817
- * @throws {VFileMessage}
818
- * Message.
819
- */
820
- fail(reason, place, origin) {
821
- const message = this.message(reason, place, origin);
822
- message.fatal = true;
823
- throw message;
824
- }
834
+ if (url.hostname !== "") {
835
+ /** @type {NodeJS.ErrnoException} */
836
+ const error = /* @__PURE__ */ new TypeError("File URL host must be \"localhost\" or empty on darwin");
837
+ error.code = "ERR_INVALID_FILE_URL_HOST";
838
+ throw error;
839
+ }
840
+ const pathname = url.pathname;
841
+ let index = -1;
842
+ while (++index < pathname.length) if (pathname.charCodeAt(index) === 37 && pathname.charCodeAt(index + 1) === 50) {
843
+ const third = pathname.charCodeAt(index + 2);
844
+ if (third === 70 || third === 102) {
845
+ /** @type {NodeJS.ErrnoException} */
846
+ const error = /* @__PURE__ */ new TypeError("File URL path must not include encoded / characters");
847
+ error.code = "ERR_INVALID_FILE_URL_PATH";
848
+ throw error;
849
+ }
850
+ }
851
+ return decodeURIComponent(pathname);
825
852
  }
853
+ //#endregion
854
+ //#region node_modules/vfile/lib/index.js
855
+ var import_is_buffer = /* @__PURE__ */ __toESM(require_is_buffer(), 1);
856
+ /**
857
+ * Order of setting (least specific to most), we need this because otherwise
858
+ * `{stem: 'a', path: '~/b.js'}` would throw, as a path is needed before a
859
+ * stem can be set.
860
+ *
861
+ * @type {Array<'basename' | 'dirname' | 'extname' | 'history' | 'path' | 'stem'>}
862
+ */
863
+ var order = [
864
+ "history",
865
+ "path",
866
+ "basename",
867
+ "stem",
868
+ "extname",
869
+ "dirname"
870
+ ];
871
+ var VFile = class {
872
+ /**
873
+ * Create a new virtual file.
874
+ *
875
+ * `options` is treated as:
876
+ *
877
+ * * `string` or `Buffer` — `{value: options}`
878
+ * * `URL` — `{path: options}`
879
+ * * `VFile` — shallow copies its data over to the new file
880
+ * * `object` — all fields are shallow copied over to the new file
881
+ *
882
+ * Path related fields are set in the following order (least specific to
883
+ * most specific): `history`, `path`, `basename`, `stem`, `extname`,
884
+ * `dirname`.
885
+ *
886
+ * You cannot set `dirname` or `extname` without setting either `history`,
887
+ * `path`, `basename`, or `stem` too.
888
+ *
889
+ * @param {Compatible | null | undefined} [value]
890
+ * File value.
891
+ * @returns
892
+ * New instance.
893
+ */
894
+ constructor(value) {
895
+ /** @type {Options | VFile} */
896
+ let options;
897
+ if (!value) options = {};
898
+ else if (typeof value === "string" || buffer(value)) options = { value };
899
+ else if (isUrl(value)) options = { path: value };
900
+ else options = value;
901
+ /**
902
+ * Place to store custom information (default: `{}`).
903
+ *
904
+ * It’s OK to store custom data directly on the file but moving it to
905
+ * `data` is recommended.
906
+ *
907
+ * @type {Data}
908
+ */
909
+ this.data = {};
910
+ /**
911
+ * List of messages associated with the file.
912
+ *
913
+ * @type {Array<VFileMessage>}
914
+ */
915
+ this.messages = [];
916
+ /**
917
+ * List of filepaths the file moved between.
918
+ *
919
+ * The first is the original path and the last is the current path.
920
+ *
921
+ * @type {Array<string>}
922
+ */
923
+ this.history = [];
924
+ /**
925
+ * Base of `path` (default: `process.cwd()` or `'/'` in browsers).
926
+ *
927
+ * @type {string}
928
+ */
929
+ this.cwd = proc.cwd();
930
+ /**
931
+ * Raw value.
932
+ *
933
+ * @type {Value}
934
+ */
935
+ this.value;
936
+ /**
937
+ * Whether a file was saved to disk.
938
+ *
939
+ * This is used by vfile reporters.
940
+ *
941
+ * @type {boolean}
942
+ */
943
+ this.stored;
944
+ /**
945
+ * Custom, non-string, compiled, representation.
946
+ *
947
+ * This is used by unified to store non-string results.
948
+ * One example is when turning markdown into React nodes.
949
+ *
950
+ * @type {unknown}
951
+ */
952
+ this.result;
953
+ /**
954
+ * Source map.
955
+ *
956
+ * This type is equivalent to the `RawSourceMap` type from the `source-map`
957
+ * module.
958
+ *
959
+ * @type {Map | null | undefined}
960
+ */
961
+ this.map;
962
+ let index = -1;
963
+ while (++index < order.length) {
964
+ const prop = order[index];
965
+ if (prop in options && options[prop] !== void 0 && options[prop] !== null) this[prop] = prop === "history" ? [...options[prop]] : options[prop];
966
+ }
967
+ /** @type {string} */
968
+ let prop;
969
+ for (prop in options) if (!order.includes(prop)) this[prop] = options[prop];
970
+ }
971
+ /**
972
+ * Get the full path (example: `'~/index.min.js'`).
973
+ *
974
+ * @returns {string}
975
+ */
976
+ get path() {
977
+ return this.history[this.history.length - 1];
978
+ }
979
+ /**
980
+ * Set the full path (example: `'~/index.min.js'`).
981
+ *
982
+ * Cannot be nullified.
983
+ * You can set a file URL (a `URL` object with a `file:` protocol) which will
984
+ * be turned into a path with `url.fileURLToPath`.
985
+ *
986
+ * @param {string | URL} path
987
+ */
988
+ set path(path) {
989
+ if (isUrl(path)) path = urlToPath(path);
990
+ assertNonEmpty(path, "path");
991
+ if (this.path !== path) this.history.push(path);
992
+ }
993
+ /**
994
+ * Get the parent path (example: `'~'`).
995
+ */
996
+ get dirname() {
997
+ return typeof this.path === "string" ? path.dirname(this.path) : void 0;
998
+ }
999
+ /**
1000
+ * Set the parent path (example: `'~'`).
1001
+ *
1002
+ * Cannot be set if there’s no `path` yet.
1003
+ */
1004
+ set dirname(dirname) {
1005
+ assertPath(this.basename, "dirname");
1006
+ this.path = path.join(dirname || "", this.basename);
1007
+ }
1008
+ /**
1009
+ * Get the basename (including extname) (example: `'index.min.js'`).
1010
+ */
1011
+ get basename() {
1012
+ return typeof this.path === "string" ? path.basename(this.path) : void 0;
1013
+ }
1014
+ /**
1015
+ * Set basename (including extname) (`'index.min.js'`).
1016
+ *
1017
+ * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
1018
+ * on windows).
1019
+ * Cannot be nullified (use `file.path = file.dirname` instead).
1020
+ */
1021
+ set basename(basename) {
1022
+ assertNonEmpty(basename, "basename");
1023
+ assertPart(basename, "basename");
1024
+ this.path = path.join(this.dirname || "", basename);
1025
+ }
1026
+ /**
1027
+ * Get the extname (including dot) (example: `'.js'`).
1028
+ */
1029
+ get extname() {
1030
+ return typeof this.path === "string" ? path.extname(this.path) : void 0;
1031
+ }
1032
+ /**
1033
+ * Set the extname (including dot) (example: `'.js'`).
1034
+ *
1035
+ * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
1036
+ * on windows).
1037
+ * Cannot be set if there’s no `path` yet.
1038
+ */
1039
+ set extname(extname) {
1040
+ assertPart(extname, "extname");
1041
+ assertPath(this.dirname, "extname");
1042
+ if (extname) {
1043
+ if (extname.charCodeAt(0) !== 46) throw new Error("`extname` must start with `.`");
1044
+ if (extname.includes(".", 1)) throw new Error("`extname` cannot contain multiple dots");
1045
+ }
1046
+ this.path = path.join(this.dirname, this.stem + (extname || ""));
1047
+ }
1048
+ /**
1049
+ * Get the stem (basename w/o extname) (example: `'index.min'`).
1050
+ */
1051
+ get stem() {
1052
+ return typeof this.path === "string" ? path.basename(this.path, this.extname) : void 0;
1053
+ }
1054
+ /**
1055
+ * Set the stem (basename w/o extname) (example: `'index.min'`).
1056
+ *
1057
+ * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
1058
+ * on windows).
1059
+ * Cannot be nullified (use `file.path = file.dirname` instead).
1060
+ */
1061
+ set stem(stem) {
1062
+ assertNonEmpty(stem, "stem");
1063
+ assertPart(stem, "stem");
1064
+ this.path = path.join(this.dirname || "", stem + (this.extname || ""));
1065
+ }
1066
+ /**
1067
+ * Serialize the file.
1068
+ *
1069
+ * @param {BufferEncoding | null | undefined} [encoding='utf8']
1070
+ * Character encoding to understand `value` as when it’s a `Buffer`
1071
+ * (default: `'utf8'`).
1072
+ * @returns {string}
1073
+ * Serialized file.
1074
+ */
1075
+ toString(encoding) {
1076
+ return (this.value || "").toString(encoding || void 0);
1077
+ }
1078
+ /**
1079
+ * Create a warning message associated with the file.
1080
+ *
1081
+ * Its `fatal` is set to `false` and `file` is set to the current file path.
1082
+ * Its added to `file.messages`.
1083
+ *
1084
+ * @param {string | Error | VFileMessage} reason
1085
+ * Reason for message, uses the stack and message of the error if given.
1086
+ * @param {Node | NodeLike | Position | Point | null | undefined} [place]
1087
+ * Place in file where the message occurred.
1088
+ * @param {string | null | undefined} [origin]
1089
+ * Place in code where the message originates (example:
1090
+ * `'my-package:my-rule'` or `'my-rule'`).
1091
+ * @returns {VFileMessage}
1092
+ * Message.
1093
+ */
1094
+ message(reason, place, origin) {
1095
+ const message = new VFileMessage(reason, place, origin);
1096
+ if (this.path) {
1097
+ message.name = this.path + ":" + message.name;
1098
+ message.file = this.path;
1099
+ }
1100
+ message.fatal = false;
1101
+ this.messages.push(message);
1102
+ return message;
1103
+ }
1104
+ /**
1105
+ * Create an info message associated with the file.
1106
+ *
1107
+ * Its `fatal` is set to `null` and `file` is set to the current file path.
1108
+ * Its added to `file.messages`.
1109
+ *
1110
+ * @param {string | Error | VFileMessage} reason
1111
+ * Reason for message, uses the stack and message of the error if given.
1112
+ * @param {Node | NodeLike | Position | Point | null | undefined} [place]
1113
+ * Place in file where the message occurred.
1114
+ * @param {string | null | undefined} [origin]
1115
+ * Place in code where the message originates (example:
1116
+ * `'my-package:my-rule'` or `'my-rule'`).
1117
+ * @returns {VFileMessage}
1118
+ * Message.
1119
+ */
1120
+ info(reason, place, origin) {
1121
+ const message = this.message(reason, place, origin);
1122
+ message.fatal = null;
1123
+ return message;
1124
+ }
1125
+ /**
1126
+ * Create a fatal error associated with the file.
1127
+ *
1128
+ * Its `fatal` is set to `true` and `file` is set to the current file path.
1129
+ * Its added to `file.messages`.
1130
+ *
1131
+ * > 👉 **Note**: a fatal error means that a file is no longer processable.
1132
+ *
1133
+ * @param {string | Error | VFileMessage} reason
1134
+ * Reason for message, uses the stack and message of the error if given.
1135
+ * @param {Node | NodeLike | Position | Point | null | undefined} [place]
1136
+ * Place in file where the message occurred.
1137
+ * @param {string | null | undefined} [origin]
1138
+ * Place in code where the message originates (example:
1139
+ * `'my-package:my-rule'` or `'my-rule'`).
1140
+ * @returns {never}
1141
+ * Message.
1142
+ * @throws {VFileMessage}
1143
+ * Message.
1144
+ */
1145
+ fail(reason, place, origin) {
1146
+ const message = this.message(reason, place, origin);
1147
+ message.fatal = true;
1148
+ throw message;
1149
+ }
1150
+ };
1151
+ /**
1152
+ * Assert that `part` is not a path (as in, does not contain `path.sep`).
1153
+ *
1154
+ * @param {string | null | undefined} part
1155
+ * File path part.
1156
+ * @param {string} name
1157
+ * Part name.
1158
+ * @returns {void}
1159
+ * Nothing.
1160
+ */
826
1161
  function assertPart(part, name) {
827
- if (part && part.includes(path.sep)) {
828
- throw new Error(
829
- "`" + name + "` cannot be a path: did not expect `" + path.sep + "`"
830
- );
831
- }
1162
+ if (part && part.includes(path.sep)) throw new Error("`" + name + "` cannot be a path: did not expect `" + path.sep + "`");
832
1163
  }
1164
+ /**
1165
+ * Assert that `part` is not empty.
1166
+ *
1167
+ * @param {string | undefined} part
1168
+ * Thing.
1169
+ * @param {string} name
1170
+ * Part name.
1171
+ * @returns {asserts part is string}
1172
+ * Nothing.
1173
+ */
833
1174
  function assertNonEmpty(part, name) {
834
- if (!part) {
835
- throw new Error("`" + name + "` cannot be empty");
836
- }
1175
+ if (!part) throw new Error("`" + name + "` cannot be empty");
837
1176
  }
838
- function assertPath(path2, name) {
839
- if (!path2) {
840
- throw new Error("Setting `" + name + "` requires `path` to be set too");
841
- }
1177
+ /**
1178
+ * Assert `path` exists.
1179
+ *
1180
+ * @param {string | undefined} path
1181
+ * Path.
1182
+ * @param {string} name
1183
+ * Dependency name.
1184
+ * @returns {asserts path is string}
1185
+ * Nothing.
1186
+ */
1187
+ function assertPath(path, name) {
1188
+ if (!path) throw new Error("Setting `" + name + "` requires `path` to be set too");
842
1189
  }
1190
+ /**
1191
+ * Assert `value` is a buffer.
1192
+ *
1193
+ * @param {unknown} value
1194
+ * thing.
1195
+ * @returns {value is Buffer}
1196
+ * Whether `value` is a Node.js buffer.
1197
+ */
843
1198
  function buffer(value) {
844
- return isBuffer(value);
1199
+ return (0, import_is_buffer.default)(value);
845
1200
  }
846
- const unified = base().freeze();
847
- const own = {}.hasOwnProperty;
1201
+ //#endregion
1202
+ //#region node_modules/unified/lib/index.js
1203
+ /**
1204
+ * @typedef {import('unist').Node} Node
1205
+ * @typedef {import('vfile').VFileCompatible} VFileCompatible
1206
+ * @typedef {import('vfile').VFileValue} VFileValue
1207
+ * @typedef {import('..').Processor} Processor
1208
+ * @typedef {import('..').Plugin} Plugin
1209
+ * @typedef {import('..').Preset} Preset
1210
+ * @typedef {import('..').Pluggable} Pluggable
1211
+ * @typedef {import('..').PluggableList} PluggableList
1212
+ * @typedef {import('..').Transformer} Transformer
1213
+ * @typedef {import('..').Parser} Parser
1214
+ * @typedef {import('..').Compiler} Compiler
1215
+ * @typedef {import('..').RunCallback} RunCallback
1216
+ * @typedef {import('..').ProcessCallback} ProcessCallback
1217
+ *
1218
+ * @typedef Context
1219
+ * @property {Node} tree
1220
+ * @property {VFile} file
1221
+ */
1222
+ var import_extend = /* @__PURE__ */ __toESM(require_extend(), 1);
1223
+ var unified = base().freeze();
1224
+ var own = {}.hasOwnProperty;
1225
+ /**
1226
+ * @returns {Processor}
1227
+ */
848
1228
  function base() {
849
- const transformers = trough();
850
- const attachers = [];
851
- let namespace = {};
852
- let frozen;
853
- let freezeIndex = -1;
854
- processor.data = data;
855
- processor.Parser = void 0;
856
- processor.Compiler = void 0;
857
- processor.freeze = freeze;
858
- processor.attachers = attachers;
859
- processor.use = use;
860
- processor.parse = parse;
861
- processor.stringify = stringify;
862
- processor.run = run;
863
- processor.runSync = runSync;
864
- processor.process = process;
865
- processor.processSync = processSync;
866
- return processor;
867
- function processor() {
868
- const destination = base();
869
- let index2 = -1;
870
- while (++index2 < attachers.length) {
871
- destination.use(...attachers[index2]);
872
- }
873
- destination.data(extend(true, {}, namespace));
874
- return destination;
875
- }
876
- function data(key, value) {
877
- if (typeof key === "string") {
878
- if (arguments.length === 2) {
879
- assertUnfrozen("data", frozen);
880
- namespace[key] = value;
881
- return processor;
882
- }
883
- return own.call(namespace, key) && namespace[key] || null;
884
- }
885
- if (key) {
886
- assertUnfrozen("data", frozen);
887
- namespace = key;
888
- return processor;
889
- }
890
- return namespace;
891
- }
892
- function freeze() {
893
- if (frozen) {
894
- return processor;
895
- }
896
- while (++freezeIndex < attachers.length) {
897
- const [attacher, ...options] = attachers[freezeIndex];
898
- if (options[0] === false) {
899
- continue;
900
- }
901
- if (options[0] === true) {
902
- options[0] = void 0;
903
- }
904
- const transformer = attacher.call(processor, ...options);
905
- if (typeof transformer === "function") {
906
- transformers.use(transformer);
907
- }
908
- }
909
- frozen = true;
910
- freezeIndex = Number.POSITIVE_INFINITY;
911
- return processor;
912
- }
913
- function use(value, ...options) {
914
- let settings;
915
- assertUnfrozen("use", frozen);
916
- if (value === null || value === void 0) ;
917
- else if (typeof value === "function") {
918
- addPlugin(value, ...options);
919
- } else if (typeof value === "object") {
920
- if (Array.isArray(value)) {
921
- addList(value);
922
- } else {
923
- addPreset(value);
924
- }
925
- } else {
926
- throw new TypeError("Expected usable value, not `" + value + "`");
927
- }
928
- if (settings) {
929
- namespace.settings = Object.assign(namespace.settings || {}, settings);
930
- }
931
- return processor;
932
- function add(value2) {
933
- if (typeof value2 === "function") {
934
- addPlugin(value2);
935
- } else if (typeof value2 === "object") {
936
- if (Array.isArray(value2)) {
937
- const [plugin, ...options2] = value2;
938
- addPlugin(plugin, ...options2);
939
- } else {
940
- addPreset(value2);
941
- }
942
- } else {
943
- throw new TypeError("Expected usable value, not `" + value2 + "`");
944
- }
945
- }
946
- function addPreset(result) {
947
- addList(result.plugins);
948
- if (result.settings) {
949
- settings = Object.assign(settings || {}, result.settings);
950
- }
951
- }
952
- function addList(plugins) {
953
- let index2 = -1;
954
- if (plugins === null || plugins === void 0) ;
955
- else if (Array.isArray(plugins)) {
956
- while (++index2 < plugins.length) {
957
- const thing = plugins[index2];
958
- add(thing);
959
- }
960
- } else {
961
- throw new TypeError("Expected a list of plugins, not `" + plugins + "`");
962
- }
963
- }
964
- function addPlugin(plugin, value2) {
965
- let index2 = -1;
966
- let entry;
967
- while (++index2 < attachers.length) {
968
- if (attachers[index2][0] === plugin) {
969
- entry = attachers[index2];
970
- break;
971
- }
972
- }
973
- if (entry) {
974
- if (isPlainObject(entry[1]) && isPlainObject(value2)) {
975
- value2 = extend(true, entry[1], value2);
976
- }
977
- entry[1] = value2;
978
- } else {
979
- attachers.push([...arguments]);
980
- }
981
- }
982
- }
983
- function parse(doc) {
984
- processor.freeze();
985
- const file = vfile(doc);
986
- const Parser = processor.Parser;
987
- assertParser("parse", Parser);
988
- if (newable(Parser, "parse")) {
989
- return new Parser(String(file), file).parse();
990
- }
991
- return Parser(String(file), file);
992
- }
993
- function stringify(node, doc) {
994
- processor.freeze();
995
- const file = vfile(doc);
996
- const Compiler = processor.Compiler;
997
- assertCompiler("stringify", Compiler);
998
- assertNode(node);
999
- if (newable(Compiler, "compile")) {
1000
- return new Compiler(node, file).compile();
1001
- }
1002
- return Compiler(node, file);
1003
- }
1004
- function run(node, doc, callback) {
1005
- assertNode(node);
1006
- processor.freeze();
1007
- if (!callback && typeof doc === "function") {
1008
- callback = doc;
1009
- doc = void 0;
1010
- }
1011
- if (!callback) {
1012
- return new Promise(executor);
1013
- }
1014
- executor(null, callback);
1015
- function executor(resolve, reject) {
1016
- transformers.run(node, vfile(doc), done);
1017
- function done(error, tree, file) {
1018
- tree = tree || node;
1019
- if (error) {
1020
- reject(error);
1021
- } else if (resolve) {
1022
- resolve(tree);
1023
- } else {
1024
- callback(null, tree, file);
1025
- }
1026
- }
1027
- }
1028
- }
1029
- function runSync(node, file) {
1030
- let result;
1031
- let complete;
1032
- processor.run(node, file, done);
1033
- assertDone("runSync", "run", complete);
1034
- return result;
1035
- function done(error, tree) {
1036
- bail(error);
1037
- result = tree;
1038
- complete = true;
1039
- }
1040
- }
1041
- function process(doc, callback) {
1042
- processor.freeze();
1043
- assertParser("process", processor.Parser);
1044
- assertCompiler("process", processor.Compiler);
1045
- if (!callback) {
1046
- return new Promise(executor);
1047
- }
1048
- executor(null, callback);
1049
- function executor(resolve, reject) {
1050
- const file = vfile(doc);
1051
- processor.run(processor.parse(file), file, (error, tree, file2) => {
1052
- if (error || !tree || !file2) {
1053
- done(error);
1054
- } else {
1055
- const result = processor.stringify(tree, file2);
1056
- if (result === void 0 || result === null) ;
1057
- else if (looksLikeAVFileValue(result)) {
1058
- file2.value = result;
1059
- } else {
1060
- file2.result = result;
1061
- }
1062
- done(error, file2);
1063
- }
1064
- });
1065
- function done(error, file2) {
1066
- if (error || !file2) {
1067
- reject(error);
1068
- } else if (resolve) {
1069
- resolve(file2);
1070
- } else {
1071
- callback(null, file2);
1072
- }
1073
- }
1074
- }
1075
- }
1076
- function processSync(doc) {
1077
- let complete;
1078
- processor.freeze();
1079
- assertParser("processSync", processor.Parser);
1080
- assertCompiler("processSync", processor.Compiler);
1081
- const file = vfile(doc);
1082
- processor.process(file, done);
1083
- assertDone("processSync", "process", complete);
1084
- return file;
1085
- function done(error) {
1086
- complete = true;
1087
- bail(error);
1088
- }
1089
- }
1229
+ const transformers = trough();
1230
+ /** @type {Processor['attachers']} */
1231
+ const attachers = [];
1232
+ /** @type {Record<string, unknown>} */
1233
+ let namespace = {};
1234
+ /** @type {boolean|undefined} */
1235
+ let frozen;
1236
+ let freezeIndex = -1;
1237
+ processor.data = data;
1238
+ processor.Parser = void 0;
1239
+ processor.Compiler = void 0;
1240
+ processor.freeze = freeze;
1241
+ processor.attachers = attachers;
1242
+ processor.use = use;
1243
+ processor.parse = parse;
1244
+ processor.stringify = stringify;
1245
+ processor.run = run;
1246
+ processor.runSync = runSync;
1247
+ processor.process = process;
1248
+ processor.processSync = processSync;
1249
+ return processor;
1250
+ /** @type {Processor} */
1251
+ function processor() {
1252
+ const destination = base();
1253
+ let index = -1;
1254
+ while (++index < attachers.length) destination.use(...attachers[index]);
1255
+ destination.data((0, import_extend.default)(true, {}, namespace));
1256
+ return destination;
1257
+ }
1258
+ /**
1259
+ * @param {string|Record<string, unknown>} [key]
1260
+ * @param {unknown} [value]
1261
+ * @returns {unknown}
1262
+ */
1263
+ function data(key, value) {
1264
+ if (typeof key === "string") {
1265
+ if (arguments.length === 2) {
1266
+ assertUnfrozen("data", frozen);
1267
+ namespace[key] = value;
1268
+ return processor;
1269
+ }
1270
+ return own.call(namespace, key) && namespace[key] || null;
1271
+ }
1272
+ if (key) {
1273
+ assertUnfrozen("data", frozen);
1274
+ namespace = key;
1275
+ return processor;
1276
+ }
1277
+ return namespace;
1278
+ }
1279
+ /** @type {Processor['freeze']} */
1280
+ function freeze() {
1281
+ if (frozen) return processor;
1282
+ while (++freezeIndex < attachers.length) {
1283
+ const [attacher, ...options] = attachers[freezeIndex];
1284
+ if (options[0] === false) continue;
1285
+ if (options[0] === true) options[0] = void 0;
1286
+ /** @type {Transformer|void} */
1287
+ const transformer = attacher.call(processor, ...options);
1288
+ if (typeof transformer === "function") transformers.use(transformer);
1289
+ }
1290
+ frozen = true;
1291
+ freezeIndex = Number.POSITIVE_INFINITY;
1292
+ return processor;
1293
+ }
1294
+ /**
1295
+ * @param {Pluggable|null|undefined} [value]
1296
+ * @param {...unknown} options
1297
+ * @returns {Processor}
1298
+ */
1299
+ function use(value, ...options) {
1300
+ /** @type {Record<string, unknown>|undefined} */
1301
+ let settings;
1302
+ assertUnfrozen("use", frozen);
1303
+ if (value === null || value === void 0) {} else if (typeof value === "function") addPlugin(value, ...options);
1304
+ else if (typeof value === "object") if (Array.isArray(value)) addList(value);
1305
+ else addPreset(value);
1306
+ else throw new TypeError("Expected usable value, not `" + value + "`");
1307
+ if (settings) namespace.settings = Object.assign(namespace.settings || {}, settings);
1308
+ return processor;
1309
+ /**
1310
+ * @param {import('..').Pluggable<unknown[]>} value
1311
+ * @returns {void}
1312
+ */
1313
+ function add(value) {
1314
+ if (typeof value === "function") addPlugin(value);
1315
+ else if (typeof value === "object") if (Array.isArray(value)) {
1316
+ const [plugin, ...options] = value;
1317
+ addPlugin(plugin, ...options);
1318
+ } else addPreset(value);
1319
+ else throw new TypeError("Expected usable value, not `" + value + "`");
1320
+ }
1321
+ /**
1322
+ * @param {Preset} result
1323
+ * @returns {void}
1324
+ */
1325
+ function addPreset(result) {
1326
+ addList(result.plugins);
1327
+ if (result.settings) settings = Object.assign(settings || {}, result.settings);
1328
+ }
1329
+ /**
1330
+ * @param {PluggableList|null|undefined} [plugins]
1331
+ * @returns {void}
1332
+ */
1333
+ function addList(plugins) {
1334
+ let index = -1;
1335
+ if (plugins === null || plugins === void 0) {} else if (Array.isArray(plugins)) while (++index < plugins.length) {
1336
+ const thing = plugins[index];
1337
+ add(thing);
1338
+ }
1339
+ else throw new TypeError("Expected a list of plugins, not `" + plugins + "`");
1340
+ }
1341
+ /**
1342
+ * @param {Plugin} plugin
1343
+ * @param {...unknown} [value]
1344
+ * @returns {void}
1345
+ */
1346
+ function addPlugin(plugin, value) {
1347
+ let index = -1;
1348
+ /** @type {Processor['attachers'][number]|undefined} */
1349
+ let entry;
1350
+ while (++index < attachers.length) if (attachers[index][0] === plugin) {
1351
+ entry = attachers[index];
1352
+ break;
1353
+ }
1354
+ if (entry) {
1355
+ if (isPlainObject(entry[1]) && isPlainObject(value)) value = (0, import_extend.default)(true, entry[1], value);
1356
+ entry[1] = value;
1357
+ } else attachers.push([...arguments]);
1358
+ }
1359
+ }
1360
+ /** @type {Processor['parse']} */
1361
+ function parse(doc) {
1362
+ processor.freeze();
1363
+ const file = vfile(doc);
1364
+ const Parser = processor.Parser;
1365
+ assertParser("parse", Parser);
1366
+ if (newable(Parser, "parse")) return new Parser(String(file), file).parse();
1367
+ return Parser(String(file), file);
1368
+ }
1369
+ /** @type {Processor['stringify']} */
1370
+ function stringify(node, doc) {
1371
+ processor.freeze();
1372
+ const file = vfile(doc);
1373
+ const Compiler = processor.Compiler;
1374
+ assertCompiler("stringify", Compiler);
1375
+ assertNode(node);
1376
+ if (newable(Compiler, "compile")) return new Compiler(node, file).compile();
1377
+ return Compiler(node, file);
1378
+ }
1379
+ /**
1380
+ * @param {Node} node
1381
+ * @param {VFileCompatible|RunCallback} [doc]
1382
+ * @param {RunCallback} [callback]
1383
+ * @returns {Promise<Node>|void}
1384
+ */
1385
+ function run(node, doc, callback) {
1386
+ assertNode(node);
1387
+ processor.freeze();
1388
+ if (!callback && typeof doc === "function") {
1389
+ callback = doc;
1390
+ doc = void 0;
1391
+ }
1392
+ if (!callback) return new Promise(executor);
1393
+ executor(null, callback);
1394
+ /**
1395
+ * @param {null|((node: Node) => void)} resolve
1396
+ * @param {(error: Error) => void} reject
1397
+ * @returns {void}
1398
+ */
1399
+ function executor(resolve, reject) {
1400
+ transformers.run(node, vfile(doc), done);
1401
+ /**
1402
+ * @param {Error|null} error
1403
+ * @param {Node} tree
1404
+ * @param {VFile} file
1405
+ * @returns {void}
1406
+ */
1407
+ function done(error, tree, file) {
1408
+ tree = tree || node;
1409
+ if (error) reject(error);
1410
+ else if (resolve) resolve(tree);
1411
+ else callback(null, tree, file);
1412
+ }
1413
+ }
1414
+ }
1415
+ /** @type {Processor['runSync']} */
1416
+ function runSync(node, file) {
1417
+ /** @type {Node|undefined} */
1418
+ let result;
1419
+ /** @type {boolean|undefined} */
1420
+ let complete;
1421
+ processor.run(node, file, done);
1422
+ assertDone("runSync", "run", complete);
1423
+ return result;
1424
+ /**
1425
+ * @param {Error|null} [error]
1426
+ * @param {Node} [tree]
1427
+ * @returns {void}
1428
+ */
1429
+ function done(error, tree) {
1430
+ bail(error);
1431
+ result = tree;
1432
+ complete = true;
1433
+ }
1434
+ }
1435
+ /**
1436
+ * @param {VFileCompatible} doc
1437
+ * @param {ProcessCallback} [callback]
1438
+ * @returns {Promise<VFile>|undefined}
1439
+ */
1440
+ function process(doc, callback) {
1441
+ processor.freeze();
1442
+ assertParser("process", processor.Parser);
1443
+ assertCompiler("process", processor.Compiler);
1444
+ if (!callback) return new Promise(executor);
1445
+ executor(null, callback);
1446
+ /**
1447
+ * @param {null|((file: VFile) => void)} resolve
1448
+ * @param {(error?: Error|null|undefined) => void} reject
1449
+ * @returns {void}
1450
+ */
1451
+ function executor(resolve, reject) {
1452
+ const file = vfile(doc);
1453
+ processor.run(processor.parse(file), file, (error, tree, file) => {
1454
+ if (error || !tree || !file) done(error);
1455
+ else {
1456
+ /** @type {unknown} */
1457
+ const result = processor.stringify(tree, file);
1458
+ if (result === void 0 || result === null) {} else if (looksLikeAVFileValue(result)) file.value = result;
1459
+ else file.result = result;
1460
+ done(error, file);
1461
+ }
1462
+ });
1463
+ /**
1464
+ * @param {Error|null|undefined} [error]
1465
+ * @param {VFile|undefined} [file]
1466
+ * @returns {void}
1467
+ */
1468
+ function done(error, file) {
1469
+ if (error || !file) reject(error);
1470
+ else if (resolve) resolve(file);
1471
+ else callback(null, file);
1472
+ }
1473
+ }
1474
+ }
1475
+ /** @type {Processor['processSync']} */
1476
+ function processSync(doc) {
1477
+ /** @type {boolean|undefined} */
1478
+ let complete;
1479
+ processor.freeze();
1480
+ assertParser("processSync", processor.Parser);
1481
+ assertCompiler("processSync", processor.Compiler);
1482
+ const file = vfile(doc);
1483
+ processor.process(file, done);
1484
+ assertDone("processSync", "process", complete);
1485
+ return file;
1486
+ /**
1487
+ * @param {Error|null|undefined} [error]
1488
+ * @returns {void}
1489
+ */
1490
+ function done(error) {
1491
+ complete = true;
1492
+ bail(error);
1493
+ }
1494
+ }
1090
1495
  }
1496
+ /**
1497
+ * Check if `value` is a constructor.
1498
+ *
1499
+ * @param {unknown} value
1500
+ * @param {string} name
1501
+ * @returns {boolean}
1502
+ */
1091
1503
  function newable(value, name) {
1092
- return typeof value === "function" && // Prototypes do exist.
1093
- // type-coverage:ignore-next-line
1094
- value.prototype && // A function with keys in its prototype is probably a constructor.
1095
- // Classes’ prototype methods are not enumerable, so we check if some value
1096
- // exists in the prototype.
1097
- // type-coverage:ignore-next-line
1098
- (keys(value.prototype) || name in value.prototype);
1504
+ return typeof value === "function" && value.prototype && (keys(value.prototype) || name in value.prototype);
1099
1505
  }
1506
+ /**
1507
+ * Check if `value` is an object with keys.
1508
+ *
1509
+ * @param {Record<string, unknown>} value
1510
+ * @returns {boolean}
1511
+ */
1100
1512
  function keys(value) {
1101
- let key;
1102
- for (key in value) {
1103
- if (own.call(value, key)) {
1104
- return true;
1105
- }
1106
- }
1107
- return false;
1513
+ /** @type {string} */
1514
+ let key;
1515
+ for (key in value) if (own.call(value, key)) return true;
1516
+ return false;
1108
1517
  }
1518
+ /**
1519
+ * Assert a parser is available.
1520
+ *
1521
+ * @param {string} name
1522
+ * @param {unknown} value
1523
+ * @returns {asserts value is Parser}
1524
+ */
1109
1525
  function assertParser(name, value) {
1110
- if (typeof value !== "function") {
1111
- throw new TypeError("Cannot `" + name + "` without `Parser`");
1112
- }
1526
+ if (typeof value !== "function") throw new TypeError("Cannot `" + name + "` without `Parser`");
1113
1527
  }
1528
+ /**
1529
+ * Assert a compiler is available.
1530
+ *
1531
+ * @param {string} name
1532
+ * @param {unknown} value
1533
+ * @returns {asserts value is Compiler}
1534
+ */
1114
1535
  function assertCompiler(name, value) {
1115
- if (typeof value !== "function") {
1116
- throw new TypeError("Cannot `" + name + "` without `Compiler`");
1117
- }
1536
+ if (typeof value !== "function") throw new TypeError("Cannot `" + name + "` without `Compiler`");
1118
1537
  }
1538
+ /**
1539
+ * Assert the processor is not frozen.
1540
+ *
1541
+ * @param {string} name
1542
+ * @param {unknown} frozen
1543
+ * @returns {asserts frozen is false}
1544
+ */
1119
1545
  function assertUnfrozen(name, frozen) {
1120
- if (frozen) {
1121
- throw new Error(
1122
- "Cannot call `" + name + "` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`."
1123
- );
1124
- }
1546
+ if (frozen) throw new Error("Cannot call `" + name + "` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.");
1125
1547
  }
1548
+ /**
1549
+ * Assert `node` is a unist node.
1550
+ *
1551
+ * @param {unknown} node
1552
+ * @returns {asserts node is Node}
1553
+ */
1126
1554
  function assertNode(node) {
1127
- if (!isPlainObject(node) || typeof node.type !== "string") {
1128
- throw new TypeError("Expected node, got `" + node + "`");
1129
- }
1555
+ if (!isPlainObject(node) || typeof node.type !== "string") throw new TypeError("Expected node, got `" + node + "`");
1130
1556
  }
1557
+ /**
1558
+ * Assert that `complete` is `true`.
1559
+ *
1560
+ * @param {string} name
1561
+ * @param {string} asyncName
1562
+ * @param {unknown} complete
1563
+ * @returns {asserts complete is true}
1564
+ */
1131
1565
  function assertDone(name, asyncName, complete) {
1132
- if (!complete) {
1133
- throw new Error(
1134
- "`" + name + "` finished async. Use `" + asyncName + "` instead"
1135
- );
1136
- }
1566
+ if (!complete) throw new Error("`" + name + "` finished async. Use `" + asyncName + "` instead");
1137
1567
  }
1568
+ /**
1569
+ * @param {VFileCompatible} [value]
1570
+ * @returns {VFile}
1571
+ */
1138
1572
  function vfile(value) {
1139
- return looksLikeAVFile(value) ? value : new VFile(value);
1573
+ return looksLikeAVFile(value) ? value : new VFile(value);
1140
1574
  }
1575
+ /**
1576
+ * @param {VFileCompatible} [value]
1577
+ * @returns {value is VFile}
1578
+ */
1141
1579
  function looksLikeAVFile(value) {
1142
- return Boolean(
1143
- value && typeof value === "object" && "message" in value && "messages" in value
1144
- );
1580
+ return Boolean(value && typeof value === "object" && "message" in value && "messages" in value);
1145
1581
  }
1582
+ /**
1583
+ * @param {unknown} [value]
1584
+ * @returns {value is VFileValue}
1585
+ */
1146
1586
  function looksLikeAVFileValue(value) {
1147
- return typeof value === "string" || isBuffer(value);
1587
+ return typeof value === "string" || (0, import_is_buffer.default)(value);
1148
1588
  }
1149
- const processLatexViaUnified = (options) => {
1150
- return unified().use(unifiedLatexUtilParse.unifiedLatexFromString, options).use(
1151
- unifiedLatexUtilToString.unifiedLatexStringCompiler,
1152
- Object.assign({ pretty: true }, options)
1153
- );
1589
+ //#endregion
1590
+ //#region libs/unified-latex.ts
1591
+ /**
1592
+ * Use `unified()` to a string to an `Ast.Ast` and then pretty-print it.
1593
+ */
1594
+ var processLatexViaUnified = (options) => {
1595
+ return unified().use(_unified_latex_unified_latex_util_parse.unifiedLatexFromString, options).use(_unified_latex_unified_latex_util_to_string.unifiedLatexStringCompiler, Object.assign({ pretty: true }, options));
1154
1596
  };
1155
- const processLatexToAstViaUnified = () => {
1156
- return unified().use(unifiedLatexUtilParse.unifiedLatexFromString).use(unifiedLatexUtilParse.unifiedLatexAstComplier);
1597
+ /**
1598
+ * Use `unified()` to a string to an `Ast.Ast` and then return it. This function
1599
+ * will not print/pretty-print the `Ast.Ast` back to a string.
1600
+ */
1601
+ var processLatexToAstViaUnified = () => {
1602
+ return unified().use(_unified_latex_unified_latex_util_parse.unifiedLatexFromString).use(_unified_latex_unified_latex_util_parse.unifiedLatexAstComplier);
1157
1603
  };
1604
+ //#endregion
1605
+ //#region index.ts
1606
+ /**
1607
+ * ## What is this?
1608
+ *
1609
+ * Functions parse strings to a `unified-latex` Abstract Syntax Tree (AST).
1610
+ *
1611
+ * ## When should I use this?
1612
+ *
1613
+ * If you have a string that you would like to parse to a `unified-latex` `Ast.Ast`, or
1614
+ * if you are building a plugin for `unified()` that manipulates LaTeX.
1615
+ */
1616
+ //#endregion
1158
1617
  exports.processLatexToAstViaUnified = processLatexToAstViaUnified;
1159
1618
  exports.processLatexViaUnified = processLatexViaUnified;
1160
- //# sourceMappingURL=index.cjs.map
1619
+
1620
+ //# sourceMappingURL=index.cjs.map