@harbour-enterprises/superdoc 0.28.0 → 0.28.2

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