@harbour-enterprises/superdoc 0.28.0-next.9 → 0.28.1

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 (62) hide show
  1. package/dist/chunks/{PdfViewer-B13bR8VJ.cjs → PdfViewer-Can0yoW4.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-DRCcOt2t.es.js → PdfViewer-DJkdA-8o.es.js} +1 -1
  3. package/dist/chunks/default-BS6z0SoE-BS6z0SoE.es.js +5 -0
  4. package/dist/chunks/default-BS6z0SoE-Gl4f7Y7J.cjs +4 -0
  5. package/dist/chunks/{index-DcpSDyC4.cjs → index-BY-vlgKe.cjs} +3 -3
  6. package/dist/chunks/index-CHAKf7mX-C5aFF6Zl.es.js +2213 -0
  7. package/dist/chunks/index-CHAKf7mX-Dx-DOGGJ.cjs +2213 -0
  8. package/dist/chunks/index-CSaZZzfe-BzemjgYL.cjs +264 -0
  9. package/dist/chunks/index-CSaZZzfe-CSaZZzfe.es.js +265 -0
  10. package/dist/chunks/index-C_x_N6Uh-DJn8hIEt.es.js +2200 -0
  11. package/dist/chunks/index-C_x_N6Uh-Db3CUJMX.cjs +2200 -0
  12. package/dist/chunks/index-Cd3D_8gF-CFhMnajQ.es.js +862 -0
  13. package/dist/chunks/index-Cd3D_8gF-DKJ_wTu_.cjs +861 -0
  14. package/dist/chunks/index-CvBqQJbG-CvBqQJbG.es.js +878 -0
  15. package/dist/chunks/index-CvBqQJbG-Dwm0THD7.cjs +877 -0
  16. package/dist/chunks/index-DRCvimau-Cw339678.es.js +9876 -0
  17. package/dist/chunks/index-DRCvimau-H4Ck3S9a.cjs +9876 -0
  18. package/dist/chunks/index-D_sWOSiG-BtDZzJ6I.cjs +588 -0
  19. package/dist/chunks/index-D_sWOSiG-DE96TaT5.es.js +588 -0
  20. package/dist/chunks/{index-KRsMbx-o.es.js → index-DidXsI6u.es.js} +3 -3
  21. package/dist/chunks/index-njnq8umX-DU2xcaHZ.es.js +845 -0
  22. package/dist/chunks/index-njnq8umX-_TfP84XP.cjs +845 -0
  23. package/dist/chunks/{super-editor.es-DKQa7RQl.es.js → super-editor.es-Br566URP.es.js} +6462 -24112
  24. package/dist/chunks/{super-editor.es-BnJV-Q-L.cjs → super-editor.es-ksiTgGLm.cjs} +6371 -24021
  25. package/dist/core/types/index.d.ts +6 -6
  26. package/dist/core/types/index.d.ts.map +1 -1
  27. package/dist/super-editor/ai-writer.es.js +2 -2
  28. package/dist/super-editor/chunks/{converter-kpd0gAZh.js → converter-D6Z6OmA3.js} +53 -50
  29. package/dist/super-editor/chunks/default-BS6z0SoE.js +5 -0
  30. package/dist/super-editor/chunks/{docx-zipper-1SfZh-7P.js → docx-zipper-Dni97kMT.js} +1 -1
  31. package/dist/super-editor/chunks/{editor-DdEaVosL.js → editor-D3TKfdXs.js} +3762 -21427
  32. package/dist/super-editor/chunks/index-CHAKf7mX.js +2213 -0
  33. package/dist/super-editor/chunks/index-CSaZZzfe.js +265 -0
  34. package/dist/super-editor/chunks/index-C_x_N6Uh.js +2200 -0
  35. package/dist/super-editor/chunks/index-Cd3D_8gF.js +862 -0
  36. package/dist/super-editor/chunks/index-CvBqQJbG.js +878 -0
  37. package/dist/super-editor/chunks/index-DRCvimau.js +9876 -0
  38. package/dist/super-editor/chunks/index-D_sWOSiG.js +588 -0
  39. package/dist/super-editor/chunks/index-njnq8umX.js +845 -0
  40. package/dist/super-editor/chunks/{toolbar-CTt4vWNb.js → toolbar-fNE3luLB.js} +2 -2
  41. package/dist/super-editor/converter.es.js +2 -2
  42. package/dist/super-editor/docx-zipper.es.js +2 -2
  43. package/dist/super-editor/editor.es.js +3 -3
  44. package/dist/super-editor/file-zipper.es.js +1 -1
  45. package/dist/super-editor/super-editor/src/core/Editor.d.ts +2 -2
  46. package/dist/super-editor/super-editor/src/extensions/structured-content/structured-content-block.d.ts +8 -6
  47. package/dist/super-editor/super-editor/src/extensions/structured-content/structured-content.d.ts +8 -1
  48. package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentBlockTags.d.ts +11 -4
  49. package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentInlineTags.d.ts +11 -4
  50. package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentTablesById.d.ts +8 -4
  51. package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentTags.d.ts +11 -4
  52. package/dist/super-editor/super-editor/src/extensions/structured-content/structuredContentHelpers/getStructuredContentTagsById.d.ts +12 -5
  53. package/dist/super-editor/super-editor/src/extensions/track-changes/permission-helpers.d.ts +6 -6
  54. package/dist/super-editor/super-editor.es.js +15 -15
  55. package/dist/super-editor/toolbar.es.js +2 -2
  56. package/dist/super-editor.cjs +1 -1
  57. package/dist/super-editor.es.js +1 -1
  58. package/dist/superdoc.cjs +2 -2
  59. package/dist/superdoc.es.js +2 -2
  60. package/dist/superdoc.umd.js +74034 -73990
  61. package/dist/superdoc.umd.js.map +1 -1
  62. package/package.json +1 -1
