turnish 1.4.0 → 1.6.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.
package/dist/index.mjs CHANGED
@@ -1,18 +1,489 @@
1
- function H(t, e) {
1
+ class ae extends Error {
2
+ reason;
3
+ filename;
4
+ line;
5
+ column;
6
+ source;
7
+ constructor(e, n, i, r, s) {
8
+ super(`${e}:${i}:${r}: ${n}`), this.reason = n, this.filename = e, this.line = i, this.column = r, this.source = s;
9
+ }
10
+ }
11
+ class ce {
12
+ start;
13
+ end;
14
+ source;
15
+ constructor(e, n, i) {
16
+ this.start = e, this.end = n, this.source = i;
17
+ }
18
+ }
19
+ var f;
20
+ (function(t) {
21
+ t.stylesheet = "stylesheet", t.rule = "rule", t.declaration = "declaration", t.comment = "comment", t.container = "container", t.charset = "charset", t.document = "document", t.customMedia = "custom-media", t.fontFace = "font-face", t.host = "host", t.import = "import", t.keyframes = "keyframes", t.keyframe = "keyframe", t.layer = "layer", t.media = "media", t.namespace = "namespace", t.page = "page", t.startingStyle = "starting-style", t.supports = "supports";
22
+ })(f || (f = {}));
23
+ const U = (t, e, n) => {
24
+ let i = n, r = 1e4;
25
+ do {
26
+ const s = e.map((c) => t.indexOf(c, i));
27
+ s.push(t.indexOf("\\", i));
28
+ const l = s.filter((c) => c !== -1);
29
+ if (l.length === 0) return -1;
30
+ const u = Math.min(...l);
31
+ if (t[u] !== "\\") return u;
32
+ i = u + 2, r--;
33
+ } while (r > 0);
34
+ throw new Error("Too many escaping");
35
+ }, M = (t, e, n) => {
36
+ let i = n, r = 1e4;
37
+ do {
38
+ const s = e.map((c) => t.indexOf(c, i));
39
+ s.push(t.indexOf("(", i)), s.push(t.indexOf('"', i)), s.push(t.indexOf("'", i)), s.push(t.indexOf("\\", i));
40
+ const l = s.filter((c) => c !== -1);
41
+ if (l.length === 0) return -1;
42
+ const u = Math.min(...l);
43
+ switch (t[u]) {
44
+ case "\\":
45
+ i = u + 2;
46
+ break;
47
+ case "(":
48
+ {
49
+ const c = M(t, [")"], u + 1);
50
+ if (c === -1) return -1;
51
+ i = c + 1;
52
+ }
53
+ break;
54
+ case '"':
55
+ {
56
+ const c = U(t, ['"'], u + 1);
57
+ if (c === -1) return -1;
58
+ i = c + 1;
59
+ }
60
+ break;
61
+ case "'":
62
+ {
63
+ const c = U(t, ["'"], u + 1);
64
+ if (c === -1) return -1;
65
+ i = c + 1;
66
+ }
67
+ break;
68
+ default:
69
+ return u;
70
+ }
71
+ r--;
72
+ } while (r > 0);
73
+ throw new Error("Too many escaping");
74
+ }, w = /\/\*[^]*?(?:\*\/|$)/g;
75
+ function T(t) {
76
+ return t ? t.trim() : "";
77
+ }
78
+ function L(t, e) {
79
+ const n = t && typeof t.type == "string", i = n ? t : e;
80
+ for (const r in t) {
81
+ const s = t[r];
82
+ Array.isArray(s) ? s.forEach((l) => {
83
+ L(l, i);
84
+ }) : s && typeof s == "object" && L(s, i);
85
+ }
86
+ return n && Object.defineProperty(t, "parent", { configurable: !0, writable: !0, enumerable: !1, value: e || null }), t;
87
+ }
88
+ class le {
89
+ level = 0;
90
+ indentation = " ";
91
+ compress = !1;
92
+ constructor(e) {
93
+ typeof e?.indent == "string" && (this.indentation = e?.indent), e?.compress && (this.compress = !0);
94
+ }
95
+ emit(e, n) {
96
+ return e;
97
+ }
98
+ indent(e) {
99
+ return this.level = this.level || 1, e ? (this.level += e, "") : Array(this.level).join(this.indentation);
100
+ }
101
+ visit(e) {
102
+ switch (e.type) {
103
+ case f.stylesheet:
104
+ return this.stylesheet(e);
105
+ case f.rule:
106
+ return this.rule(e);
107
+ case f.declaration:
108
+ return this.declaration(e);
109
+ case f.comment:
110
+ return this.comment(e);
111
+ case f.container:
112
+ return this.container(e);
113
+ case f.charset:
114
+ return this.charset(e);
115
+ case f.document:
116
+ return this.document(e);
117
+ case f.customMedia:
118
+ return this.customMedia(e);
119
+ case f.fontFace:
120
+ return this.fontFace(e);
121
+ case f.host:
122
+ return this.host(e);
123
+ case f.import:
124
+ return this.import(e);
125
+ case f.keyframes:
126
+ return this.keyframes(e);
127
+ case f.keyframe:
128
+ return this.keyframe(e);
129
+ case f.layer:
130
+ return this.layer(e);
131
+ case f.media:
132
+ return this.media(e);
133
+ case f.namespace:
134
+ return this.namespace(e);
135
+ case f.page:
136
+ return this.page(e);
137
+ case f.startingStyle:
138
+ return this.startingStyle(e);
139
+ case f.supports:
140
+ return this.supports(e);
141
+ }
142
+ }
143
+ mapVisit(e, n) {
144
+ let i = "";
145
+ n = n || "";
146
+ for (let r = 0, s = e.length; r < s; r++) i += this.visit(e[r]), n && r < s - 1 && (i += this.emit(n));
147
+ return i;
148
+ }
149
+ compile(e) {
150
+ return this.compress ? e.stylesheet.rules.map(this.visit, this).join("") : this.stylesheet(e);
151
+ }
152
+ stylesheet(e) {
153
+ return this.mapVisit(e.stylesheet.rules, `
154
+
155
+ `);
156
+ }
157
+ comment(e) {
158
+ return this.compress ? this.emit("", e.position) : this.emit(`${this.indent()}/*${e.comment}*/`, e.position);
159
+ }
160
+ container(e) {
161
+ return this.compress ? this.emit(`@container ${e.container}`, e.position) + this.emit("{") + this.mapVisit(e.rules) + this.emit("}") : this.emit(`${this.indent()}@container ${e.container}`, e.position) + this.emit(` {
162
+ ${this.indent(1)}`) + this.mapVisit(e.rules, `
163
+
164
+ `) + this.emit(`
165
+ ${this.indent(-1)}${this.indent()}}`);
166
+ }
167
+ layer(e) {
168
+ return this.compress ? this.emit(`@layer ${e.layer}`, e.position) + (e.rules ? this.emit("{") + this.mapVisit(e.rules) + this.emit("}") : ";") : this.emit(`${this.indent()}@layer ${e.layer}`, e.position) + (e.rules ? this.emit(` {
169
+ ${this.indent(1)}`) + this.mapVisit(e.rules, `
170
+
171
+ `) + this.emit(`
172
+ ${this.indent(-1)}${this.indent()}}`) : ";");
173
+ }
174
+ import(e) {
175
+ return this.emit(`@import ${e.import};`, e.position);
176
+ }
177
+ media(e) {
178
+ return this.compress ? this.emit(`@media ${e.media}`, e.position) + this.emit("{") + this.mapVisit(e.rules) + this.emit("}") : this.emit(`${this.indent()}@media ${e.media}`, e.position) + this.emit(` {
179
+ ${this.indent(1)}`) + this.mapVisit(e.rules, `
180
+
181
+ `) + this.emit(`
182
+ ${this.indent(-1)}${this.indent()}}`);
183
+ }
184
+ document(e) {
185
+ const n = `@${e.vendor || ""}document ${e.document}`;
186
+ return this.compress ? this.emit(n, e.position) + this.emit("{") + this.mapVisit(e.rules) + this.emit("}") : this.emit(n, e.position) + this.emit(` {
187
+ ${this.indent(1)}`) + this.mapVisit(e.rules, `
188
+
189
+ `) + this.emit(`${this.indent(-1)}
190
+ }`);
191
+ }
192
+ charset(e) {
193
+ return this.emit(`@charset ${e.charset};`, e.position);
194
+ }
195
+ namespace(e) {
196
+ return this.emit(`@namespace ${e.namespace};`, e.position);
197
+ }
198
+ startingStyle(e) {
199
+ return this.compress ? this.emit("@starting-style", e.position) + this.emit("{") + this.mapVisit(e.rules) + this.emit("}") : this.emit(`${this.indent()}@starting-style`, e.position) + this.emit(` {
200
+ ${this.indent(1)}`) + this.mapVisit(e.rules, `
201
+
202
+ `) + this.emit(`
203
+ ${this.indent(-1)}${this.indent()}}`);
204
+ }
205
+ supports(e) {
206
+ return this.compress ? this.emit(`@supports ${e.supports}`, e.position) + this.emit("{") + this.mapVisit(e.rules) + this.emit("}") : this.emit(`${this.indent()}@supports ${e.supports}`, e.position) + this.emit(` {
207
+ ${this.indent(1)}`) + this.mapVisit(e.rules, `
208
+
209
+ `) + this.emit(`
210
+ ${this.indent(-1)}${this.indent()}}`);
211
+ }
212
+ keyframes(e) {
213
+ return this.compress ? this.emit(`@${e.vendor || ""}keyframes ${e.name}`, e.position) + this.emit("{") + this.mapVisit(e.keyframes) + this.emit("}") : this.emit(`@${e.vendor || ""}keyframes ${e.name}`, e.position) + this.emit(` {
214
+ ${this.indent(1)}`) + this.mapVisit(e.keyframes, `
215
+ `) + this.emit(`${this.indent(-1)}}`);
216
+ }
217
+ keyframe(e) {
218
+ const n = e.declarations;
219
+ return this.compress ? this.emit(e.values.join(","), e.position) + this.emit("{") + this.mapVisit(n) + this.emit("}") : this.emit(this.indent()) + this.emit(e.values.join(", "), e.position) + this.emit(` {
220
+ ${this.indent(1)}`) + this.mapVisit(n, `
221
+ `) + this.emit(`${this.indent(-1)}
222
+ ${this.indent()}}
223
+ `);
224
+ }
225
+ page(e) {
226
+ if (this.compress) {
227
+ const i = e.selectors.length ? e.selectors.join(", ") : "";
228
+ return this.emit(`@page ${i}`, e.position) + this.emit("{") + this.mapVisit(e.declarations) + this.emit("}");
229
+ }
230
+ const n = e.selectors.length ? `${e.selectors.join(", ")} ` : "";
231
+ return this.emit(`@page ${n}`, e.position) + this.emit(`{
232
+ `) + this.emit(this.indent(1)) + this.mapVisit(e.declarations, `
233
+ `) + this.emit(this.indent(-1)) + this.emit(`
234
+ }`);
235
+ }
236
+ fontFace(e) {
237
+ return this.compress ? this.emit("@font-face", e.position) + this.emit("{") + this.mapVisit(e.declarations) + this.emit("}") : this.emit("@font-face ", e.position) + this.emit(`{
238
+ `) + this.emit(this.indent(1)) + this.mapVisit(e.declarations, `
239
+ `) + this.emit(this.indent(-1)) + this.emit(`
240
+ }`);
241
+ }
242
+ host(e) {
243
+ return this.compress ? this.emit("@host", e.position) + this.emit("{") + this.mapVisit(e.rules) + this.emit("}") : this.emit("@host", e.position) + this.emit(` {
244
+ ${this.indent(1)}`) + this.mapVisit(e.rules, `
245
+
246
+ `) + this.emit(`${this.indent(-1)}
247
+ }`);
248
+ }
249
+ customMedia(e) {
250
+ return this.emit(`@custom-media ${e.name} ${e.media};`, e.position);
251
+ }
252
+ rule(e) {
253
+ const n = e.declarations;
254
+ if (!n.length) return "";
255
+ if (this.compress) return this.emit(e.selectors.join(","), e.position) + this.emit("{") + this.mapVisit(n) + this.emit("}");
256
+ const i = this.indent();
257
+ return this.emit(e.selectors.map((r) => i + r).join(`,
258
+ `), e.position) + this.emit(` {
259
+ `) + this.emit(this.indent(1)) + this.mapVisit(n, `
260
+ `) + this.emit(this.indent(-1)) + this.emit(`
261
+ ${this.indent()}}`);
262
+ }
263
+ declaration(e) {
264
+ return this.compress ? this.emit(`${e.property}:${e.value}`, e.position) + this.emit(";") : e.property === "grid-template-areas" ? this.emit(this.indent()) + this.emit(e.property + ": " + e.value.split(`
265
+ `).join(`
266
+ `.padEnd(22) + this.indent()), e.position) + this.emit(";") : this.emit(this.indent()) + this.emit(`${e.property}: ${e.value}`, e.position) + this.emit(";");
267
+ }
268
+ }
269
+ const ue = (t, e) => {
270
+ e = e || {};
271
+ let n = 1, i = 1;
272
+ function r() {
273
+ const a = { line: n, column: i };
274
+ return (o) => (o.position = new ce(a, { line: n, column: i }, e?.source || ""), E(), o);
275
+ }
276
+ const s = [];
277
+ function l(a) {
278
+ const o = new ae(e?.source || "", a, n, i, t);
279
+ if (!e?.silent) throw o;
280
+ s.push(o);
281
+ }
282
+ function u() {
283
+ const a = /^{\s*/.exec(t);
284
+ return !!a && (m(a), !0);
285
+ }
286
+ function c() {
287
+ const a = /^}/.exec(t);
288
+ return !!a && (m(a), !0);
289
+ }
290
+ function g() {
291
+ let a;
292
+ const o = [];
293
+ for (E(), d(o); t.length && t.charAt(0) !== "}" && (a = se() || oe(), a); ) o.push(a), d(o);
294
+ return o;
295
+ }
296
+ function m(a) {
297
+ const o = a[0];
298
+ return (function(h) {
299
+ const p = h.match(/\n/g);
300
+ p && (n += p.length);
301
+ const y = h.lastIndexOf(`
302
+ `);
303
+ i = ~y ? h.length - y : i + h.length;
304
+ })(o), t = t.slice(o.length), a;
305
+ }
306
+ function E() {
307
+ const a = /^\s*/.exec(t);
308
+ a && m(a);
309
+ }
310
+ function d(a) {
311
+ a = a || [];
312
+ let o = $();
313
+ for (; o; ) a.push(o), o = $();
314
+ return a;
315
+ }
316
+ function $() {
317
+ const a = r();
318
+ if (t.charAt(0) !== "/" || t.charAt(1) !== "*") return;
319
+ const o = /^\/\*[^]*?\*\//.exec(t);
320
+ return o ? (m(o), a({ type: f.comment, comment: o[0].slice(2, -2) })) : l("End of comment missing");
321
+ }
322
+ function V() {
323
+ const a = /^([^{]+)/.exec(t);
324
+ if (a)
325
+ return m(a), ((o, h) => {
326
+ const p = [];
327
+ let y = 0;
328
+ for (; y < o.length; ) {
329
+ const k = M(o, h, y);
330
+ if (k === -1) return p.push(o.substring(y)), p;
331
+ p.push(o.substring(y, k)), y = k + 1;
332
+ }
333
+ return p;
334
+ })(T(a[0]).replace(w, ""), [","]).map((o) => T(o));
335
+ }
336
+ function A() {
337
+ const a = r(), o = /^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/.exec(t);
338
+ if (!o) return;
339
+ m(o);
340
+ const h = T(o[0]), p = /^:\s*/.exec(t);
341
+ if (!p) return l("property missing ':'");
342
+ m(p);
343
+ let y = "";
344
+ const k = M(t, [";", "}"]);
345
+ k !== -1 && (y = t.substring(0, k), m([y]), y = T(y).replace(w, ""));
346
+ const R = a({ type: f.declaration, property: h.replace(w, ""), value: y }), _ = /^[;\s]*/.exec(t);
347
+ return _ && m(_), R;
348
+ }
349
+ function H() {
350
+ const a = [];
351
+ if (!u()) return l("missing '{'");
352
+ d(a);
353
+ let o = A();
354
+ for (; o; ) a.push(o), d(a), o = A();
355
+ return c() ? a : l("missing '}'");
356
+ }
357
+ function F() {
358
+ const a = [], o = r();
359
+ let h = /^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/.exec(t);
360
+ for (; h; ) {
361
+ const p = m(h);
362
+ a.push(p[1]);
363
+ const y = /^,\s*/.exec(t);
364
+ y && m(y), h = /^((\d+\.\d+|\.\d+|\d+)%?|[a-z]+)\s*/.exec(t);
365
+ }
366
+ if (a.length) return o({ type: f.keyframe, values: a, declarations: H() || [] });
367
+ }
368
+ const ne = C("import"), ie = C("charset"), re = C("namespace");
369
+ function C(a) {
370
+ const o = new RegExp("^@" + a + `\\s*((?::?[^;'"]|"(?:\\\\"|[^"])*?"|'(?:\\\\'|[^'])*?')+)(?:;|$)`);
371
+ return () => {
372
+ const h = r(), p = o.exec(t);
373
+ if (!p) return;
374
+ const y = m(p), k = { type: a };
375
+ return k[a] = y[1].trim(), h(k);
376
+ };
377
+ }
378
+ function se() {
379
+ if (t[0] === "@") return (function() {
380
+ const a = r(), o = /^@([-\w]+)?keyframes\s*/.exec(t);
381
+ if (!o) return;
382
+ const h = m(o)[1], p = /^([-\w]+)\s*/.exec(t);
383
+ if (!p) return l("@keyframes missing name");
384
+ const y = m(p)[1];
385
+ if (!u()) return l("@keyframes missing '{'");
386
+ let k = d(), R = F();
387
+ for (; R; ) k.push(R), k = k.concat(d()), R = F();
388
+ return c() ? a({ type: f.keyframes, name: y, vendor: h, keyframes: k }) : l("@keyframes missing '}'");
389
+ })() || (function() {
390
+ const a = r(), o = /^@media *([^{]+)/.exec(t);
391
+ if (!o) return;
392
+ const h = T(m(o)[1]);
393
+ if (!u()) return l("@media missing '{'");
394
+ const p = d().concat(g());
395
+ return c() ? a({ type: f.media, media: h, rules: p }) : l("@media missing '}'");
396
+ })() || (function() {
397
+ const a = r(), o = /^@custom-media\s+(--\S+)\s+([^{;\s][^{;]*);/.exec(t);
398
+ if (!o) return;
399
+ const h = m(o);
400
+ return a({ type: f.customMedia, name: T(h[1]), media: T(h[2]) });
401
+ })() || (function() {
402
+ const a = r(), o = /^@supports *([^{]+)/.exec(t);
403
+ if (!o) return;
404
+ const h = T(m(o)[1]);
405
+ if (!u()) return l("@supports missing '{'");
406
+ const p = d().concat(g());
407
+ return c() ? a({ type: f.supports, supports: h, rules: p }) : l("@supports missing '}'");
408
+ })() || ne() || ie() || re() || (function() {
409
+ const a = r(), o = /^@([-\w]+)?document *([^{]+)/.exec(t);
410
+ if (!o) return;
411
+ const h = m(o), p = T(h[1]), y = T(h[2]);
412
+ if (!u()) return l("@document missing '{'");
413
+ const k = d().concat(g());
414
+ return c() ? a({ type: f.document, document: y, vendor: p, rules: k }) : l("@document missing '}'");
415
+ })() || (function() {
416
+ const a = r(), o = /^@page */.exec(t);
417
+ if (!o) return;
418
+ m(o);
419
+ const h = V() || [];
420
+ if (!u()) return l("@page missing '{'");
421
+ let p = d(), y = A();
422
+ for (; y; ) p.push(y), p = p.concat(d()), y = A();
423
+ return c() ? a({ type: f.page, selectors: h, declarations: p }) : l("@page missing '}'");
424
+ })() || (function() {
425
+ const a = r(), o = /^@host\s*/.exec(t);
426
+ if (!o) return;
427
+ if (m(o), !u()) return l("@host missing '{'");
428
+ const h = d().concat(g());
429
+ return c() ? a({ type: f.host, rules: h }) : l("@host missing '}'");
430
+ })() || (function() {
431
+ const a = r(), o = /^@font-face\s*/.exec(t);
432
+ if (!o) return;
433
+ if (m(o), !u()) return l("@font-face missing '{'");
434
+ let h = d(), p = A();
435
+ for (; p; ) h.push(p), h = h.concat(d()), p = A();
436
+ return c() ? a({ type: f.fontFace, declarations: h }) : l("@font-face missing '}'");
437
+ })() || (function() {
438
+ const a = r(), o = /^@container *([^{]+)/.exec(t);
439
+ if (!o) return;
440
+ const h = T(m(o)[1]);
441
+ if (!u()) return l("@container missing '{'");
442
+ const p = d().concat(g());
443
+ return c() ? a({ type: f.container, container: h, rules: p }) : l("@container missing '}'");
444
+ })() || (function() {
445
+ const a = r(), o = /^@starting-style\s*/.exec(t);
446
+ if (!o) return;
447
+ if (m(o), !u()) return l("@starting-style missing '{'");
448
+ const h = d().concat(g());
449
+ return c() ? a({ type: f.startingStyle, rules: h }) : l("@starting-style missing '}'");
450
+ })() || (function() {
451
+ const a = r(), o = /^@layer *([^{;@]+)/.exec(t);
452
+ if (!o) return;
453
+ const h = T(m(o)[1]);
454
+ if (!u()) {
455
+ const y = /^[;\s]*/.exec(t);
456
+ return y && m(y), a({ type: f.layer, layer: h });
457
+ }
458
+ const p = d().concat(g());
459
+ return c() ? a({ type: f.layer, layer: h, rules: p }) : l("@layer missing '}'");
460
+ })();
461
+ }
462
+ function oe() {
463
+ const a = r(), o = V();
464
+ return o ? (d(), a({ type: f.rule, selectors: o, declarations: H() || [] })) : l("selector missing");
465
+ }
466
+ return L((function() {
467
+ const a = g();
468
+ return { type: f.stylesheet, stylesheet: { source: e?.source, rules: a, parsingErrors: s } };
469
+ })());
470
+ }, me = (t, e) => new le(e || {}).compile(t);
471
+ var he = { parse: ue, stringify: me };
472
+ function fe(t, e) {
2
473
  const n = t;
3
- return n.isBlock = E(n), n.isCode = n.nodeName === "CODE" || n.parentNode?.isCode, n.isBlank = v(n), n.flankingWhitespace = _(n, e), n;
474
+ return n.isBlock = B(n), n.isCode = n.nodeName === "CODE" || n.parentNode?.isCode, n.isBlank = pe(n), n.flankingWhitespace = de(n, e), n;
4
475
  }
5
- function v(t) {
6
- return !L(t) && !V(t) && /^\s*$/i.test(t.textContent || "") && !U(t) && !W(t);
476
+ function pe(t) {
477
+ return !X(t) && !Ee(t) && /^\s*$/i.test(t.textContent || "") && !ke(t) && !Te(t);
7
478
  }
8
- function _(t, e) {
479
+ function de(t, e) {
9
480
  const n = t;
10
481
  if (n.isBlock || e.preformattedCode && n.isCode)
11
482
  return { leading: "", trailing: "" };
12
- const r = $(t.textContent || "");
13
- return r.leadingAscii && b("left", t, e) && (r.leading = r.leadingNonAscii), r.trailingAscii && b("right", t, e) && (r.trailing = r.trailingNonAscii), { leading: r.leading, trailing: r.trailing };
483
+ const i = ge(t.textContent || "");
484
+ return i.leadingAscii && j("left", t, e) && (i.leading = i.leadingNonAscii), i.trailingAscii && j("right", t, e) && (i.trailing = i.trailingNonAscii), { leading: i.leading, trailing: i.trailing };
14
485
  }
15
- function $(t) {
486
+ function ge(t) {
16
487
  const e = t.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/);
17
488
  return e ? {
18
489
  leading: e[1],
@@ -32,31 +503,31 @@ function $(t) {
32
503
  trailingAscii: ""
33
504
  };
34
505
  }
35
- function b(t, e, n) {
36
- let r, i, l;
37
- return t === "left" ? (r = e.previousSibling, i = / $/) : (r = e.nextSibling, i = /^ /), r && (r.nodeType === 3 ? l = i.test(r.nodeValue || "") : n.preformattedCode && r.nodeName === "CODE" ? l = !1 : r.nodeType === 1 && !E(r) && (l = i.test(r.textContent || ""))), l || !1;
506
+ function j(t, e, n) {
507
+ let i, r, s;
508
+ return t === "left" ? (i = e.previousSibling, r = / $/) : (i = e.nextSibling, r = /^ /), i && (i.nodeType === 3 ? s = r.test(i.nodeValue || "") : n.preformattedCode && i.nodeName === "CODE" ? s = !1 : i.nodeType === 1 && !B(i) && (s = r.test(i.textContent || ""))), s || !1;
38
509
  }
39
- const p = {
510
+ const x = {
40
511
  Element: 1,
41
512
  Text: 3,
42
513
  CDATASection: 4
43
514
  };
44
- function T(t, e) {
515
+ function v(t, e) {
45
516
  return Array(e + 1).join(t);
46
517
  }
47
- function I(t) {
518
+ function K(t) {
48
519
  return t.replace(/^\n*/, "");
49
520
  }
50
- function O(t) {
521
+ function Y(t) {
51
522
  let e = t.length;
52
523
  for (; e > 0 && t[e - 1] === `
53
524
  `; ) e--;
54
525
  return t.substring(0, e);
55
526
  }
56
- function w(t) {
57
- return O(I(t));
527
+ function q(t) {
528
+ return Y(K(t));
58
529
  }
59
- const F = [
530
+ const ye = [
60
531
  "ADDRESS",
61
532
  "ARTICLE",
62
533
  "ASIDE",
@@ -107,10 +578,10 @@ const F = [
107
578
  "TR",
108
579
  "UL"
109
580
  ];
110
- function E(t) {
111
- return A(t, F);
581
+ function B(t) {
582
+ return P(t, ye);
112
583
  }
113
- const D = [
584
+ const Q = [
114
585
  "AREA",
115
586
  "BASE",
116
587
  "BR",
@@ -128,13 +599,13 @@ const D = [
128
599
  "TRACK",
129
600
  "WBR"
130
601
  ];
131
- function L(t) {
132
- return A(t, D);
602
+ function X(t) {
603
+ return P(t, Q);
133
604
  }
134
- function U(t) {
135
- return B(t, D);
605
+ function ke(t) {
606
+ return Z(t, Q);
136
607
  }
137
- const M = [
608
+ const J = [
138
609
  "A",
139
610
  "TABLE",
140
611
  "THEAD",
@@ -146,7 +617,7 @@ const M = [
146
617
  "SCRIPT",
147
618
  "AUDIO",
148
619
  "VIDEO"
149
- ], z = [
620
+ ], Ne = [
150
621
  "P",
151
622
  "BR",
152
623
  "H1",
@@ -177,32 +648,54 @@ const M = [
177
648
  "TH",
178
649
  "TD"
179
650
  ];
180
- function V(t) {
181
- return A(t, M);
651
+ function Ee(t) {
652
+ return P(t, J);
182
653
  }
183
- function W(t) {
184
- return B(t, M);
654
+ function Te(t) {
655
+ return Z(t, J);
185
656
  }
186
- function A(t, e) {
657
+ function P(t, e) {
187
658
  return e.indexOf(t.nodeName) >= 0;
188
659
  }
189
- function B(t, e) {
660
+ function Z(t, e) {
190
661
  return e.some(function(n) {
191
- return t.nodeType !== p.Element ? !1 : t.getElementsByTagName(n).length;
662
+ return t.nodeType !== x.Element ? !1 : t.getElementsByTagName(n).length;
192
663
  });
193
664
  }
194
- function P(t) {
665
+ function ee(t) {
195
666
  return t ? t.replace(/(\n+\s*)+/g, `
196
667
  `) : "";
197
668
  }
198
- function G(t) {
199
- return P(t).replace(/[\t\r\n]+/g, " ").replace(/ {2,}/g, " ").trim();
669
+ function xe(t) {
670
+ return ee(t).replace(/[\t\r\n]+/g, " ").replace(/ {2,}/g, " ").trim();
671
+ }
672
+ function b(t) {
673
+ return ee(t).replace(/[\t\r\n]+/g, " ");
674
+ }
675
+ function $e(t) {
676
+ const e = t.parentNode;
677
+ return e ? e.nodeType === x.Element && e.classList && e.classList.contains("code") && e.nodeName === "TD" && t.nodeName === "PRE" : !1;
200
678
  }
201
- function h(t) {
202
- return P(t).replace(/[\t\r\n]+/g, " ");
679
+ function Ae(t) {
680
+ if (t.nodeName !== "PRE" || t.nodeType !== x.Element)
681
+ return !1;
682
+ const e = t.getAttribute("style");
683
+ if (!e)
684
+ return !1;
685
+ const n = he.parse("pre {" + e + "}");
686
+ if (!n.stylesheet.rules.length)
687
+ return !1;
688
+ const i = n.stylesheet.rules[0];
689
+ if (!("declarations" in i) || !i.declarations)
690
+ return !1;
691
+ const r = i.declarations.find((l) => "property" in l ? l.property.toLowerCase() === "font-family" : !1);
692
+ return !r || "value" in r && !r.value ? !1 : "value" in r && r.value.split(",").map((l) => l.trim().toLowerCase()).indexOf("monospace") >= 0;
203
693
  }
204
- const f = {};
205
- f.paragraph = {
694
+ function te(t) {
695
+ return $e(t) || Ae(t) ? !0 : t.nodeName === "PRE" && t.firstChild && t.firstChild.nodeName === "CODE" || !1;
696
+ }
697
+ const N = {};
698
+ N.paragraph = {
206
699
  filter: "p",
207
700
  replacement: function(t) {
208
701
  return `
@@ -212,44 +705,44 @@ f.paragraph = {
212
705
  `;
213
706
  }
214
707
  };
215
- f.lineBreak = {
708
+ N.lineBreak = {
216
709
  filter: "br",
217
710
  replacement: function(t, e, n) {
218
711
  return n.br + `
219
712
  `;
220
713
  }
221
714
  };
222
- f.heading = {
715
+ N.heading = {
223
716
  filter: ["h1", "h2", "h3", "h4", "h5", "h6"],
224
717
  replacement: function(t, e, n) {
225
- const r = Number(e.nodeName.charAt(1));
226
- if (n.headingStyle === "setext" && r < 3) {
227
- const i = T(r === 1 ? "=" : "-", t.length);
718
+ const i = Number(e.nodeName.charAt(1));
719
+ if (n.headingStyle === "setext" && i < 3) {
720
+ const r = v(i === 1 ? "=" : "-", t.length);
228
721
  return `
229
722
 
230
723
  ` + t + `
231
- ` + i + `
724
+ ` + r + `
232
725
 
233
726
  `;
234
727
  } else
235
728
  return `
236
729
 
237
- ` + T("#", r) + " " + t + `
730
+ ` + v("#", i) + " " + t + `
238
731
 
239
732
  `;
240
733
  }
241
734
  };
242
- f.blockquote = {
735
+ N.blockquote = {
243
736
  filter: "blockquote",
244
737
  replacement: function(t) {
245
- return t = w(t).replace(/^/gm, "> "), `
738
+ return t = q(t).replace(/^/gm, "> "), `
246
739
 
247
740
  ` + t + `
248
741
 
249
742
  `;
250
743
  }
251
744
  };
252
- f.list = {
745
+ N.list = {
253
746
  filter: ["ul", "ol"],
254
747
  replacement: function(t, e) {
255
748
  const n = e.parentNode;
@@ -261,36 +754,36 @@ f.list = {
261
754
  `;
262
755
  }
263
756
  };
264
- f.listItem = {
757
+ N.listItem = {
265
758
  filter: "li",
266
759
  replacement: function(t, e, n) {
267
- let r = n.bulletListMarker + " ".repeat(n.listMarkerSpaceCount);
268
- const i = e.parentNode;
269
- if (i.nodeName === "OL") {
270
- const m = i.getAttribute("start"), y = Array.prototype.indexOf.call(i.children, e);
271
- r = (m ? Number(m) + y : y + 1) + "." + " ".repeat(n.listMarkerSpaceCount);
760
+ let i = n.bulletListMarker + " ".repeat(n.listMarkerSpaceCount);
761
+ const r = e.parentNode;
762
+ if (r.nodeName === "OL") {
763
+ const d = r.getAttribute("start"), $ = Array.prototype.indexOf.call(r.children, e);
764
+ i = (d ? Number(d) + $ : $ + 1) + "." + " ".repeat(n.listMarkerSpaceCount);
272
765
  }
273
- const l = /\n$/.test(t);
274
- if (t = w(t) + (l ? `
275
- ` : ""), e.childNodes.length > 0 && Array.from(e.childNodes).every((m) => m.nodeType === p.Text && /^\s*$/.test(m.nodeValue || "") || m.nodeType === p.Element && ["UL", "OL"].includes(m.nodeName)) && t.trim() !== "")
766
+ const s = /\n$/.test(t);
767
+ if (t = q(t) + (s ? `
768
+ ` : ""), e.childNodes.length > 0 && Array.from(e.childNodes).every((d) => d.nodeType === x.Text && /^\s*$/.test(d.nodeValue || "") || d.nodeType === x.Element && ["UL", "OL"].includes(d.nodeName)) && t.trim() !== "")
276
769
  return t + (e.nextSibling ? `
277
770
  ` : "");
278
- let a = 0, s = i;
279
- for (; s; ) {
280
- if (s.nodeName === "UL" || s.nodeName === "OL") {
281
- const m = s.parentNode;
282
- m && m.nodeName === "LI" && a++;
771
+ let u = 0, c = r;
772
+ for (; c; ) {
773
+ if (c.nodeName === "UL" || c.nodeName === "OL") {
774
+ const d = c.parentNode;
775
+ d && d.nodeName === "LI" && u++;
283
776
  }
284
- s = s.parentNode;
777
+ c = c.parentNode;
285
778
  }
286
- let c = n.listItemIndent === "tab" ? " " : " ".repeat(n.listItemIndentSpaceCount), u = c.repeat(a);
287
- const d = /\n(?!\s*(?:\d+\.\s|[-+*]\s))/gm;
288
- return t = t.replace(d, `
289
- ` + c), u + r + t + (e.nextSibling ? `
779
+ let g = n.listItemIndent === "tab" ? " " : " ".repeat(n.listItemIndentSpaceCount), m = g.repeat(u);
780
+ const E = /\n(?!\s*(?:\d+\.\s|[-+*]\s))/gm;
781
+ return t = t.replace(E, `
782
+ ` + g), m + i + t + (e.nextSibling ? `
290
783
  ` : "");
291
784
  }
292
785
  };
293
- f.indentedCodeBlock = {
786
+ N.indentedCodeBlock = {
294
787
  filter: function(t, e) {
295
788
  return !!(e && e.codeBlockStyle === "indented" && t.nodeName === "PRE" && t.firstChild && t.firstChild.nodeName === "CODE");
296
789
  },
@@ -303,30 +796,28 @@ f.indentedCodeBlock = {
303
796
  `;
304
797
  }
305
798
  };
306
- f.fencedCodeBlock = {
799
+ N.fencedCodeBlock = {
307
800
  filter: function(t, e) {
308
- return !!(e && e.codeBlockStyle === "fenced" && t.nodeName === "PRE" && t.firstChild && t.firstChild.nodeName === "CODE");
801
+ return !!(e && e.codeBlockStyle === "fenced" && t.nodeName === "PRE");
309
802
  },
310
803
  replacement: function(t, e, n) {
311
- if (!e.firstChild)
312
- return "";
313
- const r = e.firstChild, l = ((r.getAttribute("class") || "").match(/language-(\S+)/) || [null, ""])[1], o = r.textContent || "", a = n.fence?.charAt(0) || "`";
314
- let s = 3;
315
- const c = new RegExp("^" + a + "{3,}", "gm");
316
- let u;
317
- for (; u = c.exec(o); )
318
- u[0].length >= s && (s = u[0].length + 1);
319
- const d = T(a, s);
804
+ const i = e, r = i.firstChild, s = r && r.nodeName === "CODE" ? r : i, u = ((s.getAttribute("class") || "").match(/(?:lang|language)-(\S+)/) || [null, ""])[1], c = s.textContent || "", g = n.fence?.charAt(0) || "`";
805
+ let m = 3;
806
+ const E = new RegExp("^" + g + "{3,}", "gm");
807
+ let d;
808
+ for (; d = E.exec(c); )
809
+ d[0].length >= m && (m = d[0].length + 1);
810
+ const $ = v(g, m);
320
811
  return `
321
812
 
322
- ` + d + l + `
323
- ` + o.replace(/\n$/, "") + `
324
- ` + d + `
813
+ ` + $ + u + `
814
+ ` + c.replace(/\n$/, "") + `
815
+ ` + $ + `
325
816
 
326
817
  `;
327
818
  }
328
819
  };
329
- f.horizontalRule = {
820
+ N.horizontalRule = {
330
821
  filter: "hr",
331
822
  replacement: function(t, e, n) {
332
823
  return `
@@ -336,48 +827,48 @@ f.horizontalRule = {
336
827
  `;
337
828
  }
338
829
  };
339
- f.inlineLink = {
830
+ N.inlineLink = {
340
831
  filter: function(t, e) {
341
832
  return !!(e?.linkStyle === "inlined" && t.nodeName === "A" && t.getAttribute("href"));
342
833
  },
343
834
  replacement: function(t, e) {
344
- const n = G(t);
345
- let r = e.getAttribute("href")?.replace(/([()])/g, "\\$1"), i;
346
- const l = e.getAttribute("title");
347
- return l ? i = ' "' + h(l).replace(/"/g, '\\"') + '"' : i = "", "[" + n + "](" + r + i + ")";
835
+ const n = xe(t);
836
+ let i = e.getAttribute("href")?.replace(/([()])/g, "\\$1"), r;
837
+ const s = e.getAttribute("title");
838
+ return s ? r = ' "' + b(s).replace(/"/g, '\\"') + '"' : r = "", "[" + n + "](" + i + r + ")";
348
839
  }
349
840
  };
350
- const k = {
841
+ const D = {
351
842
  filter: function(t, e) {
352
843
  return !!(e && e.linkStyle === "referenced" && t.nodeName === "A" && t.getAttribute("href"));
353
844
  },
354
845
  replacement: function(t, e, n) {
355
- const r = k, i = e.getAttribute("href");
356
- let l;
357
- const o = e.getAttribute("title");
358
- o ? l = ' "' + h(o) + '"' : l = "";
359
- const a = i + l;
360
- let s, c;
846
+ const i = D, r = e.getAttribute("href");
847
+ let s;
848
+ const l = e.getAttribute("title");
849
+ l ? s = ' "' + b(l) + '"' : s = "";
850
+ const u = r + s;
851
+ let c, g;
361
852
  switch (n.linkReferenceStyle) {
362
853
  case "collapsed":
363
- s = "[" + t + "][]", c = "[" + t + "]: " + a;
854
+ c = "[" + t + "][]", g = "[" + t + "]: " + u;
364
855
  break;
365
856
  case "shortcut":
366
- s = "[" + t + "]", c = "[" + t + "]: " + a;
857
+ c = "[" + t + "]", g = "[" + t + "]: " + u;
367
858
  break;
368
859
  default: {
369
- let u;
370
- const d = r.urlReferenceIdMap.get(a);
371
- n.linkReferenceDeduplication === "full" && d ? (u = d, c = "[" + u + "]: " + i + l) : (u = r.references.length + 1, r.urlReferenceIdMap.set(a, u), c = "[" + u + "]: " + i + l, r.references.push(c)), s = "[" + t + "][" + u + "]";
860
+ let m;
861
+ const E = i.urlReferenceIdMap.get(u);
862
+ n.linkReferenceDeduplication === "full" && E ? (m = E, g = "[" + m + "]: " + r + s) : (m = i.references.length + 1, i.urlReferenceIdMap.set(u, m), g = "[" + m + "]: " + r + s, i.references.push(g)), c = "[" + t + "][" + m + "]";
372
863
  break;
373
864
  }
374
865
  }
375
- return n.linkReferenceStyle !== "full" && (n.linkReferenceDeduplication === "full" ? r.urlReferenceIdMap.has(a) || (r.urlReferenceIdMap.set(a, 1), r.references.push(c)) : r.references.push(c)), s;
866
+ return n.linkReferenceStyle !== "full" && (n.linkReferenceDeduplication === "full" ? i.urlReferenceIdMap.has(u) || (i.urlReferenceIdMap.set(u, 1), i.references.push(g)) : i.references.push(g)), c;
376
867
  },
377
868
  references: [],
378
869
  urlReferenceIdMap: /* @__PURE__ */ new Map(),
379
870
  append: () => {
380
- const t = k;
871
+ const t = D;
381
872
  let e = "";
382
873
  return t.references && t.references.length && (e = `
383
874
 
@@ -387,36 +878,36 @@ const k = {
387
878
  `, t.references = [], t.urlReferenceIdMap = /* @__PURE__ */ new Map()), e;
388
879
  }
389
880
  };
390
- f.referenceLink = k;
391
- f.emphasis = {
881
+ N.referenceLink = D;
882
+ N.emphasis = {
392
883
  filter: ["em", "i"],
393
884
  replacement: (t, e, n) => (t = t.trim(), t ? n.emDelimiter + t + n.emDelimiter : "")
394
885
  };
395
- f.strong = {
886
+ N.strong = {
396
887
  filter: ["strong", "b"],
397
888
  replacement: (t, e, n) => (t = t.trim(), t ? n.strongDelimiter + t + n.strongDelimiter : "")
398
889
  };
399
- f.code = {
890
+ N.code = {
400
891
  filter: (t) => {
401
- const e = t.previousSibling || t.nextSibling, r = t.parentNode.nodeName === "PRE" && !e;
402
- return t.nodeName === "CODE" && !r;
892
+ const e = t.parentNode, n = te(e);
893
+ return t.nodeName === "CODE" && !n;
403
894
  },
404
895
  replacement: (t) => {
405
896
  const e = t.replace(/\r?\n|\r/g, " "), n = /^`|^ .*?[^ ].* $|`$/.test(e) ? " " : "";
406
- let r = "`";
407
- const i = e.match(/`+/gm) || [];
408
- for (; i.includes(r); ) r = r + "`";
409
- return r + n + e + n + r;
897
+ let i = "`";
898
+ const r = e.match(/`+/gm) || [];
899
+ for (; r.includes(i); ) i = i + "`";
900
+ return i + n + e + n + i;
410
901
  }
411
902
  };
412
- f.image = {
903
+ N.image = {
413
904
  filter: "img",
414
905
  replacement: function(t, e) {
415
- const n = e.getAttribute("alt"), r = n ? h(n) : "", i = e.getAttribute("src") || "", l = e.getAttribute("title"), o = l ? h(l) : "", a = o ? ' "' + o + '"' : "";
416
- return i ? "![" + r + "](" + i + a + ")" : "";
906
+ const n = e.getAttribute("alt"), i = n ? b(n) : "", r = e.getAttribute("src") || "", s = e.getAttribute("title"), l = s ? b(s) : "", u = l ? ' "' + l + '"' : "";
907
+ return r ? "![" + i + "](" + r + u + ")" : "";
417
908
  }
418
909
  };
419
- class K {
910
+ class Re {
420
911
  options;
421
912
  _keep;
422
913
  _remove;
@@ -463,110 +954,110 @@ class K {
463
954
  replacement: this.markdownIncludingHtmlReplacement
464
955
  };
465
956
  let n;
466
- return (n = g(this.array, e, this.options)) || (n = g(this._keep, e, this.options)) || (n = g(this._remove, e, this.options)) ? n : this.defaultRule;
957
+ return (n = O(this.array, e, this.options)) || (n = O(this._keep, e, this.options)) || (n = O(this._remove, e, this.options)) ? n : this.defaultRule;
467
958
  }
468
959
  /// Check if an element is unsupported for Markdown conversion.
469
960
  isUnsupportedElement(e) {
470
961
  const n = e.nodeName;
471
962
  if (n === "PRE" && e.firstChild && e.firstChild.nodeName === "CODE") {
472
- const r = e.firstChild;
473
- if (r.attributes && r.attributes.length > 0) {
474
- for (let i = 0; i < r.attributes.length; i++)
475
- if (r.attributes[i].name.toLowerCase() !== "class")
963
+ const i = e.firstChild;
964
+ if (i.attributes && i.attributes.length > 0) {
965
+ for (let r = 0; r < i.attributes.length; r++)
966
+ if (i.attributes[r].name.toLowerCase() !== "class")
476
967
  return !0;
477
968
  }
478
969
  }
479
970
  if (e.attributes && e.attributes.length > 0)
480
971
  switch (n) {
481
972
  case "IMG":
482
- for (let i = 0; i < e.attributes.length; i++) {
483
- const l = e.attributes[i].name.toLowerCase();
484
- if (l !== "src" && l !== "alt" && l !== "title")
973
+ for (let r = 0; r < e.attributes.length; r++) {
974
+ const s = e.attributes[r].name.toLowerCase();
975
+ if (s !== "src" && s !== "alt" && s !== "title")
485
976
  return !0;
486
977
  }
487
978
  return !1;
488
979
  case "A":
489
- for (let i = 0; i < e.attributes.length; i++) {
490
- const l = e.attributes[i].name.toLowerCase();
491
- if (l !== "href" && l !== "title")
980
+ for (let r = 0; r < e.attributes.length; r++) {
981
+ const s = e.attributes[r].name.toLowerCase();
982
+ if (s !== "href" && s !== "title")
492
983
  return !0;
493
984
  }
494
985
  return !1;
495
986
  case "CODE":
496
- const r = e.parentNode;
497
- if (r && r.nodeName === "PRE") {
498
- for (let i = 0; i < e.attributes.length; i++)
499
- if (e.attributes[i].name.toLowerCase() !== "class")
987
+ const i = e.parentNode;
988
+ if (i && i.nodeName === "PRE") {
989
+ for (let r = 0; r < e.attributes.length; r++)
990
+ if (e.attributes[r].name.toLowerCase() !== "class")
500
991
  return !0;
501
992
  return !1;
502
993
  }
503
994
  default:
504
995
  return !0;
505
996
  }
506
- return z.indexOf(n) === -1;
997
+ return Ne.indexOf(n) === -1;
507
998
  }
508
999
  forEach(e) {
509
1000
  for (let n = 0; n < this.array.length; n++)
510
1001
  e(this.array[n], n);
511
1002
  }
512
1003
  }
513
- function g(t, e, n) {
514
- for (let r = 0; r < t.length; r++) {
515
- const i = t[r];
516
- if (j(i, e, n)) return i;
1004
+ function O(t, e, n) {
1005
+ for (let i = 0; i < t.length; i++) {
1006
+ const r = t[i];
1007
+ if (be(r, e, n)) return r;
517
1008
  }
518
1009
  }
519
- function j(t, e, n) {
520
- const r = t.filter;
521
- if (typeof r == "string") {
522
- if (r === e.nodeName.toLowerCase())
1010
+ function be(t, e, n) {
1011
+ const i = t.filter;
1012
+ if (typeof i == "string") {
1013
+ if (i === e.nodeName.toLowerCase())
523
1014
  return !0;
524
- } else if (Array.isArray(r)) {
525
- if (r.indexOf(e.nodeName.toLowerCase()) > -1)
1015
+ } else if (Array.isArray(i)) {
1016
+ if (i.indexOf(e.nodeName.toLowerCase()) > -1)
526
1017
  return !0;
527
- } else if (typeof r == "function") {
528
- if (r(e, n))
1018
+ } else if (typeof i == "function") {
1019
+ if (i(e, n))
529
1020
  return !0;
530
1021
  } else
531
1022
  throw new TypeError("`filter` needs to be a string, array, or function");
532
1023
  return !1;
533
1024
  }
534
- function Y(t) {
535
- const e = t.element, n = t.isBlock, r = t.isVoid, i = t.isPre || function(c) {
536
- return c.nodeName === "PRE";
1025
+ function Ce(t) {
1026
+ const e = t.element, n = t.isBlock, i = t.isVoid, r = t.isPre || function(g) {
1027
+ return g.nodeName === "PRE";
537
1028
  };
538
- if (!e.firstChild || i(e)) return;
539
- let l = null, o = !1, a = null, s = C(a, e, i);
540
- for (; s !== e; ) {
541
- if (s.nodeType === p.Text || s.nodeType === p.CDATASection) {
542
- const u = s;
543
- let d = u.data.replace(/[ \r\n\t]+/g, " ");
544
- if ((!l || / $/.test(l.data)) && !o && d[0] === " " && (d = d.substr(1)), !d) {
545
- s = N(s);
1029
+ if (!e.firstChild || r(e)) return;
1030
+ let s = null, l = !1, u = null, c = z(u, e, r);
1031
+ for (; c !== e; ) {
1032
+ if (c.nodeType === x.Text || c.nodeType === x.CDATASection) {
1033
+ const m = c;
1034
+ let E = m.data.replace(/[ \r\n\t]+/g, " ");
1035
+ if ((!s || / $/.test(s.data)) && !l && E[0] === " " && (E = E.substr(1)), !E) {
1036
+ c = S(c);
546
1037
  continue;
547
1038
  }
548
- u.data = d, l = u;
549
- } else if (s.nodeType === p.Element)
550
- n(s) || s.nodeName === "BR" ? (l && (l.data = l.data.replace(/ $/, "")), l = null, o = !1) : r(s) || i(s) ? (l = null, o = !0) : l && (o = !1);
1039
+ m.data = E, s = m;
1040
+ } else if (c.nodeType === x.Element)
1041
+ n(c) || c.nodeName === "BR" ? (s && (s.data = s.data.replace(/ $/, "")), s = null, l = !1) : i(c) || r(c) ? (s = null, l = !0) : s && (l = !1);
551
1042
  else {
552
- s = N(s);
1043
+ c = S(c);
553
1044
  continue;
554
1045
  }
555
- const c = C(a, s, i);
556
- a = s, s = c;
1046
+ const g = z(u, c, r);
1047
+ u = c, c = g;
557
1048
  }
558
- l && (l.data = l.data.replace(/ $/, ""), l.data || N(l));
1049
+ s && (s.data = s.data.replace(/ $/, ""), s.data || S(s));
559
1050
  }
560
- function N(t) {
1051
+ function S(t) {
561
1052
  const e = t.nextSibling ?? t.parentNode;
562
1053
  return t.parentNode && t.parentNode.removeChild(t), e;
563
1054
  }
564
- function C(t, e, n) {
1055
+ function z(t, e, n) {
565
1056
  return t && t.parentNode === e || n(e) ? e.nextSibling ?? e.parentNode : e.firstChild ?? e.nextSibling ?? e.parentNode;
566
1057
  }
567
- const R = typeof window < "u" ? window : typeof globalThis < "u" ? globalThis : {};
568
- function q() {
569
- const t = typeof R.DOMParser < "u" ? R.DOMParser : void 0;
1058
+ const I = typeof window < "u" ? window : typeof globalThis < "u" ? globalThis : {};
1059
+ function we() {
1060
+ const t = typeof I.DOMParser < "u" ? I.DOMParser : void 0;
570
1061
  let e = !1;
571
1062
  if (!t) return !1;
572
1063
  try {
@@ -575,55 +1066,55 @@ function q() {
575
1066
  }
576
1067
  return e;
577
1068
  }
578
- class S {
1069
+ class W {
579
1070
  // This will be assigned per environment below
580
1071
  parseFromString(e, n) {
581
1072
  throw new Error("Not implemented");
582
1073
  }
583
1074
  }
584
- function Q() {
1075
+ function Oe() {
585
1076
  if (typeof window < "u" && typeof document < "u" && (typeof process > "u" || process.browser), typeof window < "u") {
586
- class t extends S {
587
- parseFromString(n, r) {
588
- const i = document.implementation.createHTMLDocument("");
589
- return i.open(), i.write(n), i.close(), i;
1077
+ class t extends W {
1078
+ parseFromString(n, i) {
1079
+ const r = document.implementation.createHTMLDocument("");
1080
+ return r.open(), r.write(n), r.close(), r;
590
1081
  }
591
1082
  }
592
1083
  return new t();
593
1084
  } else {
594
1085
  const t = require("@mixmark-io/domino");
595
- class e extends S {
596
- parseFromString(r, i) {
597
- return t.createDocument(r);
1086
+ class e extends W {
1087
+ parseFromString(i, r) {
1088
+ return t.createDocument(i);
598
1089
  }
599
1090
  }
600
1091
  return new e();
601
1092
  }
602
1093
  }
603
- const X = () => q() ? new R.DOMParser() : Q();
604
- function J(t, { preformattedCode: e }) {
1094
+ const Se = () => we() ? new I.DOMParser() : Oe();
1095
+ function Me(t, { preformattedCode: e }) {
605
1096
  let n;
606
- return typeof t == "string" ? n = ee().parseFromString(
1097
+ return typeof t == "string" ? n = ve().parseFromString(
607
1098
  // DOM parsers arrange elements in the <head> and <body>.
608
1099
  // Wrapping in a custom element ensures elements are reliably arranged in
609
1100
  // a single element.
610
1101
  '<x-turnish id="turnish-root">' + t + "</x-turnish>",
611
1102
  "text/html"
612
- ).getElementById("turnish-root") : n = t.cloneNode(!0), Y({
1103
+ ).getElementById("turnish-root") : n = t.cloneNode(!0), Ce({
613
1104
  element: n,
614
- isBlock: E,
615
- isVoid: L,
616
- isPre: e ? te : void 0
1105
+ isBlock: B,
1106
+ isVoid: X,
1107
+ isPre: e ? De : void 0
617
1108
  }), n;
618
1109
  }
619
- let Z;
620
- function ee() {
621
- return Z ??= X();
1110
+ let Le;
1111
+ function ve() {
1112
+ return Le ??= Se();
622
1113
  }
623
- function te(t) {
1114
+ function De(t) {
624
1115
  return t.nodeName === "PRE" || t.nodeName === "CODE";
625
1116
  }
626
- const ne = [
1117
+ const Ie = [
627
1118
  [/\\/g, "\\\\"],
628
1119
  [/\*/g, "\\*"],
629
1120
  [/_/g, "\\_"],
@@ -638,8 +1129,8 @@ const ne = [
638
1129
  [/<([^>]*)>/g, "\\<$1\\>"],
639
1130
  [/^>/g, "\\>"],
640
1131
  [/^(\d+)\. /g, "$1\\. "]
641
- ], re = {
642
- rules: f,
1132
+ ], Be = {
1133
+ rules: N,
643
1134
  headingStyle: "atx",
644
1135
  hr: "---",
645
1136
  bulletListMarker: "-",
@@ -666,24 +1157,24 @@ const ne = [
666
1157
  ` : e.outerHTML,
667
1158
  markdownIncludingHtmlReplacement: (t, e) => {
668
1159
  const n = e.nodeName.toLowerCase();
669
- let r = "";
1160
+ let i = "";
670
1161
  if (e.attributes && e.attributes.length > 0) {
671
- const s = [];
672
- for (let c = 0; c < e.attributes.length; c++) {
673
- const u = e.attributes[c];
674
- s.push(`${u.name}="${u.value}"`);
1162
+ const c = [];
1163
+ for (let g = 0; g < e.attributes.length; g++) {
1164
+ const m = e.attributes[g];
1165
+ c.push(`${m.name}="${m.value}"`);
675
1166
  }
676
- r = " " + s.join(" ");
1167
+ i = " " + c.join(" ");
677
1168
  }
678
- r += ' markdown="1"';
679
- const i = `<${n}${r}>`, l = `</${n}>`, o = t.trim(), a = i + `
680
- ` + o + `
681
- ` + l;
1169
+ i += ' markdown="1"';
1170
+ const r = `<${n}${i}>`, s = `</${n}>`, l = t.trim(), u = r + `
1171
+ ` + l + `
1172
+ ` + s;
682
1173
  return e.isBlock ? `
683
1174
 
684
- ` + a + `
1175
+ ` + u + `
685
1176
 
686
- ` : a;
1177
+ ` : u;
687
1178
  },
688
1179
  defaultReplacement: function(t, e) {
689
1180
  return e.isBlock ? `
@@ -693,11 +1184,11 @@ const ne = [
693
1184
  ` : t;
694
1185
  }
695
1186
  };
696
- class le {
1187
+ class Ve {
697
1188
  options;
698
1189
  rules;
699
1190
  constructor(e) {
700
- this.options = Object.assign({}, re, e), this.rules = new K(this.options);
1191
+ this.options = Object.assign({}, Be, e), this.rules = new Re(this.options);
701
1192
  }
702
1193
  /**
703
1194
  * The entry point for converting a string or DOM node to Markdown
@@ -707,13 +1198,13 @@ class le {
707
1198
  * @type string
708
1199
  */
709
1200
  render(e) {
710
- if (!ie(e))
1201
+ if (!Pe(e))
711
1202
  throw new TypeError(
712
1203
  e + " is not a string, or an element/document/fragment node."
713
1204
  );
714
1205
  if (e === "")
715
1206
  return "";
716
- const n = this.process(J(e, this.options));
1207
+ const n = this.process(Me(e, this.options));
717
1208
  return this.postProcess(n);
718
1209
  }
719
1210
  /**
@@ -771,8 +1262,8 @@ class le {
771
1262
  * @type string
772
1263
  */
773
1264
  escape(e) {
774
- return ne.reduce(function(n, r) {
775
- return n.replace(r[0], r[1]);
1265
+ return Ie.reduce(function(n, i) {
1266
+ return n.replace(i[0], i[1]);
776
1267
  }, e);
777
1268
  }
778
1269
  /**
@@ -783,18 +1274,18 @@ class le {
783
1274
  * @type string
784
1275
  */
785
1276
  process(e) {
786
- return Array.from(e.childNodes).reduce((n, r) => {
787
- const i = H(r, this.options);
788
- let l = "";
789
- if (i.nodeType === p.Text) {
790
- let o = i.nodeValue ?? "";
791
- if (r.previousSibling && r.previousSibling.nodeType === p.Element) {
792
- const a = r.previousSibling;
793
- a.nodeName === "INPUT" && a.getAttribute("type") === "checkbox" && (o = o.replace(/^\s+/, ""));
1277
+ return Array.from(e.childNodes).reduce((n, i) => {
1278
+ const r = fe(i, this.options);
1279
+ let s = "";
1280
+ if (r.nodeType === x.Text) {
1281
+ let l = r.nodeValue ?? "";
1282
+ if (i.previousSibling && i.previousSibling.nodeType === x.Element) {
1283
+ const u = i.previousSibling;
1284
+ u.nodeName === "INPUT" && u.getAttribute("type") === "checkbox" && (l = l.replace(/^\s+/, ""));
794
1285
  }
795
- l = i.isCode ? o : this.escape(o);
796
- } else i.nodeType === p.Element && (l = this.replacementForNode(i));
797
- return x(n, l);
1286
+ s = r.isCode ? l : this.escape(l);
1287
+ } else r.nodeType === x.Element && (s = this.replacementForNode(r));
1288
+ return G(n, s);
798
1289
  }, "");
799
1290
  }
800
1291
  /**
@@ -806,7 +1297,7 @@ class le {
806
1297
  */
807
1298
  postProcess(e) {
808
1299
  for (const n of this.rules.array)
809
- n.append && (e = x(e, n.append(this.options)));
1300
+ n.append && (e = G(e, n.append(this.options)));
810
1301
  return e.replace(/^[\t\r\n]+/, "").replace(/[\t\r\n\s]+$/, "");
811
1302
  }
812
1303
  /**
@@ -818,21 +1309,24 @@ class le {
818
1309
  */
819
1310
  replacementForNode(e) {
820
1311
  const n = this.rules.forNode(e);
821
- let r = this.process(e);
822
- const i = e.flankingWhitespace;
823
- return (i.leading || i.trailing) && (r = r.trim()), i.leading + n.replacement(r, e, this.options) + i.trailing;
1312
+ let i = this.process(e);
1313
+ const r = e.flankingWhitespace;
1314
+ return (r.leading || r.trailing) && (i = i.trim()), r.leading + n.replacement(i, e, this.options) + r.trailing;
1315
+ }
1316
+ isCodeBlock(e) {
1317
+ return te(e);
824
1318
  }
825
1319
  }
826
- function x(t, e) {
827
- const n = O(t), r = I(e), i = Math.max(t.length - n.length, e.length - r.length), l = `
1320
+ function G(t, e) {
1321
+ const n = Y(t), i = K(e), r = Math.max(t.length - n.length, e.length - i.length), s = `
828
1322
 
829
- `.substring(0, i);
830
- return n + l + r;
1323
+ `.substring(0, r);
1324
+ return n + s + i;
831
1325
  }
832
- function ie(t) {
1326
+ function Pe(t) {
833
1327
  return t != null && (typeof t == "string" || t.nodeType && (t.nodeType === 1 || t.nodeType === 9 || t.nodeType === 11));
834
1328
  }
835
1329
  export {
836
- le as default
1330
+ Ve as default
837
1331
  };
838
1332
  //# sourceMappingURL=index.mjs.map