@muibook/components 11.0.1 → 12.0.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.
@@ -1,111 +1,306 @@
1
- import { marked as m } from "marked";
2
- const u = (n) => n.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;").replace(/'/g, "&#39;"), p = (n) => {
3
- const i = n.split(`
4
- `);
5
- let d = !1, t = !1;
6
- const o = [];
7
- for (const e of i) {
1
+ import { marked as $ } from "../../node_modules/marked/lib/marked.esm/index.js";
2
+ const u = (d) => d.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\"/g, "&quot;").replace(/'/g, "&#39;"), w = (d) => {
3
+ const c = d.split(`
4
+ `), a = [], i = [], o = (e, s, r) => {
5
+ i.push(s), a.push({ type: e, closeTag: r });
6
+ }, t = (e) => {
7
+ if (a.length !== 0) {
8
+ if (!e) {
9
+ const s = a.pop();
10
+ s && i.push(s.closeTag);
11
+ return;
12
+ }
13
+ for (let s = a.length - 1; s >= 0; s -= 1)
14
+ if (a[s].type === e) {
15
+ const [r] = a.splice(s, 1);
16
+ r && i.push(r.closeTag);
17
+ return;
18
+ }
19
+ }
20
+ };
21
+ for (const e of c) {
22
+ const s = e.match(/^--\s*table-columns-([a-z0-9-]+)\s*--$/i);
23
+ if (s) {
24
+ i.push(`<div data-md-table-columns="${s[1].replace(/-/g, " ")}"></div>`);
25
+ continue;
26
+ }
27
+ const r = e.match(/^--\s*vstack-space-(\d{3})-start\s*--$/i);
28
+ if (r) {
29
+ o(
30
+ "vstack",
31
+ `<mui-v-stack space="var(--space-${r[1]})">`,
32
+ "</mui-v-stack>"
33
+ );
34
+ continue;
35
+ }
36
+ if (e.match(/^--\s*vstack-end\s*--$/i)) {
37
+ t("vstack");
38
+ continue;
39
+ }
40
+ const l = e.match(/^--\s*vstack-space-(\d{3})\s*--$/i);
41
+ if (l) {
42
+ const n = a[a.length - 1];
43
+ (n == null ? void 0 : n.type) === "vstack" ? t("vstack") : o(
44
+ "vstack",
45
+ `<mui-v-stack space="var(--space-${l[1]})">`,
46
+ "</mui-v-stack>"
47
+ );
48
+ continue;
49
+ }
50
+ const m = e.match(/^--\s*hstack-space-(\d{3})-start\s*--$/i);
51
+ if (m) {
52
+ o(
53
+ "hstack",
54
+ `<mui-h-stack space="var(--space-${m[1]})">`,
55
+ "</mui-h-stack>"
56
+ );
57
+ continue;
58
+ }
59
+ if (e.match(/^--\s*hstack-end\s*--$/i)) {
60
+ t("hstack");
61
+ continue;
62
+ }
63
+ const p = e.match(/^--\s*hstack-space-(\d{3})\s*--$/i);
64
+ if (p) {
65
+ const n = a[a.length - 1];
66
+ (n == null ? void 0 : n.type) === "hstack" ? t("hstack") : o(
67
+ "hstack",
68
+ `<mui-h-stack space="var(--space-${p[1]})">`,
69
+ "</mui-h-stack>"
70
+ );
71
+ continue;
72
+ }
73
+ const g = e.match(/^--\s*stack-space-(\d{3})-bp-(\d{3}|medium)-start\s*--$/i);
74
+ if (g) {
75
+ const n = g[1], h = g[2].toLowerCase();
76
+ o(
77
+ "stack",
78
+ `<div class="md-stack-responsive md-stack-responsive-${h === "medium" ? "768" : h}" style="display:flex;gap:var(--space-${n});align-items:stretch;">`,
79
+ "</div>"
80
+ );
81
+ continue;
82
+ }
83
+ if (e.match(/^--\s*stack-end\s*--$/i)) {
84
+ t("stack");
85
+ continue;
86
+ }
87
+ const b = e.match(/^--\s*stack-space-(\d{3})-bp-(\d{3}|medium)\s*--$/i);
88
+ if (b) {
89
+ const n = a[a.length - 1];
90
+ if ((n == null ? void 0 : n.type) === "stack") t("stack");
91
+ else {
92
+ const h = b[1], v = b[2].toLowerCase();
93
+ o(
94
+ "stack",
95
+ `<div class="md-stack-responsive md-stack-responsive-${v === "medium" ? "768" : v}" style="display:flex;gap:var(--space-${h});align-items:stretch;">`,
96
+ "</div>"
97
+ );
98
+ }
99
+ continue;
100
+ }
101
+ if (e.match(/^--\s*box-start\s*--$/i)) {
102
+ o("box", "<div>", "</div>");
103
+ continue;
104
+ }
105
+ if (e.match(/^--\s*box-end\s*--$/i)) {
106
+ t("box");
107
+ continue;
108
+ }
8
109
  if (e.match(/^--\s*box\s*--$/i)) {
9
- t ? (o.push("</div>"), t = !1) : (o.push("<div>"), t = !0);
110
+ const n = a[a.length - 1];
111
+ (n == null ? void 0 : n.type) === "box" ? t("box") : o("box", "<div>", "</div>");
10
112
  continue;
11
113
  }
12
114
  if (e.match(/^--\s*rule\s*--$/i)) {
13
- o.push("<mui-rule></mui-rule>");
115
+ i.push("<mui-rule></mui-rule>");
14
116
  continue;
15
117
  }
16
- const c = e.match(/^--\s*space-(\d{3})\s*--$/i);
17
- if (c) {
18
- const l = c[1];
19
- o.push(`<div style="height:var(--space-${l});"></div>`);
118
+ const k = e.match(/^--\s*space-(\d{3})\s*--$/i);
119
+ if (k) {
120
+ i.push(`<div style="height:var(--space-${k[1]});"></div>`);
20
121
  continue;
21
122
  }
22
- const r = e.match(/^--\s*grid-col-([^-]+(?:-[^-]+)*)\s*--$/);
23
- if (r) {
24
- if (d)
25
- o.push("</div>"), d = !1;
123
+ if (e.match(/^--\s*grid-end\s*--$/i)) {
124
+ t("grid");
125
+ continue;
126
+ }
127
+ const f = e.match(/^--\s*grid-col-([^-]+(?:-[^-]+)*)-start\s*--$/i);
128
+ if (f) {
129
+ const n = f[1].split("-").join(" ");
130
+ o(
131
+ "grid",
132
+ `<div style="display:grid;grid-template-columns:${n};gap:var(--space-300);align-items:start;">`,
133
+ "</div>"
134
+ );
135
+ continue;
136
+ }
137
+ const x = e.match(/^--\s*grid-col-([^-]+(?:-[^-]+)*)\s*--$/);
138
+ if (x) {
139
+ const n = a[a.length - 1];
140
+ if ((n == null ? void 0 : n.type) === "grid") t("grid");
26
141
  else {
27
- const l = r[1].split("-").join(" ");
28
- o.push(
29
- `<div style="display:grid;grid-template-columns:${l};gap:var(--space-300);align-items:start;">`
30
- ), d = !0;
142
+ const h = x[1].split("-").join(" ");
143
+ o(
144
+ "grid",
145
+ `<div style="display:grid;grid-template-columns:${h};gap:var(--space-300);align-items:start;">`,
146
+ "</div>"
147
+ );
31
148
  }
32
149
  continue;
33
150
  }
34
- o.push(e);
151
+ i.push(e);
35
152
  }
36
- return d && o.push("</div>"), t && o.push("</div>"), o.join(`
153
+ for (; a.length > 0; ) {
154
+ const e = a.pop();
155
+ e && i.push(e.closeTag);
156
+ }
157
+ return i.join(`
37
158
  `);
38
- }, h = (n) => n.toLowerCase().trim().replace(/<[^>]+>/g, "").replace(/[^\w\s-]/g, "").replace(/\s+/g, "-"), b = (n) => {
39
- const { bodySize: i, codeSize: d } = n, t = new m.Renderer(), o = /* @__PURE__ */ new Map();
40
- return t.heading = (e, s) => {
41
- const a = {
159
+ }, y = (d) => d.toLowerCase().trim().replace(/<[^>]+>/g, "").replace(/[^\w\s-]/g, "").replace(/\s+/g, "-"), z = (d) => {
160
+ const { bodySize: c, codeSize: a } = d, i = new $.Renderer(), o = /* @__PURE__ */ new Map();
161
+ return i.heading = (t, e) => {
162
+ const s = {
42
163
  1: { size: "2", level: "2" },
43
164
  2: { size: "2", level: "2" },
44
165
  3: { size: "4", level: "4" },
45
166
  4: { size: "5", level: "5" },
46
167
  5: { size: "5", level: "5" },
47
168
  6: { size: "5", level: "5" }
48
- }, c = a[s] ?? a[4], r = h(e), l = (o.get(r) ?? 0) + 1;
49
- return o.set(r, l), `<mui-heading id="${l > 1 ? `${r}-${l}` : r}" size="${c.size}" level="${c.level}">${e}</mui-heading>`;
50
- }, t.paragraph = (e) => `<mui-body size="${i}" weight="regular" variant="default">${e}</mui-body>`, t.link = (e, s, a) => {
51
- const c = e ? u(e) : "", r = s ? ` title="${u(s)}"` : "";
52
- return `<mui-link href="${c}"${r}>${a}</mui-link>`;
53
- }, t.list = (e, s) => `<mui-list size="${i}" as="${s ? "ol" : "ul"}">${e}</mui-list>`, t.listitem = (e) => `<mui-list-item size="${i}">${e}</mui-list-item>`, t.hr = () => "<mui-rule></mui-rule>", t.blockquote = (e) => `<mui-quote>${e}</mui-quote>`, t.codespan = (e) => `<span class="md-inline-code">${u(e)}</span>`, t.code = (e) => `<div class="md-code-block">
54
- <mui-button class="md-code-copy" size="x-small" variant="tertiary" data-copy-code>Copy</mui-button>
55
- <mui-code size="${d}" scrollable>${u(e)}</mui-code>
56
- </div>`, t.image = (e, s, a) => {
57
- const c = e ? u(e) : "", r = a ? u(a) : "", l = s ? ` title="${u(s)}"` : "";
58
- return `<mui-image src="${c}" alt="${r}"${l}></mui-image>`;
59
- }, t.table = (e, s) => `<mui-card class="md-table-card">
169
+ }, r = s[e] ?? s[4], l = y(t), m = (o.get(l) ?? 0) + 1;
170
+ return o.set(l, m), `<mui-heading id="${m > 1 ? `${l}-${m}` : l}" size="${r.size}" level="${r.level}">${t}</mui-heading>`;
171
+ }, i.paragraph = (t) => `<mui-body size="${c}" weight="regular" variant="default">${t}</mui-body>`, i.link = (t, e, s) => {
172
+ const r = t ? u(t) : "", l = e ? ` title="${u(e)}"` : "";
173
+ return `<mui-link href="${r}"${l}>${s}</mui-link>`;
174
+ }, i.list = (t, e) => `<mui-list size="${c}" as="${e ? "ol" : "ul"}">${t}</mui-list>`, i.listitem = (t) => `<mui-list-item size="${c}">${t}</mui-list-item>`, i.hr = () => "<mui-rule></mui-rule>", i.blockquote = (t) => `<mui-quote>${t}</mui-quote>`, i.codespan = (t) => `<span class="md-inline-code">${u(t)}</span>`, i.code = (t) => `<div class="md-code-block" data-code-block>
175
+ <div class="md-code-actions">
176
+ <mui-button class="md-code-expand" size="x-small" variant="tertiary" data-toggle-code>Expand</mui-button>
177
+ <mui-button class="md-code-copy" size="x-small" variant="tertiary" data-copy-code>Copy</mui-button>
178
+ </div>
179
+ <div class="md-code-wrap" data-code-wrap>
180
+ <mui-code size="${a}" scrollable>${u(t)}</mui-code>
181
+ </div>
182
+ </div>`, i.image = (t, e, s) => {
183
+ const r = t ? u(t) : "", l = s ? u(s) : "", m = e ? ` title="${u(e)}"` : "", p = e ? ` data-title="${u(e)}"` : "";
184
+ return `<mui-image src="${r}" alt="${l}"${m} data-md-image data-src="${r}" data-alt="${l}"${p}></mui-image>`;
185
+ }, i.table = (t, e) => `<mui-card class="md-table-card">
60
186
  <mui-card-body condensed>
61
187
  <div class="md-table-scroll">
62
188
  <mui-table class="md-table">
63
- <mui-row-group heading>${e}</mui-row-group>
64
- <mui-row-group>${s}</mui-row-group>
189
+ <mui-row-group heading>${t}</mui-row-group>
190
+ <mui-row-group>${e}</mui-row-group>
65
191
  </mui-table>
66
192
  </div>
67
193
  </mui-card-body>
68
- </mui-card>`, t.tablerow = (e) => {
69
- const s = (e.match(/<mui-cell\b/g) || []).length;
70
- return `<mui-row columns="${s ? Array(s).fill("1fr").join(" ") : "1fr"}">${e}</mui-row>`;
71
- }, t.tablecell = (e) => `<mui-cell>${e}</mui-cell>`, t;
194
+ </mui-card>`, i.tablerow = (t) => {
195
+ const e = (t.match(/<mui-cell\b/g) || []).length;
196
+ return `<mui-row columns="${e ? Array(e).fill("1fr").join(" ") : "1fr"}">${t}</mui-row>`;
197
+ }, i.tablecell = (t) => `<mui-cell>${t}</mui-cell>`, i;
72
198
  };
73
- class g extends HTMLElement {
74
- static get observedAttributes() {
75
- return ["markdown", "body-size", "code-size"];
76
- }
199
+ class S extends HTMLElement {
77
200
  constructor() {
78
- super(), this.attachShadow({ mode: "open" });
201
+ super(...arguments), this.lightboxEl = null;
202
+ }
203
+ static get observedAttributes() {
204
+ return ["markdown", "body-size", "code-size", "render-mode", "lightbox"];
79
205
  }
80
206
  connectedCallback() {
81
207
  this.render(), this.hasAttribute("markdown") || (this.observer = new MutationObserver(() => this.render()), this.observer.observe(this, { childList: !0, subtree: !0, characterData: !0 }));
82
208
  }
83
209
  disconnectedCallback() {
84
- this.observer && this.observer.disconnect();
210
+ this.observer && this.observer.disconnect(), this.closeLightbox();
85
211
  }
86
212
  attributeChangedCallback() {
87
213
  this.render();
88
214
  }
89
215
  getBodySize() {
90
- const i = this.getAttribute("body-size");
91
- return i || "small";
216
+ return this.getAttribute("body-size") || "small";
92
217
  }
93
218
  getCodeSize() {
94
- const i = this.getAttribute("code-size");
95
- return i || "x-small";
219
+ return this.getAttribute("code-size") || "x-small";
96
220
  }
97
221
  getMarkdown() {
98
- const i = this.getAttribute("markdown");
99
- return i !== null ? i : this.textContent ?? "";
222
+ const c = this.getAttribute("markdown");
223
+ return c !== null ? c : this.textContent ?? "";
224
+ }
225
+ getRenderRoot() {
226
+ return this.getAttribute("render-mode") === "light" ? this : (this.shadowRoot || this.attachShadow({ mode: "open" }), this.shadowRoot);
227
+ }
228
+ isLightboxEnabled() {
229
+ return this.hasAttribute("lightbox");
230
+ }
231
+ applyTableColumns(c) {
232
+ Array.from(c.querySelectorAll("[data-md-table-columns]")).forEach((i) => {
233
+ const o = i.getAttribute("data-md-table-columns") || "";
234
+ let t = i.nextElementSibling;
235
+ for (; t && t.tagName.toLowerCase() !== "mui-card"; )
236
+ t = t.nextElementSibling;
237
+ t && t.querySelectorAll("mui-row").forEach((s) => s.setAttribute("columns", o)), i.remove();
238
+ });
239
+ }
240
+ openLightbox(c, a, i) {
241
+ this.closeLightbox();
242
+ const o = document.createElement("div");
243
+ o.className = "md-lightbox-overlay", o.innerHTML = `
244
+ <div class="md-lightbox-content" role="dialog" aria-modal="true">
245
+ <img src="${c}" alt="${a || "Markdown image"}" />
246
+ ${i ? `<mui-body size="small" variant="optional">${i}</mui-body>` : ""}
247
+ </div>
248
+ `, o.addEventListener("click", (t) => {
249
+ t.target === o && this.closeLightbox();
250
+ }), document.body.appendChild(o), this.lightboxEl = o, this.dispatchEvent(
251
+ new CustomEvent("mui-markdown-lightbox-change", {
252
+ detail: { open: !0 },
253
+ bubbles: !0,
254
+ composed: !0
255
+ })
256
+ );
257
+ }
258
+ closeLightbox() {
259
+ this.lightboxEl && (this.lightboxEl.remove(), this.lightboxEl = null, this.dispatchEvent(
260
+ new CustomEvent("mui-markdown-lightbox-change", {
261
+ detail: { open: !1 },
262
+ bubbles: !0,
263
+ composed: !0
264
+ })
265
+ ));
266
+ }
267
+ bindHandlers(c) {
268
+ c.querySelectorAll("[data-copy-code]").forEach((t) => {
269
+ t.onclick = () => {
270
+ var l;
271
+ const e = t.closest("[data-code-block]"), s = e == null ? void 0 : e.querySelector("mui-code"), r = (s == null ? void 0 : s.textContent) ?? "";
272
+ r && ((l = navigator.clipboard) == null || l.writeText(r).catch(() => {
273
+ }));
274
+ };
275
+ }), c.querySelectorAll("[data-toggle-code]").forEach((t) => {
276
+ t.onclick = () => {
277
+ const e = t.closest("[data-code-block]");
278
+ if (!e) return;
279
+ const s = e.toggleAttribute("data-expanded");
280
+ t.textContent = s ? "Collapse" : "Expand";
281
+ };
282
+ }), c.querySelectorAll("[data-md-image]").forEach((t) => {
283
+ t.onclick = () => {
284
+ const e = t.getAttribute("data-src") || "", s = t.getAttribute("data-alt") || "", r = t.getAttribute("data-title") || void 0;
285
+ this.dispatchEvent(
286
+ new CustomEvent("mui-markdown-image-click", {
287
+ detail: { src: e, alt: s, title: r },
288
+ bubbles: !0,
289
+ composed: !0
290
+ })
291
+ ), this.isLightboxEnabled() && e && this.openLightbox(e, s, r);
292
+ };
293
+ });
100
294
  }
101
295
  render() {
102
- if (!this.shadowRoot) return;
103
- const i = this.getMarkdown(), d = p(i), t = b({
296
+ const c = this.getRenderRoot();
297
+ if (!c) return;
298
+ const a = this.getMarkdown(), i = w(a), o = z({
104
299
  bodySize: this.getBodySize(),
105
300
  codeSize: this.getCodeSize()
106
- }), o = m.parse(d, { renderer: t, gfm: !0 });
107
- this.shadowRoot.innerHTML = /*html*/
108
- `
301
+ }), e = (
302
+ /*html*/
303
+ `
109
304
  <style>
110
305
  :host { display: block; }
111
306
  .md-inline-code {
@@ -119,11 +314,21 @@ class g extends HTMLElement {
119
314
  .md-code-block {
120
315
  position: relative;
121
316
  }
122
- .md-code-copy {
317
+ .md-code-actions {
123
318
  position: absolute;
124
319
  top: var(--space-200);
125
320
  right: var(--space-200);
126
321
  z-index: 1;
322
+ display: flex;
323
+ gap: var(--space-100);
324
+ }
325
+ .md-code-wrap {
326
+ max-height: 24rem;
327
+ overflow: auto;
328
+ transition: max-height 180ms ease;
329
+ }
330
+ .md-code-block[data-expanded] .md-code-wrap {
331
+ max-height: none;
127
332
  }
128
333
  .md-table-card {
129
334
  overflow-x: auto;
@@ -134,16 +339,51 @@ class g extends HTMLElement {
134
339
  .md-table {
135
340
  min-width: 888px;
136
341
  }
342
+ .md-stack-responsive {
343
+ flex-direction: column;
344
+ }
345
+ .md-stack-responsive > * {
346
+ flex: 1;
347
+ }
348
+ @media (min-width: 768px) {
349
+ .md-stack-responsive-768 {
350
+ flex-direction: row;
351
+ }
352
+ }
353
+ @media (min-width: 550px) {
354
+ .md-stack-responsive-550 {
355
+ flex-direction: row;
356
+ }
357
+ }
358
+ .md-lightbox-overlay {
359
+ position: fixed;
360
+ inset: 0;
361
+ z-index: 9999;
362
+ background: rgba(0, 0, 0, 0.9);
363
+ display: flex;
364
+ align-items: center;
365
+ justify-content: center;
366
+ backdrop-filter: blur(var(--space-300));
367
+ }
368
+ .md-lightbox-content {
369
+ display: flex;
370
+ flex-direction: column;
371
+ gap: var(--space-200);
372
+ align-items: center;
373
+ max-width: min(90vw, 120rem);
374
+ }
375
+ .md-lightbox-content img {
376
+ max-width: min(90vw, 120rem);
377
+ max-height: 75vh;
378
+ object-fit: contain;
379
+ }
137
380
  </style>
138
- <div class="md-root">${o}</div>
139
- `, this.shadowRoot.querySelectorAll("[data-copy-code]").forEach((s) => {
140
- s.onclick = () => {
141
- var l;
142
- const a = s.closest(".md-code-block"), c = a == null ? void 0 : a.querySelector("mui-code"), r = (c == null ? void 0 : c.textContent) ?? "";
143
- r && ((l = navigator.clipboard) == null || l.writeText(r).catch(() => {
144
- }));
145
- };
146
- });
381
+ <div class="md-root">${$.parse(i, { renderer: o, gfm: !0 })}</div>
382
+ `
383
+ );
384
+ c === this ? this.innerHTML = e : c.innerHTML = e;
385
+ const s = c === this ? this : c;
386
+ this.applyTableColumns(s), this.bindHandlers(s);
147
387
  }
148
388
  }
149
- customElements.get("mui-markdown") || customElements.define("mui-markdown", g);
389
+ customElements.get("mui-markdown") || customElements.define("mui-markdown", S);