@likec4/core 1.48.0 → 1.49.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/dist/THIRD-PARTY-LICENSES.md +1012 -0
- package/dist/_chunks/Builder.view-element.mjs +2 -3284
- package/dist/_chunks/LikeC4Model.d.mts +21 -25
- package/dist/_chunks/RichText.mjs +1 -148
- package/dist/_chunks/_types.d.mts +1 -5
- package/dist/_chunks/_types2.d.mts +2 -4
- package/dist/_chunks/assignTagColors.mjs +1 -24
- package/dist/_chunks/calcDriftsFromSnapshot.mjs +1 -379
- package/dist/_chunks/guards.d.mts +2026 -0
- package/dist/_chunks/guards.mjs +4 -0
- package/dist/_chunks/index.d.mts +255 -136
- package/dist/_chunks/libs/@mantine/colors-generator.mjs +2 -3403
- package/dist/_chunks/libs/@radix-ui/colors.mjs +1 -0
- package/dist/_chunks/libs/@ungap/structured-clone.mjs +1 -213
- package/dist/_chunks/libs/bail.mjs +1 -14
- package/dist/_chunks/libs/ccount.mjs +1 -25
- package/dist/_chunks/libs/character-entities-html4.mjs +1 -263
- package/dist/_chunks/libs/character-entities-legacy.mjs +1 -117
- package/dist/_chunks/libs/character-entities.mjs +2 -2136
- package/dist/_chunks/libs/comma-separated-tokens.mjs +1 -18
- package/dist/_chunks/libs/decode-named-character-reference.mjs +1 -21
- package/dist/_chunks/libs/defu.mjs +1 -42
- package/dist/_chunks/libs/devlop.mjs +1 -5
- package/dist/_chunks/libs/escape-string-regexp.mjs +1 -8
- package/dist/_chunks/libs/extend.mjs +1 -77
- package/dist/_chunks/libs/graphology-dag.mjs +1 -703
- package/dist/_chunks/libs/graphology.mjs +1 -4565
- package/dist/_chunks/libs/hast-util-sanitize.mjs +1 -863
- package/dist/_chunks/libs/hast-util-to-html.mjs +9 -2696
- package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
- package/dist/_chunks/libs/longest-streak.mjs +1 -30
- package/dist/_chunks/libs/markdown-table.mjs +2 -290
- package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +1 -653
- package/dist/_chunks/libs/mdast-util-from-markdown.mjs +3 -8522
- package/dist/_chunks/libs/mdast-util-gfm.mjs +15 -2393
- package/dist/_chunks/libs/mdast-util-to-hast.mjs +11 -1803
- package/dist/_chunks/libs/micromark-extension-gfm.mjs +1 -2243
- package/dist/_chunks/libs/mnemonist.d.mts +1 -91
- package/dist/_chunks/libs/mnemonist.mjs +1 -1978
- package/dist/_chunks/libs/natural-compare-lite.mjs +9 -42
- package/dist/_chunks/libs/ohash.mjs +1 -0
- package/dist/_chunks/libs/rehype-sanitize.mjs +1 -29
- package/dist/_chunks/libs/rehype-stringify.mjs +1 -34
- package/dist/_chunks/libs/remark-gfm.mjs +1 -36
- package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +3 -100
- package/dist/_chunks/libs/remark-parse.mjs +1 -39
- package/dist/_chunks/libs/remark-rehype.mjs +1 -171
- package/dist/_chunks/libs/remeda.mjs +1 -702
- package/dist/_chunks/libs/trough.mjs +1 -158
- package/dist/_chunks/libs/unified.mjs +1 -2212
- package/dist/_chunks/rolldown-runtime.mjs +1 -42
- package/dist/_chunks/{index3.d.mts → theme.d.mts} +15 -13
- package/dist/_chunks/{index7.d.mts → to-text.d.mts} +165 -29
- package/dist/_chunks/to-text.mjs +1 -0
- package/dist/_chunks/vector.d.mts +198 -0
- package/dist/_chunks/vector.mjs +1 -0
- package/dist/builder/index.d.mts +2 -8
- package/dist/builder/index.mjs +1 -662
- package/dist/compute-view/index.d.mts +86 -15
- package/dist/compute-view/index.mjs +2 -262
- package/dist/geometry/index.d.mts +2 -2
- package/dist/geometry/index.mjs +1 -3
- package/dist/index.d.mts +9 -13
- package/dist/index.mjs +1 -27
- package/dist/model/index.d.mts +4 -14
- package/dist/model/index.mjs +1 -11
- package/dist/styles/index.d.mts +2 -8
- package/dist/styles/index.mjs +1 -30
- package/dist/types/index.d.mts +3 -9
- package/dist/types/index.mjs +1 -15
- package/dist/utils/graphology/index.d.mts +1 -1
- package/dist/utils/graphology/index.mjs +1 -3
- package/dist/utils/index.d.mts +4 -11
- package/dist/utils/index.mjs +1 -17
- package/package.json +13 -12
- package/dist/_chunks/LikeC4Styles.mjs +0 -691
- package/dist/_chunks/RichText.d.mts +0 -84
- package/dist/_chunks/_aux.d.mts +0 -289
- package/dist/_chunks/_aux.mjs +0 -18
- package/dist/_chunks/connection.mjs +0 -0
- package/dist/_chunks/const.d.mts +0 -43
- package/dist/_chunks/const.mjs +0 -33
- package/dist/_chunks/expression-model.d.mts +0 -192
- package/dist/_chunks/expression-model.mjs +0 -103
- package/dist/_chunks/expression.d.mts +0 -347
- package/dist/_chunks/expression.mjs +0 -107
- package/dist/_chunks/find.d.mts +0 -82
- package/dist/_chunks/find.mjs +0 -646
- package/dist/_chunks/find2.d.mts +0 -78
- package/dist/_chunks/find2.mjs +0 -287
- package/dist/_chunks/fqnRef.d.mts +0 -58
- package/dist/_chunks/fqnRef.mjs +0 -41
- package/dist/_chunks/geometry.mjs +0 -335
- package/dist/_chunks/index2.d.mts +0 -937
- package/dist/_chunks/index4.d.mts +0 -62
- package/dist/_chunks/index5.d.mts +0 -42
- package/dist/_chunks/index6.d.mts +0 -43
- package/dist/_chunks/index8.d.mts +0 -144
- package/dist/_chunks/invariant.mjs +0 -18
- package/dist/_chunks/iterable.mjs +0 -146
- package/dist/_chunks/libs/graphology-types.d.mts +0 -601
- package/dist/_chunks/libs/graphology.d.mts +0 -6
- package/dist/_chunks/mnemonist.d.mts +0 -1
- package/dist/_chunks/mnemonist.mjs +0 -0
- package/dist/_chunks/model.mjs +0 -1898
- package/dist/_chunks/model2.mjs +0 -0
- package/dist/_chunks/relationships-view.mjs +0 -132
- package/dist/_chunks/scalar.d.mts +0 -109
- package/dist/_chunks/scalar.mjs +0 -84
- package/dist/_chunks/utils.mjs +0 -483
- package/dist/compute-view/relationships-view/index.d.mts +0 -16
- package/dist/compute-view/relationships-view/index.mjs +0 -7
- package/dist/model/connection/deployment/index.d.mts +0 -12
- package/dist/model/connection/deployment/index.mjs +0 -9
- package/dist/model/connection/index.d.mts +0 -14
- package/dist/model/connection/index.mjs +0 -10
- package/dist/model/connection/model/index.d.mts +0 -12
- package/dist/model/connection/model/index.mjs +0 -8
- package/dist/types/RichText.d.mts +0 -3
- package/dist/types/RichText.mjs +0 -7
- package/dist/types/_aux.d.mts +0 -3
- package/dist/types/_aux.mjs +0 -3
- package/dist/types/expression-model.d.mts +0 -6
- package/dist/types/expression-model.mjs +0 -7
- package/dist/types/expression.d.mts +0 -5
- package/dist/types/expression.mjs +0 -7
- package/dist/types/fqnRef.d.mts +0 -4
- package/dist/types/fqnRef.mjs +0 -7
- package/dist/types/scalar.d.mts +0 -2
- package/dist/types/scalar.mjs +0 -7
- package/dist/utils/iterable/index.d.mts +0 -9
- package/dist/utils/iterable/index.mjs +0 -3
- package/dist/utils/mnemonist.d.mts +0 -2
- package/dist/utils/mnemonist.mjs +0 -12
|
@@ -1,653 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region ../../node_modules/.pnpm/unist-util-is@6.0.0/node_modules/unist-util-is/lib/index.js
|
|
4
|
-
/**
|
|
5
|
-
* Generate an assertion from a test.
|
|
6
|
-
*
|
|
7
|
-
* Useful if you’re going to test many nodes, for example when creating a
|
|
8
|
-
* utility where something else passes a compatible test.
|
|
9
|
-
*
|
|
10
|
-
* The created function is a bit faster because it expects valid input only:
|
|
11
|
-
* a `node`, `index`, and `parent`.
|
|
12
|
-
*
|
|
13
|
-
* @param {Test} test
|
|
14
|
-
* * when nullish, checks if `node` is a `Node`.
|
|
15
|
-
* * when `string`, works like passing `(node) => node.type === test`.
|
|
16
|
-
* * when `function` checks if function passed the node is true.
|
|
17
|
-
* * when `object`, checks that all keys in test are in node, and that they have (strictly) equal values.
|
|
18
|
-
* * when `array`, checks if any one of the subtests pass.
|
|
19
|
-
* @returns {Check}
|
|
20
|
-
* An assertion.
|
|
21
|
-
*/
|
|
22
|
-
const convert = (function(test) {
|
|
23
|
-
if (test === null || test === void 0) return ok;
|
|
24
|
-
if (typeof test === "function") return castFactory(test);
|
|
25
|
-
if (typeof test === "object") return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
|
|
26
|
-
if (typeof test === "string") return typeFactory(test);
|
|
27
|
-
throw new Error("Expected function, string, or object as test");
|
|
28
|
-
});
|
|
29
|
-
/**
|
|
30
|
-
* @param {Array<Props | TestFunction | string>} tests
|
|
31
|
-
* @returns {Check}
|
|
32
|
-
*/
|
|
33
|
-
function anyFactory(tests) {
|
|
34
|
-
/** @type {Array<Check>} */
|
|
35
|
-
const checks = [];
|
|
36
|
-
let index = -1;
|
|
37
|
-
while (++index < tests.length) checks[index] = convert(tests[index]);
|
|
38
|
-
return castFactory(any);
|
|
39
|
-
/**
|
|
40
|
-
* @this {unknown}
|
|
41
|
-
* @type {TestFunction}
|
|
42
|
-
*/
|
|
43
|
-
function any(...parameters) {
|
|
44
|
-
let index = -1;
|
|
45
|
-
while (++index < checks.length) if (checks[index].apply(this, parameters)) return true;
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Turn an object into a test for a node with a certain fields.
|
|
51
|
-
*
|
|
52
|
-
* @param {Props} check
|
|
53
|
-
* @returns {Check}
|
|
54
|
-
*/
|
|
55
|
-
function propsFactory(check) {
|
|
56
|
-
const checkAsRecord = check;
|
|
57
|
-
return castFactory(all);
|
|
58
|
-
/**
|
|
59
|
-
* @param {Node} node
|
|
60
|
-
* @returns {boolean}
|
|
61
|
-
*/
|
|
62
|
-
function all(node) {
|
|
63
|
-
const nodeAsRecord = node;
|
|
64
|
-
/** @type {string} */
|
|
65
|
-
let key;
|
|
66
|
-
for (key in check) if (nodeAsRecord[key] !== checkAsRecord[key]) return false;
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Turn a string into a test for a node with a certain type.
|
|
72
|
-
*
|
|
73
|
-
* @param {string} check
|
|
74
|
-
* @returns {Check}
|
|
75
|
-
*/
|
|
76
|
-
function typeFactory(check) {
|
|
77
|
-
return castFactory(type);
|
|
78
|
-
/**
|
|
79
|
-
* @param {Node} node
|
|
80
|
-
*/
|
|
81
|
-
function type(node) {
|
|
82
|
-
return node && node.type === check;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Turn a custom test into a test for a node that passes that test.
|
|
87
|
-
*
|
|
88
|
-
* @param {TestFunction} testFunction
|
|
89
|
-
* @returns {Check}
|
|
90
|
-
*/
|
|
91
|
-
function castFactory(testFunction) {
|
|
92
|
-
return check;
|
|
93
|
-
/**
|
|
94
|
-
* @this {unknown}
|
|
95
|
-
* @type {Check}
|
|
96
|
-
*/
|
|
97
|
-
function check(value, index, parent) {
|
|
98
|
-
return Boolean(looksLikeANode(value) && testFunction.call(this, value, typeof index === "number" ? index : void 0, parent || void 0));
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
function ok() {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* @param {unknown} value
|
|
106
|
-
* @returns {value is Node}
|
|
107
|
-
*/
|
|
108
|
-
function looksLikeANode(value) {
|
|
109
|
-
return value !== null && typeof value === "object" && "type" in value;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region ../../node_modules/.pnpm/unist-util-visit-parents@6.0.2/node_modules/unist-util-visit-parents/lib/color.js
|
|
114
|
-
/**
|
|
115
|
-
* @param {string} d
|
|
116
|
-
* @returns {string}
|
|
117
|
-
*/
|
|
118
|
-
function color(d) {
|
|
119
|
-
return d;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
//#endregion
|
|
123
|
-
//#region ../../node_modules/.pnpm/unist-util-visit-parents@6.0.2/node_modules/unist-util-visit-parents/lib/index.js
|
|
124
|
-
/**
|
|
125
|
-
* @import {Node as UnistNode, Parent as UnistParent} from 'unist'
|
|
126
|
-
*/
|
|
127
|
-
/**
|
|
128
|
-
* @typedef {Exclude<import('unist-util-is').Test, undefined> | undefined} Test
|
|
129
|
-
* Test from `unist-util-is`.
|
|
130
|
-
*
|
|
131
|
-
* Note: we have remove and add `undefined`, because otherwise when generating
|
|
132
|
-
* automatic `.d.ts` files, TS tries to flatten paths from a local perspective,
|
|
133
|
-
* which doesn’t work when publishing on npm.
|
|
134
|
-
*/
|
|
135
|
-
/**
|
|
136
|
-
* @typedef {(
|
|
137
|
-
* Fn extends (value: any) => value is infer Thing
|
|
138
|
-
* ? Thing
|
|
139
|
-
* : Fallback
|
|
140
|
-
* )} Predicate
|
|
141
|
-
* Get the value of a type guard `Fn`.
|
|
142
|
-
* @template Fn
|
|
143
|
-
* Value; typically function that is a type guard (such as `(x): x is Y`).
|
|
144
|
-
* @template Fallback
|
|
145
|
-
* Value to yield if `Fn` is not a type guard.
|
|
146
|
-
*/
|
|
147
|
-
/**
|
|
148
|
-
* @typedef {(
|
|
149
|
-
* Check extends null | undefined // No test.
|
|
150
|
-
* ? Value
|
|
151
|
-
* : Value extends {type: Check} // String (type) test.
|
|
152
|
-
* ? Value
|
|
153
|
-
* : Value extends Check // Partial test.
|
|
154
|
-
* ? Value
|
|
155
|
-
* : Check extends Function // Function test.
|
|
156
|
-
* ? Predicate<Check, Value> extends Value
|
|
157
|
-
* ? Predicate<Check, Value>
|
|
158
|
-
* : never
|
|
159
|
-
* : never // Some other test?
|
|
160
|
-
* )} MatchesOne
|
|
161
|
-
* Check whether a node matches a primitive check in the type system.
|
|
162
|
-
* @template Value
|
|
163
|
-
* Value; typically unist `Node`.
|
|
164
|
-
* @template Check
|
|
165
|
-
* Value; typically `unist-util-is`-compatible test, but not arrays.
|
|
166
|
-
*/
|
|
167
|
-
/**
|
|
168
|
-
* @typedef {(
|
|
169
|
-
* Check extends ReadonlyArray<infer T>
|
|
170
|
-
* ? MatchesOne<Value, T>
|
|
171
|
-
* : Check extends Array<infer T>
|
|
172
|
-
* ? MatchesOne<Value, T>
|
|
173
|
-
* : MatchesOne<Value, Check>
|
|
174
|
-
* )} Matches
|
|
175
|
-
* Check whether a node matches a check in the type system.
|
|
176
|
-
* @template Value
|
|
177
|
-
* Value; typically unist `Node`.
|
|
178
|
-
* @template Check
|
|
179
|
-
* Value; typically `unist-util-is`-compatible test.
|
|
180
|
-
*/
|
|
181
|
-
/**
|
|
182
|
-
* @typedef {0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10} Uint
|
|
183
|
-
* Number; capped reasonably.
|
|
184
|
-
*/
|
|
185
|
-
/**
|
|
186
|
-
* @typedef {I extends 0 ? 1 : I extends 1 ? 2 : I extends 2 ? 3 : I extends 3 ? 4 : I extends 4 ? 5 : I extends 5 ? 6 : I extends 6 ? 7 : I extends 7 ? 8 : I extends 8 ? 9 : 10} Increment
|
|
187
|
-
* Increment a number in the type system.
|
|
188
|
-
* @template {Uint} [I=0]
|
|
189
|
-
* Index.
|
|
190
|
-
*/
|
|
191
|
-
/**
|
|
192
|
-
* @typedef {(
|
|
193
|
-
* Node extends UnistParent
|
|
194
|
-
* ? Node extends {children: Array<infer Children>}
|
|
195
|
-
* ? Child extends Children ? Node : never
|
|
196
|
-
* : never
|
|
197
|
-
* : never
|
|
198
|
-
* )} InternalParent
|
|
199
|
-
* Collect nodes that can be parents of `Child`.
|
|
200
|
-
* @template {UnistNode} Node
|
|
201
|
-
* All node types in a tree.
|
|
202
|
-
* @template {UnistNode} Child
|
|
203
|
-
* Node to search for.
|
|
204
|
-
*/
|
|
205
|
-
/**
|
|
206
|
-
* @typedef {InternalParent<InclusiveDescendant<Tree>, Child>} Parent
|
|
207
|
-
* Collect nodes in `Tree` that can be parents of `Child`.
|
|
208
|
-
* @template {UnistNode} Tree
|
|
209
|
-
* All node types in a tree.
|
|
210
|
-
* @template {UnistNode} Child
|
|
211
|
-
* Node to search for.
|
|
212
|
-
*/
|
|
213
|
-
/**
|
|
214
|
-
* @typedef {(
|
|
215
|
-
* Depth extends Max
|
|
216
|
-
* ? never
|
|
217
|
-
* :
|
|
218
|
-
* | InternalParent<Node, Child>
|
|
219
|
-
* | InternalAncestor<Node, InternalParent<Node, Child>, Max, Increment<Depth>>
|
|
220
|
-
* )} InternalAncestor
|
|
221
|
-
* Collect nodes in `Tree` that can be ancestors of `Child`.
|
|
222
|
-
* @template {UnistNode} Node
|
|
223
|
-
* All node types in a tree.
|
|
224
|
-
* @template {UnistNode} Child
|
|
225
|
-
* Node to search for.
|
|
226
|
-
* @template {Uint} [Max=10]
|
|
227
|
-
* Max; searches up to this depth.
|
|
228
|
-
* @template {Uint} [Depth=0]
|
|
229
|
-
* Current depth.
|
|
230
|
-
*/
|
|
231
|
-
/**
|
|
232
|
-
* @typedef {InternalAncestor<InclusiveDescendant<Tree>, Child>} Ancestor
|
|
233
|
-
* Collect nodes in `Tree` that can be ancestors of `Child`.
|
|
234
|
-
* @template {UnistNode} Tree
|
|
235
|
-
* All node types in a tree.
|
|
236
|
-
* @template {UnistNode} Child
|
|
237
|
-
* Node to search for.
|
|
238
|
-
*/
|
|
239
|
-
/**
|
|
240
|
-
* @typedef {(
|
|
241
|
-
* Tree extends UnistParent
|
|
242
|
-
* ? Depth extends Max
|
|
243
|
-
* ? Tree
|
|
244
|
-
* : Tree | InclusiveDescendant<Tree['children'][number], Max, Increment<Depth>>
|
|
245
|
-
* : Tree
|
|
246
|
-
* )} InclusiveDescendant
|
|
247
|
-
* Collect all (inclusive) descendants of `Tree`.
|
|
248
|
-
*
|
|
249
|
-
* > 👉 **Note**: for performance reasons, this seems to be the fastest way to
|
|
250
|
-
* > recurse without actually running into an infinite loop, which the
|
|
251
|
-
* > previous version did.
|
|
252
|
-
* >
|
|
253
|
-
* > Practically, a max of `2` is typically enough assuming a `Root` is
|
|
254
|
-
* > passed, but it doesn’t improve performance.
|
|
255
|
-
* > It gets higher with `List > ListItem > Table > TableRow > TableCell`.
|
|
256
|
-
* > Using up to `10` doesn’t hurt or help either.
|
|
257
|
-
* @template {UnistNode} Tree
|
|
258
|
-
* Tree type.
|
|
259
|
-
* @template {Uint} [Max=10]
|
|
260
|
-
* Max; searches up to this depth.
|
|
261
|
-
* @template {Uint} [Depth=0]
|
|
262
|
-
* Current depth.
|
|
263
|
-
*/
|
|
264
|
-
/**
|
|
265
|
-
* @typedef {'skip' | boolean} Action
|
|
266
|
-
* Union of the action types.
|
|
267
|
-
*
|
|
268
|
-
* @typedef {number} Index
|
|
269
|
-
* Move to the sibling at `index` next (after node itself is completely
|
|
270
|
-
* traversed).
|
|
271
|
-
*
|
|
272
|
-
* Useful if mutating the tree, such as removing the node the visitor is
|
|
273
|
-
* currently on, or any of its previous siblings.
|
|
274
|
-
* Results less than 0 or greater than or equal to `children.length` stop
|
|
275
|
-
* traversing the parent.
|
|
276
|
-
*
|
|
277
|
-
* @typedef {[(Action | null | undefined | void)?, (Index | null | undefined)?]} ActionTuple
|
|
278
|
-
* List with one or two values, the first an action, the second an index.
|
|
279
|
-
*
|
|
280
|
-
* @typedef {Action | ActionTuple | Index | null | undefined | void} VisitorResult
|
|
281
|
-
* Any value that can be returned from a visitor.
|
|
282
|
-
*/
|
|
283
|
-
/**
|
|
284
|
-
* @callback Visitor
|
|
285
|
-
* Handle a node (matching `test`, if given).
|
|
286
|
-
*
|
|
287
|
-
* Visitors are free to transform `node`.
|
|
288
|
-
* They can also transform the parent of node (the last of `ancestors`).
|
|
289
|
-
*
|
|
290
|
-
* Replacing `node` itself, if `SKIP` is not returned, still causes its
|
|
291
|
-
* descendants to be walked (which is a bug).
|
|
292
|
-
*
|
|
293
|
-
* When adding or removing previous siblings of `node` (or next siblings, in
|
|
294
|
-
* case of reverse), the `Visitor` should return a new `Index` to specify the
|
|
295
|
-
* sibling to traverse after `node` is traversed.
|
|
296
|
-
* Adding or removing next siblings of `node` (or previous siblings, in case
|
|
297
|
-
* of reverse) is handled as expected without needing to return a new `Index`.
|
|
298
|
-
*
|
|
299
|
-
* Removing the children property of an ancestor still results in them being
|
|
300
|
-
* traversed.
|
|
301
|
-
* @param {Visited} node
|
|
302
|
-
* Found node.
|
|
303
|
-
* @param {Array<VisitedParents>} ancestors
|
|
304
|
-
* Ancestors of `node`.
|
|
305
|
-
* @returns {VisitorResult}
|
|
306
|
-
* What to do next.
|
|
307
|
-
*
|
|
308
|
-
* An `Index` is treated as a tuple of `[CONTINUE, Index]`.
|
|
309
|
-
* An `Action` is treated as a tuple of `[Action]`.
|
|
310
|
-
*
|
|
311
|
-
* Passing a tuple back only makes sense if the `Action` is `SKIP`.
|
|
312
|
-
* When the `Action` is `EXIT`, that action can be returned.
|
|
313
|
-
* When the `Action` is `CONTINUE`, `Index` can be returned.
|
|
314
|
-
* @template {UnistNode} [Visited=UnistNode]
|
|
315
|
-
* Visited node type.
|
|
316
|
-
* @template {UnistParent} [VisitedParents=UnistParent]
|
|
317
|
-
* Ancestor type.
|
|
318
|
-
*/
|
|
319
|
-
/**
|
|
320
|
-
* @typedef {Visitor<Matches<InclusiveDescendant<Tree>, Check>, Ancestor<Tree, Matches<InclusiveDescendant<Tree>, Check>>>} BuildVisitor
|
|
321
|
-
* Build a typed `Visitor` function from a tree and a test.
|
|
322
|
-
*
|
|
323
|
-
* It will infer which values are passed as `node` and which as `parents`.
|
|
324
|
-
* @template {UnistNode} [Tree=UnistNode]
|
|
325
|
-
* Tree type.
|
|
326
|
-
* @template {Test} [Check=Test]
|
|
327
|
-
* Test type.
|
|
328
|
-
*/
|
|
329
|
-
/** @type {Readonly<ActionTuple>} */
|
|
330
|
-
const empty = [];
|
|
331
|
-
/**
|
|
332
|
-
* Continue traversing as normal.
|
|
333
|
-
*/
|
|
334
|
-
const CONTINUE = true;
|
|
335
|
-
/**
|
|
336
|
-
* Stop traversing immediately.
|
|
337
|
-
*/
|
|
338
|
-
const EXIT = false;
|
|
339
|
-
/**
|
|
340
|
-
* Do not traverse this node’s children.
|
|
341
|
-
*/
|
|
342
|
-
const SKIP = "skip";
|
|
343
|
-
/**
|
|
344
|
-
* Visit nodes, with ancestral information.
|
|
345
|
-
*
|
|
346
|
-
* This algorithm performs *depth-first* *tree traversal* in *preorder*
|
|
347
|
-
* (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).
|
|
348
|
-
*
|
|
349
|
-
* You can choose for which nodes `visitor` is called by passing a `test`.
|
|
350
|
-
* For complex tests, you should test yourself in `visitor`, as it will be
|
|
351
|
-
* faster and will have improved type information.
|
|
352
|
-
*
|
|
353
|
-
* Walking the tree is an intensive task.
|
|
354
|
-
* Make use of the return values of the visitor when possible.
|
|
355
|
-
* Instead of walking a tree multiple times, walk it once, use `unist-util-is`
|
|
356
|
-
* to check if a node matches, and then perform different operations.
|
|
357
|
-
*
|
|
358
|
-
* You can change the tree.
|
|
359
|
-
* See `Visitor` for more info.
|
|
360
|
-
*
|
|
361
|
-
* @overload
|
|
362
|
-
* @param {Tree} tree
|
|
363
|
-
* @param {Check} check
|
|
364
|
-
* @param {BuildVisitor<Tree, Check>} visitor
|
|
365
|
-
* @param {boolean | null | undefined} [reverse]
|
|
366
|
-
* @returns {undefined}
|
|
367
|
-
*
|
|
368
|
-
* @overload
|
|
369
|
-
* @param {Tree} tree
|
|
370
|
-
* @param {BuildVisitor<Tree>} visitor
|
|
371
|
-
* @param {boolean | null | undefined} [reverse]
|
|
372
|
-
* @returns {undefined}
|
|
373
|
-
*
|
|
374
|
-
* @param {UnistNode} tree
|
|
375
|
-
* Tree to traverse.
|
|
376
|
-
* @param {Visitor | Test} test
|
|
377
|
-
* `unist-util-is`-compatible test
|
|
378
|
-
* @param {Visitor | boolean | null | undefined} [visitor]
|
|
379
|
-
* Handle each node.
|
|
380
|
-
* @param {boolean | null | undefined} [reverse]
|
|
381
|
-
* Traverse in reverse preorder (NRL) instead of the default preorder (NLR).
|
|
382
|
-
* @returns {undefined}
|
|
383
|
-
* Nothing.
|
|
384
|
-
*
|
|
385
|
-
* @template {UnistNode} Tree
|
|
386
|
-
* Node type.
|
|
387
|
-
* @template {Test} Check
|
|
388
|
-
* `unist-util-is`-compatible test.
|
|
389
|
-
*/
|
|
390
|
-
function visitParents(tree, test, visitor, reverse) {
|
|
391
|
-
/** @type {Test} */
|
|
392
|
-
let check;
|
|
393
|
-
if (typeof test === "function" && typeof visitor !== "function") {
|
|
394
|
-
reverse = visitor;
|
|
395
|
-
visitor = test;
|
|
396
|
-
} else check = test;
|
|
397
|
-
const is = convert(check);
|
|
398
|
-
const step = reverse ? -1 : 1;
|
|
399
|
-
factory(tree, void 0, [])();
|
|
400
|
-
/**
|
|
401
|
-
* @param {UnistNode} node
|
|
402
|
-
* @param {number | undefined} index
|
|
403
|
-
* @param {Array<UnistParent>} parents
|
|
404
|
-
*/
|
|
405
|
-
function factory(node, index, parents) {
|
|
406
|
-
const value = node && typeof node === "object" ? node : {};
|
|
407
|
-
if (typeof value.type === "string") {
|
|
408
|
-
const name = typeof value.tagName === "string" ? value.tagName : typeof value.name === "string" ? value.name : void 0;
|
|
409
|
-
Object.defineProperty(visit, "name", { value: "node (" + color(node.type + (name ? "<" + name + ">" : "")) + ")" });
|
|
410
|
-
}
|
|
411
|
-
return visit;
|
|
412
|
-
function visit() {
|
|
413
|
-
/** @type {Readonly<ActionTuple>} */
|
|
414
|
-
let result = empty;
|
|
415
|
-
/** @type {Readonly<ActionTuple>} */
|
|
416
|
-
let subresult;
|
|
417
|
-
/** @type {number} */
|
|
418
|
-
let offset;
|
|
419
|
-
/** @type {Array<UnistParent>} */
|
|
420
|
-
let grandparents;
|
|
421
|
-
if (!test || is(node, index, parents[parents.length - 1] || void 0)) {
|
|
422
|
-
result = toResult(visitor(node, parents));
|
|
423
|
-
if (result[0] === EXIT) return result;
|
|
424
|
-
}
|
|
425
|
-
if ("children" in node && node.children) {
|
|
426
|
-
const nodeAsParent = node;
|
|
427
|
-
if (nodeAsParent.children && result[0] !== SKIP) {
|
|
428
|
-
offset = (reverse ? nodeAsParent.children.length : -1) + step;
|
|
429
|
-
grandparents = parents.concat(nodeAsParent);
|
|
430
|
-
while (offset > -1 && offset < nodeAsParent.children.length) {
|
|
431
|
-
const child = nodeAsParent.children[offset];
|
|
432
|
-
subresult = factory(child, offset, grandparents)();
|
|
433
|
-
if (subresult[0] === EXIT) return subresult;
|
|
434
|
-
offset = typeof subresult[1] === "number" ? subresult[1] : offset + step;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
return result;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
/**
|
|
443
|
-
* Turn a return value into a clean result.
|
|
444
|
-
*
|
|
445
|
-
* @param {VisitorResult} value
|
|
446
|
-
* Valid return values from visitors.
|
|
447
|
-
* @returns {Readonly<ActionTuple>}
|
|
448
|
-
* Clean result.
|
|
449
|
-
*/
|
|
450
|
-
function toResult(value) {
|
|
451
|
-
if (Array.isArray(value)) return value;
|
|
452
|
-
if (typeof value === "number") return [CONTINUE, value];
|
|
453
|
-
return value === null || value === void 0 ? empty : [value];
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
//#endregion
|
|
457
|
-
//#region ../../node_modules/.pnpm/mdast-util-find-and-replace@3.0.2/node_modules/mdast-util-find-and-replace/lib/index.js
|
|
458
|
-
/**
|
|
459
|
-
* @import {Nodes, Parents, PhrasingContent, Root, Text} from 'mdast'
|
|
460
|
-
* @import {BuildVisitor, Test, VisitorResult} from 'unist-util-visit-parents'
|
|
461
|
-
*/
|
|
462
|
-
/**
|
|
463
|
-
* @typedef RegExpMatchObject
|
|
464
|
-
* Info on the match.
|
|
465
|
-
* @property {number} index
|
|
466
|
-
* The index of the search at which the result was found.
|
|
467
|
-
* @property {string} input
|
|
468
|
-
* A copy of the search string in the text node.
|
|
469
|
-
* @property {[...Array<Parents>, Text]} stack
|
|
470
|
-
* All ancestors of the text node, where the last node is the text itself.
|
|
471
|
-
*
|
|
472
|
-
* @typedef {RegExp | string} Find
|
|
473
|
-
* Pattern to find.
|
|
474
|
-
*
|
|
475
|
-
* Strings are escaped and then turned into global expressions.
|
|
476
|
-
*
|
|
477
|
-
* @typedef {Array<FindAndReplaceTuple>} FindAndReplaceList
|
|
478
|
-
* Several find and replaces, in array form.
|
|
479
|
-
*
|
|
480
|
-
* @typedef {[Find, Replace?]} FindAndReplaceTuple
|
|
481
|
-
* Find and replace in tuple form.
|
|
482
|
-
*
|
|
483
|
-
* @typedef {ReplaceFunction | string | null | undefined} Replace
|
|
484
|
-
* Thing to replace with.
|
|
485
|
-
*
|
|
486
|
-
* @callback ReplaceFunction
|
|
487
|
-
* Callback called when a search matches.
|
|
488
|
-
* @param {...any} parameters
|
|
489
|
-
* The parameters are the result of corresponding search expression:
|
|
490
|
-
*
|
|
491
|
-
* * `value` (`string`) — whole match
|
|
492
|
-
* * `...capture` (`Array<string>`) — matches from regex capture groups
|
|
493
|
-
* * `match` (`RegExpMatchObject`) — info on the match
|
|
494
|
-
* @returns {Array<PhrasingContent> | PhrasingContent | string | false | null | undefined}
|
|
495
|
-
* Thing to replace with.
|
|
496
|
-
*
|
|
497
|
-
* * when `null`, `undefined`, `''`, remove the match
|
|
498
|
-
* * …or when `false`, do not replace at all
|
|
499
|
-
* * …or when `string`, replace with a text node of that value
|
|
500
|
-
* * …or when `Node` or `Array<Node>`, replace with those nodes
|
|
501
|
-
*
|
|
502
|
-
* @typedef {[RegExp, ReplaceFunction]} Pair
|
|
503
|
-
* Normalized find and replace.
|
|
504
|
-
*
|
|
505
|
-
* @typedef {Array<Pair>} Pairs
|
|
506
|
-
* All find and replaced.
|
|
507
|
-
*
|
|
508
|
-
* @typedef Options
|
|
509
|
-
* Configuration.
|
|
510
|
-
* @property {Test | null | undefined} [ignore]
|
|
511
|
-
* Test for which nodes to ignore (optional).
|
|
512
|
-
*/
|
|
513
|
-
/**
|
|
514
|
-
* Find patterns in a tree and replace them.
|
|
515
|
-
*
|
|
516
|
-
* The algorithm searches the tree in *preorder* for complete values in `Text`
|
|
517
|
-
* nodes.
|
|
518
|
-
* Partial matches are not supported.
|
|
519
|
-
*
|
|
520
|
-
* @param {Nodes} tree
|
|
521
|
-
* Tree to change.
|
|
522
|
-
* @param {FindAndReplaceList | FindAndReplaceTuple} list
|
|
523
|
-
* Patterns to find.
|
|
524
|
-
* @param {Options | null | undefined} [options]
|
|
525
|
-
* Configuration (when `find` is not `Find`).
|
|
526
|
-
* @returns {undefined}
|
|
527
|
-
* Nothing.
|
|
528
|
-
*/
|
|
529
|
-
function findAndReplace(tree, list, options) {
|
|
530
|
-
const ignored = convert((options || {}).ignore || []);
|
|
531
|
-
const pairs = toPairs(list);
|
|
532
|
-
let pairIndex = -1;
|
|
533
|
-
while (++pairIndex < pairs.length) visitParents(tree, "text", visitor);
|
|
534
|
-
/** @type {BuildVisitor<Root, 'text'>} */
|
|
535
|
-
function visitor(node, parents) {
|
|
536
|
-
let index = -1;
|
|
537
|
-
/** @type {Parents | undefined} */
|
|
538
|
-
let grandparent;
|
|
539
|
-
while (++index < parents.length) {
|
|
540
|
-
const parent = parents[index];
|
|
541
|
-
/** @type {Array<Nodes> | undefined} */
|
|
542
|
-
const siblings = grandparent ? grandparent.children : void 0;
|
|
543
|
-
if (ignored(parent, siblings ? siblings.indexOf(parent) : void 0, grandparent)) return;
|
|
544
|
-
grandparent = parent;
|
|
545
|
-
}
|
|
546
|
-
if (grandparent) return handler(node, parents);
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* Handle a text node which is not in an ignored parent.
|
|
550
|
-
*
|
|
551
|
-
* @param {Text} node
|
|
552
|
-
* Text node.
|
|
553
|
-
* @param {Array<Parents>} parents
|
|
554
|
-
* Parents.
|
|
555
|
-
* @returns {VisitorResult}
|
|
556
|
-
* Result.
|
|
557
|
-
*/
|
|
558
|
-
function handler(node, parents) {
|
|
559
|
-
const parent = parents[parents.length - 1];
|
|
560
|
-
const find = pairs[pairIndex][0];
|
|
561
|
-
const replace = pairs[pairIndex][1];
|
|
562
|
-
let start = 0;
|
|
563
|
-
const index = parent.children.indexOf(node);
|
|
564
|
-
let change = false;
|
|
565
|
-
/** @type {Array<PhrasingContent>} */
|
|
566
|
-
let nodes = [];
|
|
567
|
-
find.lastIndex = 0;
|
|
568
|
-
let match = find.exec(node.value);
|
|
569
|
-
while (match) {
|
|
570
|
-
const position = match.index;
|
|
571
|
-
/** @type {RegExpMatchObject} */
|
|
572
|
-
const matchObject = {
|
|
573
|
-
index: match.index,
|
|
574
|
-
input: match.input,
|
|
575
|
-
stack: [...parents, node]
|
|
576
|
-
};
|
|
577
|
-
let value = replace(...match, matchObject);
|
|
578
|
-
if (typeof value === "string") value = value.length > 0 ? {
|
|
579
|
-
type: "text",
|
|
580
|
-
value
|
|
581
|
-
} : void 0;
|
|
582
|
-
if (value === false) find.lastIndex = position + 1;
|
|
583
|
-
else {
|
|
584
|
-
if (start !== position) nodes.push({
|
|
585
|
-
type: "text",
|
|
586
|
-
value: node.value.slice(start, position)
|
|
587
|
-
});
|
|
588
|
-
if (Array.isArray(value)) nodes.push(...value);
|
|
589
|
-
else if (value) nodes.push(value);
|
|
590
|
-
start = position + match[0].length;
|
|
591
|
-
change = true;
|
|
592
|
-
}
|
|
593
|
-
if (!find.global) break;
|
|
594
|
-
match = find.exec(node.value);
|
|
595
|
-
}
|
|
596
|
-
if (change) {
|
|
597
|
-
if (start < node.value.length) nodes.push({
|
|
598
|
-
type: "text",
|
|
599
|
-
value: node.value.slice(start)
|
|
600
|
-
});
|
|
601
|
-
parent.children.splice(index, 1, ...nodes);
|
|
602
|
-
} else nodes = [node];
|
|
603
|
-
return index + nodes.length;
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Turn a tuple or a list of tuples into pairs.
|
|
608
|
-
*
|
|
609
|
-
* @param {FindAndReplaceList | FindAndReplaceTuple} tupleOrList
|
|
610
|
-
* Schema.
|
|
611
|
-
* @returns {Pairs}
|
|
612
|
-
* Clean pairs.
|
|
613
|
-
*/
|
|
614
|
-
function toPairs(tupleOrList) {
|
|
615
|
-
/** @type {Pairs} */
|
|
616
|
-
const result = [];
|
|
617
|
-
if (!Array.isArray(tupleOrList)) throw new TypeError("Expected find and replace tuple or list of tuples");
|
|
618
|
-
/** @type {FindAndReplaceList} */
|
|
619
|
-
const list = !tupleOrList[0] || Array.isArray(tupleOrList[0]) ? tupleOrList : [tupleOrList];
|
|
620
|
-
let index = -1;
|
|
621
|
-
while (++index < list.length) {
|
|
622
|
-
const tuple = list[index];
|
|
623
|
-
result.push([toExpression(tuple[0]), toFunction(tuple[1])]);
|
|
624
|
-
}
|
|
625
|
-
return result;
|
|
626
|
-
}
|
|
627
|
-
/**
|
|
628
|
-
* Turn a find into an expression.
|
|
629
|
-
*
|
|
630
|
-
* @param {Find} find
|
|
631
|
-
* Find.
|
|
632
|
-
* @returns {RegExp}
|
|
633
|
-
* Expression.
|
|
634
|
-
*/
|
|
635
|
-
function toExpression(find) {
|
|
636
|
-
return typeof find === "string" ? new RegExp(escapeStringRegexp(find), "g") : find;
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Turn a replace into a function.
|
|
640
|
-
*
|
|
641
|
-
* @param {Replace} replace
|
|
642
|
-
* Replace.
|
|
643
|
-
* @returns {ReplaceFunction}
|
|
644
|
-
* Function.
|
|
645
|
-
*/
|
|
646
|
-
function toFunction(replace) {
|
|
647
|
-
return typeof replace === "function" ? replace : function() {
|
|
648
|
-
return replace;
|
|
649
|
-
};
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
//#endregion
|
|
653
|
-
export { convert as i, EXIT as n, visitParents as r, findAndReplace as t };
|
|
1
|
+
import{t as escapeStringRegexp}from"./escape-string-regexp.mjs";const convert=(function(e){if(e==null)return ok;if(typeof e==`function`)return castFactory(e);if(typeof e==`object`)return Array.isArray(e)?anyFactory(e):propsFactory(e);if(typeof e==`string`)return typeFactory(e);throw Error(`Expected function, string, or object as test`)});function anyFactory(e){let n=[],r=-1;for(;++r<e.length;)n[r]=convert(e[r]);return castFactory(i);function i(...e){let t=-1;for(;++t<n.length;)if(n[t].apply(this,e))return!0;return!1}}function propsFactory(e){let t=e;return castFactory(n);function n(n){let r=n,i;for(i in e)if(r[i]!==t[i])return!1;return!0}}function typeFactory(e){return castFactory(t);function t(t){return t&&t.type===e}}function castFactory(e){return t;function t(t,n,r){return!!(looksLikeANode(t)&&e.call(this,t,typeof n==`number`?n:void 0,r||void 0))}}function ok(){return!0}function looksLikeANode(e){return typeof e==`object`&&!!e&&`type`in e}function color(e){return e}const empty=[],EXIT=!1;function visitParents(e,n,r,i){let a;typeof n==`function`&&typeof r!=`function`?(i=r,r=n):a=n;let o=convert(a),s=i?-1:1;u(e,void 0,[])();function u(e,t,a){let d=e&&typeof e==`object`?e:{};if(typeof d.type==`string`){let t=typeof d.tagName==`string`?d.tagName:typeof d.name==`string`?d.name:void 0;Object.defineProperty(f,`name`,{value:`node (`+color(e.type+(t?`<`+t+`>`:``))+`)`})}return f;function f(){let c=empty,d,f,p;if((!n||o(e,t,a[a.length-1]||void 0))&&(c=toResult(r(e,a)),c[0]===!1))return c;if(`children`in e&&e.children){let t=e;if(t.children&&c[0]!==`skip`)for(f=(i?t.children.length:-1)+s,p=a.concat(t);f>-1&&f<t.children.length;){let e=t.children[f];if(d=u(e,f,p)(),d[0]===!1)return d;f=typeof d[1]==`number`?d[1]:f+s}}return c}}}function toResult(e){return Array.isArray(e)?e:typeof e==`number`?[!0,e]:e==null?empty:[e]}function findAndReplace(e,n,r){let i=convert((r||{}).ignore||[]),a=toPairs(n),o=-1;for(;++o<a.length;)visitParents(e,`text`,s);function s(e,t){let n=-1,r;for(;++n<t.length;){let e=t[n],a=r?r.children:void 0;if(i(e,a?a.indexOf(e):void 0,r))return;r=e}if(r)return c(e,t)}function c(e,t){let n=t[t.length-1],r=a[o][0],i=a[o][1],s=0,c=n.children.indexOf(e),l=!1,u=[];r.lastIndex=0;let d=r.exec(e.value);for(;d;){let n=d.index,a={index:d.index,input:d.input,stack:[...t,e]},o=i(...d,a);if(typeof o==`string`&&(o=o.length>0?{type:`text`,value:o}:void 0),o===!1?r.lastIndex=n+1:(s!==n&&u.push({type:`text`,value:e.value.slice(s,n)}),Array.isArray(o)?u.push(...o):o&&u.push(o),s=n+d[0].length,l=!0),!r.global)break;d=r.exec(e.value)}return l?(s<e.value.length&&u.push({type:`text`,value:e.value.slice(s)}),n.children.splice(c,1,...u)):u=[e],c+u.length}}function toPairs(e){let t=[];if(!Array.isArray(e))throw TypeError(`Expected find and replace tuple or list of tuples`);let n=!e[0]||Array.isArray(e[0])?e:[e],r=-1;for(;++r<n.length;){let e=n[r];t.push([toExpression(e[0]),toFunction(e[1])])}return t}function toExpression(t){return typeof t==`string`?new RegExp(escapeStringRegexp(t),`g`):t}function toFunction(e){return typeof e==`function`?e:function(){return e}}export{convert as i,EXIT as n,visitParents as r,findAndReplace as t};
|