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