@meandr/chat-sdk 0.0.1 → 0.0.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.
package/dist/markdown.js CHANGED
@@ -31,7 +31,7 @@ var CODE = 4;
31
31
  var NOTE = 5;
32
32
  function parseMarkdown(text) {
33
33
  const lines = String(text == null ? "" : text).replace(/\r\n?/g, "\n").split("\n").map(detab);
34
- return blockTree(parseBlocks(lines, 0).out, false);
34
+ return blockTree(parseBlocks(lines, 0).ga, false);
35
35
  }
36
36
  function renderMarkdown(text, doc = document) {
37
37
  const frag = doc.createDocumentFragment();
@@ -55,12 +55,12 @@ function parseBlocks(lines, depth) {
55
55
  let f, h, li, align;
56
56
  if (f = fenceOpen(line)) {
57
57
  const code = [];
58
- for (i++; i < n && !fenceClose(lines[i], f); i++) code.push(dedent(lines[i], f.ind));
58
+ for (i++; i < n && !fenceClose(lines[i], f); i++) code.push(dedent(lines[i], f.Za));
59
59
  i++;
60
- const lang = f.info.split(/\s/)[0];
61
- out.push({ t: "pre", s: code.join("\n"), lang: LANG.test(lang) ? lang : "" });
60
+ const lang = f._a.split(/\s/)[0];
61
+ out.push({ t: "pre", s: code.join("\n"), Ha: LANG.test(lang) ? lang : "" });
62
62
  } else if (h = heading(line)) {
63
- out.push({ t: "h" + h.level, s: h.text });
63
+ out.push({ t: "h" + h.$a, s: h.W });
64
64
  i++;
65
65
  } else if (isHr(line)) {
66
66
  out.push({ t: "hr", s: "" });
@@ -76,23 +76,23 @@ function parseBlocks(lines, depth) {
76
76
  fs = fenceStep(fs, l);
77
77
  i++;
78
78
  }
79
- out.push({ t: "blockquote", s: "", kids: parseBlocks(inner, depth + 1).out });
79
+ out.push({ t: "blockquote", s: "", ab: parseBlocks(inner, depth + 1).ga });
80
80
  } else if (nest && (li = listItem(line))) {
81
81
  const first = li, items = [];
82
82
  let cur = li, lz = false;
83
83
  for (; ; ) {
84
- const body = [cur.content];
85
- let fs = fenceStep(null, cur.content), blank = -1;
84
+ const body = [cur.Ia];
85
+ let fs = fenceStep(null, cur.Ia), blank = -1;
86
86
  for (i++; i < n; i++) {
87
87
  const l = lines[i];
88
88
  if (isBlank(l)) {
89
89
  if (blank < 0) blank = i;
90
90
  continue;
91
91
  }
92
- if (indentOf(l) >= cur.indent) {
92
+ if (indentOf(l) >= cur.Ja) {
93
93
  for (; blank >= 0 && blank < i; blank++) body.push("");
94
94
  blank = -1;
95
- const d = dedent(l, cur.indent);
95
+ const d = dedent(l, cur.Ja);
96
96
  body.push(d);
97
97
  fs = fenceStep(fs, d);
98
98
  continue;
@@ -102,28 +102,28 @@ function parseBlocks(lines, depth) {
102
102
  }
103
103
  if (blank >= 0) i = blank;
104
104
  const r = parseBlocks(body, depth + 1);
105
- items.push(r.out);
106
- if (r.loose) lz = true;
105
+ items.push(r.ga);
106
+ if (r.bb) lz = true;
107
107
  let j = i;
108
108
  while (j < n && isBlank(lines[j])) j++;
109
109
  const next = j < n ? listItem(lines[j]) : null;
110
- if (!next || next.ordered !== first.ordered || next.mark !== first.mark) break;
110
+ if (!next || next.X !== first.X || next.Ka !== first.Ka) break;
111
111
  if (j > i) lz = true;
112
112
  i = j;
113
113
  cur = next;
114
114
  }
115
- out.push({ t: first.ordered ? "ol" : "ul", s: "", start: first.start, tight: !lz, items });
115
+ out.push({ t: first.X ? "ol" : "ul", s: "", M: first.M, cb: !lz, db: items });
116
116
  } else if (align = tableAt(lines, i)) {
117
117
  const rows = [cells(line, MAX_COLS)];
118
118
  for (i += 2; i < n && !isBlank(lines[i]) && !startsBlock(lines[i], nest); i++) rows.push(cells(lines[i], MAX_COLS));
119
- out.push({ t: "table", s: "", rows, align: align.slice(0, MAX_COLS) });
119
+ out.push({ t: "table", s: "", eb: rows, fb: align.slice(0, MAX_COLS) });
120
120
  } else {
121
121
  const buf = [line.trim()];
122
122
  for (i++; i < n && !isBlank(lines[i]) && !startsBlock(lines[i], nest) && !tableAt(lines, i); i++) buf.push(lines[i].trim());
123
123
  out.push({ t: "p", s: buf.join("\n") });
124
124
  }
125
125
  }
126
- return { out, loose };
126
+ return { ga: out, bb: loose };
127
127
  }
128
128
  function isBlank(l) {
129
129
  if (l === void 0) return true;
@@ -166,13 +166,13 @@ function fenceOpen(l) {
166
166
  let e = ind;
167
167
  while (l.charAt(e) === ch) e++;
168
168
  const info = l.slice(e).trim();
169
- return e - ind >= 3 && !(ch === "`" && info.indexOf("`") >= 0) ? { ch, len: e - ind, ind, info } : null;
169
+ return e - ind >= 3 && !(ch === "`" && info.indexOf("`") >= 0) ? { ch, gb: e - ind, Za: ind, _a: info } : null;
170
170
  }
171
171
  function fenceClose(l, f) {
172
172
  const s = lead(l);
173
173
  let e = s;
174
174
  while (l.charAt(e) === f.ch) e++;
175
- return e - s >= f.len && isBlank(l.slice(e));
175
+ return e - s >= f.gb && isBlank(l.slice(e));
176
176
  }
177
177
  function fenceStep(f, l) {
178
178
  return f ? fenceClose(l, f) ? null : f : fenceOpen(l);
@@ -186,7 +186,7 @@ function heading(l) {
186
186
  let t = l.slice(e).trim(), k = t.length;
187
187
  while (k > 0 && t.charAt(k - 1) === "#") k--;
188
188
  if (k === 0 || t.charAt(k - 1) === " " || t.charAt(k - 1) === " ") t = t.slice(0, k).trim();
189
- return { level, text: t };
189
+ return { $a: level, W: t };
190
190
  }
191
191
  function isHr(l) {
192
192
  const s = lead(l), ch = l.charAt(s);
@@ -223,14 +223,14 @@ function listItem(l) {
223
223
  while (l.charAt(e) === " " || l.charAt(e) === " ") e++;
224
224
  if (e === p && e < l.length) return null;
225
225
  const empty = e >= l.length, wide = e - p > 4;
226
- return { ordered, mark, start, indent: empty || wide ? p + 1 : e, content: empty ? "" : l.slice(wide ? p + 1 : e), empty };
226
+ return { X: ordered, Ka: mark, M: start, Ja: empty || wide ? p + 1 : e, Ia: empty ? "" : l.slice(wide ? p + 1 : e), hb: empty };
227
227
  }
228
228
  function startsBlock(l, nest) {
229
229
  if (fenceOpen(l) || heading(l) || isHr(l)) return true;
230
230
  if (!nest) return false;
231
231
  if (quoteStrip(l) !== null) return true;
232
232
  const m = listItem(l);
233
- return m !== null && !m.empty && (!m.ordered || m.start === 1);
233
+ return m !== null && !m.hb && (!m.X || m.M === 1);
234
234
  }
235
235
  function cells(l, max) {
236
236
  const s = l.trim(), out = [];
@@ -268,12 +268,12 @@ function tableAt(lines, i) {
268
268
  return align && lines[i].indexOf("|") >= 0 && cells(lines[i], Infinity).length === align.length ? align : null;
269
269
  }
270
270
  function mk(k, s) {
271
- return { k, s, href: "", dest: "", kid: null, prev: null, next: null };
271
+ return { k, s, z: "", u: "", I: null, d: null, b: null };
272
272
  }
273
273
  function anchor(href, kid) {
274
274
  const a = mk(EL, "a");
275
- a.href = href;
276
- a.kid = kid;
275
+ a.z = href;
276
+ a.I = kid;
277
277
  return a;
278
278
  }
279
279
  function isAsciiPunct(ch) {
@@ -302,8 +302,8 @@ function parseInline(src) {
302
302
  const head = mk(EL, ""), len = src.length;
303
303
  let tail = head, dtop = null, btop = null, ids = 0, i = 0, rp = 0, url = -1;
304
304
  const push = (x) => {
305
- tail.next = x;
306
- x.prev = tail;
305
+ tail.b = x;
306
+ x.d = tail;
307
307
  tail = x;
308
308
  };
309
309
  const text = (s) => {
@@ -311,62 +311,62 @@ function parseInline(src) {
311
311
  else push(mk(TEXT, s));
312
312
  };
313
313
  const unlink = (x) => {
314
- x.prev.next = x.next;
315
- if (x.next) x.next.prev = x.prev;
316
- else tail = x.prev;
314
+ x.d.b = x.b;
315
+ if (x.b) x.b.d = x.d;
316
+ else tail = x.d;
317
317
  };
318
318
  const drop = (d) => {
319
- d.node.s = d.node.s.slice(0, d.n);
320
- if (d.prev) d.prev.next = d.next;
321
- if (d.next) d.next.prev = d.prev;
322
- else dtop = d.prev;
319
+ d.f.s = d.f.s.slice(0, d.n);
320
+ if (d.d) d.d.b = d.b;
321
+ if (d.b) d.b.d = d.d;
322
+ else dtop = d.d;
323
323
  };
324
324
  const emphasis = (bottom) => {
325
325
  const bid = bottom ? bottom.id : -1, floor = {};
326
326
  let c = dtop;
327
327
  if (!c || c.id <= bid) return;
328
- while (c.prev && c.prev.id > bid) c = c.prev;
328
+ while (c.d && c.d.id > bid) c = c.d;
329
329
  while (c) {
330
- if (!c.close) {
331
- c = c.next;
330
+ if (!c.La) {
331
+ c = c.b;
332
332
  continue;
333
333
  }
334
- const key = c.ch + (c.open ? "1" : "0") + c.orig % 3;
334
+ const key = c.ch + (c.Y ? "1" : "0") + c.N % 3;
335
335
  const lim = Math.max(bid, key in floor ? floor[key] : -1);
336
- let o = c.prev;
337
- while (o && o.id > lim && !(o.ch === c.ch && o.open && pairs(o, c))) o = o.prev;
336
+ let o = c.d;
337
+ while (o && o.id > lim && !(o.ch === c.ch && o.Y && pairs(o, c))) o = o.d;
338
338
  if (o && o.id > lim) {
339
339
  const use = c.ch === "~" || c.n > 1 && o.n > 1 ? 2 : 1;
340
340
  o.n -= use;
341
341
  c.n -= use;
342
342
  const el = mk(EL, c.ch === "~" ? "del" : use === 2 ? "strong" : "em");
343
- if (o.node.next !== c.node) {
344
- const first = o.node.next, last = c.node.prev;
345
- first.prev = null;
346
- last.next = null;
347
- el.kid = first;
343
+ if (o.f.b !== c.f) {
344
+ const first = o.f.b, last = c.f.d;
345
+ first.d = null;
346
+ last.b = null;
347
+ el.I = first;
348
348
  }
349
- o.node.next = el;
350
- el.prev = o.node;
351
- el.next = c.node;
352
- c.node.prev = el;
353
- for (let d = o.next; d && d !== c; d = d.next) d.node.s = d.node.s.slice(0, d.n);
354
- o.next = c;
355
- c.prev = o;
349
+ o.f.b = el;
350
+ el.d = o.f;
351
+ el.b = c.f;
352
+ c.f.d = el;
353
+ for (let d = o.b; d && d !== c; d = d.b) d.f.s = d.f.s.slice(0, d.n);
354
+ o.b = c;
355
+ c.d = o;
356
356
  if (!o.n) {
357
- unlink(o.node);
357
+ unlink(o.f);
358
358
  drop(o);
359
359
  }
360
360
  if (!c.n) {
361
- unlink(c.node);
362
- const nx = c.next;
361
+ unlink(c.f);
362
+ const nx = c.b;
363
363
  drop(c);
364
364
  c = nx;
365
365
  }
366
366
  } else {
367
- floor[key] = c.prev ? c.prev.id : -1;
368
- const nx = c.next;
369
- if (!c.open) drop(c);
367
+ floor[key] = c.d ? c.d.id : -1;
368
+ const nx = c.b;
369
+ if (!c.Y) drop(c);
370
370
  c = nx;
371
371
  }
372
372
  }
@@ -435,55 +435,55 @@ function parseInline(src) {
435
435
  const x = mk(DELIM, src.slice(i, e));
436
436
  push(x);
437
437
  if ((open || close) && (c !== 126 || e - i === 2)) {
438
- const d = { node: x, ch: src.charAt(i), n: e - i, orig: e - i, open, close, id: ids++, prev: dtop, next: null };
439
- if (dtop) dtop.next = d;
438
+ const d = { f: x, ch: src.charAt(i), n: e - i, N: e - i, Y: open, La: close, id: ids++, d: dtop, b: null };
439
+ if (dtop) dtop.b = d;
440
440
  dtop = d;
441
441
  }
442
442
  i = e;
443
443
  } else if (c === 91 || c === 33 && src.charCodeAt(i + 1) === 91) {
444
444
  const img = c === 33, x = mk(DELIM, img ? "![" : "[");
445
445
  push(x);
446
- btop = { node: x, img, active: true, inner: false, delim: dtop, prev: btop };
446
+ btop = { f: x, O: img, ha: true, A: false, ib: dtop, d: btop };
447
447
  i += img ? 2 : 1;
448
448
  } else if (c === 93) {
449
- const b = btop, L = b && b.active ? linkTail(src, i + 1) : null;
450
- if (b) btop = b.prev;
449
+ const b = btop, L = b && b.ha ? linkTail(src, i + 1) : null;
450
+ if (b) btop = b.d;
451
451
  if (!b || !L) {
452
- if (b && b.inner && btop) btop.inner = true;
452
+ if (b && b.A && btop) btop.A = true;
453
453
  text("]");
454
454
  i++;
455
455
  continue;
456
456
  }
457
- emphasis(b.delim);
458
- const kids = b.node.next, href = safeHref(L.dest);
459
- if (b.img || href) {
460
- let label = !b.img && kids ? kids : mk(TEXT, b.img && !(href && b.inner) ? plain(kids) : "");
457
+ emphasis(b.ib);
458
+ const kids = b.f.b, href = safeHref(L.u);
459
+ if (b.O || href) {
460
+ let label = !b.O && kids ? kids : mk(TEXT, b.O && !(href && b.A) ? plain(kids) : "");
461
461
  if (href) tidy(label);
462
- if (!plain(label)) label = mk(TEXT, href ? shown(href) : L.dest);
463
- label.prev = null;
464
- b.node.next = null;
465
- tail = b.node;
462
+ if (!plain(label)) label = mk(TEXT, href ? shown(href) : L.u);
463
+ label.d = null;
464
+ b.f.b = null;
465
+ tail = b.f;
466
466
  if (href) {
467
467
  const a = anchor(href, label);
468
- let p = b.node.prev;
469
- a.dest = note(plain(label), href);
470
- if (a.dest) {
471
- const n = mk(NOTE, "[" + a.dest + "] ");
472
- p.next = n;
473
- n.prev = p;
468
+ let p = b.f.d;
469
+ a.u = note(plain(label), href);
470
+ if (a.u) {
471
+ const n = mk(NOTE, "[" + a.u + "] ");
472
+ p.b = n;
473
+ n.d = p;
474
474
  p = n;
475
475
  }
476
- p.next = a;
477
- a.prev = p;
476
+ p.b = a;
477
+ a.d = p;
478
478
  tail = a;
479
479
  } else {
480
- b.node.k = TEXT;
481
- b.node.s = label.s;
480
+ b.f.k = TEXT;
481
+ b.f.s = label.s;
482
482
  }
483
- } else unlink(b.node);
484
- if (!b.img) for (let x = btop; x && x.active; x = x.prev) x.active = false;
485
- if (btop && (b.img || href || b.inner)) btop.inner = true;
486
- i = L.end;
483
+ } else unlink(b.f);
484
+ if (!b.O) for (let x = btop; x && x.ha; x = x.d) x.ha = false;
485
+ if (btop && (b.O || href || b.A)) btop.A = true;
486
+ i = L.F;
487
487
  } else if (c === 60) {
488
488
  const al = autolink(src, i);
489
489
  if (!al) {
@@ -491,11 +491,11 @@ function parseInline(src) {
491
491
  i++;
492
492
  continue;
493
493
  }
494
- if (al.href) {
495
- push(anchor(al.href, mk(TEXT, shown(al.href))));
496
- if (btop) btop.inner = true;
497
- } else text(al.text);
498
- i = al.end;
494
+ if (al.z) {
495
+ push(anchor(al.z, mk(TEXT, shown(al.z))));
496
+ if (btop) btop.A = true;
497
+ } else text(al.W);
498
+ i = al.F;
499
499
  } else if (c === 38) {
500
500
  const en = entity(src, i);
501
501
  if (en) {
@@ -513,7 +513,7 @@ function parseInline(src) {
513
513
  const u = src.slice(i, url), href = safeHref(u);
514
514
  if (href) {
515
515
  push(anchor(href, mk(TEXT, shown(href))));
516
- if (btop) btop.inner = true;
516
+ if (btop) btop.A = true;
517
517
  } else text(u);
518
518
  i = url;
519
519
  } else {
@@ -524,10 +524,10 @@ function parseInline(src) {
524
524
  }
525
525
  }
526
526
  emphasis(null);
527
- return head.next;
527
+ return head.b;
528
528
  }
529
529
  function pairs(o, c) {
530
- return c.ch === "~" || !((o.close || c.open) && (o.orig + c.orig) % 3 === 0 && (o.orig % 3 !== 0 || c.orig % 3 !== 0));
530
+ return c.ch === "~" || !((o.La || c.Y) && (o.N + c.N) % 3 === 0 && (o.N % 3 !== 0 || c.N % 3 !== 0));
531
531
  }
532
532
  function plain(n) {
533
533
  let s = "";
@@ -539,12 +539,12 @@ function plain(n) {
539
539
  continue;
540
540
  }
541
541
  if (n.k === EL) {
542
- resume.push(n.next);
543
- n = n.kid;
542
+ resume.push(n.b);
543
+ n = n.I;
544
544
  continue;
545
545
  }
546
546
  if (n.k !== NOTE) s += n.k === BR ? " " : n.s;
547
- n = n.next;
547
+ n = n.b;
548
548
  }
549
549
  }
550
550
  function skipWs(s, p, lim) {
@@ -597,7 +597,7 @@ function linkTail(s, p) {
597
597
  p = skipWs(s, p + 1, lim);
598
598
  }
599
599
  if (s.charAt(p) !== ")") return null;
600
- return { dest: decode(dest), end: p + 1 };
600
+ return { u: decode(dest), F: p + 1 };
601
601
  }
602
602
  function autolink(s, p) {
603
603
  const lim = Math.min(s.length, p + 2048);
@@ -609,8 +609,8 @@ function autolink(s, p) {
609
609
  }
610
610
  if (s.charAt(q) !== ">" || q === p + 1) return null;
611
611
  const t = s.slice(p + 1, q);
612
- if (/^[A-Za-z][A-Za-z0-9+.-]{1,31}:/.test(t)) return { text: t, href: safeHref(t), end: q + 1 };
613
- if (/^[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/.test(t)) return { text: t, href: safeHref("mailto:" + t), end: q + 1 };
612
+ if (/^[A-Za-z][A-Za-z0-9+.-]{1,31}:/.test(t)) return { W: t, z: safeHref(t), F: q + 1 };
613
+ if (/^[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/.test(t)) return { W: t, z: safeHref("mailto:" + t), F: q + 1 };
614
614
  return null;
615
615
  }
616
616
  function bareUrl(s, p, inBracket) {
@@ -790,12 +790,12 @@ function eachText(n, fn) {
790
790
  continue;
791
791
  }
792
792
  if (n.k === EL) {
793
- resume.push(n.next);
794
- n = n.kid;
793
+ resume.push(n.b);
794
+ n = n.I;
795
795
  continue;
796
796
  }
797
797
  if (n.k !== NOTE && !fn(n)) return;
798
- n = n.next;
798
+ n = n.b;
799
799
  }
800
800
  }
801
801
  function unscheme(s) {
@@ -813,21 +813,21 @@ function blockTree(bs, tight) {
813
813
  else out.push({ tag: "p", children: inlineTree(parseInline(b.s), [], 0, false) });
814
814
  break;
815
815
  case "pre":
816
- out.push(b.lang ? { tag: "pre", language: b.lang, children: [clean(b.s)] } : { tag: "pre", children: [clean(b.s)] });
816
+ out.push(b.Ha ? { tag: "pre", language: b.Ha, children: [clean(b.s)] } : { tag: "pre", children: [clean(b.s)] });
817
817
  break;
818
818
  case "blockquote":
819
- out.push({ tag: "blockquote", children: blockTree(b.kids || [], false) });
819
+ out.push({ tag: "blockquote", children: blockTree(b.ab || [], false) });
820
820
  break;
821
821
  case "ul":
822
822
  case "ol": {
823
- const items = (b.items || []).map((item) => ({ tag: "li", children: blockTree(item, !!b.tight) }));
823
+ const items = (b.db || []).map((item) => ({ tag: "li", children: blockTree(item, !!b.cb) }));
824
824
  const list = { tag: b.t, children: items };
825
- if (b.t === "ol" && b.start !== 1) list.start = b.start;
825
+ if (b.t === "ol" && b.M !== 1) list.start = b.M;
826
826
  out.push(list);
827
827
  break;
828
828
  }
829
829
  case "table":
830
- out.push(tableTree(b.rows || [], b.align || []));
830
+ out.push(tableTree(b.eb || [], b.fb || []));
831
831
  break;
832
832
  case "hr":
833
833
  out.push({ tag: "hr" });
@@ -865,24 +865,24 @@ function tableTree(rows, align) {
865
865
  }
866
866
  function inlineTree(n, out, depth, inA) {
867
867
  let run = "";
868
- for (; n; n = n.next) {
868
+ for (; n; n = n.b) {
869
869
  if (n.k === TEXT || n.k === DELIM) run += n.s;
870
870
  else if (n.k === NOTE) {
871
871
  if (inA || depth >= MAX_INLINE) continue;
872
872
  pushText(out, run);
873
873
  pushText(out, n.s);
874
874
  run = "";
875
- } else if (n.k === EL && (n.s === "a" && inA || depth >= MAX_INLINE)) run += plain(n.kid);
875
+ } else if (n.k === EL && (n.s === "a" && inA || depth >= MAX_INLINE)) run += plain(n.I);
876
876
  else {
877
877
  pushText(out, run);
878
878
  run = "";
879
879
  if (n.k === BR) out.push({ tag: "br" });
880
880
  else if (n.k === CODE) out.push({ tag: "code", children: [clean(n.s)] });
881
881
  else {
882
- const el = { tag: n.s, children: inlineTree(n.kid, [], depth + 1, inA || n.s === "a") };
882
+ const el = { tag: n.s, children: inlineTree(n.I, [], depth + 1, inA || n.s === "a") };
883
883
  if (n.s === "a") {
884
- el.href = n.href;
885
- if (n.dest) el.dest = n.dest;
884
+ el.href = n.z;
885
+ if (n.u) el.dest = n.u;
886
886
  }
887
887
  out.push(el);
888
888
  }