UNPKG

laif-ds

Version:

Design System di Laif con componenti React basati su principi di Atomic Design

85 lines (84 loc) 3.33 kB
"use client"; import { push as d, splice as S } from "../../micromark-util-chunked/index.js"; import { classifyCharacter as h } from "../../micromark-util-classify-character/index.js"; import { resolveAll as q } from "../../micromark-util-resolve-all/index.js"; const z = { name: "attention", resolveAll: g, tokenize: y }; function g(t, i) { let e = -1, r, a, l, u, s, n, o, f; for (; ++e < t.length; ) if (t[e][0] === "enter" && t[e][1].type === "attentionSequence" && t[e][1]._close) { for (r = e; r--; ) if (t[r][0] === "exit" && t[r][1].type === "attentionSequence" && t[r][1]._open && // If the markers are the same: i.sliceSerialize(t[r][1]).charCodeAt(0) === i.sliceSerialize(t[e][1]).charCodeAt(0)) { if ((t[r][1]._close || t[e][1]._open) && (t[e][1].end.offset - t[e][1].start.offset) % 3 && !((t[r][1].end.offset - t[r][1].start.offset + t[e][1].end.offset - t[e][1].start.offset) % 3)) continue; n = t[r][1].end.offset - t[r][1].start.offset > 1 && t[e][1].end.offset - t[e][1].start.offset > 1 ? 2 : 1; const p = { ...t[r][1].end }, c = { ...t[e][1].start }; m(p, -n), m(c, n), u = { type: n > 1 ? "strongSequence" : "emphasisSequence", start: p, end: { ...t[r][1].end } }, s = { type: n > 1 ? "strongSequence" : "emphasisSequence", start: { ...t[e][1].start }, end: c }, l = { type: n > 1 ? "strongText" : "emphasisText", start: { ...t[r][1].end }, end: { ...t[e][1].start } }, a = { type: n > 1 ? "strong" : "emphasis", start: { ...u.start }, end: { ...s.end } }, t[r][1].end = { ...u.start }, t[e][1].start = { ...s.end }, o = [], t[r][1].end.offset - t[r][1].start.offset && (o = d(o, [["enter", t[r][1], i], ["exit", t[r][1], i]])), o = d(o, [["enter", a, i], ["enter", u, i], ["exit", u, i], ["enter", l, i]]), o = d(o, q(i.parser.constructs.insideSpan.null, t.slice(r + 1, e), i)), o = d(o, [["exit", l, i], ["enter", s, i], ["exit", s, i], ["exit", a, i]]), t[e][1].end.offset - t[e][1].start.offset ? (f = 2, o = d(o, [["enter", t[e][1], i], ["exit", t[e][1], i]])) : f = 0, S(t, r - 1, e - r + 3, o), e = r + o.length - f - 2; break; } } for (e = -1; ++e < t.length; ) t[e][1].type === "attentionSequence" && (t[e][1].type = "data"); return t; } function y(t, i) { const e = this.parser.constructs.attentionMarkers.null, r = this.previous, a = h(r); let l; return u; function u(n) { return l = n, t.enter("attentionSequence"), s(n); } function s(n) { if (n === l) return t.consume(n), s; const o = t.exit("attentionSequence"), f = h(n), p = !f || f === 2 && a || e.includes(n), c = !a || a === 2 && f || e.includes(r); return o._open = !!(l === 42 ? p : p && (a || !c)), o._close = !!(l === 42 ? c : c && (f || !p)), i(n); } } function m(t, i) { t.column += i, t.offset += i, t._bufferIndex += i; } export { z as attention };