hermium 0.2.0 → 0.3.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 (157) hide show
  1. package/bin/hermium.mjs +102 -58
  2. package/dist/server/__23tanstack-start-plugin-adapters-Cwee5PKy.mjs +6 -0
  3. package/dist/server/_chunks/ssr-renderer.mjs +22 -0
  4. package/dist/server/_libs/bail.mjs +8 -0
  5. package/dist/server/_libs/base-ui__react.mjs +9858 -0
  6. package/dist/server/_libs/base-ui__utils.mjs +1106 -0
  7. package/dist/server/_libs/ccount.mjs +16 -0
  8. package/dist/server/_libs/character-entities.mjs +2130 -0
  9. package/dist/server/_libs/class-variance-authority.mjs +44 -0
  10. package/dist/server/_libs/clsx.mjs +16 -0
  11. package/dist/server/_libs/comma-separated-tokens.mjs +10 -0
  12. package/dist/server/_libs/cookie-es.mjs +1 -0
  13. package/dist/server/_libs/croner.mjs +1 -0
  14. package/dist/server/_libs/crossws.mjs +1 -0
  15. package/dist/server/_libs/decode-named-character-reference+[...].mjs +8 -0
  16. package/dist/server/_libs/devlop.mjs +8 -0
  17. package/dist/server/_libs/escape-string-regexp.mjs +9 -0
  18. package/dist/server/_libs/estree-util-is-identifier-name.mjs +11 -0
  19. package/dist/server/_libs/extend.mjs +97 -0
  20. package/dist/server/_libs/floating-ui__core.mjs +663 -0
  21. package/dist/server/_libs/floating-ui__dom.mjs +624 -0
  22. package/dist/server/_libs/floating-ui__react-dom.mjs +279 -0
  23. package/dist/server/_libs/floating-ui__utils.mjs +322 -0
  24. package/dist/server/_libs/h3.mjs +408 -0
  25. package/dist/server/_libs/hast-util-is-element.mjs +75 -0
  26. package/dist/server/_libs/hast-util-to-jsx-runtime.mjs +388 -0
  27. package/dist/server/_libs/hast-util-to-text.mjs +305 -0
  28. package/dist/server/_libs/hast-util-whitespace.mjs +10 -0
  29. package/dist/server/_libs/highlight.js.mjs +14756 -0
  30. package/dist/server/_libs/hookable.mjs +1 -0
  31. package/dist/server/_libs/html-url-attributes.mjs +26 -0
  32. package/dist/server/_libs/inline-style-parser.mjs +142 -0
  33. package/dist/server/_libs/is-plain-obj.mjs +10 -0
  34. package/dist/server/_libs/isbot.mjs +21 -0
  35. package/dist/server/_libs/longest-streak.mjs +25 -0
  36. package/dist/server/_libs/lowlight.mjs +262 -0
  37. package/dist/server/_libs/markdown-table.mjs +142 -0
  38. package/dist/server/_libs/mdast-util-find-and-replace.mjs +109 -0
  39. package/dist/server/_libs/mdast-util-from-markdown.mjs +717 -0
  40. package/dist/server/_libs/mdast-util-gfm-autolink-literal+[...].mjs +156 -0
  41. package/dist/server/_libs/mdast-util-gfm-footnote.mjs +117 -0
  42. package/dist/server/_libs/mdast-util-gfm-strikethrough.mjs +54 -0
  43. package/dist/server/_libs/mdast-util-gfm-table.mjs +157 -0
  44. package/dist/server/_libs/mdast-util-gfm-task-list-item.mjs +77 -0
  45. package/dist/server/_libs/mdast-util-gfm.mjs +29 -0
  46. package/dist/server/_libs/mdast-util-phrasing.mjs +30 -0
  47. package/dist/server/_libs/mdast-util-to-hast.mjs +710 -0
  48. package/dist/server/_libs/mdast-util-to-markdown.mjs +798 -0
  49. package/dist/server/_libs/mdast-util-to-string.mjs +38 -0
  50. package/dist/server/_libs/micromark-core-commonmark.mjs +2259 -0
  51. package/dist/server/_libs/micromark-extension-gfm-autolink-literal+[...].mjs +344 -0
  52. package/dist/server/_libs/micromark-extension-gfm-footnote+[...].mjs +279 -0
  53. package/dist/server/_libs/micromark-extension-gfm-strikethrough+[...].mjs +98 -0
  54. package/dist/server/_libs/micromark-extension-gfm-table.mjs +491 -0
  55. package/dist/server/_libs/micromark-extension-gfm-tagfilter+[...].mjs +1 -0
  56. package/dist/server/_libs/micromark-extension-gfm-task-list-item+[...].mjs +77 -0
  57. package/dist/server/_libs/micromark-extension-gfm.mjs +18 -0
  58. package/dist/server/_libs/micromark-factory-destination.mjs +94 -0
  59. package/dist/server/_libs/micromark-factory-label.mjs +63 -0
  60. package/dist/server/_libs/micromark-factory-space.mjs +24 -0
  61. package/dist/server/_libs/micromark-factory-title.mjs +65 -0
  62. package/dist/server/_libs/micromark-factory-whitespace.mjs +22 -0
  63. package/dist/server/_libs/micromark-util-character.mjs +44 -0
  64. package/dist/server/_libs/micromark-util-chunked.mjs +36 -0
  65. package/dist/server/_libs/micromark-util-classify-character+[...].mjs +12 -0
  66. package/dist/server/_libs/micromark-util-combine-extensions+[...].mjs +41 -0
  67. package/dist/server/_libs/micromark-util-decode-numeric-character-reference+[...].mjs +19 -0
  68. package/dist/server/_libs/micromark-util-decode-string.mjs +21 -0
  69. package/dist/server/_libs/micromark-util-encode.mjs +1 -0
  70. package/dist/server/_libs/micromark-util-html-tag-name.mjs +69 -0
  71. package/dist/server/_libs/micromark-util-normalize-identifier+[...].mjs +6 -0
  72. package/dist/server/_libs/micromark-util-resolve-all.mjs +15 -0
  73. package/dist/server/_libs/micromark-util-sanitize-uri.mjs +41 -0
  74. package/dist/server/_libs/micromark-util-subtokenize.mjs +346 -0
  75. package/dist/server/_libs/micromark.mjs +906 -0
  76. package/dist/server/_libs/ocache.mjs +1 -0
  77. package/dist/server/_libs/ohash.mjs +1 -0
  78. package/dist/server/_libs/property-information.mjs +1209 -0
  79. package/dist/server/_libs/react-dom.mjs +10779 -0
  80. package/dist/server/_libs/react-markdown.mjs +147 -0
  81. package/dist/server/_libs/react.mjs +513 -0
  82. package/dist/server/_libs/rehype-highlight.mjs +94 -0
  83. package/dist/server/_libs/remark-gfm.mjs +20 -0
  84. package/dist/server/_libs/remark-parse.mjs +19 -0
  85. package/dist/server/_libs/remark-rehype.mjs +21 -0
  86. package/dist/server/_libs/reselect.mjs +1 -0
  87. package/dist/server/_libs/rou3.mjs +8 -0
  88. package/dist/server/_libs/seroval-plugins.mjs +1 -0
  89. package/dist/server/_libs/seroval.mjs +1 -0
  90. package/dist/server/_libs/space-separated-tokens.mjs +6 -0
  91. package/dist/server/_libs/srvx.mjs +781 -0
  92. package/dist/server/_libs/style-to-js.mjs +72 -0
  93. package/dist/server/_libs/style-to-object.mjs +38 -0
  94. package/dist/server/_libs/tabler__icons-react.mjs +140 -0
  95. package/dist/server/_libs/tailwind-merge.mjs +3255 -0
  96. package/dist/server/_libs/tanstack__history.mjs +29 -0
  97. package/dist/server/_libs/tanstack__react-router.mjs +1120 -0
  98. package/dist/server/_libs/tanstack__react-store.mjs +2 -0
  99. package/dist/server/_libs/tanstack__router-core.mjs +3594 -0
  100. package/dist/server/_libs/tanstack__store.mjs +1 -0
  101. package/dist/server/_libs/trim-lines.mjs +41 -0
  102. package/dist/server/_libs/trough.mjs +85 -0
  103. package/dist/server/_libs/ufo.mjs +54 -0
  104. package/dist/server/_libs/unctx.mjs +1 -0
  105. package/dist/server/_libs/ungap__structured-clone.mjs +224 -0
  106. package/dist/server/_libs/unified.mjs +661 -0
  107. package/dist/server/_libs/unist-util-find-after.mjs +41 -0
  108. package/dist/server/_libs/unist-util-is.mjs +100 -0
  109. package/dist/server/_libs/unist-util-position.mjs +27 -0
  110. package/dist/server/_libs/unist-util-stringify-position.mjs +27 -0
  111. package/dist/server/_libs/unist-util-visit-parents.mjs +83 -0
  112. package/dist/server/_libs/unist-util-visit.mjs +24 -0
  113. package/dist/server/_libs/unstorage.mjs +1 -0
  114. package/dist/server/_libs/use-sync-external-store.mjs +139 -0
  115. package/dist/server/_libs/vfile-message.mjs +138 -0
  116. package/dist/server/_libs/vfile.mjs +467 -0
  117. package/dist/server/_libs/zustand.mjs +43 -0
  118. package/dist/server/_libs/zwitch.mjs +1 -0
  119. package/dist/server/_ssr/ChatInputBlock-Bu2-iop_.mjs +220 -0
  120. package/dist/server/_ssr/MarkdownMessage-CNS7OSKN.mjs +68 -0
  121. package/dist/server/_ssr/chat._sessionId-P02iSfut.mjs +477 -0
  122. package/dist/server/_ssr/chat.index-BYB_48NC.mjs +64 -0
  123. package/dist/server/_ssr/index-C1mT_2d8.mjs +4890 -0
  124. package/dist/server/_ssr/index-DFV9_oCk.mjs +43 -0
  125. package/dist/server/_ssr/memory-CW_fSOG9.mjs +257 -0
  126. package/dist/server/_ssr/router-CUAfx91O.mjs +2035 -0
  127. package/dist/server/_ssr/settings-DoXurzvn.mjs +10 -0
  128. package/dist/server/_ssr/skills-Cs7A5ZwO.mjs +422 -0
  129. package/dist/server/_ssr/theme-BK4-7E2h.mjs +42 -0
  130. package/dist/server/_ssr/usage-Bs2-LXGz.mjs +298 -0
  131. package/dist/server/_tanstack-start-manifest_v-C7Upe2TI.mjs +4 -0
  132. package/dist/server/index.mjs +506 -0
  133. package/package.json +4 -3
  134. package/dist/public/assets/css/index-Dfs9RUU9.css +0 -1
  135. package/dist/public/assets/css/styles-B8p6jk5Z.css +0 -1
  136. package/dist/public/assets/js/ChatInputBlock-Bw7AL70H.js +0 -1
  137. package/dist/public/assets/js/MarkdownMessage-8d7Y6VL-.js +0 -1
  138. package/dist/public/assets/js/base-ui-BvQbAt_1.js +0 -1
  139. package/dist/public/assets/js/chat._sessionId-BG6lVraH.js +0 -1
  140. package/dist/public/assets/js/chat.index-D2zdMPTT.js +0 -1
  141. package/dist/public/assets/js/index-C0AK45FU.js +0 -60
  142. package/dist/public/assets/js/index-Cx5En4FK.js +0 -1
  143. package/dist/public/assets/js/memory-CeSRdTkW.js +0 -3
  144. package/dist/public/assets/js/router-8uDKazL-.js +0 -1
  145. package/dist/public/assets/js/settings-Bc3Y5zXO.js +0 -1
  146. package/dist/public/assets/js/skills-DZv7sA_5.js +0 -1
  147. package/dist/public/assets/js/theme-CPkdkpaj.js +0 -1
  148. package/dist/public/assets/js/usage-DXQsT9_b.js +0 -1
  149. package/dist/public/assets/woff2/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
  150. package/dist/public/assets/woff2/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
  151. package/dist/public/assets/woff2/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
  152. package/dist/public/assets/woff2/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
  153. package/dist/public/assets/woff2/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
  154. package/dist/public/favicon.ico +0 -0
  155. package/dist/public/logo.png +0 -0
  156. package/dist/public/manifest.json +0 -25
  157. package/dist/public/robots.txt +0 -3
