hexagon-editor 0.1.0 → 0.1.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/renderer.js CHANGED
@@ -2,9 +2,10 @@ import { defineComponent as M, ref as S, getCurrentInstance as w, computed as I,
2
2
  import { M as x, k as W } from "./katex-ByXcxnHy.js";
3
3
  import { d as B } from "./index-uerphigI.js";
4
4
  import { i as D, s as E, a as O } from "./index-CqpK5VVw.js";
5
- const h = new x().utils.escapeHtml;
6
- function z(t) {
7
- t.inline.ruler.after("backticks", "inline_math", (e, r) => {
5
+ import { _ as z } from "./_plugin-vue_export-helper-CHgC5LLL.js";
6
+ import './renderer.css';const h = new x().utils.escapeHtml;
7
+ function L(n) {
8
+ n.inline.ruler.after("backticks", "inline_math", (e, r) => {
8
9
  if (e.src[e.pos] !== "$" || e.src[e.pos + 1] === "$" || y(e.src, e.pos)) return !1;
9
10
  let i = e.pos + 1;
10
11
  for (; i < e.posMax; ) {
@@ -14,18 +15,18 @@ function z(t) {
14
15
  }
15
16
  if (i <= e.pos + 1 || /\s/.test(e.src[e.pos + 1] ?? "") || /\s/.test(e.src[i - 1] ?? "")) return !1;
16
17
  if (!r) {
17
- const n = e.push("inline_math", "", 0);
18
- n.content = e.src.slice(e.pos + 1, i);
18
+ const t = e.push("inline_math", "", 0);
19
+ t.content = e.src.slice(e.pos + 1, i);
19
20
  }
20
21
  return e.pos = i + 1, !0;
21
- }), t.block.ruler.before("fence", "math_block", (e, r, i, n) => {
22
+ }), n.block.ruler.before("fence", "math_block", (e, r, i, t) => {
22
23
  const o = e.getLines(r, r + 1, 0, !1).trim();
23
24
  if (!o.startsWith("$$")) return !1;
24
- const l = o.match(/^\$\$\s*(.*?)\s*\$\$$/);
25
- if (l !== null) {
26
- if (!n) {
27
- const s = e.push("math_block", "", 0);
28
- s.content = l[1] ?? "";
25
+ const s = o.match(/^\$\$\s*(.*?)\s*\$\$$/);
26
+ if (s !== null) {
27
+ if (!t) {
28
+ const l = e.push("math_block", "", 0);
29
+ l.content = s[1] ?? "";
29
30
  }
30
31
  return e.line = r + 1, !0;
31
32
  }
@@ -33,183 +34,183 @@ function z(t) {
33
34
  let c = r + 1;
34
35
  for (; c < i && e.getLines(c, c + 1, 0, !1).trim() !== "$$"; ) c += 1;
35
36
  if (c === i) return !1;
36
- if (!n) {
37
- const s = e.push("math_block", "", 0);
38
- s.content = e.getLines(r + 1, c, 0, !1).trim();
37
+ if (!t) {
38
+ const l = e.push("math_block", "", 0);
39
+ l.content = e.getLines(r + 1, c, 0, !1).trim();
39
40
  }
40
41
  return e.line = c + 1, !0;
41
42
  });
42
43
  }
43
- function L(t) {
44
- t.block.ruler.before("fence", "yfm_html_block", (e, r, i, n) => {
44
+ function F(n) {
45
+ n.block.ruler.before("fence", "yfm_html_block", (e, r, i, t) => {
45
46
  if (e.getLines(r, r + 1, 0, !1).trim() !== ":::html") return !1;
46
47
  let o = r + 1;
47
48
  for (; o < i && e.getLines(o, o + 1, 0, !1).trim() !== ":::"; ) o += 1;
48
49
  if (o === i) return !1;
49
- if (!n) {
50
- const l = e.push("yfm_html_block", "", 0);
51
- l.content = e.getLines(r + 1, o, 0, !1).trim();
50
+ if (!t) {
51
+ const s = e.push("yfm_html_block", "", 0);
52
+ s.content = e.getLines(r + 1, o, 0, !1).trim();
52
53
  }
53
54
  return e.line = o + 1, !0;
54
- }), t.block.ruler.before("fence", "directive", (e, r, i, n) => {
55
- const l = e.getLines(r, r + 1, 0, !1).trim().match(/^:::\s*(\w+)\s*$/);
56
- if (l === null) return !1;
55
+ }), n.block.ruler.before("fence", "directive", (e, r, i, t) => {
56
+ const s = e.getLines(r, r + 1, 0, !1).trim().match(/^:::\s*(\w+)\s*$/);
57
+ if (s === null) return !1;
57
58
  let c = r + 1;
58
59
  for (; c < i && e.getLines(c, c + 1, 0, !1).trim() !== ":::"; ) c += 1;
59
60
  if (c === i) return !1;
60
- if (!n) {
61
- const s = e.push("directive", "", 0);
62
- s.info = l[1] ?? "note", s.content = e.getLines(r + 1, c, 0, !1).trim();
61
+ if (!t) {
62
+ const l = e.push("directive", "", 0);
63
+ l.info = s[1] ?? "note", l.content = e.getLines(r + 1, c, 0, !1).trim();
63
64
  }
64
65
  return e.line = c + 1, !0;
65
66
  });
66
67
  }
67
- function F(t) {
68
- t.core.ruler.after("block", "mermaid_fences", (e) => {
68
+ function P(n) {
69
+ n.core.ruler.after("block", "mermaid_fences", (e) => {
69
70
  for (const r of e.tokens)
70
71
  r.type === "fence" && r.info.trim() === "mermaid" && (r.type = "mermaid");
71
- }), t.core.ruler.after("inline", "renderer_extensions", (e) => {
72
+ }), n.core.ruler.after("inline", "renderer_extensions", (e) => {
72
73
  for (let r = 0; r < e.tokens.length; r += 1) {
73
- const i = e.tokens[r], n = e.tokens[r + 1], o = e.tokens[r + 2];
74
- if (i?.type === "paragraph_open" && n?.type === "inline" && o?.type === "paragraph_close") {
75
- const c = n.content.match(/^(#{1,6})\+\s+(.+)$/);
76
- c !== null && (i.type = "heading_open", i.tag = `h${c[1]?.length ?? 1}`, i.attrSet("data-folding", "true"), n.content = c[2] ?? "", _(e, n), o.type = "heading_close", o.tag = i.tag);
74
+ const i = e.tokens[r], t = e.tokens[r + 1], o = e.tokens[r + 2];
75
+ if (i?.type === "paragraph_open" && t?.type === "inline" && o?.type === "paragraph_close") {
76
+ const c = t.content.match(/^(#{1,6})\+\s+(.+)$/);
77
+ c !== null && (i.type = "heading_open", i.tag = `h${c[1]?.length ?? 1}`, i.attrSet("data-folding", "true"), t.content = c[2] ?? "", k(e, t), o.type = "heading_close", o.tag = i.tag);
77
78
  }
78
- if (i?.type === "heading_open" && n?.type === "inline") {
79
- n.content.startsWith("+ ") && (n.content = n.content.slice(2), i.attrSet("data-folding", "true"), _(e, n));
80
- const c = n.content.match(/\s+\{([^}]+)\}$/);
79
+ if (i?.type === "heading_open" && t?.type === "inline") {
80
+ t.content.startsWith("+ ") && (t.content = t.content.slice(2), i.attrSet("data-folding", "true"), k(e, t));
81
+ const c = t.content.match(/\s+\{([^}]+)\}$/);
81
82
  if (c !== null) {
82
- n.content = n.content.slice(0, c.index), _(e, n);
83
- for (const s of c[1]?.split(/\s+/) ?? [])
84
- s.startsWith("#") && i.attrSet("id", s.slice(1)), s.startsWith(".") && i.attrJoin("class", s.slice(1));
83
+ t.content = t.content.slice(0, c.index), k(e, t);
84
+ for (const l of c[1]?.split(/\s+/) ?? [])
85
+ l.startsWith("#") && i.attrSet("id", l.slice(1)), l.startsWith(".") && i.attrJoin("class", l.slice(1));
85
86
  }
86
87
  }
87
- const l = i?.children;
88
- l != null && P(l);
88
+ const s = i?.children;
89
+ s != null && J(s);
89
90
  }
90
91
  });
91
92
  }
92
- function _(t, e) {
93
+ function k(n, e) {
93
94
  const r = [];
94
- t.md.inline.parse(e.content, t.md, t.env, r), e.children = r;
95
+ n.md.inline.parse(e.content, n.md, n.env, r), e.children = r;
95
96
  }
96
- function P(t) {
97
- for (let e = 0; e < t.length; e += 1) {
98
- const r = t[e], i = t[e + 1];
97
+ function J(n) {
98
+ for (let e = 0; e < n.length; e += 1) {
99
+ const r = n[e], i = n[e + 1];
99
100
  if (r?.type === "image" && i?.type === "text") {
100
- const n = i.content.match(/^\{width=(\d+%?)(?:\s+height=(\d+))?(?:\s+object-fit=(contain|cover|fill|none|scale-down))?}/);
101
- n !== null && (r.attrSet("width", n[1] ?? ""), n[2] !== void 0 && r.attrSet("height", n[2]), n[3] !== void 0 && r.attrSet("data-image-object-fit", n[3]), i.content = i.content.slice(n[0].length));
101
+ const t = i.content.match(/^\{width=(\d+%?)(?:\s+height=(\d+))?(?:\s+object-fit=(contain|cover|fill|none|scale-down))?}/);
102
+ t !== null && (r.attrSet("width", t[1] ?? ""), t[2] !== void 0 && r.attrSet("height", t[2]), t[3] !== void 0 && r.attrSet("data-image-object-fit", t[3]), i.content = i.content.slice(t[0].length));
102
103
  }
103
104
  if (r?.type === "link_close" && i?.type === "text") {
104
- const n = i.content.match(/^\s*\{target="_blank" rel="noopener noreferrer"}/);
105
- if (n !== null)
105
+ const t = i.content.match(/^\s*\{target="_blank" rel="noopener noreferrer"}/);
106
+ if (t !== null)
106
107
  for (let o = e - 1; o >= 0; o -= 1) {
107
- const l = t[o];
108
- if (l?.type === "link_open") {
109
- l.attrSet("target", "_blank"), l.attrSet("rel", "noopener noreferrer"), i.content = i.content.slice(n[0].length);
108
+ const s = n[o];
109
+ if (s?.type === "link_open") {
110
+ s.attrSet("target", "_blank"), s.attrSet("rel", "noopener noreferrer"), i.content = i.content.slice(t[0].length);
110
111
  break;
111
112
  }
112
113
  }
113
114
  }
114
115
  }
115
116
  }
116
- function J(t) {
117
- t.core.ruler.after("renderer_extensions", "quote_links", (e) => {
117
+ function K(n) {
118
+ n.core.ruler.after("renderer_extensions", "quote_links", (e) => {
118
119
  for (let r = 0; r < e.tokens.length; r += 1) {
119
- const i = e.tokens[r], n = e.tokens[r + 1], o = e.tokens[r + 2], l = e.tokens[r + 3];
120
- if (i?.type !== "blockquote_open" || n?.type !== "paragraph_open" || o?.type !== "inline" || l?.type !== "paragraph_close") continue;
120
+ const i = e.tokens[r], t = e.tokens[r + 1], o = e.tokens[r + 2], s = e.tokens[r + 3];
121
+ if (i?.type !== "blockquote_open" || t?.type !== "paragraph_open" || o?.type !== "inline" || s?.type !== "paragraph_close") continue;
121
122
  const c = o.content.match(/^\[([^\]]+)]\(([^)]+)\)\{data-quotelink=true}$/);
122
123
  c === null || e.tokens.findIndex((f, d) => d > r && f.type === "blockquote_close") < 0 || (i.attrSet("cite", c[2] ?? ""), i.attrSet("data-content", c[1] ?? ""), i.attrSet("data-quote-link", ""), e.tokens.splice(r + 1, 3));
123
124
  }
124
125
  });
125
126
  }
126
- function K(t) {
127
- t.renderer.rules.inline_math = (n, o) => v(n[o]?.content ?? "", !1), t.renderer.rules.math_block = (n, o) => v(n[o]?.content ?? "", !0), t.renderer.rules.mermaid = (n, o) => `<div data-mermaid aria-busy="true"><pre>${h(n[o]?.content ?? "")}</pre></div>
128
- `, t.renderer.rules.yfm_html_block = (n, o) => `<p data-yfm-html>:::html<br>${h(n[o]?.content ?? "")}<br>:::</p>
129
- `, t.renderer.rules.directive = (n, o) => {
130
- const l = n[o];
131
- return l?.info === "html" ? `${l.content}
132
- ` : `<div data-directive="${h(l?.info || "note")}">${h(l?.content ?? "")}</div>
127
+ function N(n) {
128
+ n.renderer.rules.inline_math = (t, o) => v(t[o]?.content ?? "", !1), n.renderer.rules.math_block = (t, o) => v(t[o]?.content ?? "", !0), n.renderer.rules.mermaid = (t, o) => `<div data-mermaid aria-busy="true"><pre>${h(t[o]?.content ?? "")}</pre></div>
129
+ `, n.renderer.rules.yfm_html_block = (t, o) => `<p data-yfm-html>:::html<br>${h(t[o]?.content ?? "")}<br>:::</p>
130
+ `, n.renderer.rules.directive = (t, o) => {
131
+ const s = t[o];
132
+ return s?.info === "html" ? `${s.content}
133
+ ` : `<div data-directive="${h(s?.info || "note")}">${h(s?.content ?? "")}</div>
133
134
  `;
134
- }, t.renderer.rules.html_block = (n, o) => `<div data-raw-html>${h(n[o]?.content ?? "")}</div>
135
- `, t.renderer.rules.html_inline = (n, o) => N(n[o]?.content ?? "");
136
- const e = t.renderer.rules.image;
137
- t.renderer.rules.image = (n, o, l, c, s) => {
138
- const f = n[o], d = f?.attrGet("width"), a = f?.attrGet("height"), u = f?.attrGet("data-image-object-fit"), m = [];
139
- return d != null && /^\d+%?$/.test(d) && m.push(`width: ${d.endsWith("%") ? d : `${d}px`}`), a != null && /^\d+$/.test(a) && m.push(`height: ${a}px`), u != null && m.push(`object-fit: ${u}`), m.length > 0 && f?.attrSet("style", m.join("; ")), e?.(n, o, l, c, s) ?? s.renderToken(n, o, l);
135
+ }, n.renderer.rules.html_block = (t, o) => `<div data-raw-html>${h(t[o]?.content ?? "")}</div>
136
+ `, n.renderer.rules.html_inline = (t, o) => Q(t[o]?.content ?? "");
137
+ const e = n.renderer.rules.image;
138
+ n.renderer.rules.image = (t, o, s, c, l) => {
139
+ const f = t[o], d = f?.attrGet("width"), a = f?.attrGet("height"), u = f?.attrGet("data-image-object-fit"), m = [];
140
+ return d != null && /^\d+%?$/.test(d) && m.push(`width: ${d.endsWith("%") ? d : `${d}px`}`), a != null && /^\d+$/.test(a) && m.push(`height: ${a}px`), u != null && m.push(`object-fit: ${u}`), m.length > 0 && f?.attrSet("style", m.join("; ")), e?.(t, o, s, c, l) ?? l.renderToken(t, o, s);
140
141
  };
141
- const r = t.renderer.rules.heading_open ?? ((n, o, l, c, s) => s.renderToken(n, o, l)), i = t.renderer.rules.heading_close ?? ((n, o, l, c, s) => s.renderToken(n, o, l));
142
- t.renderer.rules.heading_open = (n, o, l, c, s) => {
143
- const f = n[o], d = Number(f?.tag.slice(1)) || 1, a = c.foldingHeadings ??= [];
142
+ const r = n.renderer.rules.heading_open ?? ((t, o, s, c, l) => l.renderToken(t, o, s)), i = n.renderer.rules.heading_close ?? ((t, o, s, c, l) => l.renderToken(t, o, s));
143
+ n.renderer.rules.heading_open = (t, o, s, c, l) => {
144
+ const f = t[o], d = Number(f?.tag.slice(1)) || 1, a = c.foldingHeadings ??= [];
144
145
  let u = "";
145
146
  for (; (a.at(-1) ?? 0) >= d; )
146
147
  a.pop(), u += "</details>";
147
- return f?.attrGet("data-folding") === "true" && (a.push(d), u += "<details data-folding-section open><summary>"), u + r(n, o, l, c, s);
148
- }, t.renderer.rules.heading_close = (n, o, l, c, s) => {
149
- const f = n[o - 2];
150
- return i(n, o, l, c, s) + (f?.attrGet("data-folding") === "true" ? "</summary>" : "");
148
+ return f?.attrGet("data-folding") === "true" && (a.push(d), u += "<details data-folding-section open><summary>"), u + r(t, o, s, c, l);
149
+ }, n.renderer.rules.heading_close = (t, o, s, c, l) => {
150
+ const f = t[o - 2];
151
+ return i(t, o, s, c, l) + (f?.attrGet("data-folding") === "true" ? "</summary>" : "");
151
152
  };
152
153
  }
153
- function v(t, e) {
154
+ function v(n, e) {
154
155
  try {
155
- return W.renderToString(t, { displayMode: e, throwOnError: !0 });
156
+ return W.renderToString(n, { displayMode: e, throwOnError: !0 });
156
157
  } catch {
157
158
  const r = e ? "pre" : "span";
158
- return `<${r} data-math-error>${h(t)}</${r}>`;
159
+ return `<${r} data-math-error>${h(n)}</${r}>`;
159
160
  }
160
161
  }
161
- function N(t) {
162
- if (/^<\/?u>$/.test(t) || t === "</span>") return t;
163
- const e = t.match(/^<span style="color:\s*([^";<>]+)">$/i)?.[1]?.trim();
164
- return e !== void 0 && /^(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\([^;<>]+\)|[a-z]+)$/i.test(e) ? `<span style="color: ${h(e)}">` : h(t);
162
+ function Q(n) {
163
+ if (/^<\/?u>$/.test(n) || n === "</span>") return n;
164
+ const e = n.match(/^<span style="color:\s*([^";<>]+)">$/i)?.[1]?.trim();
165
+ return e !== void 0 && /^(?:#[\da-f]{3,8}|(?:rgb|hsl)a?\([^;<>]+\)|[a-z]+)$/i.test(e) ? `<span style="color: ${h(e)}">` : h(n);
165
166
  }
166
- function y(t, e) {
167
+ function y(n, e) {
167
168
  let r = 0;
168
- for (let i = e - 1; i >= 0 && t[i] === "\\"; i -= 1) r += 1;
169
+ for (let i = e - 1; i >= 0 && n[i] === "\\"; i -= 1) r += 1;
169
170
  return r % 2 === 1;
170
171
  }
171
- function Q() {
172
- const t = new x("commonmark", { html: !0 }).enable("table").enable("strikethrough").use(B).use(D).use(E).use(O);
173
- return z(t), L(t), F(t), J(t), K(t), t;
172
+ function U() {
173
+ const n = new x("commonmark", { html: !0 }).enable("table").enable("strikethrough").use(B).use(D).use(E).use(O);
174
+ return L(n), F(n), P(n), K(n), N(n), n;
174
175
  }
175
- const U = Q();
176
- function V(t) {
177
- const e = {}, r = U.render(t, e), i = e.foldingHeadings?.length ?? 0;
176
+ const V = U();
177
+ function X(n) {
178
+ const e = {}, r = V.render(n, e), i = e.foldingHeadings?.length ?? 0;
178
179
  return r + "</details>".repeat(i);
179
180
  }
180
- let X = 0, $;
181
- function Y() {
182
- return $ ??= import("./mermaid.core-CR0bA2Wa.js").then((t) => t.bq).then(({ default: t }) => (t.initialize({ securityLevel: "strict", startOnLoad: !1 }), t)), $;
183
- }
181
+ let Y = 0, $;
184
182
  function Z() {
185
- return `markdown-renderer-mermaid-${++X}`;
183
+ return $ ??= import("./mermaid.core-CR0bA2Wa.js").then((n) => n.bq).then(({ default: n }) => (n.initialize({ securityLevel: "strict", startOnLoad: !1 }), n)), $;
184
+ }
185
+ function ee() {
186
+ return `markdown-renderer-mermaid-${++Y}`;
186
187
  }
187
- const ee = ["innerHTML"], ie = /* @__PURE__ */ M({
188
+ const te = ["innerHTML"], ne = /* @__PURE__ */ M({
188
189
  name: "MarkdownRenderer",
189
190
  __name: "MarkdownRenderer",
190
191
  props: {
191
192
  content: {},
192
193
  directiveComponents: {}
193
194
  },
194
- setup(t) {
195
- const e = t, r = S(), i = w()?.appContext, n = I(() => V(e.content));
196
- let o = 0, l = !1, c = [];
197
- function s() {
195
+ setup(n) {
196
+ const e = n, r = S(), i = w()?.appContext, t = I(() => X(e.content));
197
+ let o = 0, s = !1, c = [];
198
+ function l() {
198
199
  for (const a of c) b(null, a);
199
200
  c = [];
200
201
  }
201
202
  function f() {
202
- if (s(), e.directiveComponents !== void 0)
203
+ if (l(), e.directiveComponents !== void 0)
203
204
  for (const a of r.value?.querySelectorAll("[data-directive]") ?? []) {
204
205
  const u = a.dataset.directive ?? "", m = e.directiveComponents[u];
205
206
  if (m === void 0) continue;
206
- const k = {
207
+ const _ = {
207
208
  content: a.textContent ?? "",
208
209
  name: u,
209
210
  readonly: !0,
210
211
  updateContent: () => {
211
212
  }
212
- }, g = R(m, k);
213
+ }, g = R(m, _);
213
214
  g.appContext = i ?? null, b(g, a), c.push(a);
214
215
  }
215
216
  }
@@ -218,18 +219,18 @@ const ee = ["innerHTML"], ie = /* @__PURE__ */ M({
218
219
  if (u.length === 0) return;
219
220
  let m;
220
221
  try {
221
- m = await Y();
222
+ m = await Z();
222
223
  } catch {
223
224
  for (const p of u)
224
225
  p.removeAttribute("aria-busy"), p.setAttribute("data-mermaid-error", "");
225
226
  return;
226
227
  }
227
228
  for (const p of u) {
228
- if (l || a !== o || !p.isConnected) return;
229
- const k = p.querySelector("pre")?.textContent ?? "";
229
+ if (s || a !== o || !p.isConnected) return;
230
+ const _ = p.querySelector("pre")?.textContent ?? "";
230
231
  try {
231
- const { bindFunctions: g, svg: C } = await m.render(Z(), k);
232
- if (l || a !== o || !p.isConnected) return;
232
+ const { bindFunctions: g, svg: C } = await m.render(ee(), _);
233
+ if (s || a !== o || !p.isConnected) return;
233
234
  p.innerHTML = C, p.removeAttribute("aria-busy"), g?.(p);
234
235
  } catch {
235
236
  p.removeAttribute("aria-busy"), p.setAttribute("data-mermaid-error", "");
@@ -244,15 +245,15 @@ const ee = ["innerHTML"], ie = /* @__PURE__ */ M({
244
245
  ), H(() => {
245
246
  f(), d();
246
247
  }), A(() => {
247
- l = !0, o += 1, s();
248
+ s = !0, o += 1, l();
248
249
  }), (a, u) => (j(), G("div", {
249
250
  ref_key: "root",
250
251
  ref: r,
251
252
  class: "markdown-renderer",
252
- innerHTML: n.value
253
- }, null, 8, ee));
253
+ innerHTML: t.value
254
+ }, null, 8, te));
254
255
  }
255
- });
256
+ }), le = /* @__PURE__ */ z(ne, [["__scopeId", "data-v-91962f8a"]]);
256
257
  export {
257
- ie as MarkdownRenderer
258
+ le as MarkdownRenderer
258
259
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexagon-editor",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Vue 3 Markdown/YFM WYSIWYG and markup editor",
5
5
  "license": "MIT",
6
6
  "type": "module",