@likec4/core 1.47.0 → 1.48.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.
- package/LICENSE +1 -1
- package/dist/_chunks/Builder.view-element.mjs +3284 -0
- package/dist/_chunks/LikeC4Model.d.mts +1287 -0
- package/dist/_chunks/LikeC4Styles.mjs +691 -0
- package/dist/_chunks/RichText.d.mts +84 -0
- package/dist/_chunks/RichText.mjs +148 -0
- package/dist/_chunks/_aux.d.mts +289 -0
- package/dist/_chunks/_aux.mjs +18 -0
- package/dist/_chunks/_types.d.mts +781 -0
- package/dist/_chunks/_types2.d.mts +38 -0
- package/dist/_chunks/assignTagColors.mjs +24 -0
- package/dist/_chunks/calcDriftsFromSnapshot.mjs +379 -0
- package/dist/_chunks/connection.mjs +0 -0
- package/dist/_chunks/const.d.mts +43 -0
- package/dist/_chunks/const.mjs +33 -0
- package/dist/_chunks/expression-model.d.mts +192 -0
- package/dist/_chunks/expression-model.mjs +103 -0
- package/dist/_chunks/expression.d.mts +347 -0
- package/dist/_chunks/expression.mjs +107 -0
- package/dist/_chunks/find.d.mts +82 -0
- package/dist/_chunks/find.mjs +646 -0
- package/dist/_chunks/find2.d.mts +78 -0
- package/dist/_chunks/find2.mjs +287 -0
- package/dist/_chunks/fqnRef.d.mts +58 -0
- package/dist/_chunks/fqnRef.mjs +41 -0
- package/dist/_chunks/geometry.mjs +335 -0
- package/dist/_chunks/index.d.mts +169 -0
- package/dist/_chunks/index2.d.mts +937 -0
- package/dist/_chunks/index3.d.mts +146 -0
- package/dist/_chunks/index4.d.mts +62 -0
- package/dist/_chunks/index5.d.mts +42 -0
- package/dist/_chunks/index6.d.mts +43 -0
- package/dist/{shared/core.OtRNdMxy.d.mts → _chunks/index7.d.mts} +113 -197
- package/dist/_chunks/index8.d.mts +144 -0
- package/dist/_chunks/invariant.mjs +18 -0
- package/dist/_chunks/iterable.mjs +146 -0
- package/dist/_chunks/libs/@mantine/colors-generator.mjs +3416 -0
- package/dist/_chunks/libs/@ungap/structured-clone.mjs +213 -0
- package/dist/_chunks/libs/bail.mjs +14 -0
- package/dist/_chunks/libs/ccount.mjs +25 -0
- package/dist/_chunks/libs/character-entities-html4.mjs +263 -0
- package/dist/_chunks/libs/character-entities-legacy.mjs +117 -0
- package/dist/_chunks/libs/character-entities.mjs +2136 -0
- package/dist/_chunks/libs/comma-separated-tokens.mjs +18 -0
- package/dist/_chunks/libs/decode-named-character-reference.mjs +21 -0
- package/dist/_chunks/libs/defu.mjs +42 -0
- package/dist/_chunks/libs/devlop.mjs +5 -0
- package/dist/_chunks/libs/escape-string-regexp.mjs +8 -0
- package/dist/_chunks/libs/extend.mjs +77 -0
- package/dist/_chunks/libs/graphology-dag.mjs +703 -0
- package/dist/_chunks/libs/graphology-types.d.mts +601 -0
- package/dist/_chunks/libs/graphology.d.mts +6 -0
- package/dist/_chunks/libs/graphology.mjs +4565 -0
- package/dist/_chunks/libs/hast-util-sanitize.mjs +863 -0
- package/dist/_chunks/libs/hast-util-to-html.mjs +2696 -0
- package/dist/_chunks/libs/is-plain-obj.mjs +9 -0
- package/dist/_chunks/libs/longest-streak.mjs +30 -0
- package/dist/_chunks/libs/markdown-table.mjs +290 -0
- package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +653 -0
- package/dist/_chunks/libs/mdast-util-from-markdown.mjs +8522 -0
- package/dist/_chunks/libs/mdast-util-gfm.mjs +2393 -0
- package/dist/_chunks/libs/mdast-util-to-hast.mjs +1803 -0
- package/dist/_chunks/libs/micromark-extension-gfm.mjs +2243 -0
- package/dist/_chunks/libs/mnemonist.d.mts +254 -0
- package/dist/_chunks/libs/mnemonist.mjs +1978 -0
- package/dist/_chunks/libs/natural-compare-lite.mjs +42 -0
- package/dist/_chunks/libs/rehype-sanitize.mjs +29 -0
- package/dist/_chunks/libs/rehype-stringify.mjs +34 -0
- package/dist/_chunks/libs/remark-gfm.mjs +36 -0
- package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +100 -0
- package/dist/_chunks/libs/remark-parse.mjs +39 -0
- package/dist/_chunks/libs/remark-rehype.mjs +171 -0
- package/dist/_chunks/libs/remeda.mjs +702 -0
- package/dist/_chunks/libs/trough.mjs +158 -0
- package/dist/_chunks/libs/unified.mjs +2212 -0
- package/dist/_chunks/mnemonist.d.mts +1 -0
- package/dist/_chunks/mnemonist.mjs +0 -0
- package/dist/_chunks/model.mjs +1898 -0
- package/dist/_chunks/model2.mjs +0 -0
- package/dist/_chunks/relationships-view.mjs +132 -0
- package/dist/_chunks/rolldown-runtime.mjs +42 -0
- package/dist/{shared/core.C_3y3eqV.d.mts → _chunks/scalar.d.mts} +13 -43
- package/dist/_chunks/scalar.mjs +84 -0
- package/dist/_chunks/utils.mjs +483 -0
- package/dist/builder/index.d.mts +11 -775
- package/dist/builder/index.mjs +631 -1022
- package/dist/compute-view/index.d.mts +85 -56
- package/dist/compute-view/index.mjs +247 -214
- package/dist/compute-view/relationships-view/index.d.mts +16 -51
- package/dist/compute-view/relationships-view/index.mjs +6 -184
- package/dist/geometry/index.d.mts +2 -109
- package/dist/geometry/index.mjs +2 -327
- package/dist/index.d.mts +18 -20
- package/dist/index.mjs +27 -18
- package/dist/model/connection/deployment/index.d.mts +12 -15
- package/dist/model/connection/deployment/index.mjs +9 -2
- package/dist/model/connection/index.d.mts +14 -75
- package/dist/model/connection/index.mjs +10 -3
- package/dist/model/connection/model/index.d.mts +12 -15
- package/dist/model/connection/model/index.mjs +8 -2
- package/dist/model/index.d.mts +15 -57
- package/dist/model/index.mjs +11 -4
- package/dist/styles/index.d.mts +9 -117
- package/dist/styles/index.mjs +26 -59
- package/dist/types/RichText.d.mts +3 -0
- package/dist/types/RichText.mjs +7 -0
- package/dist/types/_aux.d.mts +3 -4
- package/dist/types/_aux.mjs +2 -7
- package/dist/types/expression-model.d.mts +6 -190
- package/dist/types/expression-model.mjs +6 -108
- package/dist/types/expression.d.mts +5 -6
- package/dist/types/expression.mjs +6 -112
- package/dist/types/fqnRef.d.mts +4 -60
- package/dist/types/fqnRef.mjs +6 -44
- package/dist/types/index.d.mts +9 -47
- package/dist/types/index.mjs +14 -16
- package/dist/types/scalar.d.mts +2 -2
- package/dist/types/scalar.mjs +7 -4
- package/dist/utils/graphology/index.d.mts +2 -1864
- package/dist/utils/graphology/index.mjs +3 -1
- package/dist/utils/index.d.mts +11 -124
- package/dist/utils/index.mjs +16 -43
- package/dist/utils/iterable/index.d.mts +9 -132
- package/dist/utils/iterable/index.mjs +2 -61
- package/dist/utils/mnemonist.d.mts +2 -0
- package/dist/utils/mnemonist.mjs +12 -0
- package/package.json +17 -22
- package/compute-view/relationships/package.json +0 -4
- package/dist/shared/core.3ZhnKAlZ.mjs +0 -106
- package/dist/shared/core.78IWAHAE.mjs +0 -332
- package/dist/shared/core.B85MJLTf.mjs +0 -5
- package/dist/shared/core.BFd1lU9R.mjs +0 -29
- package/dist/shared/core.BKlholso.mjs +0 -3
- package/dist/shared/core.BNN-3vPH.mjs +0 -1255
- package/dist/shared/core.BPGOjone.d.mts +0 -46
- package/dist/shared/core.BP_QHEXs.mjs +0 -785
- package/dist/shared/core.BbE4y-yl.mjs +0 -177
- package/dist/shared/core.Bdy3hhTc.mjs +0 -28382
- package/dist/shared/core.BfCKSW-g.d.mts +0 -1266
- package/dist/shared/core.BhNcrwzK.mjs +0 -7
- package/dist/shared/core.BkVA6gjl.mjs +0 -5
- package/dist/shared/core.BoYfZOBm.mjs +0 -3
- package/dist/shared/core.BsSXS-_R.mjs +0 -7
- package/dist/shared/core.C3JowhaZ.mjs +0 -32
- package/dist/shared/core.C4x8aaWa.mjs +0 -27
- package/dist/shared/core.CAgYpDtM.d.mts +0 -98
- package/dist/shared/core.CHf8VEa3.mjs +0 -1206
- package/dist/shared/core.CLSZtnFh.mjs +0 -69
- package/dist/shared/core.CbT8JVYL.mjs +0 -5
- package/dist/shared/core.CdNCAwq7.mjs +0 -176
- package/dist/shared/core.CmGY9blO.mjs +0 -6717
- package/dist/shared/core.CmPXpJ8l.mjs +0 -21
- package/dist/shared/core.Coi_LOUZ.mjs +0 -7
- package/dist/shared/core.CqAJJpK_.mjs +0 -3
- package/dist/shared/core.CywrQs86.d.mts +0 -31
- package/dist/shared/core.D00YbOhQ.d.mts +0 -300
- package/dist/shared/core.D0WZutNd.mjs +0 -94
- package/dist/shared/core.D4npX2q8.mjs +0 -18
- package/dist/shared/core.DB0Ue5Wx.d.mts +0 -70
- package/dist/shared/core.DC5IAaDT.d.mts +0 -334
- package/dist/shared/core.DE9qzhn8.d.mts +0 -83
- package/dist/shared/core.DGcIbsj4.mjs +0 -3946
- package/dist/shared/core.DH7TXqXf.mjs +0 -136
- package/dist/shared/core.DKhRkHRN.d.mts +0 -41
- package/dist/shared/core.DRJma0Ol.mjs +0 -22
- package/dist/shared/core.DU5SRqNF.mjs +0 -2209
- package/dist/shared/core.DXhDWKFZ.d.mts +0 -3
- package/dist/shared/core.DbfO90vF.mjs +0 -434
- package/dist/shared/core.DcS-0zys.mjs +0 -10
- package/dist/shared/core.Dh119QSP.mjs +0 -4995
- package/dist/shared/core.DjcWextK.mjs +0 -1371
- package/dist/shared/core.Dojz4bvg.d.mts +0 -504
- package/dist/shared/core.FZ305VYd.mjs +0 -21
- package/dist/shared/core.RfnaEmgA.mjs +0 -7
- package/dist/shared/core.btEq3i3f.mjs +0 -300
- package/dist/shared/core.oSV6SRfk.mjs +0 -13
- package/dist/shared/core.om36dXXW.mjs +0 -41
- package/dist/shared/core.osFs8tU7.d.mts +0 -466
- package/dist/shared/core.q10OP9oJ.mjs +0 -5
- package/dist/shared/core.tpvDGvdC.d.mts +0 -87
- package/dist/shared/core.uFk_o9X6.mjs +0 -13
|
@@ -0,0 +1,2212 @@
|
|
|
1
|
+
import { r as __toESM } from "../rolldown-runtime.mjs";
|
|
2
|
+
import { t as ok } from "./devlop.mjs";
|
|
3
|
+
import { n as stringifyPosition } from "./mdast-util-from-markdown.mjs";
|
|
4
|
+
import { t as bail } from "./bail.mjs";
|
|
5
|
+
import { t as require_extend } from "./extend.mjs";
|
|
6
|
+
import { t as isPlainObject } from "./is-plain-obj.mjs";
|
|
7
|
+
import { t as trough } from "./trough.mjs";
|
|
8
|
+
|
|
9
|
+
//#region ../../node_modules/.pnpm/vfile-message@4.0.2/node_modules/vfile-message/lib/index.js
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {import('unist').Node} Node
|
|
12
|
+
* @typedef {import('unist').Point} Point
|
|
13
|
+
* @typedef {import('unist').Position} Position
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {object & {type: string, position?: Position | undefined}} NodeLike
|
|
17
|
+
*
|
|
18
|
+
* @typedef Options
|
|
19
|
+
* Configuration.
|
|
20
|
+
* @property {Array<Node> | null | undefined} [ancestors]
|
|
21
|
+
* Stack of (inclusive) ancestor nodes surrounding the message (optional).
|
|
22
|
+
* @property {Error | null | undefined} [cause]
|
|
23
|
+
* Original error cause of the message (optional).
|
|
24
|
+
* @property {Point | Position | null | undefined} [place]
|
|
25
|
+
* Place of message (optional).
|
|
26
|
+
* @property {string | null | undefined} [ruleId]
|
|
27
|
+
* Category of message (optional, example: `'my-rule'`).
|
|
28
|
+
* @property {string | null | undefined} [source]
|
|
29
|
+
* Namespace of who sent the message (optional, example: `'my-package'`).
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Message.
|
|
33
|
+
*/
|
|
34
|
+
var VFileMessage = class extends Error {
|
|
35
|
+
/**
|
|
36
|
+
* Create a message for `reason`.
|
|
37
|
+
*
|
|
38
|
+
* > 🪦 **Note**: also has obsolete signatures.
|
|
39
|
+
*
|
|
40
|
+
* @overload
|
|
41
|
+
* @param {string} reason
|
|
42
|
+
* @param {Options | null | undefined} [options]
|
|
43
|
+
* @returns
|
|
44
|
+
*
|
|
45
|
+
* @overload
|
|
46
|
+
* @param {string} reason
|
|
47
|
+
* @param {Node | NodeLike | null | undefined} parent
|
|
48
|
+
* @param {string | null | undefined} [origin]
|
|
49
|
+
* @returns
|
|
50
|
+
*
|
|
51
|
+
* @overload
|
|
52
|
+
* @param {string} reason
|
|
53
|
+
* @param {Point | Position | null | undefined} place
|
|
54
|
+
* @param {string | null | undefined} [origin]
|
|
55
|
+
* @returns
|
|
56
|
+
*
|
|
57
|
+
* @overload
|
|
58
|
+
* @param {string} reason
|
|
59
|
+
* @param {string | null | undefined} [origin]
|
|
60
|
+
* @returns
|
|
61
|
+
*
|
|
62
|
+
* @overload
|
|
63
|
+
* @param {Error | VFileMessage} cause
|
|
64
|
+
* @param {Node | NodeLike | null | undefined} parent
|
|
65
|
+
* @param {string | null | undefined} [origin]
|
|
66
|
+
* @returns
|
|
67
|
+
*
|
|
68
|
+
* @overload
|
|
69
|
+
* @param {Error | VFileMessage} cause
|
|
70
|
+
* @param {Point | Position | null | undefined} place
|
|
71
|
+
* @param {string | null | undefined} [origin]
|
|
72
|
+
* @returns
|
|
73
|
+
*
|
|
74
|
+
* @overload
|
|
75
|
+
* @param {Error | VFileMessage} cause
|
|
76
|
+
* @param {string | null | undefined} [origin]
|
|
77
|
+
* @returns
|
|
78
|
+
*
|
|
79
|
+
* @param {Error | VFileMessage | string} causeOrReason
|
|
80
|
+
* Reason for message, should use markdown.
|
|
81
|
+
* @param {Node | NodeLike | Options | Point | Position | string | null | undefined} [optionsOrParentOrPlace]
|
|
82
|
+
* Configuration (optional).
|
|
83
|
+
* @param {string | null | undefined} [origin]
|
|
84
|
+
* Place in code where the message originates (example:
|
|
85
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
86
|
+
* @returns
|
|
87
|
+
* Instance of `VFileMessage`.
|
|
88
|
+
*/
|
|
89
|
+
constructor(causeOrReason, optionsOrParentOrPlace, origin) {
|
|
90
|
+
super();
|
|
91
|
+
if (typeof optionsOrParentOrPlace === "string") {
|
|
92
|
+
origin = optionsOrParentOrPlace;
|
|
93
|
+
optionsOrParentOrPlace = void 0;
|
|
94
|
+
}
|
|
95
|
+
/** @type {string} */
|
|
96
|
+
let reason = "";
|
|
97
|
+
/** @type {Options} */
|
|
98
|
+
let options = {};
|
|
99
|
+
let legacyCause = false;
|
|
100
|
+
if (optionsOrParentOrPlace) if ("line" in optionsOrParentOrPlace && "column" in optionsOrParentOrPlace) options = { place: optionsOrParentOrPlace };
|
|
101
|
+
else if ("start" in optionsOrParentOrPlace && "end" in optionsOrParentOrPlace) options = { place: optionsOrParentOrPlace };
|
|
102
|
+
else if ("type" in optionsOrParentOrPlace) options = {
|
|
103
|
+
ancestors: [optionsOrParentOrPlace],
|
|
104
|
+
place: optionsOrParentOrPlace.position
|
|
105
|
+
};
|
|
106
|
+
else options = { ...optionsOrParentOrPlace };
|
|
107
|
+
if (typeof causeOrReason === "string") reason = causeOrReason;
|
|
108
|
+
else if (!options.cause && causeOrReason) {
|
|
109
|
+
legacyCause = true;
|
|
110
|
+
reason = causeOrReason.message;
|
|
111
|
+
options.cause = causeOrReason;
|
|
112
|
+
}
|
|
113
|
+
if (!options.ruleId && !options.source && typeof origin === "string") {
|
|
114
|
+
const index = origin.indexOf(":");
|
|
115
|
+
if (index === -1) options.ruleId = origin;
|
|
116
|
+
else {
|
|
117
|
+
options.source = origin.slice(0, index);
|
|
118
|
+
options.ruleId = origin.slice(index + 1);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (!options.place && options.ancestors && options.ancestors) {
|
|
122
|
+
const parent = options.ancestors[options.ancestors.length - 1];
|
|
123
|
+
if (parent) options.place = parent.position;
|
|
124
|
+
}
|
|
125
|
+
const start = options.place && "start" in options.place ? options.place.start : options.place;
|
|
126
|
+
/**
|
|
127
|
+
* Stack of ancestor nodes surrounding the message.
|
|
128
|
+
*
|
|
129
|
+
* @type {Array<Node> | undefined}
|
|
130
|
+
*/
|
|
131
|
+
this.ancestors = options.ancestors || void 0;
|
|
132
|
+
/**
|
|
133
|
+
* Original error cause of the message.
|
|
134
|
+
*
|
|
135
|
+
* @type {Error | undefined}
|
|
136
|
+
*/
|
|
137
|
+
this.cause = options.cause || void 0;
|
|
138
|
+
/**
|
|
139
|
+
* Starting column of message.
|
|
140
|
+
*
|
|
141
|
+
* @type {number | undefined}
|
|
142
|
+
*/
|
|
143
|
+
this.column = start ? start.column : void 0;
|
|
144
|
+
/**
|
|
145
|
+
* State of problem.
|
|
146
|
+
*
|
|
147
|
+
* * `true` — error, file not usable
|
|
148
|
+
* * `false` — warning, change may be needed
|
|
149
|
+
* * `undefined` — change likely not needed
|
|
150
|
+
*
|
|
151
|
+
* @type {boolean | null | undefined}
|
|
152
|
+
*/
|
|
153
|
+
this.fatal = void 0;
|
|
154
|
+
/**
|
|
155
|
+
* Path of a file (used throughout the `VFile` ecosystem).
|
|
156
|
+
*
|
|
157
|
+
* @type {string | undefined}
|
|
158
|
+
*/
|
|
159
|
+
this.file;
|
|
160
|
+
/**
|
|
161
|
+
* Reason for message.
|
|
162
|
+
*
|
|
163
|
+
* @type {string}
|
|
164
|
+
*/
|
|
165
|
+
this.message = reason;
|
|
166
|
+
/**
|
|
167
|
+
* Starting line of error.
|
|
168
|
+
*
|
|
169
|
+
* @type {number | undefined}
|
|
170
|
+
*/
|
|
171
|
+
this.line = start ? start.line : void 0;
|
|
172
|
+
/**
|
|
173
|
+
* Serialized positional info of message.
|
|
174
|
+
*
|
|
175
|
+
* On normal errors, this would be something like `ParseError`, buit in
|
|
176
|
+
* `VFile` messages we use this space to show where an error happened.
|
|
177
|
+
*/
|
|
178
|
+
this.name = stringifyPosition(options.place) || "1:1";
|
|
179
|
+
/**
|
|
180
|
+
* Place of message.
|
|
181
|
+
*
|
|
182
|
+
* @type {Point | Position | undefined}
|
|
183
|
+
*/
|
|
184
|
+
this.place = options.place || void 0;
|
|
185
|
+
/**
|
|
186
|
+
* Reason for message, should use markdown.
|
|
187
|
+
*
|
|
188
|
+
* @type {string}
|
|
189
|
+
*/
|
|
190
|
+
this.reason = this.message;
|
|
191
|
+
/**
|
|
192
|
+
* Category of message (example: `'my-rule'`).
|
|
193
|
+
*
|
|
194
|
+
* @type {string | undefined}
|
|
195
|
+
*/
|
|
196
|
+
this.ruleId = options.ruleId || void 0;
|
|
197
|
+
/**
|
|
198
|
+
* Namespace of message (example: `'my-package'`).
|
|
199
|
+
*
|
|
200
|
+
* @type {string | undefined}
|
|
201
|
+
*/
|
|
202
|
+
this.source = options.source || void 0;
|
|
203
|
+
/**
|
|
204
|
+
* Stack of message.
|
|
205
|
+
*
|
|
206
|
+
* This is used by normal errors to show where something happened in
|
|
207
|
+
* programming code, irrelevant for `VFile` messages,
|
|
208
|
+
*
|
|
209
|
+
* @type {string}
|
|
210
|
+
*/
|
|
211
|
+
this.stack = legacyCause && options.cause && typeof options.cause.stack === "string" ? options.cause.stack : "";
|
|
212
|
+
/**
|
|
213
|
+
* Specify the source value that’s being reported, which is deemed
|
|
214
|
+
* incorrect.
|
|
215
|
+
*
|
|
216
|
+
* @type {string | undefined}
|
|
217
|
+
*/
|
|
218
|
+
this.actual;
|
|
219
|
+
/**
|
|
220
|
+
* Suggest acceptable values that can be used instead of `actual`.
|
|
221
|
+
*
|
|
222
|
+
* @type {Array<string> | undefined}
|
|
223
|
+
*/
|
|
224
|
+
this.expected;
|
|
225
|
+
/**
|
|
226
|
+
* Long form description of the message (you should use markdown).
|
|
227
|
+
*
|
|
228
|
+
* @type {string | undefined}
|
|
229
|
+
*/
|
|
230
|
+
this.note;
|
|
231
|
+
/**
|
|
232
|
+
* Link to docs for the message.
|
|
233
|
+
*
|
|
234
|
+
* > 👉 **Note**: this must be an absolute URL that can be passed as `x`
|
|
235
|
+
* > to `new URL(x)`.
|
|
236
|
+
*
|
|
237
|
+
* @type {string | undefined}
|
|
238
|
+
*/
|
|
239
|
+
this.url;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
VFileMessage.prototype.file = "";
|
|
243
|
+
VFileMessage.prototype.name = "";
|
|
244
|
+
VFileMessage.prototype.reason = "";
|
|
245
|
+
VFileMessage.prototype.message = "";
|
|
246
|
+
VFileMessage.prototype.stack = "";
|
|
247
|
+
VFileMessage.prototype.column = void 0;
|
|
248
|
+
VFileMessage.prototype.line = void 0;
|
|
249
|
+
VFileMessage.prototype.ancestors = void 0;
|
|
250
|
+
VFileMessage.prototype.cause = void 0;
|
|
251
|
+
VFileMessage.prototype.fatal = void 0;
|
|
252
|
+
VFileMessage.prototype.place = void 0;
|
|
253
|
+
VFileMessage.prototype.ruleId = void 0;
|
|
254
|
+
VFileMessage.prototype.source = void 0;
|
|
255
|
+
|
|
256
|
+
//#endregion
|
|
257
|
+
//#region ../../node_modules/.pnpm/vfile@6.0.3/node_modules/vfile/lib/minpath.browser.js
|
|
258
|
+
const minpath = {
|
|
259
|
+
basename,
|
|
260
|
+
dirname,
|
|
261
|
+
extname,
|
|
262
|
+
join,
|
|
263
|
+
sep: "/"
|
|
264
|
+
};
|
|
265
|
+
/**
|
|
266
|
+
* Get the basename from a path.
|
|
267
|
+
*
|
|
268
|
+
* @param {string} path
|
|
269
|
+
* File path.
|
|
270
|
+
* @param {string | null | undefined} [extname]
|
|
271
|
+
* Extension to strip.
|
|
272
|
+
* @returns {string}
|
|
273
|
+
* Stem or basename.
|
|
274
|
+
*/
|
|
275
|
+
function basename(path, extname) {
|
|
276
|
+
if (extname !== void 0 && typeof extname !== "string") throw new TypeError("\"ext\" argument must be a string");
|
|
277
|
+
assertPath$1(path);
|
|
278
|
+
let start = 0;
|
|
279
|
+
let end = -1;
|
|
280
|
+
let index = path.length;
|
|
281
|
+
/** @type {boolean | undefined} */
|
|
282
|
+
let seenNonSlash;
|
|
283
|
+
if (extname === void 0 || extname.length === 0 || extname.length > path.length) {
|
|
284
|
+
while (index--) if (path.codePointAt(index) === 47) {
|
|
285
|
+
if (seenNonSlash) {
|
|
286
|
+
start = index + 1;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
} else if (end < 0) {
|
|
290
|
+
seenNonSlash = true;
|
|
291
|
+
end = index + 1;
|
|
292
|
+
}
|
|
293
|
+
return end < 0 ? "" : path.slice(start, end);
|
|
294
|
+
}
|
|
295
|
+
if (extname === path) return "";
|
|
296
|
+
let firstNonSlashEnd = -1;
|
|
297
|
+
let extnameIndex = extname.length - 1;
|
|
298
|
+
while (index--) if (path.codePointAt(index) === 47) {
|
|
299
|
+
if (seenNonSlash) {
|
|
300
|
+
start = index + 1;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
} else {
|
|
304
|
+
if (firstNonSlashEnd < 0) {
|
|
305
|
+
seenNonSlash = true;
|
|
306
|
+
firstNonSlashEnd = index + 1;
|
|
307
|
+
}
|
|
308
|
+
if (extnameIndex > -1) if (path.codePointAt(index) === extname.codePointAt(extnameIndex--)) {
|
|
309
|
+
if (extnameIndex < 0) end = index;
|
|
310
|
+
} else {
|
|
311
|
+
extnameIndex = -1;
|
|
312
|
+
end = firstNonSlashEnd;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (start === end) end = firstNonSlashEnd;
|
|
316
|
+
else if (end < 0) end = path.length;
|
|
317
|
+
return path.slice(start, end);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Get the dirname from a path.
|
|
321
|
+
*
|
|
322
|
+
* @param {string} path
|
|
323
|
+
* File path.
|
|
324
|
+
* @returns {string}
|
|
325
|
+
* File path.
|
|
326
|
+
*/
|
|
327
|
+
function dirname(path) {
|
|
328
|
+
assertPath$1(path);
|
|
329
|
+
if (path.length === 0) return ".";
|
|
330
|
+
let end = -1;
|
|
331
|
+
let index = path.length;
|
|
332
|
+
/** @type {boolean | undefined} */
|
|
333
|
+
let unmatchedSlash;
|
|
334
|
+
while (--index) if (path.codePointAt(index) === 47) {
|
|
335
|
+
if (unmatchedSlash) {
|
|
336
|
+
end = index;
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
} else if (!unmatchedSlash) unmatchedSlash = true;
|
|
340
|
+
return end < 0 ? path.codePointAt(0) === 47 ? "/" : "." : end === 1 && path.codePointAt(0) === 47 ? "//" : path.slice(0, end);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Get an extname from a path.
|
|
344
|
+
*
|
|
345
|
+
* @param {string} path
|
|
346
|
+
* File path.
|
|
347
|
+
* @returns {string}
|
|
348
|
+
* Extname.
|
|
349
|
+
*/
|
|
350
|
+
function extname(path) {
|
|
351
|
+
assertPath$1(path);
|
|
352
|
+
let index = path.length;
|
|
353
|
+
let end = -1;
|
|
354
|
+
let startPart = 0;
|
|
355
|
+
let startDot = -1;
|
|
356
|
+
let preDotState = 0;
|
|
357
|
+
/** @type {boolean | undefined} */
|
|
358
|
+
let unmatchedSlash;
|
|
359
|
+
while (index--) {
|
|
360
|
+
const code = path.codePointAt(index);
|
|
361
|
+
if (code === 47) {
|
|
362
|
+
if (unmatchedSlash) {
|
|
363
|
+
startPart = index + 1;
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
if (end < 0) {
|
|
369
|
+
unmatchedSlash = true;
|
|
370
|
+
end = index + 1;
|
|
371
|
+
}
|
|
372
|
+
if (code === 46) {
|
|
373
|
+
if (startDot < 0) startDot = index;
|
|
374
|
+
else if (preDotState !== 1) preDotState = 1;
|
|
375
|
+
} else if (startDot > -1) preDotState = -1;
|
|
376
|
+
}
|
|
377
|
+
if (startDot < 0 || end < 0 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) return "";
|
|
378
|
+
return path.slice(startDot, end);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Join segments from a path.
|
|
382
|
+
*
|
|
383
|
+
* @param {Array<string>} segments
|
|
384
|
+
* Path segments.
|
|
385
|
+
* @returns {string}
|
|
386
|
+
* File path.
|
|
387
|
+
*/
|
|
388
|
+
function join(...segments) {
|
|
389
|
+
let index = -1;
|
|
390
|
+
/** @type {string | undefined} */
|
|
391
|
+
let joined;
|
|
392
|
+
while (++index < segments.length) {
|
|
393
|
+
assertPath$1(segments[index]);
|
|
394
|
+
if (segments[index]) joined = joined === void 0 ? segments[index] : joined + "/" + segments[index];
|
|
395
|
+
}
|
|
396
|
+
return joined === void 0 ? "." : normalize(joined);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Normalize a basic file path.
|
|
400
|
+
*
|
|
401
|
+
* @param {string} path
|
|
402
|
+
* File path.
|
|
403
|
+
* @returns {string}
|
|
404
|
+
* File path.
|
|
405
|
+
*/
|
|
406
|
+
function normalize(path) {
|
|
407
|
+
assertPath$1(path);
|
|
408
|
+
const absolute = path.codePointAt(0) === 47;
|
|
409
|
+
let value = normalizeString(path, !absolute);
|
|
410
|
+
if (value.length === 0 && !absolute) value = ".";
|
|
411
|
+
if (value.length > 0 && path.codePointAt(path.length - 1) === 47) value += "/";
|
|
412
|
+
return absolute ? "/" + value : value;
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Resolve `.` and `..` elements in a path with directory names.
|
|
416
|
+
*
|
|
417
|
+
* @param {string} path
|
|
418
|
+
* File path.
|
|
419
|
+
* @param {boolean} allowAboveRoot
|
|
420
|
+
* Whether `..` can move above root.
|
|
421
|
+
* @returns {string}
|
|
422
|
+
* File path.
|
|
423
|
+
*/
|
|
424
|
+
function normalizeString(path, allowAboveRoot) {
|
|
425
|
+
let result = "";
|
|
426
|
+
let lastSegmentLength = 0;
|
|
427
|
+
let lastSlash = -1;
|
|
428
|
+
let dots = 0;
|
|
429
|
+
let index = -1;
|
|
430
|
+
/** @type {number | undefined} */
|
|
431
|
+
let code;
|
|
432
|
+
/** @type {number} */
|
|
433
|
+
let lastSlashIndex;
|
|
434
|
+
while (++index <= path.length) {
|
|
435
|
+
if (index < path.length) code = path.codePointAt(index);
|
|
436
|
+
else if (code === 47) break;
|
|
437
|
+
else code = 47;
|
|
438
|
+
if (code === 47) {
|
|
439
|
+
if (lastSlash === index - 1 || dots === 1) {} else if (lastSlash !== index - 1 && dots === 2) {
|
|
440
|
+
if (result.length < 2 || lastSegmentLength !== 2 || result.codePointAt(result.length - 1) !== 46 || result.codePointAt(result.length - 2) !== 46) {
|
|
441
|
+
if (result.length > 2) {
|
|
442
|
+
lastSlashIndex = result.lastIndexOf("/");
|
|
443
|
+
if (lastSlashIndex !== result.length - 1) {
|
|
444
|
+
if (lastSlashIndex < 0) {
|
|
445
|
+
result = "";
|
|
446
|
+
lastSegmentLength = 0;
|
|
447
|
+
} else {
|
|
448
|
+
result = result.slice(0, lastSlashIndex);
|
|
449
|
+
lastSegmentLength = result.length - 1 - result.lastIndexOf("/");
|
|
450
|
+
}
|
|
451
|
+
lastSlash = index;
|
|
452
|
+
dots = 0;
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
} else if (result.length > 0) {
|
|
456
|
+
result = "";
|
|
457
|
+
lastSegmentLength = 0;
|
|
458
|
+
lastSlash = index;
|
|
459
|
+
dots = 0;
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (allowAboveRoot) {
|
|
464
|
+
result = result.length > 0 ? result + "/.." : "..";
|
|
465
|
+
lastSegmentLength = 2;
|
|
466
|
+
}
|
|
467
|
+
} else {
|
|
468
|
+
if (result.length > 0) result += "/" + path.slice(lastSlash + 1, index);
|
|
469
|
+
else result = path.slice(lastSlash + 1, index);
|
|
470
|
+
lastSegmentLength = index - lastSlash - 1;
|
|
471
|
+
}
|
|
472
|
+
lastSlash = index;
|
|
473
|
+
dots = 0;
|
|
474
|
+
} else if (code === 46 && dots > -1) dots++;
|
|
475
|
+
else dots = -1;
|
|
476
|
+
}
|
|
477
|
+
return result;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Make sure `path` is a string.
|
|
481
|
+
*
|
|
482
|
+
* @param {string} path
|
|
483
|
+
* File path.
|
|
484
|
+
* @returns {asserts path is string}
|
|
485
|
+
* Nothing.
|
|
486
|
+
*/
|
|
487
|
+
function assertPath$1(path) {
|
|
488
|
+
if (typeof path !== "string") throw new TypeError("Path must be a string. Received " + JSON.stringify(path));
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
//#endregion
|
|
492
|
+
//#region ../../node_modules/.pnpm/vfile@6.0.3/node_modules/vfile/lib/minproc.browser.js
|
|
493
|
+
const minproc = { cwd };
|
|
494
|
+
function cwd() {
|
|
495
|
+
return "/";
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
//#endregion
|
|
499
|
+
//#region ../../node_modules/.pnpm/vfile@6.0.3/node_modules/vfile/lib/minurl.shared.js
|
|
500
|
+
/**
|
|
501
|
+
* Checks if a value has the shape of a WHATWG URL object.
|
|
502
|
+
*
|
|
503
|
+
* Using a symbol or instanceof would not be able to recognize URL objects
|
|
504
|
+
* coming from other implementations (e.g. in Electron), so instead we are
|
|
505
|
+
* checking some well known properties for a lack of a better test.
|
|
506
|
+
*
|
|
507
|
+
* We use `href` and `protocol` as they are the only properties that are
|
|
508
|
+
* easy to retrieve and calculate due to the lazy nature of the getters.
|
|
509
|
+
*
|
|
510
|
+
* We check for auth attribute to distinguish legacy url instance with
|
|
511
|
+
* WHATWG URL instance.
|
|
512
|
+
*
|
|
513
|
+
* @param {unknown} fileUrlOrPath
|
|
514
|
+
* File path or URL.
|
|
515
|
+
* @returns {fileUrlOrPath is URL}
|
|
516
|
+
* Whether it’s a URL.
|
|
517
|
+
*/
|
|
518
|
+
function isUrl(fileUrlOrPath) {
|
|
519
|
+
return Boolean(fileUrlOrPath !== null && typeof fileUrlOrPath === "object" && "href" in fileUrlOrPath && fileUrlOrPath.href && "protocol" in fileUrlOrPath && fileUrlOrPath.protocol && fileUrlOrPath.auth === void 0);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region ../../node_modules/.pnpm/vfile@6.0.3/node_modules/vfile/lib/minurl.browser.js
|
|
524
|
+
/**
|
|
525
|
+
* @param {URL | string} path
|
|
526
|
+
* File URL.
|
|
527
|
+
* @returns {string}
|
|
528
|
+
* File URL.
|
|
529
|
+
*/
|
|
530
|
+
function urlToPath(path) {
|
|
531
|
+
if (typeof path === "string") path = new URL(path);
|
|
532
|
+
else if (!isUrl(path)) {
|
|
533
|
+
/** @type {NodeJS.ErrnoException} */
|
|
534
|
+
const error = /* @__PURE__ */ new TypeError("The \"path\" argument must be of type string or an instance of URL. Received `" + path + "`");
|
|
535
|
+
error.code = "ERR_INVALID_ARG_TYPE";
|
|
536
|
+
throw error;
|
|
537
|
+
}
|
|
538
|
+
if (path.protocol !== "file:") {
|
|
539
|
+
/** @type {NodeJS.ErrnoException} */
|
|
540
|
+
const error = /* @__PURE__ */ new TypeError("The URL must be of scheme file");
|
|
541
|
+
error.code = "ERR_INVALID_URL_SCHEME";
|
|
542
|
+
throw error;
|
|
543
|
+
}
|
|
544
|
+
return getPathFromURLPosix(path);
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Get a path from a POSIX URL.
|
|
548
|
+
*
|
|
549
|
+
* @param {URL} url
|
|
550
|
+
* URL.
|
|
551
|
+
* @returns {string}
|
|
552
|
+
* File path.
|
|
553
|
+
*/
|
|
554
|
+
function getPathFromURLPosix(url) {
|
|
555
|
+
if (url.hostname !== "") {
|
|
556
|
+
/** @type {NodeJS.ErrnoException} */
|
|
557
|
+
const error = /* @__PURE__ */ new TypeError("File URL host must be \"localhost\" or empty on darwin");
|
|
558
|
+
error.code = "ERR_INVALID_FILE_URL_HOST";
|
|
559
|
+
throw error;
|
|
560
|
+
}
|
|
561
|
+
const pathname = url.pathname;
|
|
562
|
+
let index = -1;
|
|
563
|
+
while (++index < pathname.length) if (pathname.codePointAt(index) === 37 && pathname.codePointAt(index + 1) === 50) {
|
|
564
|
+
const third = pathname.codePointAt(index + 2);
|
|
565
|
+
if (third === 70 || third === 102) {
|
|
566
|
+
/** @type {NodeJS.ErrnoException} */
|
|
567
|
+
const error = /* @__PURE__ */ new TypeError("File URL path must not include encoded / characters");
|
|
568
|
+
error.code = "ERR_INVALID_FILE_URL_PATH";
|
|
569
|
+
throw error;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return decodeURIComponent(pathname);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
//#endregion
|
|
576
|
+
//#region ../../node_modules/.pnpm/vfile@6.0.3/node_modules/vfile/lib/index.js
|
|
577
|
+
/**
|
|
578
|
+
* @import {Node, Point, Position} from 'unist'
|
|
579
|
+
* @import {Options as MessageOptions} from 'vfile-message'
|
|
580
|
+
* @import {Compatible, Data, Map, Options, Value} from 'vfile'
|
|
581
|
+
*/
|
|
582
|
+
/**
|
|
583
|
+
* @typedef {object & {type: string, position?: Position | undefined}} NodeLike
|
|
584
|
+
*/
|
|
585
|
+
/**
|
|
586
|
+
* Order of setting (least specific to most), we need this because otherwise
|
|
587
|
+
* `{stem: 'a', path: '~/b.js'}` would throw, as a path is needed before a
|
|
588
|
+
* stem can be set.
|
|
589
|
+
*/
|
|
590
|
+
const order = [
|
|
591
|
+
"history",
|
|
592
|
+
"path",
|
|
593
|
+
"basename",
|
|
594
|
+
"stem",
|
|
595
|
+
"extname",
|
|
596
|
+
"dirname"
|
|
597
|
+
];
|
|
598
|
+
var VFile = class {
|
|
599
|
+
/**
|
|
600
|
+
* Create a new virtual file.
|
|
601
|
+
*
|
|
602
|
+
* `options` is treated as:
|
|
603
|
+
*
|
|
604
|
+
* * `string` or `Uint8Array` — `{value: options}`
|
|
605
|
+
* * `URL` — `{path: options}`
|
|
606
|
+
* * `VFile` — shallow copies its data over to the new file
|
|
607
|
+
* * `object` — all fields are shallow copied over to the new file
|
|
608
|
+
*
|
|
609
|
+
* Path related fields are set in the following order (least specific to
|
|
610
|
+
* most specific): `history`, `path`, `basename`, `stem`, `extname`,
|
|
611
|
+
* `dirname`.
|
|
612
|
+
*
|
|
613
|
+
* You cannot set `dirname` or `extname` without setting either `history`,
|
|
614
|
+
* `path`, `basename`, or `stem` too.
|
|
615
|
+
*
|
|
616
|
+
* @param {Compatible | null | undefined} [value]
|
|
617
|
+
* File value.
|
|
618
|
+
* @returns
|
|
619
|
+
* New instance.
|
|
620
|
+
*/
|
|
621
|
+
constructor(value) {
|
|
622
|
+
/** @type {Options | VFile} */
|
|
623
|
+
let options;
|
|
624
|
+
if (!value) options = {};
|
|
625
|
+
else if (isUrl(value)) options = { path: value };
|
|
626
|
+
else if (typeof value === "string" || isUint8Array$1(value)) options = { value };
|
|
627
|
+
else options = value;
|
|
628
|
+
/**
|
|
629
|
+
* Base of `path` (default: `process.cwd()` or `'/'` in browsers).
|
|
630
|
+
*
|
|
631
|
+
* @type {string}
|
|
632
|
+
*/
|
|
633
|
+
this.cwd = "cwd" in options ? "" : minproc.cwd();
|
|
634
|
+
/**
|
|
635
|
+
* Place to store custom info (default: `{}`).
|
|
636
|
+
*
|
|
637
|
+
* It’s OK to store custom data directly on the file but moving it to
|
|
638
|
+
* `data` is recommended.
|
|
639
|
+
*
|
|
640
|
+
* @type {Data}
|
|
641
|
+
*/
|
|
642
|
+
this.data = {};
|
|
643
|
+
/**
|
|
644
|
+
* List of file paths the file moved between.
|
|
645
|
+
*
|
|
646
|
+
* The first is the original path and the last is the current path.
|
|
647
|
+
*
|
|
648
|
+
* @type {Array<string>}
|
|
649
|
+
*/
|
|
650
|
+
this.history = [];
|
|
651
|
+
/**
|
|
652
|
+
* List of messages associated with the file.
|
|
653
|
+
*
|
|
654
|
+
* @type {Array<VFileMessage>}
|
|
655
|
+
*/
|
|
656
|
+
this.messages = [];
|
|
657
|
+
/**
|
|
658
|
+
* Raw value.
|
|
659
|
+
*
|
|
660
|
+
* @type {Value}
|
|
661
|
+
*/
|
|
662
|
+
this.value;
|
|
663
|
+
/**
|
|
664
|
+
* Source map.
|
|
665
|
+
*
|
|
666
|
+
* This type is equivalent to the `RawSourceMap` type from the `source-map`
|
|
667
|
+
* module.
|
|
668
|
+
*
|
|
669
|
+
* @type {Map | null | undefined}
|
|
670
|
+
*/
|
|
671
|
+
this.map;
|
|
672
|
+
/**
|
|
673
|
+
* Custom, non-string, compiled, representation.
|
|
674
|
+
*
|
|
675
|
+
* This is used by unified to store non-string results.
|
|
676
|
+
* One example is when turning markdown into React nodes.
|
|
677
|
+
*
|
|
678
|
+
* @type {unknown}
|
|
679
|
+
*/
|
|
680
|
+
this.result;
|
|
681
|
+
/**
|
|
682
|
+
* Whether a file was saved to disk.
|
|
683
|
+
*
|
|
684
|
+
* This is used by vfile reporters.
|
|
685
|
+
*
|
|
686
|
+
* @type {boolean}
|
|
687
|
+
*/
|
|
688
|
+
this.stored;
|
|
689
|
+
let index = -1;
|
|
690
|
+
while (++index < order.length) {
|
|
691
|
+
const field = order[index];
|
|
692
|
+
if (field in options && options[field] !== void 0 && options[field] !== null) this[field] = field === "history" ? [...options[field]] : options[field];
|
|
693
|
+
}
|
|
694
|
+
/** @type {string} */
|
|
695
|
+
let field;
|
|
696
|
+
for (field in options) if (!order.includes(field)) this[field] = options[field];
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Get the basename (including extname) (example: `'index.min.js'`).
|
|
700
|
+
*
|
|
701
|
+
* @returns {string | undefined}
|
|
702
|
+
* Basename.
|
|
703
|
+
*/
|
|
704
|
+
get basename() {
|
|
705
|
+
return typeof this.path === "string" ? minpath.basename(this.path) : void 0;
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* Set basename (including extname) (`'index.min.js'`).
|
|
709
|
+
*
|
|
710
|
+
* Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
|
|
711
|
+
* on windows).
|
|
712
|
+
* Cannot be nullified (use `file.path = file.dirname` instead).
|
|
713
|
+
*
|
|
714
|
+
* @param {string} basename
|
|
715
|
+
* Basename.
|
|
716
|
+
* @returns {undefined}
|
|
717
|
+
* Nothing.
|
|
718
|
+
*/
|
|
719
|
+
set basename(basename) {
|
|
720
|
+
assertNonEmpty(basename, "basename");
|
|
721
|
+
assertPart(basename, "basename");
|
|
722
|
+
this.path = minpath.join(this.dirname || "", basename);
|
|
723
|
+
}
|
|
724
|
+
/**
|
|
725
|
+
* Get the parent path (example: `'~'`).
|
|
726
|
+
*
|
|
727
|
+
* @returns {string | undefined}
|
|
728
|
+
* Dirname.
|
|
729
|
+
*/
|
|
730
|
+
get dirname() {
|
|
731
|
+
return typeof this.path === "string" ? minpath.dirname(this.path) : void 0;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Set the parent path (example: `'~'`).
|
|
735
|
+
*
|
|
736
|
+
* Cannot be set if there’s no `path` yet.
|
|
737
|
+
*
|
|
738
|
+
* @param {string | undefined} dirname
|
|
739
|
+
* Dirname.
|
|
740
|
+
* @returns {undefined}
|
|
741
|
+
* Nothing.
|
|
742
|
+
*/
|
|
743
|
+
set dirname(dirname) {
|
|
744
|
+
assertPath(this.basename, "dirname");
|
|
745
|
+
this.path = minpath.join(dirname || "", this.basename);
|
|
746
|
+
}
|
|
747
|
+
/**
|
|
748
|
+
* Get the extname (including dot) (example: `'.js'`).
|
|
749
|
+
*
|
|
750
|
+
* @returns {string | undefined}
|
|
751
|
+
* Extname.
|
|
752
|
+
*/
|
|
753
|
+
get extname() {
|
|
754
|
+
return typeof this.path === "string" ? minpath.extname(this.path) : void 0;
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Set the extname (including dot) (example: `'.js'`).
|
|
758
|
+
*
|
|
759
|
+
* Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
|
|
760
|
+
* on windows).
|
|
761
|
+
* Cannot be set if there’s no `path` yet.
|
|
762
|
+
*
|
|
763
|
+
* @param {string | undefined} extname
|
|
764
|
+
* Extname.
|
|
765
|
+
* @returns {undefined}
|
|
766
|
+
* Nothing.
|
|
767
|
+
*/
|
|
768
|
+
set extname(extname) {
|
|
769
|
+
assertPart(extname, "extname");
|
|
770
|
+
assertPath(this.dirname, "extname");
|
|
771
|
+
if (extname) {
|
|
772
|
+
if (extname.codePointAt(0) !== 46) throw new Error("`extname` must start with `.`");
|
|
773
|
+
if (extname.includes(".", 1)) throw new Error("`extname` cannot contain multiple dots");
|
|
774
|
+
}
|
|
775
|
+
this.path = minpath.join(this.dirname, this.stem + (extname || ""));
|
|
776
|
+
}
|
|
777
|
+
/**
|
|
778
|
+
* Get the full path (example: `'~/index.min.js'`).
|
|
779
|
+
*
|
|
780
|
+
* @returns {string}
|
|
781
|
+
* Path.
|
|
782
|
+
*/
|
|
783
|
+
get path() {
|
|
784
|
+
return this.history[this.history.length - 1];
|
|
785
|
+
}
|
|
786
|
+
/**
|
|
787
|
+
* Set the full path (example: `'~/index.min.js'`).
|
|
788
|
+
*
|
|
789
|
+
* Cannot be nullified.
|
|
790
|
+
* You can set a file URL (a `URL` object with a `file:` protocol) which will
|
|
791
|
+
* be turned into a path with `url.fileURLToPath`.
|
|
792
|
+
*
|
|
793
|
+
* @param {URL | string} path
|
|
794
|
+
* Path.
|
|
795
|
+
* @returns {undefined}
|
|
796
|
+
* Nothing.
|
|
797
|
+
*/
|
|
798
|
+
set path(path) {
|
|
799
|
+
if (isUrl(path)) path = urlToPath(path);
|
|
800
|
+
assertNonEmpty(path, "path");
|
|
801
|
+
if (this.path !== path) this.history.push(path);
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Get the stem (basename w/o extname) (example: `'index.min'`).
|
|
805
|
+
*
|
|
806
|
+
* @returns {string | undefined}
|
|
807
|
+
* Stem.
|
|
808
|
+
*/
|
|
809
|
+
get stem() {
|
|
810
|
+
return typeof this.path === "string" ? minpath.basename(this.path, this.extname) : void 0;
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Set the stem (basename w/o extname) (example: `'index.min'`).
|
|
814
|
+
*
|
|
815
|
+
* Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
|
|
816
|
+
* on windows).
|
|
817
|
+
* Cannot be nullified (use `file.path = file.dirname` instead).
|
|
818
|
+
*
|
|
819
|
+
* @param {string} stem
|
|
820
|
+
* Stem.
|
|
821
|
+
* @returns {undefined}
|
|
822
|
+
* Nothing.
|
|
823
|
+
*/
|
|
824
|
+
set stem(stem) {
|
|
825
|
+
assertNonEmpty(stem, "stem");
|
|
826
|
+
assertPart(stem, "stem");
|
|
827
|
+
this.path = minpath.join(this.dirname || "", stem + (this.extname || ""));
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Create a fatal message for `reason` associated with the file.
|
|
831
|
+
*
|
|
832
|
+
* The `fatal` field of the message is set to `true` (error; file not usable)
|
|
833
|
+
* and the `file` field is set to the current file path.
|
|
834
|
+
* The message is added to the `messages` field on `file`.
|
|
835
|
+
*
|
|
836
|
+
* > 🪦 **Note**: also has obsolete signatures.
|
|
837
|
+
*
|
|
838
|
+
* @overload
|
|
839
|
+
* @param {string} reason
|
|
840
|
+
* @param {MessageOptions | null | undefined} [options]
|
|
841
|
+
* @returns {never}
|
|
842
|
+
*
|
|
843
|
+
* @overload
|
|
844
|
+
* @param {string} reason
|
|
845
|
+
* @param {Node | NodeLike | null | undefined} parent
|
|
846
|
+
* @param {string | null | undefined} [origin]
|
|
847
|
+
* @returns {never}
|
|
848
|
+
*
|
|
849
|
+
* @overload
|
|
850
|
+
* @param {string} reason
|
|
851
|
+
* @param {Point | Position | null | undefined} place
|
|
852
|
+
* @param {string | null | undefined} [origin]
|
|
853
|
+
* @returns {never}
|
|
854
|
+
*
|
|
855
|
+
* @overload
|
|
856
|
+
* @param {string} reason
|
|
857
|
+
* @param {string | null | undefined} [origin]
|
|
858
|
+
* @returns {never}
|
|
859
|
+
*
|
|
860
|
+
* @overload
|
|
861
|
+
* @param {Error | VFileMessage} cause
|
|
862
|
+
* @param {Node | NodeLike | null | undefined} parent
|
|
863
|
+
* @param {string | null | undefined} [origin]
|
|
864
|
+
* @returns {never}
|
|
865
|
+
*
|
|
866
|
+
* @overload
|
|
867
|
+
* @param {Error | VFileMessage} cause
|
|
868
|
+
* @param {Point | Position | null | undefined} place
|
|
869
|
+
* @param {string | null | undefined} [origin]
|
|
870
|
+
* @returns {never}
|
|
871
|
+
*
|
|
872
|
+
* @overload
|
|
873
|
+
* @param {Error | VFileMessage} cause
|
|
874
|
+
* @param {string | null | undefined} [origin]
|
|
875
|
+
* @returns {never}
|
|
876
|
+
*
|
|
877
|
+
* @param {Error | VFileMessage | string} causeOrReason
|
|
878
|
+
* Reason for message, should use markdown.
|
|
879
|
+
* @param {Node | NodeLike | MessageOptions | Point | Position | string | null | undefined} [optionsOrParentOrPlace]
|
|
880
|
+
* Configuration (optional).
|
|
881
|
+
* @param {string | null | undefined} [origin]
|
|
882
|
+
* Place in code where the message originates (example:
|
|
883
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
884
|
+
* @returns {never}
|
|
885
|
+
* Never.
|
|
886
|
+
* @throws {VFileMessage}
|
|
887
|
+
* Message.
|
|
888
|
+
*/
|
|
889
|
+
fail(causeOrReason, optionsOrParentOrPlace, origin) {
|
|
890
|
+
const message = this.message(causeOrReason, optionsOrParentOrPlace, origin);
|
|
891
|
+
message.fatal = true;
|
|
892
|
+
throw message;
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Create an info message for `reason` associated with the file.
|
|
896
|
+
*
|
|
897
|
+
* The `fatal` field of the message is set to `undefined` (info; change
|
|
898
|
+
* likely not needed) and the `file` field is set to the current file path.
|
|
899
|
+
* The message is added to the `messages` field on `file`.
|
|
900
|
+
*
|
|
901
|
+
* > 🪦 **Note**: also has obsolete signatures.
|
|
902
|
+
*
|
|
903
|
+
* @overload
|
|
904
|
+
* @param {string} reason
|
|
905
|
+
* @param {MessageOptions | null | undefined} [options]
|
|
906
|
+
* @returns {VFileMessage}
|
|
907
|
+
*
|
|
908
|
+
* @overload
|
|
909
|
+
* @param {string} reason
|
|
910
|
+
* @param {Node | NodeLike | null | undefined} parent
|
|
911
|
+
* @param {string | null | undefined} [origin]
|
|
912
|
+
* @returns {VFileMessage}
|
|
913
|
+
*
|
|
914
|
+
* @overload
|
|
915
|
+
* @param {string} reason
|
|
916
|
+
* @param {Point | Position | null | undefined} place
|
|
917
|
+
* @param {string | null | undefined} [origin]
|
|
918
|
+
* @returns {VFileMessage}
|
|
919
|
+
*
|
|
920
|
+
* @overload
|
|
921
|
+
* @param {string} reason
|
|
922
|
+
* @param {string | null | undefined} [origin]
|
|
923
|
+
* @returns {VFileMessage}
|
|
924
|
+
*
|
|
925
|
+
* @overload
|
|
926
|
+
* @param {Error | VFileMessage} cause
|
|
927
|
+
* @param {Node | NodeLike | null | undefined} parent
|
|
928
|
+
* @param {string | null | undefined} [origin]
|
|
929
|
+
* @returns {VFileMessage}
|
|
930
|
+
*
|
|
931
|
+
* @overload
|
|
932
|
+
* @param {Error | VFileMessage} cause
|
|
933
|
+
* @param {Point | Position | null | undefined} place
|
|
934
|
+
* @param {string | null | undefined} [origin]
|
|
935
|
+
* @returns {VFileMessage}
|
|
936
|
+
*
|
|
937
|
+
* @overload
|
|
938
|
+
* @param {Error | VFileMessage} cause
|
|
939
|
+
* @param {string | null | undefined} [origin]
|
|
940
|
+
* @returns {VFileMessage}
|
|
941
|
+
*
|
|
942
|
+
* @param {Error | VFileMessage | string} causeOrReason
|
|
943
|
+
* Reason for message, should use markdown.
|
|
944
|
+
* @param {Node | NodeLike | MessageOptions | Point | Position | string | null | undefined} [optionsOrParentOrPlace]
|
|
945
|
+
* Configuration (optional).
|
|
946
|
+
* @param {string | null | undefined} [origin]
|
|
947
|
+
* Place in code where the message originates (example:
|
|
948
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
949
|
+
* @returns {VFileMessage}
|
|
950
|
+
* Message.
|
|
951
|
+
*/
|
|
952
|
+
info(causeOrReason, optionsOrParentOrPlace, origin) {
|
|
953
|
+
const message = this.message(causeOrReason, optionsOrParentOrPlace, origin);
|
|
954
|
+
message.fatal = void 0;
|
|
955
|
+
return message;
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Create a message for `reason` associated with the file.
|
|
959
|
+
*
|
|
960
|
+
* The `fatal` field of the message is set to `false` (warning; change may be
|
|
961
|
+
* needed) and the `file` field is set to the current file path.
|
|
962
|
+
* The message is added to the `messages` field on `file`.
|
|
963
|
+
*
|
|
964
|
+
* > 🪦 **Note**: also has obsolete signatures.
|
|
965
|
+
*
|
|
966
|
+
* @overload
|
|
967
|
+
* @param {string} reason
|
|
968
|
+
* @param {MessageOptions | null | undefined} [options]
|
|
969
|
+
* @returns {VFileMessage}
|
|
970
|
+
*
|
|
971
|
+
* @overload
|
|
972
|
+
* @param {string} reason
|
|
973
|
+
* @param {Node | NodeLike | null | undefined} parent
|
|
974
|
+
* @param {string | null | undefined} [origin]
|
|
975
|
+
* @returns {VFileMessage}
|
|
976
|
+
*
|
|
977
|
+
* @overload
|
|
978
|
+
* @param {string} reason
|
|
979
|
+
* @param {Point | Position | null | undefined} place
|
|
980
|
+
* @param {string | null | undefined} [origin]
|
|
981
|
+
* @returns {VFileMessage}
|
|
982
|
+
*
|
|
983
|
+
* @overload
|
|
984
|
+
* @param {string} reason
|
|
985
|
+
* @param {string | null | undefined} [origin]
|
|
986
|
+
* @returns {VFileMessage}
|
|
987
|
+
*
|
|
988
|
+
* @overload
|
|
989
|
+
* @param {Error | VFileMessage} cause
|
|
990
|
+
* @param {Node | NodeLike | null | undefined} parent
|
|
991
|
+
* @param {string | null | undefined} [origin]
|
|
992
|
+
* @returns {VFileMessage}
|
|
993
|
+
*
|
|
994
|
+
* @overload
|
|
995
|
+
* @param {Error | VFileMessage} cause
|
|
996
|
+
* @param {Point | Position | null | undefined} place
|
|
997
|
+
* @param {string | null | undefined} [origin]
|
|
998
|
+
* @returns {VFileMessage}
|
|
999
|
+
*
|
|
1000
|
+
* @overload
|
|
1001
|
+
* @param {Error | VFileMessage} cause
|
|
1002
|
+
* @param {string | null | undefined} [origin]
|
|
1003
|
+
* @returns {VFileMessage}
|
|
1004
|
+
*
|
|
1005
|
+
* @param {Error | VFileMessage | string} causeOrReason
|
|
1006
|
+
* Reason for message, should use markdown.
|
|
1007
|
+
* @param {Node | NodeLike | MessageOptions | Point | Position | string | null | undefined} [optionsOrParentOrPlace]
|
|
1008
|
+
* Configuration (optional).
|
|
1009
|
+
* @param {string | null | undefined} [origin]
|
|
1010
|
+
* Place in code where the message originates (example:
|
|
1011
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
1012
|
+
* @returns {VFileMessage}
|
|
1013
|
+
* Message.
|
|
1014
|
+
*/
|
|
1015
|
+
message(causeOrReason, optionsOrParentOrPlace, origin) {
|
|
1016
|
+
const message = new VFileMessage(causeOrReason, optionsOrParentOrPlace, origin);
|
|
1017
|
+
if (this.path) {
|
|
1018
|
+
message.name = this.path + ":" + message.name;
|
|
1019
|
+
message.file = this.path;
|
|
1020
|
+
}
|
|
1021
|
+
message.fatal = false;
|
|
1022
|
+
this.messages.push(message);
|
|
1023
|
+
return message;
|
|
1024
|
+
}
|
|
1025
|
+
/**
|
|
1026
|
+
* Serialize the file.
|
|
1027
|
+
*
|
|
1028
|
+
* > **Note**: which encodings are supported depends on the engine.
|
|
1029
|
+
* > For info on Node.js, see:
|
|
1030
|
+
* > <https://nodejs.org/api/util.html#whatwg-supported-encodings>.
|
|
1031
|
+
*
|
|
1032
|
+
* @param {string | null | undefined} [encoding='utf8']
|
|
1033
|
+
* Character encoding to understand `value` as when it’s a `Uint8Array`
|
|
1034
|
+
* (default: `'utf-8'`).
|
|
1035
|
+
* @returns {string}
|
|
1036
|
+
* Serialized file.
|
|
1037
|
+
*/
|
|
1038
|
+
toString(encoding) {
|
|
1039
|
+
if (this.value === void 0) return "";
|
|
1040
|
+
if (typeof this.value === "string") return this.value;
|
|
1041
|
+
return new TextDecoder(encoding || void 0).decode(this.value);
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
/**
|
|
1045
|
+
* Assert that `part` is not a path (as in, does not contain `path.sep`).
|
|
1046
|
+
*
|
|
1047
|
+
* @param {string | null | undefined} part
|
|
1048
|
+
* File path part.
|
|
1049
|
+
* @param {string} name
|
|
1050
|
+
* Part name.
|
|
1051
|
+
* @returns {undefined}
|
|
1052
|
+
* Nothing.
|
|
1053
|
+
*/
|
|
1054
|
+
function assertPart(part, name) {
|
|
1055
|
+
if (part && part.includes(minpath.sep)) throw new Error("`" + name + "` cannot be a path: did not expect `" + minpath.sep + "`");
|
|
1056
|
+
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Assert that `part` is not empty.
|
|
1059
|
+
*
|
|
1060
|
+
* @param {string | undefined} part
|
|
1061
|
+
* Thing.
|
|
1062
|
+
* @param {string} name
|
|
1063
|
+
* Part name.
|
|
1064
|
+
* @returns {asserts part is string}
|
|
1065
|
+
* Nothing.
|
|
1066
|
+
*/
|
|
1067
|
+
function assertNonEmpty(part, name) {
|
|
1068
|
+
if (!part) throw new Error("`" + name + "` cannot be empty");
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Assert `path` exists.
|
|
1072
|
+
*
|
|
1073
|
+
* @param {string | undefined} path
|
|
1074
|
+
* Path.
|
|
1075
|
+
* @param {string} name
|
|
1076
|
+
* Dependency name.
|
|
1077
|
+
* @returns {asserts path is string}
|
|
1078
|
+
* Nothing.
|
|
1079
|
+
*/
|
|
1080
|
+
function assertPath(path, name) {
|
|
1081
|
+
if (!path) throw new Error("Setting `" + name + "` requires `path` to be set too");
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* Assert `value` is an `Uint8Array`.
|
|
1085
|
+
*
|
|
1086
|
+
* @param {unknown} value
|
|
1087
|
+
* thing.
|
|
1088
|
+
* @returns {value is Uint8Array}
|
|
1089
|
+
* Whether `value` is an `Uint8Array`.
|
|
1090
|
+
*/
|
|
1091
|
+
function isUint8Array$1(value) {
|
|
1092
|
+
return Boolean(value && typeof value === "object" && "byteLength" in value && "byteOffset" in value);
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
//#endregion
|
|
1096
|
+
//#region ../../node_modules/.pnpm/unified@11.0.5/node_modules/unified/lib/callable-instance.js
|
|
1097
|
+
const CallableInstance = (function(property) {
|
|
1098
|
+
const proto = this.constructor.prototype;
|
|
1099
|
+
const value = proto[property];
|
|
1100
|
+
/** @type {(...parameters: Array<unknown>) => unknown} */
|
|
1101
|
+
const apply = function() {
|
|
1102
|
+
return value.apply(apply, arguments);
|
|
1103
|
+
};
|
|
1104
|
+
Object.setPrototypeOf(apply, proto);
|
|
1105
|
+
return apply;
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
//#endregion
|
|
1109
|
+
//#region ../../node_modules/.pnpm/unified@11.0.5/node_modules/unified/lib/index.js
|
|
1110
|
+
/**
|
|
1111
|
+
* @typedef {import('trough').Pipeline} Pipeline
|
|
1112
|
+
*
|
|
1113
|
+
* @typedef {import('unist').Node} Node
|
|
1114
|
+
*
|
|
1115
|
+
* @typedef {import('vfile').Compatible} Compatible
|
|
1116
|
+
* @typedef {import('vfile').Value} Value
|
|
1117
|
+
*
|
|
1118
|
+
* @typedef {import('../index.js').CompileResultMap} CompileResultMap
|
|
1119
|
+
* @typedef {import('../index.js').Data} Data
|
|
1120
|
+
* @typedef {import('../index.js').Settings} Settings
|
|
1121
|
+
*/
|
|
1122
|
+
/**
|
|
1123
|
+
* @typedef {CompileResultMap[keyof CompileResultMap]} CompileResults
|
|
1124
|
+
* Acceptable results from compilers.
|
|
1125
|
+
*
|
|
1126
|
+
* To register custom results, add them to
|
|
1127
|
+
* {@linkcode CompileResultMap}.
|
|
1128
|
+
*/
|
|
1129
|
+
/**
|
|
1130
|
+
* @template {Node} [Tree=Node]
|
|
1131
|
+
* The node that the compiler receives (default: `Node`).
|
|
1132
|
+
* @template {CompileResults} [Result=CompileResults]
|
|
1133
|
+
* The thing that the compiler yields (default: `CompileResults`).
|
|
1134
|
+
* @callback Compiler
|
|
1135
|
+
* A **compiler** handles the compiling of a syntax tree to something else
|
|
1136
|
+
* (in most cases, text) (TypeScript type).
|
|
1137
|
+
*
|
|
1138
|
+
* It is used in the stringify phase and called with a {@linkcode Node}
|
|
1139
|
+
* and {@linkcode VFile} representation of the document to compile.
|
|
1140
|
+
* It should return the textual representation of the given tree (typically
|
|
1141
|
+
* `string`).
|
|
1142
|
+
*
|
|
1143
|
+
* > **Note**: unified typically compiles by serializing: most compilers
|
|
1144
|
+
* > return `string` (or `Uint8Array`).
|
|
1145
|
+
* > Some compilers, such as the one configured with
|
|
1146
|
+
* > [`rehype-react`][rehype-react], return other values (in this case, a
|
|
1147
|
+
* > React tree).
|
|
1148
|
+
* > If you’re using a compiler that doesn’t serialize, expect different
|
|
1149
|
+
* > result values.
|
|
1150
|
+
* >
|
|
1151
|
+
* > To register custom results in TypeScript, add them to
|
|
1152
|
+
* > {@linkcode CompileResultMap}.
|
|
1153
|
+
*
|
|
1154
|
+
* [rehype-react]: https://github.com/rehypejs/rehype-react
|
|
1155
|
+
* @param {Tree} tree
|
|
1156
|
+
* Tree to compile.
|
|
1157
|
+
* @param {VFile} file
|
|
1158
|
+
* File associated with `tree`.
|
|
1159
|
+
* @returns {Result}
|
|
1160
|
+
* New content: compiled text (`string` or `Uint8Array`, for `file.value`) or
|
|
1161
|
+
* something else (for `file.result`).
|
|
1162
|
+
*/
|
|
1163
|
+
/**
|
|
1164
|
+
* @template {Node} [Tree=Node]
|
|
1165
|
+
* The node that the parser yields (default: `Node`)
|
|
1166
|
+
* @callback Parser
|
|
1167
|
+
* A **parser** handles the parsing of text to a syntax tree.
|
|
1168
|
+
*
|
|
1169
|
+
* It is used in the parse phase and is called with a `string` and
|
|
1170
|
+
* {@linkcode VFile} of the document to parse.
|
|
1171
|
+
* It must return the syntax tree representation of the given file
|
|
1172
|
+
* ({@linkcode Node}).
|
|
1173
|
+
* @param {string} document
|
|
1174
|
+
* Document to parse.
|
|
1175
|
+
* @param {VFile} file
|
|
1176
|
+
* File associated with `document`.
|
|
1177
|
+
* @returns {Tree}
|
|
1178
|
+
* Node representing the given file.
|
|
1179
|
+
*/
|
|
1180
|
+
/**
|
|
1181
|
+
* @typedef {(
|
|
1182
|
+
* Plugin<Array<any>, any, any> |
|
|
1183
|
+
* PluginTuple<Array<any>, any, any> |
|
|
1184
|
+
* Preset
|
|
1185
|
+
* )} Pluggable
|
|
1186
|
+
* Union of the different ways to add plugins and settings.
|
|
1187
|
+
*/
|
|
1188
|
+
/**
|
|
1189
|
+
* @typedef {Array<Pluggable>} PluggableList
|
|
1190
|
+
* List of plugins and presets.
|
|
1191
|
+
*/
|
|
1192
|
+
/**
|
|
1193
|
+
* @template {Array<unknown>} [PluginParameters=[]]
|
|
1194
|
+
* Arguments passed to the plugin (default: `[]`, the empty tuple).
|
|
1195
|
+
* @template {Node | string | undefined} [Input=Node]
|
|
1196
|
+
* Value that is expected as input (default: `Node`).
|
|
1197
|
+
*
|
|
1198
|
+
* * If the plugin returns a {@linkcode Transformer}, this
|
|
1199
|
+
* should be the node it expects.
|
|
1200
|
+
* * If the plugin sets a {@linkcode Parser}, this should be
|
|
1201
|
+
* `string`.
|
|
1202
|
+
* * If the plugin sets a {@linkcode Compiler}, this should be the
|
|
1203
|
+
* node it expects.
|
|
1204
|
+
* @template [Output=Input]
|
|
1205
|
+
* Value that is yielded as output (default: `Input`).
|
|
1206
|
+
*
|
|
1207
|
+
* * If the plugin returns a {@linkcode Transformer}, this
|
|
1208
|
+
* should be the node that that yields.
|
|
1209
|
+
* * If the plugin sets a {@linkcode Parser}, this should be the
|
|
1210
|
+
* node that it yields.
|
|
1211
|
+
* * If the plugin sets a {@linkcode Compiler}, this should be
|
|
1212
|
+
* result it yields.
|
|
1213
|
+
* @typedef {(
|
|
1214
|
+
* (this: Processor, ...parameters: PluginParameters) =>
|
|
1215
|
+
* Input extends string ? // Parser.
|
|
1216
|
+
* Output extends Node | undefined ? undefined | void : never :
|
|
1217
|
+
* Output extends CompileResults ? // Compiler.
|
|
1218
|
+
* Input extends Node | undefined ? undefined | void : never :
|
|
1219
|
+
* Transformer<
|
|
1220
|
+
* Input extends Node ? Input : Node,
|
|
1221
|
+
* Output extends Node ? Output : Node
|
|
1222
|
+
* > | undefined | void
|
|
1223
|
+
* )} Plugin
|
|
1224
|
+
* Single plugin.
|
|
1225
|
+
*
|
|
1226
|
+
* Plugins configure the processors they are applied on in the following
|
|
1227
|
+
* ways:
|
|
1228
|
+
*
|
|
1229
|
+
* * they change the processor, such as the parser, the compiler, or by
|
|
1230
|
+
* configuring data
|
|
1231
|
+
* * they specify how to handle trees and files
|
|
1232
|
+
*
|
|
1233
|
+
* In practice, they are functions that can receive options and configure the
|
|
1234
|
+
* processor (`this`).
|
|
1235
|
+
*
|
|
1236
|
+
* > **Note**: plugins are called when the processor is *frozen*, not when
|
|
1237
|
+
* > they are applied.
|
|
1238
|
+
*/
|
|
1239
|
+
/**
|
|
1240
|
+
* Tuple of a plugin and its configuration.
|
|
1241
|
+
*
|
|
1242
|
+
* The first item is a plugin, the rest are its parameters.
|
|
1243
|
+
*
|
|
1244
|
+
* @template {Array<unknown>} [TupleParameters=[]]
|
|
1245
|
+
* Arguments passed to the plugin (default: `[]`, the empty tuple).
|
|
1246
|
+
* @template {Node | string | undefined} [Input=undefined]
|
|
1247
|
+
* Value that is expected as input (optional).
|
|
1248
|
+
*
|
|
1249
|
+
* * If the plugin returns a {@linkcode Transformer}, this
|
|
1250
|
+
* should be the node it expects.
|
|
1251
|
+
* * If the plugin sets a {@linkcode Parser}, this should be
|
|
1252
|
+
* `string`.
|
|
1253
|
+
* * If the plugin sets a {@linkcode Compiler}, this should be the
|
|
1254
|
+
* node it expects.
|
|
1255
|
+
* @template [Output=undefined] (optional).
|
|
1256
|
+
* Value that is yielded as output.
|
|
1257
|
+
*
|
|
1258
|
+
* * If the plugin returns a {@linkcode Transformer}, this
|
|
1259
|
+
* should be the node that that yields.
|
|
1260
|
+
* * If the plugin sets a {@linkcode Parser}, this should be the
|
|
1261
|
+
* node that it yields.
|
|
1262
|
+
* * If the plugin sets a {@linkcode Compiler}, this should be
|
|
1263
|
+
* result it yields.
|
|
1264
|
+
* @typedef {(
|
|
1265
|
+
* [
|
|
1266
|
+
* plugin: Plugin<TupleParameters, Input, Output>,
|
|
1267
|
+
* ...parameters: TupleParameters
|
|
1268
|
+
* ]
|
|
1269
|
+
* )} PluginTuple
|
|
1270
|
+
*/
|
|
1271
|
+
/**
|
|
1272
|
+
* @typedef Preset
|
|
1273
|
+
* Sharable configuration.
|
|
1274
|
+
*
|
|
1275
|
+
* They can contain plugins and settings.
|
|
1276
|
+
* @property {PluggableList | undefined} [plugins]
|
|
1277
|
+
* List of plugins and presets (optional).
|
|
1278
|
+
* @property {Settings | undefined} [settings]
|
|
1279
|
+
* Shared settings for parsers and compilers (optional).
|
|
1280
|
+
*/
|
|
1281
|
+
/**
|
|
1282
|
+
* @template {VFile} [File=VFile]
|
|
1283
|
+
* The file that the callback receives (default: `VFile`).
|
|
1284
|
+
* @callback ProcessCallback
|
|
1285
|
+
* Callback called when the process is done.
|
|
1286
|
+
*
|
|
1287
|
+
* Called with either an error or a result.
|
|
1288
|
+
* @param {Error | undefined} [error]
|
|
1289
|
+
* Fatal error (optional).
|
|
1290
|
+
* @param {File | undefined} [file]
|
|
1291
|
+
* Processed file (optional).
|
|
1292
|
+
* @returns {undefined}
|
|
1293
|
+
* Nothing.
|
|
1294
|
+
*/
|
|
1295
|
+
/**
|
|
1296
|
+
* @template {Node} [Tree=Node]
|
|
1297
|
+
* The tree that the callback receives (default: `Node`).
|
|
1298
|
+
* @callback RunCallback
|
|
1299
|
+
* Callback called when transformers are done.
|
|
1300
|
+
*
|
|
1301
|
+
* Called with either an error or results.
|
|
1302
|
+
* @param {Error | undefined} [error]
|
|
1303
|
+
* Fatal error (optional).
|
|
1304
|
+
* @param {Tree | undefined} [tree]
|
|
1305
|
+
* Transformed tree (optional).
|
|
1306
|
+
* @param {VFile | undefined} [file]
|
|
1307
|
+
* File (optional).
|
|
1308
|
+
* @returns {undefined}
|
|
1309
|
+
* Nothing.
|
|
1310
|
+
*/
|
|
1311
|
+
/**
|
|
1312
|
+
* @template {Node} [Output=Node]
|
|
1313
|
+
* Node type that the transformer yields (default: `Node`).
|
|
1314
|
+
* @callback TransformCallback
|
|
1315
|
+
* Callback passed to transforms.
|
|
1316
|
+
*
|
|
1317
|
+
* If the signature of a `transformer` accepts a third argument, the
|
|
1318
|
+
* transformer may perform asynchronous operations, and must call it.
|
|
1319
|
+
* @param {Error | undefined} [error]
|
|
1320
|
+
* Fatal error to stop the process (optional).
|
|
1321
|
+
* @param {Output | undefined} [tree]
|
|
1322
|
+
* New, changed, tree (optional).
|
|
1323
|
+
* @param {VFile | undefined} [file]
|
|
1324
|
+
* New, changed, file (optional).
|
|
1325
|
+
* @returns {undefined}
|
|
1326
|
+
* Nothing.
|
|
1327
|
+
*/
|
|
1328
|
+
/**
|
|
1329
|
+
* @template {Node} [Input=Node]
|
|
1330
|
+
* Node type that the transformer expects (default: `Node`).
|
|
1331
|
+
* @template {Node} [Output=Input]
|
|
1332
|
+
* Node type that the transformer yields (default: `Input`).
|
|
1333
|
+
* @callback Transformer
|
|
1334
|
+
* Transformers handle syntax trees and files.
|
|
1335
|
+
*
|
|
1336
|
+
* They are functions that are called each time a syntax tree and file are
|
|
1337
|
+
* passed through the run phase.
|
|
1338
|
+
* When an error occurs in them (either because it’s thrown, returned,
|
|
1339
|
+
* rejected, or passed to `next`), the process stops.
|
|
1340
|
+
*
|
|
1341
|
+
* The run phase is handled by [`trough`][trough], see its documentation for
|
|
1342
|
+
* the exact semantics of these functions.
|
|
1343
|
+
*
|
|
1344
|
+
* > **Note**: you should likely ignore `next`: don’t accept it.
|
|
1345
|
+
* > it supports callback-style async work.
|
|
1346
|
+
* > But promises are likely easier to reason about.
|
|
1347
|
+
*
|
|
1348
|
+
* [trough]: https://github.com/wooorm/trough#function-fninput-next
|
|
1349
|
+
* @param {Input} tree
|
|
1350
|
+
* Tree to handle.
|
|
1351
|
+
* @param {VFile} file
|
|
1352
|
+
* File to handle.
|
|
1353
|
+
* @param {TransformCallback<Output>} next
|
|
1354
|
+
* Callback.
|
|
1355
|
+
* @returns {(
|
|
1356
|
+
* Promise<Output | undefined | void> |
|
|
1357
|
+
* Promise<never> | // For some reason this is needed separately.
|
|
1358
|
+
* Output |
|
|
1359
|
+
* Error |
|
|
1360
|
+
* undefined |
|
|
1361
|
+
* void
|
|
1362
|
+
* )}
|
|
1363
|
+
* If you accept `next`, nothing.
|
|
1364
|
+
* Otherwise:
|
|
1365
|
+
*
|
|
1366
|
+
* * `Error` — fatal error to stop the process
|
|
1367
|
+
* * `Promise<undefined>` or `undefined` — the next transformer keeps using
|
|
1368
|
+
* same tree
|
|
1369
|
+
* * `Promise<Node>` or `Node` — new, changed, tree
|
|
1370
|
+
*/
|
|
1371
|
+
/**
|
|
1372
|
+
* @template {Node | undefined} ParseTree
|
|
1373
|
+
* Output of `parse`.
|
|
1374
|
+
* @template {Node | undefined} HeadTree
|
|
1375
|
+
* Input for `run`.
|
|
1376
|
+
* @template {Node | undefined} TailTree
|
|
1377
|
+
* Output for `run`.
|
|
1378
|
+
* @template {Node | undefined} CompileTree
|
|
1379
|
+
* Input of `stringify`.
|
|
1380
|
+
* @template {CompileResults | undefined} CompileResult
|
|
1381
|
+
* Output of `stringify`.
|
|
1382
|
+
* @template {Node | string | undefined} Input
|
|
1383
|
+
* Input of plugin.
|
|
1384
|
+
* @template Output
|
|
1385
|
+
* Output of plugin (optional).
|
|
1386
|
+
* @typedef {(
|
|
1387
|
+
* Input extends string
|
|
1388
|
+
* ? Output extends Node | undefined
|
|
1389
|
+
* ? // Parser.
|
|
1390
|
+
* Processor<
|
|
1391
|
+
* Output extends undefined ? ParseTree : Output,
|
|
1392
|
+
* HeadTree,
|
|
1393
|
+
* TailTree,
|
|
1394
|
+
* CompileTree,
|
|
1395
|
+
* CompileResult
|
|
1396
|
+
* >
|
|
1397
|
+
* : // Unknown.
|
|
1398
|
+
* Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>
|
|
1399
|
+
* : Output extends CompileResults
|
|
1400
|
+
* ? Input extends Node | undefined
|
|
1401
|
+
* ? // Compiler.
|
|
1402
|
+
* Processor<
|
|
1403
|
+
* ParseTree,
|
|
1404
|
+
* HeadTree,
|
|
1405
|
+
* TailTree,
|
|
1406
|
+
* Input extends undefined ? CompileTree : Input,
|
|
1407
|
+
* Output extends undefined ? CompileResult : Output
|
|
1408
|
+
* >
|
|
1409
|
+
* : // Unknown.
|
|
1410
|
+
* Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>
|
|
1411
|
+
* : Input extends Node | undefined
|
|
1412
|
+
* ? Output extends Node | undefined
|
|
1413
|
+
* ? // Transform.
|
|
1414
|
+
* Processor<
|
|
1415
|
+
* ParseTree,
|
|
1416
|
+
* HeadTree extends undefined ? Input : HeadTree,
|
|
1417
|
+
* Output extends undefined ? TailTree : Output,
|
|
1418
|
+
* CompileTree,
|
|
1419
|
+
* CompileResult
|
|
1420
|
+
* >
|
|
1421
|
+
* : // Unknown.
|
|
1422
|
+
* Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>
|
|
1423
|
+
* : // Unknown.
|
|
1424
|
+
* Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>
|
|
1425
|
+
* )} UsePlugin
|
|
1426
|
+
* Create a processor based on the input/output of a {@link Plugin plugin}.
|
|
1427
|
+
*/
|
|
1428
|
+
/**
|
|
1429
|
+
* @template {CompileResults | undefined} Result
|
|
1430
|
+
* Node type that the transformer yields.
|
|
1431
|
+
* @typedef {(
|
|
1432
|
+
* Result extends Value | undefined ?
|
|
1433
|
+
* VFile :
|
|
1434
|
+
* VFile & {result: Result}
|
|
1435
|
+
* )} VFileWithOutput
|
|
1436
|
+
* Type to generate a {@linkcode VFile} corresponding to a compiler result.
|
|
1437
|
+
*
|
|
1438
|
+
* If a result that is not acceptable on a `VFile` is used, that will
|
|
1439
|
+
* be stored on the `result` field of {@linkcode VFile}.
|
|
1440
|
+
*/
|
|
1441
|
+
var import_extend = /* @__PURE__ */ __toESM(require_extend(), 1);
|
|
1442
|
+
const own = {}.hasOwnProperty;
|
|
1443
|
+
/**
|
|
1444
|
+
* @template {Node | undefined} [ParseTree=undefined]
|
|
1445
|
+
* Output of `parse` (optional).
|
|
1446
|
+
* @template {Node | undefined} [HeadTree=undefined]
|
|
1447
|
+
* Input for `run` (optional).
|
|
1448
|
+
* @template {Node | undefined} [TailTree=undefined]
|
|
1449
|
+
* Output for `run` (optional).
|
|
1450
|
+
* @template {Node | undefined} [CompileTree=undefined]
|
|
1451
|
+
* Input of `stringify` (optional).
|
|
1452
|
+
* @template {CompileResults | undefined} [CompileResult=undefined]
|
|
1453
|
+
* Output of `stringify` (optional).
|
|
1454
|
+
* @extends {CallableInstance<[], Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>>}
|
|
1455
|
+
*/
|
|
1456
|
+
var Processor = class Processor extends CallableInstance {
|
|
1457
|
+
/**
|
|
1458
|
+
* Create a processor.
|
|
1459
|
+
*/
|
|
1460
|
+
constructor() {
|
|
1461
|
+
super("copy");
|
|
1462
|
+
/**
|
|
1463
|
+
* Compiler to use (deprecated).
|
|
1464
|
+
*
|
|
1465
|
+
* @deprecated
|
|
1466
|
+
* Use `compiler` instead.
|
|
1467
|
+
* @type {(
|
|
1468
|
+
* Compiler<
|
|
1469
|
+
* CompileTree extends undefined ? Node : CompileTree,
|
|
1470
|
+
* CompileResult extends undefined ? CompileResults : CompileResult
|
|
1471
|
+
* > |
|
|
1472
|
+
* undefined
|
|
1473
|
+
* )}
|
|
1474
|
+
*/
|
|
1475
|
+
this.Compiler = void 0;
|
|
1476
|
+
/**
|
|
1477
|
+
* Parser to use (deprecated).
|
|
1478
|
+
*
|
|
1479
|
+
* @deprecated
|
|
1480
|
+
* Use `parser` instead.
|
|
1481
|
+
* @type {(
|
|
1482
|
+
* Parser<ParseTree extends undefined ? Node : ParseTree> |
|
|
1483
|
+
* undefined
|
|
1484
|
+
* )}
|
|
1485
|
+
*/
|
|
1486
|
+
this.Parser = void 0;
|
|
1487
|
+
/**
|
|
1488
|
+
* Internal list of configured plugins.
|
|
1489
|
+
*
|
|
1490
|
+
* @deprecated
|
|
1491
|
+
* This is a private internal property and should not be used.
|
|
1492
|
+
* @type {Array<PluginTuple<Array<unknown>>>}
|
|
1493
|
+
*/
|
|
1494
|
+
this.attachers = [];
|
|
1495
|
+
/**
|
|
1496
|
+
* Compiler to use.
|
|
1497
|
+
*
|
|
1498
|
+
* @type {(
|
|
1499
|
+
* Compiler<
|
|
1500
|
+
* CompileTree extends undefined ? Node : CompileTree,
|
|
1501
|
+
* CompileResult extends undefined ? CompileResults : CompileResult
|
|
1502
|
+
* > |
|
|
1503
|
+
* undefined
|
|
1504
|
+
* )}
|
|
1505
|
+
*/
|
|
1506
|
+
this.compiler = void 0;
|
|
1507
|
+
/**
|
|
1508
|
+
* Internal state to track where we are while freezing.
|
|
1509
|
+
*
|
|
1510
|
+
* @deprecated
|
|
1511
|
+
* This is a private internal property and should not be used.
|
|
1512
|
+
* @type {number}
|
|
1513
|
+
*/
|
|
1514
|
+
this.freezeIndex = -1;
|
|
1515
|
+
/**
|
|
1516
|
+
* Internal state to track whether we’re frozen.
|
|
1517
|
+
*
|
|
1518
|
+
* @deprecated
|
|
1519
|
+
* This is a private internal property and should not be used.
|
|
1520
|
+
* @type {boolean | undefined}
|
|
1521
|
+
*/
|
|
1522
|
+
this.frozen = void 0;
|
|
1523
|
+
/**
|
|
1524
|
+
* Internal state.
|
|
1525
|
+
*
|
|
1526
|
+
* @deprecated
|
|
1527
|
+
* This is a private internal property and should not be used.
|
|
1528
|
+
* @type {Data}
|
|
1529
|
+
*/
|
|
1530
|
+
this.namespace = {};
|
|
1531
|
+
/**
|
|
1532
|
+
* Parser to use.
|
|
1533
|
+
*
|
|
1534
|
+
* @type {(
|
|
1535
|
+
* Parser<ParseTree extends undefined ? Node : ParseTree> |
|
|
1536
|
+
* undefined
|
|
1537
|
+
* )}
|
|
1538
|
+
*/
|
|
1539
|
+
this.parser = void 0;
|
|
1540
|
+
/**
|
|
1541
|
+
* Internal list of configured transformers.
|
|
1542
|
+
*
|
|
1543
|
+
* @deprecated
|
|
1544
|
+
* This is a private internal property and should not be used.
|
|
1545
|
+
* @type {Pipeline}
|
|
1546
|
+
*/
|
|
1547
|
+
this.transformers = trough();
|
|
1548
|
+
}
|
|
1549
|
+
/**
|
|
1550
|
+
* Copy a processor.
|
|
1551
|
+
*
|
|
1552
|
+
* @deprecated
|
|
1553
|
+
* This is a private internal method and should not be used.
|
|
1554
|
+
* @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
|
|
1555
|
+
* New *unfrozen* processor ({@linkcode Processor}) that is
|
|
1556
|
+
* configured to work the same as its ancestor.
|
|
1557
|
+
* When the descendant processor is configured in the future it does not
|
|
1558
|
+
* affect the ancestral processor.
|
|
1559
|
+
*/
|
|
1560
|
+
copy() {
|
|
1561
|
+
const destination = new Processor();
|
|
1562
|
+
let index = -1;
|
|
1563
|
+
while (++index < this.attachers.length) {
|
|
1564
|
+
const attacher = this.attachers[index];
|
|
1565
|
+
destination.use(...attacher);
|
|
1566
|
+
}
|
|
1567
|
+
destination.data((0, import_extend.default)(true, {}, this.namespace));
|
|
1568
|
+
return destination;
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
* Configure the processor with info available to all plugins.
|
|
1572
|
+
* Information is stored in an object.
|
|
1573
|
+
*
|
|
1574
|
+
* Typically, options can be given to a specific plugin, but sometimes it
|
|
1575
|
+
* makes sense to have information shared with several plugins.
|
|
1576
|
+
* For example, a list of HTML elements that are self-closing, which is
|
|
1577
|
+
* needed during all phases.
|
|
1578
|
+
*
|
|
1579
|
+
* > **Note**: setting information cannot occur on *frozen* processors.
|
|
1580
|
+
* > Call the processor first to create a new unfrozen processor.
|
|
1581
|
+
*
|
|
1582
|
+
* > **Note**: to register custom data in TypeScript, augment the
|
|
1583
|
+
* > {@linkcode Data} interface.
|
|
1584
|
+
*
|
|
1585
|
+
* @example
|
|
1586
|
+
* This example show how to get and set info:
|
|
1587
|
+
*
|
|
1588
|
+
* ```js
|
|
1589
|
+
* import {unified} from 'unified'
|
|
1590
|
+
*
|
|
1591
|
+
* const processor = unified().data('alpha', 'bravo')
|
|
1592
|
+
*
|
|
1593
|
+
* processor.data('alpha') // => 'bravo'
|
|
1594
|
+
*
|
|
1595
|
+
* processor.data() // => {alpha: 'bravo'}
|
|
1596
|
+
*
|
|
1597
|
+
* processor.data({charlie: 'delta'})
|
|
1598
|
+
*
|
|
1599
|
+
* processor.data() // => {charlie: 'delta'}
|
|
1600
|
+
* ```
|
|
1601
|
+
*
|
|
1602
|
+
* @template {keyof Data} Key
|
|
1603
|
+
*
|
|
1604
|
+
* @overload
|
|
1605
|
+
* @returns {Data}
|
|
1606
|
+
*
|
|
1607
|
+
* @overload
|
|
1608
|
+
* @param {Data} dataset
|
|
1609
|
+
* @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
|
|
1610
|
+
*
|
|
1611
|
+
* @overload
|
|
1612
|
+
* @param {Key} key
|
|
1613
|
+
* @returns {Data[Key]}
|
|
1614
|
+
*
|
|
1615
|
+
* @overload
|
|
1616
|
+
* @param {Key} key
|
|
1617
|
+
* @param {Data[Key]} value
|
|
1618
|
+
* @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
|
|
1619
|
+
*
|
|
1620
|
+
* @param {Data | Key} [key]
|
|
1621
|
+
* Key to get or set, or entire dataset to set, or nothing to get the
|
|
1622
|
+
* entire dataset (optional).
|
|
1623
|
+
* @param {Data[Key]} [value]
|
|
1624
|
+
* Value to set (optional).
|
|
1625
|
+
* @returns {unknown}
|
|
1626
|
+
* The current processor when setting, the value at `key` when getting, or
|
|
1627
|
+
* the entire dataset when getting without key.
|
|
1628
|
+
*/
|
|
1629
|
+
data(key, value) {
|
|
1630
|
+
if (typeof key === "string") {
|
|
1631
|
+
if (arguments.length === 2) {
|
|
1632
|
+
assertUnfrozen("data", this.frozen);
|
|
1633
|
+
this.namespace[key] = value;
|
|
1634
|
+
return this;
|
|
1635
|
+
}
|
|
1636
|
+
return own.call(this.namespace, key) && this.namespace[key] || void 0;
|
|
1637
|
+
}
|
|
1638
|
+
if (key) {
|
|
1639
|
+
assertUnfrozen("data", this.frozen);
|
|
1640
|
+
this.namespace = key;
|
|
1641
|
+
return this;
|
|
1642
|
+
}
|
|
1643
|
+
return this.namespace;
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* Freeze a processor.
|
|
1647
|
+
*
|
|
1648
|
+
* Frozen processors are meant to be extended and not to be configured
|
|
1649
|
+
* directly.
|
|
1650
|
+
*
|
|
1651
|
+
* When a processor is frozen it cannot be unfrozen.
|
|
1652
|
+
* New processors working the same way can be created by calling the
|
|
1653
|
+
* processor.
|
|
1654
|
+
*
|
|
1655
|
+
* It’s possible to freeze processors explicitly by calling `.freeze()`.
|
|
1656
|
+
* Processors freeze automatically when `.parse()`, `.run()`, `.runSync()`,
|
|
1657
|
+
* `.stringify()`, `.process()`, or `.processSync()` are called.
|
|
1658
|
+
*
|
|
1659
|
+
* @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
|
|
1660
|
+
* The current processor.
|
|
1661
|
+
*/
|
|
1662
|
+
freeze() {
|
|
1663
|
+
if (this.frozen) return this;
|
|
1664
|
+
const self = this;
|
|
1665
|
+
while (++this.freezeIndex < this.attachers.length) {
|
|
1666
|
+
const [attacher, ...options] = this.attachers[this.freezeIndex];
|
|
1667
|
+
if (options[0] === false) continue;
|
|
1668
|
+
if (options[0] === true) options[0] = void 0;
|
|
1669
|
+
const transformer = attacher.call(self, ...options);
|
|
1670
|
+
if (typeof transformer === "function") this.transformers.use(transformer);
|
|
1671
|
+
}
|
|
1672
|
+
this.frozen = true;
|
|
1673
|
+
this.freezeIndex = Number.POSITIVE_INFINITY;
|
|
1674
|
+
return this;
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* Parse text to a syntax tree.
|
|
1678
|
+
*
|
|
1679
|
+
* > **Note**: `parse` freezes the processor if not already *frozen*.
|
|
1680
|
+
*
|
|
1681
|
+
* > **Note**: `parse` performs the parse phase, not the run phase or other
|
|
1682
|
+
* > phases.
|
|
1683
|
+
*
|
|
1684
|
+
* @param {Compatible | undefined} [file]
|
|
1685
|
+
* file to parse (optional); typically `string` or `VFile`; any value
|
|
1686
|
+
* accepted as `x` in `new VFile(x)`.
|
|
1687
|
+
* @returns {ParseTree extends undefined ? Node : ParseTree}
|
|
1688
|
+
* Syntax tree representing `file`.
|
|
1689
|
+
*/
|
|
1690
|
+
parse(file) {
|
|
1691
|
+
this.freeze();
|
|
1692
|
+
const realFile = vfile(file);
|
|
1693
|
+
const parser = this.parser || this.Parser;
|
|
1694
|
+
assertParser("parse", parser);
|
|
1695
|
+
return parser(String(realFile), realFile);
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Process the given file as configured on the processor.
|
|
1699
|
+
*
|
|
1700
|
+
* > **Note**: `process` freezes the processor if not already *frozen*.
|
|
1701
|
+
*
|
|
1702
|
+
* > **Note**: `process` performs the parse, run, and stringify phases.
|
|
1703
|
+
*
|
|
1704
|
+
* @overload
|
|
1705
|
+
* @param {Compatible | undefined} file
|
|
1706
|
+
* @param {ProcessCallback<VFileWithOutput<CompileResult>>} done
|
|
1707
|
+
* @returns {undefined}
|
|
1708
|
+
*
|
|
1709
|
+
* @overload
|
|
1710
|
+
* @param {Compatible | undefined} [file]
|
|
1711
|
+
* @returns {Promise<VFileWithOutput<CompileResult>>}
|
|
1712
|
+
*
|
|
1713
|
+
* @param {Compatible | undefined} [file]
|
|
1714
|
+
* File (optional); typically `string` or `VFile`]; any value accepted as
|
|
1715
|
+
* `x` in `new VFile(x)`.
|
|
1716
|
+
* @param {ProcessCallback<VFileWithOutput<CompileResult>> | undefined} [done]
|
|
1717
|
+
* Callback (optional).
|
|
1718
|
+
* @returns {Promise<VFile> | undefined}
|
|
1719
|
+
* Nothing if `done` is given.
|
|
1720
|
+
* Otherwise a promise, rejected with a fatal error or resolved with the
|
|
1721
|
+
* processed file.
|
|
1722
|
+
*
|
|
1723
|
+
* The parsed, transformed, and compiled value is available at
|
|
1724
|
+
* `file.value` (see note).
|
|
1725
|
+
*
|
|
1726
|
+
* > **Note**: unified typically compiles by serializing: most
|
|
1727
|
+
* > compilers return `string` (or `Uint8Array`).
|
|
1728
|
+
* > Some compilers, such as the one configured with
|
|
1729
|
+
* > [`rehype-react`][rehype-react], return other values (in this case, a
|
|
1730
|
+
* > React tree).
|
|
1731
|
+
* > If you’re using a compiler that doesn’t serialize, expect different
|
|
1732
|
+
* > result values.
|
|
1733
|
+
* >
|
|
1734
|
+
* > To register custom results in TypeScript, add them to
|
|
1735
|
+
* > {@linkcode CompileResultMap}.
|
|
1736
|
+
*
|
|
1737
|
+
* [rehype-react]: https://github.com/rehypejs/rehype-react
|
|
1738
|
+
*/
|
|
1739
|
+
process(file, done) {
|
|
1740
|
+
const self = this;
|
|
1741
|
+
this.freeze();
|
|
1742
|
+
assertParser("process", this.parser || this.Parser);
|
|
1743
|
+
assertCompiler("process", this.compiler || this.Compiler);
|
|
1744
|
+
return done ? executor(void 0, done) : new Promise(executor);
|
|
1745
|
+
/**
|
|
1746
|
+
* @param {((file: VFileWithOutput<CompileResult>) => undefined | void) | undefined} resolve
|
|
1747
|
+
* @param {(error: Error | undefined) => undefined | void} reject
|
|
1748
|
+
* @returns {undefined}
|
|
1749
|
+
*/
|
|
1750
|
+
function executor(resolve, reject) {
|
|
1751
|
+
const realFile = vfile(file);
|
|
1752
|
+
const parseTree = self.parse(realFile);
|
|
1753
|
+
self.run(parseTree, realFile, function(error, tree, file) {
|
|
1754
|
+
if (error || !tree || !file) return realDone(error);
|
|
1755
|
+
const compileTree = tree;
|
|
1756
|
+
const compileResult = self.stringify(compileTree, file);
|
|
1757
|
+
if (looksLikeAValue(compileResult)) file.value = compileResult;
|
|
1758
|
+
else file.result = compileResult;
|
|
1759
|
+
realDone(error, file);
|
|
1760
|
+
});
|
|
1761
|
+
/**
|
|
1762
|
+
* @param {Error | undefined} error
|
|
1763
|
+
* @param {VFileWithOutput<CompileResult> | undefined} [file]
|
|
1764
|
+
* @returns {undefined}
|
|
1765
|
+
*/
|
|
1766
|
+
function realDone(error, file) {
|
|
1767
|
+
if (error || !file) reject(error);
|
|
1768
|
+
else if (resolve) resolve(file);
|
|
1769
|
+
else {
|
|
1770
|
+
/* @__PURE__ */ ok(done, "`done` is defined if `resolve` is not");
|
|
1771
|
+
done(void 0, file);
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Process the given file as configured on the processor.
|
|
1778
|
+
*
|
|
1779
|
+
* An error is thrown if asynchronous transforms are configured.
|
|
1780
|
+
*
|
|
1781
|
+
* > **Note**: `processSync` freezes the processor if not already *frozen*.
|
|
1782
|
+
*
|
|
1783
|
+
* > **Note**: `processSync` performs the parse, run, and stringify phases.
|
|
1784
|
+
*
|
|
1785
|
+
* @param {Compatible | undefined} [file]
|
|
1786
|
+
* File (optional); typically `string` or `VFile`; any value accepted as
|
|
1787
|
+
* `x` in `new VFile(x)`.
|
|
1788
|
+
* @returns {VFileWithOutput<CompileResult>}
|
|
1789
|
+
* The processed file.
|
|
1790
|
+
*
|
|
1791
|
+
* The parsed, transformed, and compiled value is available at
|
|
1792
|
+
* `file.value` (see note).
|
|
1793
|
+
*
|
|
1794
|
+
* > **Note**: unified typically compiles by serializing: most
|
|
1795
|
+
* > compilers return `string` (or `Uint8Array`).
|
|
1796
|
+
* > Some compilers, such as the one configured with
|
|
1797
|
+
* > [`rehype-react`][rehype-react], return other values (in this case, a
|
|
1798
|
+
* > React tree).
|
|
1799
|
+
* > If you’re using a compiler that doesn’t serialize, expect different
|
|
1800
|
+
* > result values.
|
|
1801
|
+
* >
|
|
1802
|
+
* > To register custom results in TypeScript, add them to
|
|
1803
|
+
* > {@linkcode CompileResultMap}.
|
|
1804
|
+
*
|
|
1805
|
+
* [rehype-react]: https://github.com/rehypejs/rehype-react
|
|
1806
|
+
*/
|
|
1807
|
+
processSync(file) {
|
|
1808
|
+
/** @type {boolean} */
|
|
1809
|
+
let complete = false;
|
|
1810
|
+
/** @type {VFileWithOutput<CompileResult> | undefined} */
|
|
1811
|
+
let result;
|
|
1812
|
+
this.freeze();
|
|
1813
|
+
assertParser("processSync", this.parser || this.Parser);
|
|
1814
|
+
assertCompiler("processSync", this.compiler || this.Compiler);
|
|
1815
|
+
this.process(file, realDone);
|
|
1816
|
+
assertDone("processSync", "process", complete);
|
|
1817
|
+
/* @__PURE__ */ ok(result, "we either bailed on an error or have a tree");
|
|
1818
|
+
return result;
|
|
1819
|
+
/**
|
|
1820
|
+
* @type {ProcessCallback<VFileWithOutput<CompileResult>>}
|
|
1821
|
+
*/
|
|
1822
|
+
function realDone(error, file) {
|
|
1823
|
+
complete = true;
|
|
1824
|
+
bail(error);
|
|
1825
|
+
result = file;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
/**
|
|
1829
|
+
* Run *transformers* on a syntax tree.
|
|
1830
|
+
*
|
|
1831
|
+
* > **Note**: `run` freezes the processor if not already *frozen*.
|
|
1832
|
+
*
|
|
1833
|
+
* > **Note**: `run` performs the run phase, not other phases.
|
|
1834
|
+
*
|
|
1835
|
+
* @overload
|
|
1836
|
+
* @param {HeadTree extends undefined ? Node : HeadTree} tree
|
|
1837
|
+
* @param {RunCallback<TailTree extends undefined ? Node : TailTree>} done
|
|
1838
|
+
* @returns {undefined}
|
|
1839
|
+
*
|
|
1840
|
+
* @overload
|
|
1841
|
+
* @param {HeadTree extends undefined ? Node : HeadTree} tree
|
|
1842
|
+
* @param {Compatible | undefined} file
|
|
1843
|
+
* @param {RunCallback<TailTree extends undefined ? Node : TailTree>} done
|
|
1844
|
+
* @returns {undefined}
|
|
1845
|
+
*
|
|
1846
|
+
* @overload
|
|
1847
|
+
* @param {HeadTree extends undefined ? Node : HeadTree} tree
|
|
1848
|
+
* @param {Compatible | undefined} [file]
|
|
1849
|
+
* @returns {Promise<TailTree extends undefined ? Node : TailTree>}
|
|
1850
|
+
*
|
|
1851
|
+
* @param {HeadTree extends undefined ? Node : HeadTree} tree
|
|
1852
|
+
* Tree to transform and inspect.
|
|
1853
|
+
* @param {(
|
|
1854
|
+
* RunCallback<TailTree extends undefined ? Node : TailTree> |
|
|
1855
|
+
* Compatible
|
|
1856
|
+
* )} [file]
|
|
1857
|
+
* File associated with `node` (optional); any value accepted as `x` in
|
|
1858
|
+
* `new VFile(x)`.
|
|
1859
|
+
* @param {RunCallback<TailTree extends undefined ? Node : TailTree>} [done]
|
|
1860
|
+
* Callback (optional).
|
|
1861
|
+
* @returns {Promise<TailTree extends undefined ? Node : TailTree> | undefined}
|
|
1862
|
+
* Nothing if `done` is given.
|
|
1863
|
+
* Otherwise, a promise rejected with a fatal error or resolved with the
|
|
1864
|
+
* transformed tree.
|
|
1865
|
+
*/
|
|
1866
|
+
run(tree, file, done) {
|
|
1867
|
+
assertNode(tree);
|
|
1868
|
+
this.freeze();
|
|
1869
|
+
const transformers = this.transformers;
|
|
1870
|
+
if (!done && typeof file === "function") {
|
|
1871
|
+
done = file;
|
|
1872
|
+
file = void 0;
|
|
1873
|
+
}
|
|
1874
|
+
return done ? executor(void 0, done) : new Promise(executor);
|
|
1875
|
+
/**
|
|
1876
|
+
* @param {(
|
|
1877
|
+
* ((tree: TailTree extends undefined ? Node : TailTree) => undefined | void) |
|
|
1878
|
+
* undefined
|
|
1879
|
+
* )} resolve
|
|
1880
|
+
* @param {(error: Error) => undefined | void} reject
|
|
1881
|
+
* @returns {undefined}
|
|
1882
|
+
*/
|
|
1883
|
+
function executor(resolve, reject) {
|
|
1884
|
+
/* @__PURE__ */ ok(typeof file !== "function", "`file` can’t be a `done` anymore, we checked");
|
|
1885
|
+
const realFile = vfile(file);
|
|
1886
|
+
transformers.run(tree, realFile, realDone);
|
|
1887
|
+
/**
|
|
1888
|
+
* @param {Error | undefined} error
|
|
1889
|
+
* @param {Node} outputTree
|
|
1890
|
+
* @param {VFile} file
|
|
1891
|
+
* @returns {undefined}
|
|
1892
|
+
*/
|
|
1893
|
+
function realDone(error, outputTree, file) {
|
|
1894
|
+
const resultingTree = outputTree || tree;
|
|
1895
|
+
if (error) reject(error);
|
|
1896
|
+
else if (resolve) resolve(resultingTree);
|
|
1897
|
+
else {
|
|
1898
|
+
/* @__PURE__ */ ok(done, "`done` is defined if `resolve` is not");
|
|
1899
|
+
done(void 0, resultingTree, file);
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
/**
|
|
1905
|
+
* Run *transformers* on a syntax tree.
|
|
1906
|
+
*
|
|
1907
|
+
* An error is thrown if asynchronous transforms are configured.
|
|
1908
|
+
*
|
|
1909
|
+
* > **Note**: `runSync` freezes the processor if not already *frozen*.
|
|
1910
|
+
*
|
|
1911
|
+
* > **Note**: `runSync` performs the run phase, not other phases.
|
|
1912
|
+
*
|
|
1913
|
+
* @param {HeadTree extends undefined ? Node : HeadTree} tree
|
|
1914
|
+
* Tree to transform and inspect.
|
|
1915
|
+
* @param {Compatible | undefined} [file]
|
|
1916
|
+
* File associated with `node` (optional); any value accepted as `x` in
|
|
1917
|
+
* `new VFile(x)`.
|
|
1918
|
+
* @returns {TailTree extends undefined ? Node : TailTree}
|
|
1919
|
+
* Transformed tree.
|
|
1920
|
+
*/
|
|
1921
|
+
runSync(tree, file) {
|
|
1922
|
+
/** @type {boolean} */
|
|
1923
|
+
let complete = false;
|
|
1924
|
+
/** @type {(TailTree extends undefined ? Node : TailTree) | undefined} */
|
|
1925
|
+
let result;
|
|
1926
|
+
this.run(tree, file, realDone);
|
|
1927
|
+
assertDone("runSync", "run", complete);
|
|
1928
|
+
/* @__PURE__ */ ok(result, "we either bailed on an error or have a tree");
|
|
1929
|
+
return result;
|
|
1930
|
+
/**
|
|
1931
|
+
* @type {RunCallback<TailTree extends undefined ? Node : TailTree>}
|
|
1932
|
+
*/
|
|
1933
|
+
function realDone(error, tree) {
|
|
1934
|
+
bail(error);
|
|
1935
|
+
result = tree;
|
|
1936
|
+
complete = true;
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
/**
|
|
1940
|
+
* Compile a syntax tree.
|
|
1941
|
+
*
|
|
1942
|
+
* > **Note**: `stringify` freezes the processor if not already *frozen*.
|
|
1943
|
+
*
|
|
1944
|
+
* > **Note**: `stringify` performs the stringify phase, not the run phase
|
|
1945
|
+
* > or other phases.
|
|
1946
|
+
*
|
|
1947
|
+
* @param {CompileTree extends undefined ? Node : CompileTree} tree
|
|
1948
|
+
* Tree to compile.
|
|
1949
|
+
* @param {Compatible | undefined} [file]
|
|
1950
|
+
* File associated with `node` (optional); any value accepted as `x` in
|
|
1951
|
+
* `new VFile(x)`.
|
|
1952
|
+
* @returns {CompileResult extends undefined ? Value : CompileResult}
|
|
1953
|
+
* Textual representation of the tree (see note).
|
|
1954
|
+
*
|
|
1955
|
+
* > **Note**: unified typically compiles by serializing: most compilers
|
|
1956
|
+
* > return `string` (or `Uint8Array`).
|
|
1957
|
+
* > Some compilers, such as the one configured with
|
|
1958
|
+
* > [`rehype-react`][rehype-react], return other values (in this case, a
|
|
1959
|
+
* > React tree).
|
|
1960
|
+
* > If you’re using a compiler that doesn’t serialize, expect different
|
|
1961
|
+
* > result values.
|
|
1962
|
+
* >
|
|
1963
|
+
* > To register custom results in TypeScript, add them to
|
|
1964
|
+
* > {@linkcode CompileResultMap}.
|
|
1965
|
+
*
|
|
1966
|
+
* [rehype-react]: https://github.com/rehypejs/rehype-react
|
|
1967
|
+
*/
|
|
1968
|
+
stringify(tree, file) {
|
|
1969
|
+
this.freeze();
|
|
1970
|
+
const realFile = vfile(file);
|
|
1971
|
+
const compiler = this.compiler || this.Compiler;
|
|
1972
|
+
assertCompiler("stringify", compiler);
|
|
1973
|
+
assertNode(tree);
|
|
1974
|
+
return compiler(tree, realFile);
|
|
1975
|
+
}
|
|
1976
|
+
/**
|
|
1977
|
+
* Configure the processor to use a plugin, a list of usable values, or a
|
|
1978
|
+
* preset.
|
|
1979
|
+
*
|
|
1980
|
+
* If the processor is already using a plugin, the previous plugin
|
|
1981
|
+
* configuration is changed based on the options that are passed in.
|
|
1982
|
+
* In other words, the plugin is not added a second time.
|
|
1983
|
+
*
|
|
1984
|
+
* > **Note**: `use` cannot be called on *frozen* processors.
|
|
1985
|
+
* > Call the processor first to create a new unfrozen processor.
|
|
1986
|
+
*
|
|
1987
|
+
* @example
|
|
1988
|
+
* There are many ways to pass plugins to `.use()`.
|
|
1989
|
+
* This example gives an overview:
|
|
1990
|
+
*
|
|
1991
|
+
* ```js
|
|
1992
|
+
* import {unified} from 'unified'
|
|
1993
|
+
*
|
|
1994
|
+
* unified()
|
|
1995
|
+
* // Plugin with options:
|
|
1996
|
+
* .use(pluginA, {x: true, y: true})
|
|
1997
|
+
* // Passing the same plugin again merges configuration (to `{x: true, y: false, z: true}`):
|
|
1998
|
+
* .use(pluginA, {y: false, z: true})
|
|
1999
|
+
* // Plugins:
|
|
2000
|
+
* .use([pluginB, pluginC])
|
|
2001
|
+
* // Two plugins, the second with options:
|
|
2002
|
+
* .use([pluginD, [pluginE, {}]])
|
|
2003
|
+
* // Preset with plugins and settings:
|
|
2004
|
+
* .use({plugins: [pluginF, [pluginG, {}]], settings: {position: false}})
|
|
2005
|
+
* // Settings only:
|
|
2006
|
+
* .use({settings: {position: false}})
|
|
2007
|
+
* ```
|
|
2008
|
+
*
|
|
2009
|
+
* @template {Array<unknown>} [Parameters=[]]
|
|
2010
|
+
* @template {Node | string | undefined} [Input=undefined]
|
|
2011
|
+
* @template [Output=Input]
|
|
2012
|
+
*
|
|
2013
|
+
* @overload
|
|
2014
|
+
* @param {Preset | null | undefined} [preset]
|
|
2015
|
+
* @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
|
|
2016
|
+
*
|
|
2017
|
+
* @overload
|
|
2018
|
+
* @param {PluggableList} list
|
|
2019
|
+
* @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
|
|
2020
|
+
*
|
|
2021
|
+
* @overload
|
|
2022
|
+
* @param {Plugin<Parameters, Input, Output>} plugin
|
|
2023
|
+
* @param {...(Parameters | [boolean])} parameters
|
|
2024
|
+
* @returns {UsePlugin<ParseTree, HeadTree, TailTree, CompileTree, CompileResult, Input, Output>}
|
|
2025
|
+
*
|
|
2026
|
+
* @param {PluggableList | Plugin | Preset | null | undefined} value
|
|
2027
|
+
* Usable value.
|
|
2028
|
+
* @param {...unknown} parameters
|
|
2029
|
+
* Parameters, when a plugin is given as a usable value.
|
|
2030
|
+
* @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
|
|
2031
|
+
* Current processor.
|
|
2032
|
+
*/
|
|
2033
|
+
use(value, ...parameters) {
|
|
2034
|
+
const attachers = this.attachers;
|
|
2035
|
+
const namespace = this.namespace;
|
|
2036
|
+
assertUnfrozen("use", this.frozen);
|
|
2037
|
+
if (value === null || value === void 0) {} else if (typeof value === "function") addPlugin(value, parameters);
|
|
2038
|
+
else if (typeof value === "object") if (Array.isArray(value)) addList(value);
|
|
2039
|
+
else addPreset(value);
|
|
2040
|
+
else throw new TypeError("Expected usable value, not `" + value + "`");
|
|
2041
|
+
return this;
|
|
2042
|
+
/**
|
|
2043
|
+
* @param {Pluggable} value
|
|
2044
|
+
* @returns {undefined}
|
|
2045
|
+
*/
|
|
2046
|
+
function add(value) {
|
|
2047
|
+
if (typeof value === "function") addPlugin(value, []);
|
|
2048
|
+
else if (typeof value === "object") if (Array.isArray(value)) {
|
|
2049
|
+
const [plugin, ...parameters] = value;
|
|
2050
|
+
addPlugin(plugin, parameters);
|
|
2051
|
+
} else addPreset(value);
|
|
2052
|
+
else throw new TypeError("Expected usable value, not `" + value + "`");
|
|
2053
|
+
}
|
|
2054
|
+
/**
|
|
2055
|
+
* @param {Preset} result
|
|
2056
|
+
* @returns {undefined}
|
|
2057
|
+
*/
|
|
2058
|
+
function addPreset(result) {
|
|
2059
|
+
if (!("plugins" in result) && !("settings" in result)) throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");
|
|
2060
|
+
addList(result.plugins);
|
|
2061
|
+
if (result.settings) namespace.settings = (0, import_extend.default)(true, namespace.settings, result.settings);
|
|
2062
|
+
}
|
|
2063
|
+
/**
|
|
2064
|
+
* @param {PluggableList | null | undefined} plugins
|
|
2065
|
+
* @returns {undefined}
|
|
2066
|
+
*/
|
|
2067
|
+
function addList(plugins) {
|
|
2068
|
+
let index = -1;
|
|
2069
|
+
if (plugins === null || plugins === void 0) {} else if (Array.isArray(plugins)) while (++index < plugins.length) {
|
|
2070
|
+
const thing = plugins[index];
|
|
2071
|
+
add(thing);
|
|
2072
|
+
}
|
|
2073
|
+
else throw new TypeError("Expected a list of plugins, not `" + plugins + "`");
|
|
2074
|
+
}
|
|
2075
|
+
/**
|
|
2076
|
+
* @param {Plugin} plugin
|
|
2077
|
+
* @param {Array<unknown>} parameters
|
|
2078
|
+
* @returns {undefined}
|
|
2079
|
+
*/
|
|
2080
|
+
function addPlugin(plugin, parameters) {
|
|
2081
|
+
let index = -1;
|
|
2082
|
+
let entryIndex = -1;
|
|
2083
|
+
while (++index < attachers.length) if (attachers[index][0] === plugin) {
|
|
2084
|
+
entryIndex = index;
|
|
2085
|
+
break;
|
|
2086
|
+
}
|
|
2087
|
+
if (entryIndex === -1) attachers.push([plugin, ...parameters]);
|
|
2088
|
+
else if (parameters.length > 0) {
|
|
2089
|
+
let [primary, ...rest] = parameters;
|
|
2090
|
+
const currentPrimary = attachers[entryIndex][1];
|
|
2091
|
+
if (isPlainObject(currentPrimary) && isPlainObject(primary)) primary = (0, import_extend.default)(true, currentPrimary, primary);
|
|
2092
|
+
attachers[entryIndex] = [
|
|
2093
|
+
plugin,
|
|
2094
|
+
primary,
|
|
2095
|
+
...rest
|
|
2096
|
+
];
|
|
2097
|
+
}
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
/**
|
|
2102
|
+
* Create a new processor.
|
|
2103
|
+
*
|
|
2104
|
+
* @example
|
|
2105
|
+
* This example shows how a new processor can be created (from `remark`) and linked
|
|
2106
|
+
* to **stdin**(4) and **stdout**(4).
|
|
2107
|
+
*
|
|
2108
|
+
* ```js
|
|
2109
|
+
* import process from 'node:process'
|
|
2110
|
+
* import concatStream from 'concat-stream'
|
|
2111
|
+
* import {remark} from 'remark'
|
|
2112
|
+
*
|
|
2113
|
+
* process.stdin.pipe(
|
|
2114
|
+
* concatStream(function (buf) {
|
|
2115
|
+
* process.stdout.write(String(remark().processSync(buf)))
|
|
2116
|
+
* })
|
|
2117
|
+
* )
|
|
2118
|
+
* ```
|
|
2119
|
+
*
|
|
2120
|
+
* @returns
|
|
2121
|
+
* New *unfrozen* processor (`processor`).
|
|
2122
|
+
*
|
|
2123
|
+
* This processor is configured to work the same as its ancestor.
|
|
2124
|
+
* When the descendant processor is configured in the future it does not
|
|
2125
|
+
* affect the ancestral processor.
|
|
2126
|
+
*/
|
|
2127
|
+
const unified = new Processor().freeze();
|
|
2128
|
+
/**
|
|
2129
|
+
* Assert a parser is available.
|
|
2130
|
+
*
|
|
2131
|
+
* @param {string} name
|
|
2132
|
+
* @param {unknown} value
|
|
2133
|
+
* @returns {asserts value is Parser}
|
|
2134
|
+
*/
|
|
2135
|
+
function assertParser(name, value) {
|
|
2136
|
+
if (typeof value !== "function") throw new TypeError("Cannot `" + name + "` without `parser`");
|
|
2137
|
+
}
|
|
2138
|
+
/**
|
|
2139
|
+
* Assert a compiler is available.
|
|
2140
|
+
*
|
|
2141
|
+
* @param {string} name
|
|
2142
|
+
* @param {unknown} value
|
|
2143
|
+
* @returns {asserts value is Compiler}
|
|
2144
|
+
*/
|
|
2145
|
+
function assertCompiler(name, value) {
|
|
2146
|
+
if (typeof value !== "function") throw new TypeError("Cannot `" + name + "` without `compiler`");
|
|
2147
|
+
}
|
|
2148
|
+
/**
|
|
2149
|
+
* Assert the processor is not frozen.
|
|
2150
|
+
*
|
|
2151
|
+
* @param {string} name
|
|
2152
|
+
* @param {unknown} frozen
|
|
2153
|
+
* @returns {asserts frozen is false}
|
|
2154
|
+
*/
|
|
2155
|
+
function assertUnfrozen(name, frozen) {
|
|
2156
|
+
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`.");
|
|
2157
|
+
}
|
|
2158
|
+
/**
|
|
2159
|
+
* Assert `node` is a unist node.
|
|
2160
|
+
*
|
|
2161
|
+
* @param {unknown} node
|
|
2162
|
+
* @returns {asserts node is Node}
|
|
2163
|
+
*/
|
|
2164
|
+
function assertNode(node) {
|
|
2165
|
+
if (!isPlainObject(node) || typeof node.type !== "string") throw new TypeError("Expected node, got `" + node + "`");
|
|
2166
|
+
}
|
|
2167
|
+
/**
|
|
2168
|
+
* Assert that `complete` is `true`.
|
|
2169
|
+
*
|
|
2170
|
+
* @param {string} name
|
|
2171
|
+
* @param {string} asyncName
|
|
2172
|
+
* @param {unknown} complete
|
|
2173
|
+
* @returns {asserts complete is true}
|
|
2174
|
+
*/
|
|
2175
|
+
function assertDone(name, asyncName, complete) {
|
|
2176
|
+
if (!complete) throw new Error("`" + name + "` finished async. Use `" + asyncName + "` instead");
|
|
2177
|
+
}
|
|
2178
|
+
/**
|
|
2179
|
+
* @param {Compatible | undefined} [value]
|
|
2180
|
+
* @returns {VFile}
|
|
2181
|
+
*/
|
|
2182
|
+
function vfile(value) {
|
|
2183
|
+
return looksLikeAVFile(value) ? value : new VFile(value);
|
|
2184
|
+
}
|
|
2185
|
+
/**
|
|
2186
|
+
* @param {Compatible | undefined} [value]
|
|
2187
|
+
* @returns {value is VFile}
|
|
2188
|
+
*/
|
|
2189
|
+
function looksLikeAVFile(value) {
|
|
2190
|
+
return Boolean(value && typeof value === "object" && "message" in value && "messages" in value);
|
|
2191
|
+
}
|
|
2192
|
+
/**
|
|
2193
|
+
* @param {unknown} [value]
|
|
2194
|
+
* @returns {value is Value}
|
|
2195
|
+
*/
|
|
2196
|
+
function looksLikeAValue(value) {
|
|
2197
|
+
return typeof value === "string" || isUint8Array(value);
|
|
2198
|
+
}
|
|
2199
|
+
/**
|
|
2200
|
+
* Assert `value` is an `Uint8Array`.
|
|
2201
|
+
*
|
|
2202
|
+
* @param {unknown} value
|
|
2203
|
+
* thing.
|
|
2204
|
+
* @returns {value is Uint8Array}
|
|
2205
|
+
* Whether `value` is an `Uint8Array`.
|
|
2206
|
+
*/
|
|
2207
|
+
function isUint8Array(value) {
|
|
2208
|
+
return Boolean(value && typeof value === "object" && "byteLength" in value && "byteOffset" in value);
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
//#endregion
|
|
2212
|
+
export { unified as t };
|