@@ -0,0 +1,661 @@
1
+ import { b as bail } from "./bail.mjs";
2
+ import { e as extend } from "./extend.mjs";
3
+ import { i as isPlainObject } from "./is-plain-obj.mjs";
4
+ import { t as trough } from "./trough.mjs";
5
+ import { V as VFile } from "./vfile.mjs";
6
+ const CallableInstance = (
7
+ /**
8
+ * @type {new <Parameters extends Array<unknown>, Result>(property: string | symbol) => (...parameters: Parameters) => Result}
9
+ */
10
+ /** @type {unknown} */
11
+ /**
12
+ * @this {Function}
13
+ * @param {string | symbol} property
14
+ * @returns {(...parameters: Array<unknown>) => unknown}
15
+ */
16
+ (function(property) {
17
+ const self = this;
18
+ const constr = self.constructor;
19
+ const proto = (
20
+ /** @type {Record<string | symbol, Function>} */
21
+ // Prototypes do exist.
22
+ // type-coverage:ignore-next-line
23
+ constr.prototype
24
+ );
25
+ const value = proto[property];
26
+ const apply = function() {
27
+ return value.apply(apply, arguments);
28
+ };
29
+ Object.setPrototypeOf(apply, proto);
30
+ return apply;
31
+ })
32
+ );
33
+ const own = {}.hasOwnProperty;
34
+ class Processor extends CallableInstance {
35
+ /**
36
+ * Create a processor.
37
+ */
38
+ constructor() {
39
+ super("copy");
40
+ this.Compiler = void 0;
41
+ this.Parser = void 0;
42
+ this.attachers = [];
43
+ this.compiler = void 0;
44
+ this.freezeIndex = -1;
45
+ this.frozen = void 0;
46
+ this.namespace = {};
47
+ this.parser = void 0;
48
+ this.transformers = trough();
49
+ }
50
+ /**
51
+ * Copy a processor.
52
+ *
53
+ * @deprecated
54
+ * This is a private internal method and should not be used.
55
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
56
+ * New *unfrozen* processor ({@linkcode Processor}) that is
57
+ * configured to work the same as its ancestor.
58
+ * When the descendant processor is configured in the future it does not
59
+ * affect the ancestral processor.
60
+ */
61
+ copy() {
62
+ const destination = (
63
+ /** @type {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>} */
64
+ new Processor()
65
+ );
66
+ let index = -1;
67
+ while (++index < this.attachers.length) {
68
+ const attacher = this.attachers[index];
69
+ destination.use(...attacher);
70
+ }
71
+ destination.data(extend(true, {}, this.namespace));
72
+ return destination;
73
+ }
74
+ /**
75
+ * Configure the processor with info available to all plugins.
76
+ * Information is stored in an object.
77
+ *
78
+ * Typically, options can be given to a specific plugin, but sometimes it
79
+ * makes sense to have information shared with several plugins.
80
+ * For example, a list of HTML elements that are self-closing, which is
81
+ * needed during all phases.
82
+ *
83
+ * > **Note**: setting information cannot occur on *frozen* processors.
84
+ * > Call the processor first to create a new unfrozen processor.
85
+ *
86
+ * > **Note**: to register custom data in TypeScript, augment the
87
+ * > {@linkcode Data} interface.
88
+ *
89
+ * @example
90
+ * This example show how to get and set info:
91
+ *
92
+ * ```js
93
+ * import {unified} from 'unified'
94
+ *
95
+ * const processor = unified().data('alpha', 'bravo')
96
+ *
97
+ * processor.data('alpha') // => 'bravo'
98
+ *
99
+ * processor.data() // => {alpha: 'bravo'}
100
+ *
101
+ * processor.data({charlie: 'delta'})
102
+ *
103
+ * processor.data() // => {charlie: 'delta'}
104
+ * ```
105
+ *
106
+ * @template {keyof Data} Key
107
+ *
108
+ * @overload
109
+ * @returns {Data}
110
+ *
111
+ * @overload
112
+ * @param {Data} dataset
113
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
114
+ *
115
+ * @overload
116
+ * @param {Key} key
117
+ * @returns {Data[Key]}
118
+ *
119
+ * @overload
120
+ * @param {Key} key
121
+ * @param {Data[Key]} value
122
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
123
+ *
124
+ * @param {Data | Key} [key]
125
+ * Key to get or set, or entire dataset to set, or nothing to get the
126
+ * entire dataset (optional).
127
+ * @param {Data[Key]} [value]
128
+ * Value to set (optional).
129
+ * @returns {unknown}
130
+ * The current processor when setting, the value at `key` when getting, or
131
+ * the entire dataset when getting without key.
132
+ */
133
+ data(key, value) {
134
+ if (typeof key === "string") {
135
+ if (arguments.length === 2) {
136
+ assertUnfrozen("data", this.frozen);
137
+ this.namespace[key] = value;
138
+ return this;
139
+ }
140
+ return own.call(this.namespace, key) && this.namespace[key] || void 0;
141
+ }
142
+ if (key) {
143
+ assertUnfrozen("data", this.frozen);
144
+ this.namespace = key;
145
+ return this;
146
+ }
147
+ return this.namespace;
148
+ }
149
+ /**
150
+ * Freeze a processor.
151
+ *
152
+ * Frozen processors are meant to be extended and not to be configured
153
+ * directly.
154
+ *
155
+ * When a processor is frozen it cannot be unfrozen.
156
+ * New processors working the same way can be created by calling the
157
+ * processor.
158
+ *
159
+ * It’s possible to freeze processors explicitly by calling `.freeze()`.
160
+ * Processors freeze automatically when `.parse()`, `.run()`, `.runSync()`,
161
+ * `.stringify()`, `.process()`, or `.processSync()` are called.
162
+ *
163
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
164
+ * The current processor.
165
+ */
166
+ freeze() {
167
+ if (this.frozen) {
168
+ return this;
169
+ }
170
+ const self = (
171
+ /** @type {Processor} */
172
+ /** @type {unknown} */
173
+ this
174
+ );
175
+ while (++this.freezeIndex < this.attachers.length) {
176
+ const [attacher, ...options] = this.attachers[this.freezeIndex];
177
+ if (options[0] === false) {
178
+ continue;
179
+ }
180
+ if (options[0] === true) {
181
+ options[0] = void 0;
182
+ }
183
+ const transformer = attacher.call(self, ...options);
184
+ if (typeof transformer === "function") {
185
+ this.transformers.use(transformer);
186
+ }
187
+ }
188
+ this.frozen = true;
189
+ this.freezeIndex = Number.POSITIVE_INFINITY;
190
+ return this;
191
+ }
192
+ /**
193
+ * Parse text to a syntax tree.
194
+ *
195
+ * > **Note**: `parse` freezes the processor if not already *frozen*.
196
+ *
197
+ * > **Note**: `parse` performs the parse phase, not the run phase or other
198
+ * > phases.
199
+ *
200
+ * @param {Compatible | undefined} [file]
201
+ * file to parse (optional); typically `string` or `VFile`; any value
202
+ * accepted as `x` in `new VFile(x)`.
203
+ * @returns {ParseTree extends undefined ? Node : ParseTree}
204
+ * Syntax tree representing `file`.
205
+ */
206
+ parse(file) {
207
+ this.freeze();
208
+ const realFile = vfile(file);
209
+ const parser = this.parser || this.Parser;
210
+ assertParser("parse", parser);
211
+ return parser(String(realFile), realFile);
212
+ }
213
+ /**
214
+ * Process the given file as configured on the processor.
215
+ *
216
+ * > **Note**: `process` freezes the processor if not already *frozen*.
217
+ *
218
+ * > **Note**: `process` performs the parse, run, and stringify phases.
219
+ *
220
+ * @overload
221
+ * @param {Compatible | undefined} file
222
+ * @param {ProcessCallback<VFileWithOutput<CompileResult>>} done
223
+ * @returns {undefined}
224
+ *
225
+ * @overload
226
+ * @param {Compatible | undefined} [file]
227
+ * @returns {Promise<VFileWithOutput<CompileResult>>}
228
+ *
229
+ * @param {Compatible | undefined} [file]
230
+ * File (optional); typically `string` or `VFile`]; any value accepted as
231
+ * `x` in `new VFile(x)`.
232
+ * @param {ProcessCallback<VFileWithOutput<CompileResult>> | undefined} [done]
233
+ * Callback (optional).
234
+ * @returns {Promise<VFile> | undefined}
235
+ * Nothing if `done` is given.
236
+ * Otherwise a promise, rejected with a fatal error or resolved with the
237
+ * processed file.
238
+ *
239
+ * The parsed, transformed, and compiled value is available at
240
+ * `file.value` (see note).
241
+ *
242
+ * > **Note**: unified typically compiles by serializing: most
243
+ * > compilers return `string` (or `Uint8Array`).
244
+ * > Some compilers, such as the one configured with
245
+ * > [`rehype-react`][rehype-react], return other values (in this case, a
246
+ * > React tree).
247
+ * > If you’re using a compiler that doesn’t serialize, expect different
248
+ * > result values.
249
+ * >
250
+ * > To register custom results in TypeScript, add them to
251
+ * > {@linkcode CompileResultMap}.
252
+ *
253
+ * [rehype-react]: https://github.com/rehypejs/rehype-react
254
+ */
255
+ process(file, done) {
256
+ const self = this;
257
+ this.freeze();
258
+ assertParser("process", this.parser || this.Parser);
259
+ assertCompiler("process", this.compiler || this.Compiler);
260
+ return done ? executor(void 0, done) : new Promise(executor);
261
+ function executor(resolve, reject) {
262
+ const realFile = vfile(file);
263
+ const parseTree = (
264
+ /** @type {HeadTree extends undefined ? Node : HeadTree} */
265
+ /** @type {unknown} */
266
+ self.parse(realFile)
267
+ );
268
+ self.run(parseTree, realFile, function(error, tree, file2) {
269
+ if (error || !tree || !file2) {
270
+ return realDone(error);
271
+ }
272
+ const compileTree = (
273
+ /** @type {CompileTree extends undefined ? Node : CompileTree} */
274
+ /** @type {unknown} */
275
+ tree
276
+ );
277
+ const compileResult = self.stringify(compileTree, file2);
278
+ if (looksLikeAValue(compileResult)) {
279
+ file2.value = compileResult;
280
+ } else {
281
+ file2.result = compileResult;
282
+ }
283
+ realDone(
284
+ error,
285
+ /** @type {VFileWithOutput<CompileResult>} */
286
+ file2
287
+ );
288
+ });
289
+ function realDone(error, file2) {
290
+ if (error || !file2) {
291
+ reject(error);
292
+ } else if (resolve) {
293
+ resolve(file2);
294
+ } else {
295
+ done(void 0, file2);
296
+ }
297
+ }
298
+ }
299
+ }
300
+ /**
301
+ * Process the given file as configured on the processor.
302
+ *
303
+ * An error is thrown if asynchronous transforms are configured.
304
+ *
305
+ * > **Note**: `processSync` freezes the processor if not already *frozen*.
306
+ *
307
+ * > **Note**: `processSync` performs the parse, run, and stringify phases.
308
+ *
309
+ * @param {Compatible | undefined} [file]
310
+ * File (optional); typically `string` or `VFile`; any value accepted as
311
+ * `x` in `new VFile(x)`.
312
+ * @returns {VFileWithOutput<CompileResult>}
313
+ * The processed file.
314
+ *
315
+ * The parsed, transformed, and compiled value is available at
316
+ * `file.value` (see note).
317
+ *
318
+ * > **Note**: unified typically compiles by serializing: most
319
+ * > compilers return `string` (or `Uint8Array`).
320
+ * > Some compilers, such as the one configured with
321
+ * > [`rehype-react`][rehype-react], return other values (in this case, a
322
+ * > React tree).
323
+ * > If you’re using a compiler that doesn’t serialize, expect different
324
+ * > result values.
325
+ * >
326
+ * > To register custom results in TypeScript, add them to
327
+ * > {@linkcode CompileResultMap}.
328
+ *
329
+ * [rehype-react]: https://github.com/rehypejs/rehype-react
330
+ */
331
+ processSync(file) {
332
+ let complete = false;
333
+ let result;
334
+ this.freeze();
335
+ assertParser("processSync", this.parser || this.Parser);
336
+ assertCompiler("processSync", this.compiler || this.Compiler);
337
+ this.process(file, realDone);
338
+ assertDone("processSync", "process", complete);
339
+ return result;
340
+ function realDone(error, file2) {
341
+ complete = true;
342
+ bail(error);
343
+ result = file2;
344
+ }
345
+ }
346
+ /**
347
+ * Run *transformers* on a syntax tree.
348
+ *
349
+ * > **Note**: `run` freezes the processor if not already *frozen*.
350
+ *
351
+ * > **Note**: `run` performs the run phase, not other phases.
352
+ *
353
+ * @overload
354
+ * @param {HeadTree extends undefined ? Node : HeadTree} tree
355
+ * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} done
356
+ * @returns {undefined}
357
+ *
358
+ * @overload
359
+ * @param {HeadTree extends undefined ? Node : HeadTree} tree
360
+ * @param {Compatible | undefined} file
361
+ * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} done
362
+ * @returns {undefined}
363
+ *
364
+ * @overload
365
+ * @param {HeadTree extends undefined ? Node : HeadTree} tree
366
+ * @param {Compatible | undefined} [file]
367
+ * @returns {Promise<TailTree extends undefined ? Node : TailTree>}
368
+ *
369
+ * @param {HeadTree extends undefined ? Node : HeadTree} tree
370
+ * Tree to transform and inspect.
371
+ * @param {(
372
+ * RunCallback<TailTree extends undefined ? Node : TailTree> |
373
+ * Compatible
374
+ * )} [file]
375
+ * File associated with `node` (optional); any value accepted as `x` in
376
+ * `new VFile(x)`.
377
+ * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} [done]
378
+ * Callback (optional).
379
+ * @returns {Promise<TailTree extends undefined ? Node : TailTree> | undefined}
380
+ * Nothing if `done` is given.
381
+ * Otherwise, a promise rejected with a fatal error or resolved with the
382
+ * transformed tree.
383
+ */
384
+ run(tree, file, done) {
385
+ assertNode(tree);
386
+ this.freeze();
387
+ const transformers = this.transformers;
388
+ if (!done && typeof file === "function") {
389
+ done = file;
390
+ file = void 0;
391
+ }
392
+ return done ? executor(void 0, done) : new Promise(executor);
393
+ function executor(resolve, reject) {
394
+ const realFile = vfile(file);
395
+ transformers.run(tree, realFile, realDone);
396
+ function realDone(error, outputTree, file2) {
397
+ const resultingTree = (
398
+ /** @type {TailTree extends undefined ? Node : TailTree} */
399
+ outputTree || tree
400
+ );
401
+ if (error) {
402
+ reject(error);
403
+ } else if (resolve) {
404
+ resolve(resultingTree);
405
+ } else {
406
+ done(void 0, resultingTree, file2);
407
+ }
408
+ }
409
+ }
410
+ }
411
+ /**
412
+ * Run *transformers* on a syntax tree.
413
+ *
414
+ * An error is thrown if asynchronous transforms are configured.
415
+ *
416
+ * > **Note**: `runSync` freezes the processor if not already *frozen*.
417
+ *
418
+ * > **Note**: `runSync` performs the run phase, not other phases.
419
+ *
420
+ * @param {HeadTree extends undefined ? Node : HeadTree} tree
421
+ * Tree to transform and inspect.
422
+ * @param {Compatible | undefined} [file]
423
+ * File associated with `node` (optional); any value accepted as `x` in
424
+ * `new VFile(x)`.
425
+ * @returns {TailTree extends undefined ? Node : TailTree}
426
+ * Transformed tree.
427
+ */
428
+ runSync(tree, file) {
429
+ let complete = false;
430
+ let result;
431
+ this.run(tree, file, realDone);
432
+ assertDone("runSync", "run", complete);
433
+ return result;
434
+ function realDone(error, tree2) {
435
+ bail(error);
436
+ result = tree2;
437
+ complete = true;
438
+ }
439
+ }
440
+ /**
441
+ * Compile a syntax tree.
442
+ *
443
+ * > **Note**: `stringify` freezes the processor if not already *frozen*.
444
+ *
445
+ * > **Note**: `stringify` performs the stringify phase, not the run phase
446
+ * > or other phases.
447
+ *
448
+ * @param {CompileTree extends undefined ? Node : CompileTree} tree
449
+ * Tree to compile.
450
+ * @param {Compatible | undefined} [file]
451
+ * File associated with `node` (optional); any value accepted as `x` in
452
+ * `new VFile(x)`.
453
+ * @returns {CompileResult extends undefined ? Value : CompileResult}
454
+ * Textual representation of the tree (see note).
455
+ *
456
+ * > **Note**: unified typically compiles by serializing: most compilers
457
+ * > return `string` (or `Uint8Array`).
458
+ * > Some compilers, such as the one configured with
459
+ * > [`rehype-react`][rehype-react], return other values (in this case, a
460
+ * > React tree).
461
+ * > If you’re using a compiler that doesn’t serialize, expect different
462
+ * > result values.
463
+ * >
464
+ * > To register custom results in TypeScript, add them to
465
+ * > {@linkcode CompileResultMap}.
466
+ *
467
+ * [rehype-react]: https://github.com/rehypejs/rehype-react
468
+ */
469
+ stringify(tree, file) {
470
+ this.freeze();
471
+ const realFile = vfile(file);
472
+ const compiler = this.compiler || this.Compiler;
473
+ assertCompiler("stringify", compiler);
474
+ assertNode(tree);
475
+ return compiler(tree, realFile);
476
+ }
477
+ /**
478
+ * Configure the processor to use a plugin, a list of usable values, or a
479
+ * preset.
480
+ *
481
+ * If the processor is already using a plugin, the previous plugin
482
+ * configuration is changed based on the options that are passed in.
483
+ * In other words, the plugin is not added a second time.
484
+ *
485
+ * > **Note**: `use` cannot be called on *frozen* processors.
486
+ * > Call the processor first to create a new unfrozen processor.
487
+ *
488
+ * @example
489
+ * There are many ways to pass plugins to `.use()`.
490
+ * This example gives an overview:
491
+ *
492
+ * ```js
493
+ * import {unified} from 'unified'
494
+ *
495
+ * unified()
496
+ * // Plugin with options:
497
+ * .use(pluginA, {x: true, y: true})
498
+ * // Passing the same plugin again merges configuration (to `{x: true, y: false, z: true}`):
499
+ * .use(pluginA, {y: false, z: true})
500
+ * // Plugins:
501
+ * .use([pluginB, pluginC])
502
+ * // Two plugins, the second with options:
503
+ * .use([pluginD, [pluginE, {}]])
504
+ * // Preset with plugins and settings:
505
+ * .use({plugins: [pluginF, [pluginG, {}]], settings: {position: false}})
506
+ * // Settings only:
507
+ * .use({settings: {position: false}})
508
+ * ```
509
+ *
510
+ * @template {Array<unknown>} [Parameters=[]]
511
+ * @template {Node | string | undefined} [Input=undefined]
512
+ * @template [Output=Input]
513
+ *
514
+ * @overload
515
+ * @param {Preset | null | undefined} [preset]
516
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
517
+ *
518
+ * @overload
519
+ * @param {PluggableList} list
520
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
521
+ *
522
+ * @overload
523
+ * @param {Plugin<Parameters, Input, Output>} plugin
524
+ * @param {...(Parameters | [boolean])} parameters
525
+ * @returns {UsePlugin<ParseTree, HeadTree, TailTree, CompileTree, CompileResult, Input, Output>}
526
+ *
527
+ * @param {PluggableList | Plugin | Preset | null | undefined} value
528
+ * Usable value.
529
+ * @param {...unknown} parameters
530
+ * Parameters, when a plugin is given as a usable value.
531
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
532
+ * Current processor.
533
+ */
534
+ use(value, ...parameters) {
535
+ const attachers = this.attachers;
536
+ const namespace = this.namespace;
537
+ assertUnfrozen("use", this.frozen);
538
+ if (value === null || value === void 0) ;
539
+ else if (typeof value === "function") {
540
+ addPlugin(value, parameters);
541
+ } else if (typeof value === "object") {
542
+ if (Array.isArray(value)) {
543
+ addList(value);
544
+ } else {
545
+ addPreset(value);
546
+ }
547
+ } else {
548
+ throw new TypeError("Expected usable value, not `" + value + "`");
549
+ }
550
+ return this;
551
+ function add(value2) {
552
+ if (typeof value2 === "function") {
553
+ addPlugin(value2, []);
554
+ } else if (typeof value2 === "object") {
555
+ if (Array.isArray(value2)) {
556
+ const [plugin, ...parameters2] = (
557
+ /** @type {PluginTuple<Array<unknown>>} */
558
+ value2
559
+ );
560
+ addPlugin(plugin, parameters2);
561
+ } else {
562
+ addPreset(value2);
563
+ }
564
+ } else {
565
+ throw new TypeError("Expected usable value, not `" + value2 + "`");
566
+ }
567
+ }
568
+ function addPreset(result) {
569
+ if (!("plugins" in result) && !("settings" in result)) {
570
+ throw new Error(
571
+ "Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither"
572
+ );
573
+ }
574
+ addList(result.plugins);
575
+ if (result.settings) {
576
+ namespace.settings = extend(true, namespace.settings, result.settings);
577
+ }
578
+ }
579
+ function addList(plugins) {
580
+ let index = -1;
581
+ if (plugins === null || plugins === void 0) ;
582
+ else if (Array.isArray(plugins)) {
583
+ while (++index < plugins.length) {
584
+ const thing = plugins[index];
585
+ add(thing);
586
+ }
587
+ } else {
588
+ throw new TypeError("Expected a list of plugins, not `" + plugins + "`");
589
+ }
590
+ }
591
+ function addPlugin(plugin, parameters2) {
592
+ let index = -1;
593
+ let entryIndex = -1;
594
+ while (++index < attachers.length) {
595
+ if (attachers[index][0] === plugin) {
596
+ entryIndex = index;
597
+ break;
598
+ }
599
+ }
600
+ if (entryIndex === -1) {
601
+ attachers.push([plugin, ...parameters2]);
602
+ } else if (parameters2.length > 0) {
603
+ let [primary, ...rest] = parameters2;
604
+ const currentPrimary = attachers[entryIndex][1];
605
+ if (isPlainObject(currentPrimary) && isPlainObject(primary)) {
606
+ primary = extend(true, currentPrimary, primary);
607
+ }
608
+ attachers[entryIndex] = [plugin, primary, ...rest];
609
+ }
610
+ }
611
+ }
612
+ }
613
+ const unified = new Processor().freeze();
614
+ function assertParser(name, value) {
615
+ if (typeof value !== "function") {
616
+ throw new TypeError("Cannot `" + name + "` without `parser`");
617
+ }
618
+ }
619
+ function assertCompiler(name, value) {
620
+ if (typeof value !== "function") {
621
+ throw new TypeError("Cannot `" + name + "` without `compiler`");
622
+ }
623
+ }
624
+ function assertUnfrozen(name, frozen) {
625
+ if (frozen) {
626
+ throw new Error(
627
+ "Cannot call `" + name + "` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`."
628
+ );
629
+ }
630
+ }
631
+ function assertNode(node) {
632
+ if (!isPlainObject(node) || typeof node.type !== "string") {
633
+ throw new TypeError("Expected node, got `" + node + "`");
634
+ }
635
+ }
636
+ function assertDone(name, asyncName, complete) {
637
+ if (!complete) {
638
+ throw new Error(
639
+ "`" + name + "` finished async. Use `" + asyncName + "` instead"
640
+ );
641
+ }
642
+ }
643
+ function vfile(value) {
644
+ return looksLikeAVFile(value) ? value : new VFile(value);
645
+ }
646
+ function looksLikeAVFile(value) {
647
+ return Boolean(
648
+ value && typeof value === "object" && "message" in value && "messages" in value
649
+ );
650
+ }
651
+ function looksLikeAValue(value) {
652
+ return typeof value === "string" || isUint8Array(value);
653
+ }
654
+ function isUint8Array(value) {
655
+ return Boolean(
656
+ value && typeof value === "object" && "byteLength" in value && "byteOffset" in value
657
+ );
658
+ }
659
+ export {
660
+ unified as u
661
+ };
@@ -0,0 +1,41 @@
1
+ import { c as convert } from "./unist-util-is.mjs";
2
+ const findAfter = (
3
+ // Note: overloads like this are needed to support optional generics.
4
+ /**
5
+ * @type {(
6
+ * (<Kind extends UnistParent, Check extends Test>(parent: Kind, index: Child<Kind> | number, test: Check) => Matches<Child<Kind>, Check> | undefined) &
7
+ * (<Kind extends UnistParent>(parent: Kind, index: Child<Kind> | number, test?: null | undefined) => Child<Kind> | undefined)
8
+ * )}
9
+ */
10
+ /**
11
+ * @param {UnistParent} parent
12
+ * @param {UnistNode | number} index
13
+ * @param {Test} [test]
14
+ * @returns {UnistNode | undefined}
15
+ */
16
+ (function(parent, index, test) {
17
+ const is = convert(test);
18
+ if (!parent || !parent.type || !parent.children) {
19
+ throw new Error("Expected parent node");
20
+ }
21
+ if (typeof index === "number") {
22
+ if (index < 0 || index === Number.POSITIVE_INFINITY) {
23
+ throw new Error("Expected positive finite number as index");
24
+ }
25
+ } else {
26
+ index = parent.children.indexOf(index);
27
+ if (index < 0) {
28
+ throw new Error("Expected child node or index");
29
+ }
30
+ }
31
+ while (++index < parent.children.length) {
32
+ if (is(parent.children[index], index, parent)) {
33
+ return parent.children[index];
34
+ }
35
+ }
36
+ return void 0;
37
+ })
38
+ );
39
+ export {
40
+ findAfter as f
41
+ };