@likec4/core 1.46.4 → 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.
Files changed (181) hide show
  1. package/LICENSE +1 -1
  2. package/dist/_chunks/Builder.view-element.mjs +3284 -0
  3. package/dist/_chunks/LikeC4Model.d.mts +1287 -0
  4. package/dist/_chunks/LikeC4Styles.mjs +691 -0
  5. package/dist/_chunks/RichText.d.mts +84 -0
  6. package/dist/_chunks/RichText.mjs +148 -0
  7. package/dist/_chunks/_aux.d.mts +289 -0
  8. package/dist/_chunks/_aux.mjs +18 -0
  9. package/dist/_chunks/_types.d.mts +781 -0
  10. package/dist/_chunks/_types2.d.mts +38 -0
  11. package/dist/_chunks/assignTagColors.mjs +24 -0
  12. package/dist/_chunks/calcDriftsFromSnapshot.mjs +379 -0
  13. package/dist/_chunks/connection.mjs +0 -0
  14. package/dist/_chunks/const.d.mts +43 -0
  15. package/dist/_chunks/const.mjs +33 -0
  16. package/dist/_chunks/expression-model.d.mts +192 -0
  17. package/dist/_chunks/expression-model.mjs +103 -0
  18. package/dist/_chunks/expression.d.mts +347 -0
  19. package/dist/_chunks/expression.mjs +107 -0
  20. package/dist/_chunks/find.d.mts +82 -0
  21. package/dist/_chunks/find.mjs +646 -0
  22. package/dist/_chunks/find2.d.mts +78 -0
  23. package/dist/_chunks/find2.mjs +287 -0
  24. package/dist/_chunks/fqnRef.d.mts +58 -0
  25. package/dist/_chunks/fqnRef.mjs +41 -0
  26. package/dist/_chunks/geometry.mjs +335 -0
  27. package/dist/_chunks/index.d.mts +169 -0
  28. package/dist/_chunks/index2.d.mts +937 -0
  29. package/dist/_chunks/index3.d.mts +146 -0
  30. package/dist/_chunks/index4.d.mts +62 -0
  31. package/dist/_chunks/index5.d.mts +42 -0
  32. package/dist/_chunks/index6.d.mts +43 -0
  33. package/dist/{shared/core.OtRNdMxy.d.mts → _chunks/index7.d.mts} +113 -197
  34. package/dist/_chunks/index8.d.mts +144 -0
  35. package/dist/_chunks/invariant.mjs +18 -0
  36. package/dist/_chunks/iterable.mjs +146 -0
  37. package/dist/_chunks/libs/@mantine/colors-generator.mjs +3416 -0
  38. package/dist/_chunks/libs/@ungap/structured-clone.mjs +213 -0
  39. package/dist/_chunks/libs/bail.mjs +14 -0
  40. package/dist/_chunks/libs/ccount.mjs +25 -0
  41. package/dist/_chunks/libs/character-entities-html4.mjs +263 -0
  42. package/dist/_chunks/libs/character-entities-legacy.mjs +117 -0
  43. package/dist/_chunks/libs/character-entities.mjs +2136 -0
  44. package/dist/_chunks/libs/comma-separated-tokens.mjs +18 -0
  45. package/dist/_chunks/libs/decode-named-character-reference.mjs +21 -0
  46. package/dist/_chunks/libs/defu.mjs +42 -0
  47. package/dist/_chunks/libs/devlop.mjs +5 -0
  48. package/dist/_chunks/libs/escape-string-regexp.mjs +8 -0
  49. package/dist/_chunks/libs/extend.mjs +77 -0
  50. package/dist/_chunks/libs/graphology-dag.mjs +703 -0
  51. package/dist/_chunks/libs/graphology-types.d.mts +601 -0
  52. package/dist/_chunks/libs/graphology.d.mts +6 -0
  53. package/dist/_chunks/libs/graphology.mjs +4565 -0
  54. package/dist/_chunks/libs/hast-util-sanitize.mjs +863 -0
  55. package/dist/_chunks/libs/hast-util-to-html.mjs +2696 -0
  56. package/dist/_chunks/libs/is-plain-obj.mjs +9 -0
  57. package/dist/_chunks/libs/longest-streak.mjs +30 -0
  58. package/dist/_chunks/libs/markdown-table.mjs +290 -0
  59. package/dist/_chunks/libs/mdast-util-find-and-replace.mjs +653 -0
  60. package/dist/_chunks/libs/mdast-util-from-markdown.mjs +8522 -0
  61. package/dist/_chunks/libs/mdast-util-gfm.mjs +2393 -0
  62. package/dist/_chunks/libs/mdast-util-to-hast.mjs +1803 -0
  63. package/dist/_chunks/libs/micromark-extension-gfm.mjs +2243 -0
  64. package/dist/_chunks/libs/mnemonist.d.mts +254 -0
  65. package/dist/_chunks/libs/mnemonist.mjs +1978 -0
  66. package/dist/_chunks/libs/natural-compare-lite.mjs +42 -0
  67. package/dist/_chunks/libs/rehype-sanitize.mjs +29 -0
  68. package/dist/_chunks/libs/rehype-stringify.mjs +34 -0
  69. package/dist/_chunks/libs/remark-gfm.mjs +36 -0
  70. package/dist/_chunks/libs/remark-github-blockquote-alert.mjs +100 -0
  71. package/dist/_chunks/libs/remark-parse.mjs +39 -0
  72. package/dist/_chunks/libs/remark-rehype.mjs +171 -0
  73. package/dist/_chunks/libs/remeda.mjs +702 -0
  74. package/dist/_chunks/libs/trough.mjs +158 -0
  75. package/dist/_chunks/libs/unified.mjs +2212 -0
  76. package/dist/_chunks/mnemonist.d.mts +1 -0
  77. package/dist/_chunks/mnemonist.mjs +0 -0
  78. package/dist/_chunks/model.mjs +1898 -0
  79. package/dist/_chunks/model2.mjs +0 -0
  80. package/dist/_chunks/relationships-view.mjs +132 -0
  81. package/dist/_chunks/rolldown-runtime.mjs +42 -0
  82. package/dist/{shared/core.C_3y3eqV.d.mts → _chunks/scalar.d.mts} +13 -43
  83. package/dist/_chunks/scalar.mjs +84 -0
  84. package/dist/_chunks/utils.mjs +483 -0
  85. package/dist/builder/index.d.mts +11 -773
  86. package/dist/builder/index.mjs +631 -978
  87. package/dist/compute-view/index.d.mts +90 -27
  88. package/dist/compute-view/index.mjs +253 -83
  89. package/dist/compute-view/relationships-view/index.d.mts +16 -51
  90. package/dist/compute-view/relationships-view/index.mjs +6 -184
  91. package/dist/geometry/index.d.mts +2 -109
  92. package/dist/geometry/index.mjs +2 -327
  93. package/dist/index.d.mts +18 -20
  94. package/dist/index.mjs +27 -18
  95. package/dist/model/connection/deployment/index.d.mts +12 -15
  96. package/dist/model/connection/deployment/index.mjs +9 -2
  97. package/dist/model/connection/index.d.mts +14 -75
  98. package/dist/model/connection/index.mjs +10 -3
  99. package/dist/model/connection/model/index.d.mts +12 -15
  100. package/dist/model/connection/model/index.mjs +8 -2
  101. package/dist/model/index.d.mts +15 -57
  102. package/dist/model/index.mjs +11 -4
  103. package/dist/styles/index.d.mts +9 -117
  104. package/dist/styles/index.mjs +26 -59
  105. package/dist/types/RichText.d.mts +3 -0
  106. package/dist/types/RichText.mjs +7 -0
  107. package/dist/types/_aux.d.mts +3 -4
  108. package/dist/types/_aux.mjs +2 -7
  109. package/dist/types/expression-model.d.mts +6 -190
  110. package/dist/types/expression-model.mjs +6 -108
  111. package/dist/types/expression.d.mts +5 -6
  112. package/dist/types/expression.mjs +6 -112
  113. package/dist/types/fqnRef.d.mts +4 -60
  114. package/dist/types/fqnRef.mjs +6 -44
  115. package/dist/types/index.d.mts +9 -47
  116. package/dist/types/index.mjs +14 -16
  117. package/dist/types/scalar.d.mts +2 -2
  118. package/dist/types/scalar.mjs +7 -4
  119. package/dist/utils/graphology/index.d.mts +2 -1864
  120. package/dist/utils/graphology/index.mjs +3 -1
  121. package/dist/utils/index.d.mts +11 -124
  122. package/dist/utils/index.mjs +16 -43
  123. package/dist/utils/iterable/index.d.mts +9 -132
  124. package/dist/utils/iterable/index.mjs +2 -61
  125. package/dist/utils/mnemonist.d.mts +2 -0
  126. package/dist/utils/mnemonist.mjs +12 -0
  127. package/package.json +18 -22
  128. package/compute-view/relationships/package.json +0 -4
  129. package/dist/shared/core.3ZhnKAlZ.mjs +0 -106
  130. package/dist/shared/core.78IWAHAE.mjs +0 -332
  131. package/dist/shared/core.B85MJLTf.mjs +0 -5
  132. package/dist/shared/core.BFd1lU9R.mjs +0 -29
  133. package/dist/shared/core.BKlholso.mjs +0 -3
  134. package/dist/shared/core.BPGOjone.d.mts +0 -46
  135. package/dist/shared/core.BYdtmqY5.mjs +0 -1255
  136. package/dist/shared/core.BZCgljZd.d.mts +0 -83
  137. package/dist/shared/core.BbE4y-yl.mjs +0 -177
  138. package/dist/shared/core.BhNcrwzK.mjs +0 -7
  139. package/dist/shared/core.BkVA6gjl.mjs +0 -5
  140. package/dist/shared/core.BoYfZOBm.mjs +0 -3
  141. package/dist/shared/core.BsSXS-_R.mjs +0 -7
  142. package/dist/shared/core.BspBF3SJ.mjs +0 -3944
  143. package/dist/shared/core.BvPm_-u3.d.mts +0 -334
  144. package/dist/shared/core.C-Jdx7xo.d.mts +0 -1263
  145. package/dist/shared/core.C3JowhaZ.mjs +0 -32
  146. package/dist/shared/core.C4x8aaWa.mjs +0 -27
  147. package/dist/shared/core.CBLX4mT8.mjs +0 -28411
  148. package/dist/shared/core.CLSZtnFh.mjs +0 -69
  149. package/dist/shared/core.CRhT4Iio.mjs +0 -785
  150. package/dist/shared/core.CbT8JVYL.mjs +0 -5
  151. package/dist/shared/core.CdNCAwq7.mjs +0 -176
  152. package/dist/shared/core.ClTP6-TN.d.mts +0 -87
  153. package/dist/shared/core.CmGY9blO.mjs +0 -6717
  154. package/dist/shared/core.CmPXpJ8l.mjs +0 -21
  155. package/dist/shared/core.Coi_LOUZ.mjs +0 -7
  156. package/dist/shared/core.CqAJJpK_.mjs +0 -3
  157. package/dist/shared/core.Ctj2S3bD.d.mts +0 -466
  158. package/dist/shared/core.CywrQs86.d.mts +0 -31
  159. package/dist/shared/core.D00YbOhQ.d.mts +0 -300
  160. package/dist/shared/core.D0WZutNd.mjs +0 -94
  161. package/dist/shared/core.D4npX2q8.mjs +0 -18
  162. package/dist/shared/core.DB0Ue5Wx.d.mts +0 -70
  163. package/dist/shared/core.DEK-BO3_.mjs +0 -1206
  164. package/dist/shared/core.DH7TXqXf.mjs +0 -136
  165. package/dist/shared/core.DRJma0Ol.mjs +0 -22
  166. package/dist/shared/core.DSalPD6v.mjs +0 -1352
  167. package/dist/shared/core.DVfPJPJj.mjs +0 -2200
  168. package/dist/shared/core.DXhDWKFZ.d.mts +0 -3
  169. package/dist/shared/core.DbfO90vF.mjs +0 -434
  170. package/dist/shared/core.DcS-0zys.mjs +0 -10
  171. package/dist/shared/core.DeDCYTDR.d.mts +0 -98
  172. package/dist/shared/core.DpKY_3NF.d.mts +0 -504
  173. package/dist/shared/core.Dt0v3djy.d.mts +0 -41
  174. package/dist/shared/core.FZ305VYd.mjs +0 -21
  175. package/dist/shared/core.RfnaEmgA.mjs +0 -7
  176. package/dist/shared/core.oSV6SRfk.mjs +0 -13
  177. package/dist/shared/core.om36dXXW.mjs +0 -41
  178. package/dist/shared/core.q10OP9oJ.mjs +0 -5
  179. package/dist/shared/core.uFk_o9X6.mjs +0 -13
  180. package/dist/shared/core.xeuDd__E.mjs +0 -300
  181. package/dist/shared/core.xgoPk2RG.mjs +0 -4989
@@ -0,0 +1,653 @@
1
+ import { t as escapeStringRegexp } from "./escape-string-regexp.mjs";
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 };