@cocoar/vue-markdown 0.1.0-beta.23

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.css ADDED
@@ -0,0 +1 @@
1
+ .coar-markdown{display:block;--coar-markdown-text: var(--coar-text-neutral-primary);--coar-markdown-link: var(--coar-text-brand-primary, var(--coar-text-neutral-primary));--coar-markdown-muted-text: var(--coar-text-neutral-tertiary);--coar-markdown-border: var(--coar-border-neutral-tertiary);--coar-markdown-surface: var(--coar-background-neutral-primary);--coar-markdown-surface-muted: var( --coar-background-neutral-tertiary, var(--coar-background-neutral-primary) );--coar-markdown-radius: var(--coar-radius-xs);--coar-markdown-space-1: var(--coar-spacing-s, .5rem);--coar-markdown-space-2: var(--coar-spacing-m, 1rem);--coar-markdown-heading-block-start: var(--coar-spacing-xxxl, 4rem);color:var(--coar-markdown-text)}.coar-markdown :where(h1,h2,h3,h4,h5,h6){font-family:var(--coar-font-family-title, inherit);color:var(--coar-markdown-text)}.coar-markdown h1{font-size:var(--coar-font-size-xl);font-weight:var(--coar-font-weight-bold);line-height:var(--coar-line-height-tight)}.coar-markdown h2{font-size:var(--coar-font-size-l);font-weight:var(--coar-font-weight-bold);line-height:1.25}.coar-markdown h3{font-size:var(--coar-font-size-m);font-weight:var(--coar-font-weight-semi-bold);line-height:var(--coar-line-height-snug)}.coar-markdown h4{font-size:var(--coar-font-size-s);font-weight:var(--coar-font-weight-semi-bold);line-height:1.35}.coar-markdown h5{font-size:var(--coar-font-size-xs);font-weight:var(--coar-font-weight-semi-bold);line-height:var(--coar-line-height-normal)}.coar-markdown h6{font-size:var(--coar-font-size-xxs);font-weight:var(--coar-font-weight-medium);line-height:1.45}.coar-markdown-heading,.coar-markdown-paragraph,.coar-markdown-blockquote,.coar-markdown-list,.coar-markdown-code-block,.coar-markdown-table,.coar-markdown-hr{margin:0}.coar-markdown>:where(h1,h2,h3,h4,h5,h6,p,blockquote,ul,ol,pre,table,hr,.coar-code-block-host,.coar-table-host){margin-block:0 var(--coar-markdown-space-2)}.coar-markdown>:where(h1,h2,h3,h4,h5,h6){margin-block-start:var(--coar-markdown-heading-block-start)}.coar-markdown>:where(h1,h2,h3,h4,h5,h6)+:where(h1,h2,h3,h4,h5,h6){margin-block-start:var(--coar-markdown-space-1)}.coar-markdown>:where(h1,h2,h3,h4,h5,h6):first-child{margin-block-start:0}.coar-markdown-blockquote{padding-inline:var(--coar-markdown-space-2);border-left:2px solid var(--coar-markdown-border)}.coar-markdown-list{padding-inline-start:var(--coar-spacing-l, 1.5rem);list-style-position:outside}.coar-markdown-list--unordered{list-style-type:disc}.coar-markdown-list--ordered{list-style-type:decimal}.coar-markdown-list-item{display:list-item;margin-block:.25em}.coar-markdown-list-item--task{list-style:none;display:flex;align-items:flex-start;gap:var(--coar-spacing-s, .5rem)}.coar-markdown-list-item-content{min-width:0}.coar-markdown-task-checkbox{margin-top:.15em}.coar-markdown-code-block,.coar-markdown-code{display:block}.coar-markdown-inline-code{padding:0;border:0;border-radius:0;background:transparent;color:var(--coar-text-accent-secondary, var(--coar-markdown-link))}.coar-markdown-link{text-decoration:underline;color:var(--coar-markdown-link)}.coar-markdown-image{max-width:100%;height:auto;vertical-align:middle}.coar-markdown-table{width:100%;border:1px solid var(--coar-markdown-border);border-radius:var(--coar-markdown-radius);border-collapse:separate;border-spacing:0;overflow:hidden}.coar-markdown-table-cell{padding:var(--coar-markdown-space-1);vertical-align:top;border-right:1px solid var(--coar-markdown-border);border-bottom:1px solid var(--coar-markdown-border)}.coar-markdown-table :where(tr) .coar-markdown-table-cell:last-child{border-right:0}.coar-markdown-table :where(tbody) tr:last-child .coar-markdown-table-cell{border-bottom:0}.coar-markdown-table :where(thead) .coar-markdown-table-cell{background:var(--coar-markdown-surface-muted);font-weight:600}.coar-markdown-hr{border:0;border-top:1px solid var(--coar-markdown-border)}.coar-markdown-unsupported,.coar-markdown-unsupported-inline{font-style:italic;color:var(--coar-markdown-muted-text)}.coar-markdown-unsupported{padding:var(--coar-markdown-space-1);border:1px dashed var(--coar-markdown-border);border-radius:var(--coar-markdown-radius);background:var(--coar-markdown-surface)}
package/dist/index.js ADDED
@@ -0,0 +1,293 @@
1
+ import { defineComponent as g, resolveComponent as T, openBlock as n, createElementBlock as l, Fragment as a, renderList as k, createTextVNode as A, toDisplayString as f, createVNode as i, unref as s, createBlock as p, createCommentVNode as _, resolveDynamicComponent as L, withCtx as C, normalizeClass as y, createElementVNode as m } from "vue";
2
+ import { CoarCodeBlock as S, CoarTable as V } from "@cocoar/vue-ui";
3
+ function q(r) {
4
+ const e = r.attrs?.depth;
5
+ if (typeof e != "number") return 1;
6
+ const c = Math.trunc(e);
7
+ return c <= 1 ? 1 : c === 2 ? 2 : c === 3 ? 3 : c === 4 ? 4 : c === 5 ? 5 : 6;
8
+ }
9
+ function D(r) {
10
+ const e = r.attrs?.anchor;
11
+ return typeof e == "string" && e.length > 0 ? e : null;
12
+ }
13
+ function E(r) {
14
+ const e = r.attrs?.language;
15
+ return typeof e == "string" && e.trim().length > 0 ? e.trim() : "text";
16
+ }
17
+ function I(r) {
18
+ return !!r.attrs?.ordered;
19
+ }
20
+ function R(r) {
21
+ const e = r.attrs?.start;
22
+ return typeof e == "number" ? e : null;
23
+ }
24
+ function x(r) {
25
+ return typeof r.attrs?.checked == "boolean";
26
+ }
27
+ function z(r) {
28
+ return r.attrs?.checked === !0;
29
+ }
30
+ function w(r) {
31
+ const e = r.attrs?.url;
32
+ return typeof e == "string" && e.length > 0 ? e : null;
33
+ }
34
+ function v(r) {
35
+ const e = w(r);
36
+ return e ? e.startsWith("#") && typeof window < "u" ? `${window.location.pathname}${window.location.search}${e}` : e : null;
37
+ }
38
+ function U(r) {
39
+ const e = w(r);
40
+ return e && W(e) ? "_blank" : null;
41
+ }
42
+ function F(r) {
43
+ const e = w(r);
44
+ return e && W(e) ? "noopener noreferrer" : null;
45
+ }
46
+ function $(r) {
47
+ const e = r.attrs?.url;
48
+ return typeof e == "string" && e.trim().length > 0 ? e.trim() : null;
49
+ }
50
+ function H(r) {
51
+ const e = r.attrs?.alt;
52
+ return typeof e == "string" ? e : "";
53
+ }
54
+ function O(r) {
55
+ const e = r.attrs?.title;
56
+ return typeof e == "string" && e.trim().length > 0 ? e.trim() : null;
57
+ }
58
+ function B(r, e) {
59
+ return M(r, e) === "right";
60
+ }
61
+ function N(r, e) {
62
+ return M(r, e) === "center";
63
+ }
64
+ function j(r) {
65
+ const e = r.attrs?.originalType;
66
+ return typeof e == "string" ? e : String(r.type);
67
+ }
68
+ function M(r, e) {
69
+ const c = r.attrs?.align;
70
+ if (!Array.isArray(c)) return null;
71
+ const o = c[e];
72
+ return o === "left" || o === "right" || o === "center" ? o : null;
73
+ }
74
+ function W(r) {
75
+ const e = r.trim();
76
+ return e.startsWith("#") || e.startsWith("/") || e.startsWith("./") || e.startsWith("../") || e.startsWith("mailto:") || e.startsWith("tel:") ? !1 : e.startsWith("http://") || e.startsWith("https://");
77
+ }
78
+ const G = { key: 1 }, J = { key: 2 }, K = { key: 3 }, P = {
79
+ key: 4,
80
+ class: "coar-markdown-inline-code"
81
+ }, Q = { key: 5 }, X = ["href", "target", "rel"], Y = ["src", "alt", "title"], Z = {
82
+ key: 8,
83
+ class: "coar-markdown-unsupported-inline"
84
+ }, h = /* @__PURE__ */ g({
85
+ __name: "MarkdownInlineNode",
86
+ props: {
87
+ nodes: {}
88
+ },
89
+ setup(r) {
90
+ return (e, c) => {
91
+ const o = T("MarkdownInlineNode", !0);
92
+ return n(!0), l(a, null, k(r.nodes, (t) => (n(), l(a, {
93
+ key: t.id
94
+ }, [
95
+ t.type === "text" ? (n(), l(a, { key: 0 }, [
96
+ A(f(t.text ?? ""), 1)
97
+ ], 64)) : t.type === "emphasis" ? (n(), l("em", G, [
98
+ i(o, {
99
+ nodes: t.children ?? []
100
+ }, null, 8, ["nodes"])
101
+ ])) : t.type === "strong" ? (n(), l("strong", J, [
102
+ i(o, {
103
+ nodes: t.children ?? []
104
+ }, null, 8, ["nodes"])
105
+ ])) : t.type === "strikethrough" ? (n(), l("del", K, [
106
+ i(o, {
107
+ nodes: t.children ?? []
108
+ }, null, 8, ["nodes"])
109
+ ])) : t.type === "inlineCode" ? (n(), l("code", P, f(t.text ?? ""), 1)) : t.type === "lineBreak" ? (n(), l("br", Q)) : t.type === "link" ? (n(), l(a, { key: 6 }, [
110
+ s(v)(t) ? (n(), l("a", {
111
+ key: 0,
112
+ class: "coar-markdown-link",
113
+ href: s(v)(t),
114
+ target: s(U)(t) ?? void 0,
115
+ rel: s(F)(t) ?? void 0
116
+ }, [
117
+ i(o, {
118
+ nodes: t.children ?? []
119
+ }, null, 8, ["nodes"])
120
+ ], 8, X)) : (n(), p(o, {
121
+ key: 1,
122
+ nodes: t.children ?? []
123
+ }, null, 8, ["nodes"]))
124
+ ], 64)) : t.type === "image" ? (n(), l(a, { key: 7 }, [
125
+ s($)(t) ? (n(), l("img", {
126
+ key: 0,
127
+ class: "coar-markdown-image",
128
+ src: s($)(t),
129
+ alt: s(H)(t),
130
+ title: s(O)(t) ?? void 0,
131
+ loading: "lazy"
132
+ }, null, 8, Y)) : _("", !0)
133
+ ], 64)) : (n(), l("span", Z, "[unsupported]"))
134
+ ], 64))), 128);
135
+ };
136
+ }
137
+ }), tt = {
138
+ key: 1,
139
+ class: "coar-markdown-paragraph"
140
+ }, et = {
141
+ key: 2,
142
+ class: "coar-markdown-blockquote"
143
+ }, rt = ["start"], nt = {
144
+ key: 1,
145
+ class: "coar-markdown-list coar-markdown-list--unordered"
146
+ }, lt = ["checked"], st = { class: "coar-markdown-list-item-content" }, ot = {
147
+ key: 6,
148
+ class: "coar-markdown-hr"
149
+ }, it = {
150
+ key: 9,
151
+ class: "coar-markdown-table-cell"
152
+ }, at = {
153
+ key: 10,
154
+ class: "coar-markdown-unsupported"
155
+ }, ct = /* @__PURE__ */ g({
156
+ __name: "MarkdownBlockNode",
157
+ props: {
158
+ nodes: {},
159
+ tableNode: {}
160
+ },
161
+ setup(r) {
162
+ return (e, c) => {
163
+ const o = T("MarkdownBlockNode", !0);
164
+ return n(!0), l(a, null, k(r.nodes, (t) => (n(), l(a, {
165
+ key: t.id
166
+ }, [
167
+ t.type === "heading" ? (n(), p(L("h" + s(q)(t)), {
168
+ key: 0,
169
+ id: s(D)(t) ?? void 0,
170
+ class: "coar-markdown-heading"
171
+ }, {
172
+ default: C(() => [
173
+ i(h, {
174
+ nodes: t.children ?? []
175
+ }, null, 8, ["nodes"])
176
+ ]),
177
+ _: 2
178
+ }, 1032, ["id"])) : t.type === "paragraph" ? (n(), l("p", tt, [
179
+ i(h, {
180
+ nodes: t.children ?? []
181
+ }, null, 8, ["nodes"])
182
+ ])) : t.type === "blockquote" ? (n(), l("blockquote", et, [
183
+ i(o, {
184
+ nodes: t.children ?? []
185
+ }, null, 8, ["nodes"])
186
+ ])) : t.type === "list" ? (n(), l(a, { key: 3 }, [
187
+ s(I)(t) ? (n(), l("ol", {
188
+ key: 0,
189
+ class: "coar-markdown-list coar-markdown-list--ordered",
190
+ start: s(R)(t) ?? void 0
191
+ }, [
192
+ i(o, {
193
+ nodes: t.children ?? []
194
+ }, null, 8, ["nodes"])
195
+ ], 8, rt)) : (n(), l("ul", nt, [
196
+ i(o, {
197
+ nodes: t.children ?? []
198
+ }, null, 8, ["nodes"])
199
+ ]))
200
+ ], 64)) : t.type === "listItem" ? (n(), l("li", {
201
+ key: 4,
202
+ class: y(["coar-markdown-list-item", { "coar-markdown-list-item--task": s(x)(t) }])
203
+ }, [
204
+ s(x)(t) ? (n(), l("input", {
205
+ key: 0,
206
+ class: "coar-markdown-task-checkbox",
207
+ type: "checkbox",
208
+ checked: s(z)(t),
209
+ disabled: "",
210
+ "aria-hidden": "true",
211
+ tabindex: "-1"
212
+ }, null, 8, lt)) : _("", !0),
213
+ m("div", st, [
214
+ i(o, {
215
+ nodes: t.children ?? []
216
+ }, null, 8, ["nodes"])
217
+ ])
218
+ ], 2)) : t.type === "codeBlock" ? (n(), p(s(S), {
219
+ key: 5,
220
+ class: "coar-markdown-code-block",
221
+ code: t.text ?? "",
222
+ language: s(E)(t),
223
+ collapsible: !1,
224
+ "show-copy": !0
225
+ }, null, 8, ["code", "language"])) : t.type === "thematicBreak" ? (n(), l("hr", ot)) : t.type === "table" ? (n(), p(s(V), {
226
+ key: 7,
227
+ variant: "plain",
228
+ hover: ""
229
+ }, {
230
+ default: C(() => [
231
+ (t.children ?? []).length > 0 ? (n(), l(a, { key: 0 }, [
232
+ m("thead", null, [
233
+ m("tr", null, [
234
+ (n(!0), l(a, null, k((t.children ?? [])[0]?.children ?? [], (u, d) => (n(), l("th", {
235
+ key: u.id,
236
+ class: y({
237
+ "text-right": s(B)(t, d),
238
+ "text-center": s(N)(t, d)
239
+ })
240
+ }, [
241
+ i(h, {
242
+ nodes: u.children ?? []
243
+ }, null, 8, ["nodes"])
244
+ ], 2))), 128))
245
+ ])
246
+ ]),
247
+ m("tbody", null, [
248
+ (n(!0), l(a, null, k((t.children ?? []).slice(1), (u) => (n(), l("tr", {
249
+ key: u.id
250
+ }, [
251
+ (n(!0), l(a, null, k(u.children ?? [], (d, b) => (n(), l("td", {
252
+ key: d.id,
253
+ class: y({
254
+ "text-right": s(B)(t, b),
255
+ "text-center": s(N)(t, b)
256
+ })
257
+ }, [
258
+ i(h, {
259
+ nodes: d.children ?? []
260
+ }, null, 8, ["nodes"])
261
+ ], 2))), 128))
262
+ ]))), 128))
263
+ ])
264
+ ], 64)) : _("", !0)
265
+ ]),
266
+ _: 2
267
+ }, 1024)) : t.type === "tableRow" ? (n(), p(o, {
268
+ key: 8,
269
+ nodes: t.children ?? []
270
+ }, null, 8, ["nodes"])) : t.type === "tableCell" ? (n(), l("td", it, [
271
+ i(h, {
272
+ nodes: t.children ?? []
273
+ }, null, 8, ["nodes"])
274
+ ])) : (n(), l("div", at, " Unsupported markdown node: " + f(s(j)(t)), 1))
275
+ ], 64))), 128);
276
+ };
277
+ }
278
+ }), ut = { class: "coar-markdown" }, kt = /* @__PURE__ */ g({
279
+ __name: "CoarMarkdown",
280
+ props: {
281
+ doc: {}
282
+ },
283
+ setup(r) {
284
+ return (e, c) => (n(), l("div", ut, [
285
+ i(ct, {
286
+ nodes: r.doc.nodes
287
+ }, null, 8, ["nodes"])
288
+ ]));
289
+ }
290
+ });
291
+ export {
292
+ kt as CoarMarkdown
293
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@cocoar/vue-markdown",
3
+ "version": "0.1.0-beta.23",
4
+ "type": "module",
5
+ "sideEffects": [
6
+ "*.css"
7
+ ],
8
+ "main": "./dist/index.js",
9
+ "module": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./dist/index.d.ts"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "scripts": {
21
+ "build": "vite build",
22
+ "test": "vitest run",
23
+ "lint": "eslint src/"
24
+ },
25
+ "dependencies": {
26
+ "@cocoar/vue-markdown-core": "0.1.0-beta.23"
27
+ },
28
+ "peerDependencies": {
29
+ "@cocoar/vue-ui": "0.1.0-beta.23",
30
+ "vue": "^3.5.0"
31
+ },
32
+ "devDependencies": {
33
+ "@cocoar/vue-ui": "workspace:*",
34
+ "vue": "^3.5.0"
35
+ }
36
+ }