@@ -0,0 +1,845 @@
1
+ import { aA as getDefaultExportFromCjs } from "./converter-D6Z6OmA3.js";
2
+ import { V as VFile } from "./index-CvBqQJbG.js";
3
+ function bail(error) {
4
+ if (error) {
5
+ throw error;
6
+ }
7
+ }
8
+ var extend$1;
9
+ var hasRequiredExtend;
10
+ function requireExtend() {
11
+ if (hasRequiredExtend) return extend$1;
12
+ hasRequiredExtend = 1;
13
+ var hasOwn = Object.prototype.hasOwnProperty;
14
+ var toStr = Object.prototype.toString;
15
+ var defineProperty = Object.defineProperty;
16
+ var gOPD = Object.getOwnPropertyDescriptor;
17
+ var isArray = function isArray2(arr) {
18
+ if (typeof Array.isArray === "function") {
19
+ return Array.isArray(arr);
20
+ }
21
+ return toStr.call(arr) === "[object Array]";
22
+ };
23
+ var isPlainObject2 = function isPlainObject3(obj) {
24
+ if (!obj || toStr.call(obj) !== "[object Object]") {
25
+ return false;
26
+ }
27
+ var hasOwnConstructor = hasOwn.call(obj, "constructor");
28
+ var hasIsPrototypeOf = obj.constructor && obj.constructor.prototype && hasOwn.call(obj.constructor.prototype, "isPrototypeOf");
29
+ if (obj.constructor && !hasOwnConstructor && !hasIsPrototypeOf) {
30
+ return false;
31
+ }
32
+ var key;
33
+ for (key in obj) {
34
+ }
35
+ return typeof key === "undefined" || hasOwn.call(obj, key);
36
+ };
37
+ var setProperty = function setProperty2(target, options) {
38
+ if (defineProperty && options.name === "__proto__") {
39
+ defineProperty(target, options.name, {
40
+ enumerable: true,
41
+ configurable: true,
42
+ value: options.newValue,
43
+ writable: true
44
+ });
45
+ } else {
46
+ target[options.name] = options.newValue;
47
+ }
48
+ };
49
+ var getProperty = function getProperty2(obj, name) {
50
+ if (name === "__proto__") {
51
+ if (!hasOwn.call(obj, name)) {
52
+ return void 0;
53
+ } else if (gOPD) {
54
+ return gOPD(obj, name).value;
55
+ }
56
+ }
57
+ return obj[name];
58
+ };
59
+ extend$1 = function extend2() {
60
+ var options, name, src, copy, copyIsArray, clone;
61
+ var target = arguments[0];
62
+ var i = 1;
63
+ var length = arguments.length;
64
+ var deep = false;
65
+ if (typeof target === "boolean") {
66
+ deep = target;
67
+ target = arguments[1] || {};
68
+ i = 2;
69
+ }
70
+ if (target == null || typeof target !== "object" && typeof target !== "function") {
71
+ target = {};
72
+ }
73
+ for (; i < length; ++i) {
74
+ options = arguments[i];
75
+ if (options != null) {
76
+ for (name in options) {
77
+ src = getProperty(target, name);
78
+ copy = getProperty(options, name);
79
+ if (target !== copy) {
80
+ if (deep && copy && (isPlainObject2(copy) || (copyIsArray = isArray(copy)))) {
81
+ if (copyIsArray) {
82
+ copyIsArray = false;
83
+ clone = src && isArray(src) ? src : [];
84
+ } else {
85
+ clone = src && isPlainObject2(src) ? src : {};
86
+ }
87
+ setProperty(target, { name, newValue: extend2(deep, clone, copy) });
88
+ } else if (typeof copy !== "undefined") {
89
+ setProperty(target, { name, newValue: copy });
90
+ }
91
+ }
92
+ }
93
+ }
94
+ }
95
+ return target;
96
+ };
97
+ return extend$1;
98
+ }
99
+ var extendExports = requireExtend();
100
+ const extend = /* @__PURE__ */ getDefaultExportFromCjs(extendExports);
101
+ function isPlainObject(value) {
102
+ if (typeof value !== "object" || value === null) {
103
+ return false;
104
+ }
105
+ const prototype = Object.getPrototypeOf(value);
106
+ return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
107
+ }
108
+ function trough() {
109
+ const fns = [];
110
+ const pipeline = { run, use };
111
+ return pipeline;
112
+ function run(...values) {
113
+ let middlewareIndex = -1;
114
+ const callback = values.pop();
115
+ if (typeof callback !== "function") {
116
+ throw new TypeError("Expected function as last argument, not " + callback);
117
+ }
118
+ next(null, ...values);
119
+ function next(error, ...output) {
120
+ const fn = fns[++middlewareIndex];
121
+ let index = -1;
122
+ if (error) {
123
+ callback(error);
124
+ return;
125
+ }
126
+ while (++index < values.length) {
127
+ if (output[index] === null || output[index] === void 0) {
128
+ output[index] = values[index];
129
+ }
130
+ }
131
+ values = output;
132
+ if (fn) {
133
+ wrap(fn, next)(...output);
134
+ } else {
135
+ callback(null, ...output);
136
+ }
137
+ }
138
+ }
139
+ function use(middelware) {
140
+ if (typeof middelware !== "function") {
141
+ throw new TypeError(
142
+ "Expected `middelware` to be a function, not " + middelware
143
+ );
144
+ }
145
+ fns.push(middelware);
146
+ return pipeline;
147
+ }
148
+ }
149
+ function wrap(middleware, callback) {
150
+ let called;
151
+ return wrapped;
152
+ function wrapped(...parameters) {
153
+ const fnExpectsCallback = middleware.length > parameters.length;
154
+ let result;
155
+ if (fnExpectsCallback) {
156
+ parameters.push(done);
157
+ }
158
+ try {
159
+ result = middleware.apply(this, parameters);
160
+ } catch (error) {
161
+ const exception = (
162
+ /** @type {Error} */
163
+ error
164
+ );
165
+ if (fnExpectsCallback && called) {
166
+ throw exception;
167
+ }
168
+ return done(exception);
169
+ }
170
+ if (!fnExpectsCallback) {
171
+ if (result && result.then && typeof result.then === "function") {
172
+ result.then(then, done);
173
+ } else if (result instanceof Error) {
174
+ done(result);
175
+ } else {
176
+ then(result);
177
+ }
178
+ }
179
+ }
180
+ function done(error, ...output) {
181
+ if (!called) {
182
+ called = true;
183
+ callback(error, ...output);
184
+ }
185
+ }
186
+ function then(value) {
187
+ done(null, value);
188
+ }
189
+ }
190
+ const CallableInstance = (
191
+ /**
192
+ * @type {new <Parameters extends Array<unknown>, Result>(property: string | symbol) => (...parameters: Parameters) => Result}
193
+ */
194
+ /** @type {unknown} */
195
+ /**
196
+ * @this {Function}
197
+ * @param {string | symbol} property
198
+ * @returns {(...parameters: Array<unknown>) => unknown}
199
+ */
200
+ (function(property) {
201
+ const self = this;
202
+ const constr = self.constructor;
203
+ const proto = (
204
+ /** @type {Record<string | symbol, Function>} */
205
+ // Prototypes do exist.
206
+ // type-coverage:ignore-next-line
207
+ constr.prototype
208
+ );
209
+ const value = proto[property];
210
+ const apply = function() {
211
+ return value.apply(apply, arguments);
212
+ };
213
+ Object.setPrototypeOf(apply, proto);
214
+ return apply;
215
+ })
216
+ );
217
+ const own = {}.hasOwnProperty;
218
+ class Processor extends CallableInstance {
219
+ /**
220
+ * Create a processor.
221
+ */
222
+ constructor() {
223
+ super("copy");
224
+ this.Compiler = void 0;
225
+ this.Parser = void 0;
226
+ this.attachers = [];
227
+ this.compiler = void 0;
228
+ this.freezeIndex = -1;
229
+ this.frozen = void 0;
230
+ this.namespace = {};
231
+ this.parser = void 0;
232
+ this.transformers = trough();
233
+ }
234
+ /**
235
+ * Copy a processor.
236
+ *
237
+ * @deprecated
238
+ * This is a private internal method and should not be used.
239
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
240
+ * New *unfrozen* processor ({@linkcode Processor}) that is
241
+ * configured to work the same as its ancestor.
242
+ * When the descendant processor is configured in the future it does not
243
+ * affect the ancestral processor.
244
+ */
245
+ copy() {
246
+ const destination = (
247
+ /** @type {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>} */
248
+ new Processor()
249
+ );
250
+ let index = -1;
251
+ while (++index < this.attachers.length) {
252
+ const attacher = this.attachers[index];
253
+ destination.use(...attacher);
254
+ }
255
+ destination.data(extend(true, {}, this.namespace));
256
+ return destination;
257
+ }
258
+ /**
259
+ * Configure the processor with info available to all plugins.
260
+ * Information is stored in an object.
261
+ *
262
+ * Typically, options can be given to a specific plugin, but sometimes it
263
+ * makes sense to have information shared with several plugins.
264
+ * For example, a list of HTML elements that are self-closing, which is
265
+ * needed during all phases.
266
+ *
267
+ * > **Note**: setting information cannot occur on *frozen* processors.
268
+ * > Call the processor first to create a new unfrozen processor.
269
+ *
270
+ * > **Note**: to register custom data in TypeScript, augment the
271
+ * > {@linkcode Data} interface.
272
+ *
273
+ * @example
274
+ * This example show how to get and set info:
275
+ *
276
+ * ```js
277
+ * import {unified} from 'unified'
278
+ *
279
+ * const processor = unified().data('alpha', 'bravo')
280
+ *
281
+ * processor.data('alpha') // => 'bravo'
282
+ *
283
+ * processor.data() // => {alpha: 'bravo'}
284
+ *
285
+ * processor.data({charlie: 'delta'})
286
+ *
287
+ * processor.data() // => {charlie: 'delta'}
288
+ * ```
289
+ *
290
+ * @template {keyof Data} Key
291
+ *
292
+ * @overload
293
+ * @returns {Data}
294
+ *
295
+ * @overload
296
+ * @param {Data} dataset
297
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
298
+ *
299
+ * @overload
300
+ * @param {Key} key
301
+ * @returns {Data[Key]}
302
+ *
303
+ * @overload
304
+ * @param {Key} key
305
+ * @param {Data[Key]} value
306
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
307
+ *
308
+ * @param {Data | Key} [key]
309
+ * Key to get or set, or entire dataset to set, or nothing to get the
310
+ * entire dataset (optional).
311
+ * @param {Data[Key]} [value]
312
+ * Value to set (optional).
313
+ * @returns {unknown}
314
+ * The current processor when setting, the value at `key` when getting, or
315
+ * the entire dataset when getting without key.
316
+ */
317
+ data(key, value) {
318
+ if (typeof key === "string") {
319
+ if (arguments.length === 2) {
320
+ assertUnfrozen("data", this.frozen);
321
+ this.namespace[key] = value;
322
+ return this;
323
+ }
324
+ return own.call(this.namespace, key) && this.namespace[key] || void 0;
325
+ }
326
+ if (key) {
327
+ assertUnfrozen("data", this.frozen);
328
+ this.namespace = key;
329
+ return this;
330
+ }
331
+ return this.namespace;
332
+ }
333
+ /**
334
+ * Freeze a processor.
335
+ *
336
+ * Frozen processors are meant to be extended and not to be configured
337
+ * directly.
338
+ *
339
+ * When a processor is frozen it cannot be unfrozen.
340
+ * New processors working the same way can be created by calling the
341
+ * processor.
342
+ *
343
+ * It’s possible to freeze processors explicitly by calling `.freeze()`.
344
+ * Processors freeze automatically when `.parse()`, `.run()`, `.runSync()`,
345
+ * `.stringify()`, `.process()`, or `.processSync()` are called.
346
+ *
347
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
348
+ * The current processor.
349
+ */
350
+ freeze() {
351
+ if (this.frozen) {
352
+ return this;
353
+ }
354
+ const self = (
355
+ /** @type {Processor} */
356
+ /** @type {unknown} */
357
+ this
358
+ );
359
+ while (++this.freezeIndex < this.attachers.length) {
360
+ const [attacher, ...options] = this.attachers[this.freezeIndex];
361
+ if (options[0] === false) {
362
+ continue;
363
+ }
364
+ if (options[0] === true) {
365
+ options[0] = void 0;
366
+ }
367
+ const transformer = attacher.call(self, ...options);
368
+ if (typeof transformer === "function") {
369
+ this.transformers.use(transformer);
370
+ }
371
+ }
372
+ this.frozen = true;
373
+ this.freezeIndex = Number.POSITIVE_INFINITY;
374
+ return this;
375
+ }
376
+ /**
377
+ * Parse text to a syntax tree.
378
+ *
379
+ * > **Note**: `parse` freezes the processor if not already *frozen*.
380
+ *
381
+ * > **Note**: `parse` performs the parse phase, not the run phase or other
382
+ * > phases.
383
+ *
384
+ * @param {Compatible | undefined} [file]
385
+ * file to parse (optional); typically `string` or `VFile`; any value
386
+ * accepted as `x` in `new VFile(x)`.
387
+ * @returns {ParseTree extends undefined ? Node : ParseTree}
388
+ * Syntax tree representing `file`.
389
+ */
390
+ parse(file) {
391
+ this.freeze();
392
+ const realFile = vfile(file);
393
+ const parser = this.parser || this.Parser;
394
+ assertParser("parse", parser);
395
+ return parser(String(realFile), realFile);
396
+ }
397
+ /**
398
+ * Process the given file as configured on the processor.
399
+ *
400
+ * > **Note**: `process` freezes the processor if not already *frozen*.
401
+ *
402
+ * > **Note**: `process` performs the parse, run, and stringify phases.
403
+ *
404
+ * @overload
405
+ * @param {Compatible | undefined} file
406
+ * @param {ProcessCallback<VFileWithOutput<CompileResult>>} done
407
+ * @returns {undefined}
408
+ *
409
+ * @overload
410
+ * @param {Compatible | undefined} [file]
411
+ * @returns {Promise<VFileWithOutput<CompileResult>>}
412
+ *
413
+ * @param {Compatible | undefined} [file]
414
+ * File (optional); typically `string` or `VFile`]; any value accepted as
415
+ * `x` in `new VFile(x)`.
416
+ * @param {ProcessCallback<VFileWithOutput<CompileResult>> | undefined} [done]
417
+ * Callback (optional).
418
+ * @returns {Promise<VFile> | undefined}
419
+ * Nothing if `done` is given.
420
+ * Otherwise a promise, rejected with a fatal error or resolved with the
421
+ * processed file.
422
+ *
423
+ * The parsed, transformed, and compiled value is available at
424
+ * `file.value` (see note).
425
+ *
426
+ * > **Note**: unified typically compiles by serializing: most
427
+ * > compilers return `string` (or `Uint8Array`).
428
+ * > Some compilers, such as the one configured with
429
+ * > [`rehype-react`][rehype-react], return other values (in this case, a
430
+ * > React tree).
431
+ * > If you’re using a compiler that doesn’t serialize, expect different
432
+ * > result values.
433
+ * >
434
+ * > To register custom results in TypeScript, add them to
435
+ * > {@linkcode CompileResultMap}.
436
+ *
437
+ * [rehype-react]: https://github.com/rehypejs/rehype-react
438
+ */
439
+ process(file, done) {
440
+ const self = this;
441
+ this.freeze();
442
+ assertParser("process", this.parser || this.Parser);
443
+ assertCompiler("process", this.compiler || this.Compiler);
444
+ return done ? executor(void 0, done) : new Promise(executor);
445
+ function executor(resolve, reject) {
446
+ const realFile = vfile(file);
447
+ const parseTree = (
448
+ /** @type {HeadTree extends undefined ? Node : HeadTree} */
449
+ /** @type {unknown} */
450
+ self.parse(realFile)
451
+ );
452
+ self.run(parseTree, realFile, function(error, tree, file2) {
453
+ if (error || !tree || !file2) {
454
+ return realDone(error);
455
+ }
456
+ const compileTree = (
457
+ /** @type {CompileTree extends undefined ? Node : CompileTree} */
458
+ /** @type {unknown} */
459
+ tree
460
+ );
461
+ const compileResult = self.stringify(compileTree, file2);
462
+ if (looksLikeAValue(compileResult)) {
463
+ file2.value = compileResult;
464
+ } else {
465
+ file2.result = compileResult;
466
+ }
467
+ realDone(
468
+ error,
469
+ /** @type {VFileWithOutput<CompileResult>} */
470
+ file2
471
+ );
472
+ });
473
+ function realDone(error, file2) {
474
+ if (error || !file2) {
475
+ reject(error);
476
+ } else if (resolve) {
477
+ resolve(file2);
478
+ } else {
479
+ done(void 0, file2);
480
+ }
481
+ }
482
+ }
483
+ }
484
+ /**
485
+ * Process the given file as configured on the processor.
486
+ *
487
+ * An error is thrown if asynchronous transforms are configured.
488
+ *
489
+ * > **Note**: `processSync` freezes the processor if not already *frozen*.
490
+ *
491
+ * > **Note**: `processSync` performs the parse, run, and stringify phases.
492
+ *
493
+ * @param {Compatible | undefined} [file]
494
+ * File (optional); typically `string` or `VFile`; any value accepted as
495
+ * `x` in `new VFile(x)`.
496
+ * @returns {VFileWithOutput<CompileResult>}
497
+ * The processed file.
498
+ *
499
+ * The parsed, transformed, and compiled value is available at
500
+ * `file.value` (see note).
501
+ *
502
+ * > **Note**: unified typically compiles by serializing: most
503
+ * > compilers return `string` (or `Uint8Array`).
504
+ * > Some compilers, such as the one configured with
505
+ * > [`rehype-react`][rehype-react], return other values (in this case, a
506
+ * > React tree).
507
+ * > If you’re using a compiler that doesn’t serialize, expect different
508
+ * > result values.
509
+ * >
510
+ * > To register custom results in TypeScript, add them to
511
+ * > {@linkcode CompileResultMap}.
512
+ *
513
+ * [rehype-react]: https://github.com/rehypejs/rehype-react
514
+ */
515
+ processSync(file) {
516
+ let complete = false;
517
+ let result;
518
+ this.freeze();
519
+ assertParser("processSync", this.parser || this.Parser);
520
+ assertCompiler("processSync", this.compiler || this.Compiler);
521
+ this.process(file, realDone);
522
+ assertDone("processSync", "process", complete);
523
+ return result;
524
+ function realDone(error, file2) {
525
+ complete = true;
526
+ bail(error);
527
+ result = file2;
528
+ }
529
+ }
530
+ /**
531
+ * Run *transformers* on a syntax tree.
532
+ *
533
+ * > **Note**: `run` freezes the processor if not already *frozen*.
534
+ *
535
+ * > **Note**: `run` performs the run phase, not other phases.
536
+ *
537
+ * @overload
538
+ * @param {HeadTree extends undefined ? Node : HeadTree} tree
539
+ * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} done
540
+ * @returns {undefined}
541
+ *
542
+ * @overload
543
+ * @param {HeadTree extends undefined ? Node : HeadTree} tree
544
+ * @param {Compatible | undefined} file
545
+ * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} done
546
+ * @returns {undefined}
547
+ *
548
+ * @overload
549
+ * @param {HeadTree extends undefined ? Node : HeadTree} tree
550
+ * @param {Compatible | undefined} [file]
551
+ * @returns {Promise<TailTree extends undefined ? Node : TailTree>}
552
+ *
553
+ * @param {HeadTree extends undefined ? Node : HeadTree} tree
554
+ * Tree to transform and inspect.
555
+ * @param {(
556
+ * RunCallback<TailTree extends undefined ? Node : TailTree> |
557
+ * Compatible
558
+ * )} [file]
559
+ * File associated with `node` (optional); any value accepted as `x` in
560
+ * `new VFile(x)`.
561
+ * @param {RunCallback<TailTree extends undefined ? Node : TailTree>} [done]
562
+ * Callback (optional).
563
+ * @returns {Promise<TailTree extends undefined ? Node : TailTree> | undefined}
564
+ * Nothing if `done` is given.
565
+ * Otherwise, a promise rejected with a fatal error or resolved with the
566
+ * transformed tree.
567
+ */
568
+ run(tree, file, done) {
569
+ assertNode(tree);
570
+ this.freeze();
571
+ const transformers = this.transformers;
572
+ if (!done && typeof file === "function") {
573
+ done = file;
574
+ file = void 0;
575
+ }
576
+ return done ? executor(void 0, done) : new Promise(executor);
577
+ function executor(resolve, reject) {
578
+ const realFile = vfile(file);
579
+ transformers.run(tree, realFile, realDone);
580
+ function realDone(error, outputTree, file2) {
581
+ const resultingTree = (
582
+ /** @type {TailTree extends undefined ? Node : TailTree} */
583
+ outputTree || tree
584
+ );
585
+ if (error) {
586
+ reject(error);
587
+ } else if (resolve) {
588
+ resolve(resultingTree);
589
+ } else {
590
+ done(void 0, resultingTree, file2);
591
+ }
592
+ }
593
+ }
594
+ }
595
+ /**
596
+ * Run *transformers* on a syntax tree.
597
+ *
598
+ * An error is thrown if asynchronous transforms are configured.
599
+ *
600
+ * > **Note**: `runSync` freezes the processor if not already *frozen*.
601
+ *
602
+ * > **Note**: `runSync` performs the run phase, not other phases.
603
+ *
604
+ * @param {HeadTree extends undefined ? Node : HeadTree} tree
605
+ * Tree to transform and inspect.
606
+ * @param {Compatible | undefined} [file]
607
+ * File associated with `node` (optional); any value accepted as `x` in
608
+ * `new VFile(x)`.
609
+ * @returns {TailTree extends undefined ? Node : TailTree}
610
+ * Transformed tree.
611
+ */
612
+ runSync(tree, file) {
613
+ let complete = false;
614
+ let result;
615
+ this.run(tree, file, realDone);
616
+ assertDone("runSync", "run", complete);
617
+ return result;
618
+ function realDone(error, tree2) {
619
+ bail(error);
620
+ result = tree2;
621
+ complete = true;
622
+ }
623
+ }
624
+ /**
625
+ * Compile a syntax tree.
626
+ *
627
+ * > **Note**: `stringify` freezes the processor if not already *frozen*.
628
+ *
629
+ * > **Note**: `stringify` performs the stringify phase, not the run phase
630
+ * > or other phases.
631
+ *
632
+ * @param {CompileTree extends undefined ? Node : CompileTree} tree
633
+ * Tree to compile.
634
+ * @param {Compatible | undefined} [file]
635
+ * File associated with `node` (optional); any value accepted as `x` in
636
+ * `new VFile(x)`.
637
+ * @returns {CompileResult extends undefined ? Value : CompileResult}
638
+ * Textual representation of the tree (see note).
639
+ *
640
+ * > **Note**: unified typically compiles by serializing: most compilers
641
+ * > return `string` (or `Uint8Array`).
642
+ * > Some compilers, such as the one configured with
643
+ * > [`rehype-react`][rehype-react], return other values (in this case, a
644
+ * > React tree).
645
+ * > If you’re using a compiler that doesn’t serialize, expect different
646
+ * > result values.
647
+ * >
648
+ * > To register custom results in TypeScript, add them to
649
+ * > {@linkcode CompileResultMap}.
650
+ *
651
+ * [rehype-react]: https://github.com/rehypejs/rehype-react
652
+ */
653
+ stringify(tree, file) {
654
+ this.freeze();
655
+ const realFile = vfile(file);
656
+ const compiler = this.compiler || this.Compiler;
657
+ assertCompiler("stringify", compiler);
658
+ assertNode(tree);
659
+ return compiler(tree, realFile);
660
+ }
661
+ /**
662
+ * Configure the processor to use a plugin, a list of usable values, or a
663
+ * preset.
664
+ *
665
+ * If the processor is already using a plugin, the previous plugin
666
+ * configuration is changed based on the options that are passed in.
667
+ * In other words, the plugin is not added a second time.
668
+ *
669
+ * > **Note**: `use` cannot be called on *frozen* processors.
670
+ * > Call the processor first to create a new unfrozen processor.
671
+ *
672
+ * @example
673
+ * There are many ways to pass plugins to `.use()`.
674
+ * This example gives an overview:
675
+ *
676
+ * ```js
677
+ * import {unified} from 'unified'
678
+ *
679
+ * unified()
680
+ * // Plugin with options:
681
+ * .use(pluginA, {x: true, y: true})
682
+ * // Passing the same plugin again merges configuration (to `{x: true, y: false, z: true}`):
683
+ * .use(pluginA, {y: false, z: true})
684
+ * // Plugins:
685
+ * .use([pluginB, pluginC])
686
+ * // Two plugins, the second with options:
687
+ * .use([pluginD, [pluginE, {}]])
688
+ * // Preset with plugins and settings:
689
+ * .use({plugins: [pluginF, [pluginG, {}]], settings: {position: false}})
690
+ * // Settings only:
691
+ * .use({settings: {position: false}})
692
+ * ```
693
+ *
694
+ * @template {Array<unknown>} [Parameters=[]]
695
+ * @template {Node | string | undefined} [Input=undefined]
696
+ * @template [Output=Input]
697
+ *
698
+ * @overload
699
+ * @param {Preset | null | undefined} [preset]
700
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
701
+ *
702
+ * @overload
703
+ * @param {PluggableList} list
704
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
705
+ *
706
+ * @overload
707
+ * @param {Plugin<Parameters, Input, Output>} plugin
708
+ * @param {...(Parameters | [boolean])} parameters
709
+ * @returns {UsePlugin<ParseTree, HeadTree, TailTree, CompileTree, CompileResult, Input, Output>}
710
+ *
711
+ * @param {PluggableList | Plugin | Preset | null | undefined} value
712
+ * Usable value.
713
+ * @param {...unknown} parameters
714
+ * Parameters, when a plugin is given as a usable value.
715
+ * @returns {Processor<ParseTree, HeadTree, TailTree, CompileTree, CompileResult>}
716
+ * Current processor.
717
+ */
718
+ use(value, ...parameters) {
719
+ const attachers = this.attachers;
720
+ const namespace = this.namespace;
721
+ assertUnfrozen("use", this.frozen);
722
+ if (value === null || value === void 0) ;
723
+ else if (typeof value === "function") {
724
+ addPlugin(value, parameters);
725
+ } else if (typeof value === "object") {
726
+ if (Array.isArray(value)) {
727
+ addList(value);
728
+ } else {
729
+ addPreset(value);
730
+ }
731
+ } else {
732
+ throw new TypeError("Expected usable value, not `" + value + "`");
733
+ }
734
+ return this;
735
+ function add(value2) {
736
+ if (typeof value2 === "function") {
737
+ addPlugin(value2, []);
738
+ } else if (typeof value2 === "object") {
739
+ if (Array.isArray(value2)) {
740
+ const [plugin, ...parameters2] = (
741
+ /** @type {PluginTuple<Array<unknown>>} */
742
+ value2
743
+ );
744
+ addPlugin(plugin, parameters2);
745
+ } else {
746
+ addPreset(value2);
747
+ }
748
+ } else {
749
+ throw new TypeError("Expected usable value, not `" + value2 + "`");
750
+ }
751
+ }
752
+ function addPreset(result) {
753
+ if (!("plugins" in result) && !("settings" in result)) {
754
+ throw new Error(
755
+ "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"
756
+ );
757
+ }
758
+ addList(result.plugins);
759
+ if (result.settings) {
760
+ namespace.settings = extend(true, namespace.settings, result.settings);
761
+ }
762
+ }
763
+ function addList(plugins) {
764
+ let index = -1;
765
+ if (plugins === null || plugins === void 0) ;
766
+ else if (Array.isArray(plugins)) {
767
+ while (++index < plugins.length) {
768
+ const thing = plugins[index];
769
+ add(thing);
770
+ }
771
+ } else {
772
+ throw new TypeError("Expected a list of plugins, not `" + plugins + "`");
773
+ }
774
+ }
775
+ function addPlugin(plugin, parameters2) {
776
+ let index = -1;
777
+ let entryIndex = -1;
778
+ while (++index < attachers.length) {
779
+ if (attachers[index][0] === plugin) {
780
+ entryIndex = index;
781
+ break;
782
+ }
783
+ }
784
+ if (entryIndex === -1) {
785
+ attachers.push([plugin, ...parameters2]);
786
+ } else if (parameters2.length > 0) {
787
+ let [primary, ...rest] = parameters2;
788
+ const currentPrimary = attachers[entryIndex][1];
789
+ if (isPlainObject(currentPrimary) && isPlainObject(primary)) {
790
+ primary = extend(true, currentPrimary, primary);
791
+ }
792
+ attachers[entryIndex] = [plugin, primary, ...rest];
793
+ }
794
+ }
795
+ }
796
+ }
797
+ const unified = new Processor().freeze();
798
+ function assertParser(name, value) {
799
+ if (typeof value !== "function") {
800
+ throw new TypeError("Cannot `" + name + "` without `parser`");
801
+ }
802
+ }
803
+ function assertCompiler(name, value) {
804
+ if (typeof value !== "function") {
805
+ throw new TypeError("Cannot `" + name + "` without `compiler`");
806
+ }
807
+ }
808
+ function assertUnfrozen(name, frozen) {
809
+ if (frozen) {
810
+ throw new Error(
811
+ "Cannot call `" + name + "` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`."
812
+ );
813
+ }
814
+ }
815
+ function assertNode(node) {
816
+ if (!isPlainObject(node) || typeof node.type !== "string") {
817
+ throw new TypeError("Expected node, got `" + node + "`");
818
+ }
819
+ }
820
+ function assertDone(name, asyncName, complete) {
821
+ if (!complete) {
822
+ throw new Error(
823
+ "`" + name + "` finished async. Use `" + asyncName + "` instead"
824
+ );
825
+ }
826
+ }
827
+ function vfile(value) {
828
+ return looksLikeAVFile(value) ? value : new VFile(value);
829
+ }
830
+ function looksLikeAVFile(value) {
831
+ return Boolean(
832
+ value && typeof value === "object" && "message" in value && "messages" in value
833
+ );
834
+ }
835
+ function looksLikeAValue(value) {
836
+ return typeof value === "string" || isUint8Array(value);
837
+ }
838
+ function isUint8Array(value) {
839
+ return Boolean(
840
+ value && typeof value === "object" && "byteLength" in value && "byteOffset" in value
841
+ );
842
+ }
843
+ export {
844
+ unified
845
+ };