@cocoar/vue-markdown-core 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.
Files changed (2) hide show
  1. package/dist/index.js +483 -0
  2. package/package.json +32 -0
package/dist/index.js ADDED
@@ -0,0 +1,483 @@
1
+ import { unified as k } from "unified";
2
+ import C from "remark-parse";
3
+ import v from "remark-gfm";
4
+ import I from "remark-stringify";
5
+ const R = 2166136261, A = 16777619;
6
+ function B(t) {
7
+ let e = R;
8
+ for (let i = 0; i < t.length; i++)
9
+ e ^= t.charCodeAt(i), e = Math.imul(e, A);
10
+ return e >>> 0;
11
+ }
12
+ function d(t) {
13
+ return B(t).toString(36);
14
+ }
15
+ function K(t, e = {}) {
16
+ const i = k().use(C);
17
+ (e.gfm ?? !0) && i.use(v);
18
+ const n = i.parse(t);
19
+ return M(n);
20
+ }
21
+ function M(t) {
22
+ const e = z(), i = T(t);
23
+ return { nodes: t.children.map((l, r) => u(l, void 0, r, e, i)).filter(o) };
24
+ }
25
+ function T(t) {
26
+ const e = /* @__PURE__ */ new Map();
27
+ for (const i of t.children) {
28
+ if (i.type !== "definition") continue;
29
+ const n = i, l = typeof n.identifier == "string" ? n.identifier : "", r = typeof n.url == "string" ? n.url : "", p = typeof n.title == "string" ? n.title : void 0;
30
+ l.length === 0 || r.length === 0 || e.set(l, { url: r, title: p });
31
+ }
32
+ return e;
33
+ }
34
+ function o(t) {
35
+ return t !== null;
36
+ }
37
+ function u(t, e, i, n, l) {
38
+ const r = O(t.position), p = `${t.type}|${r?.start ?? "na"}-${r?.end ?? "na"}|${e ?? "root"}|${i}`, s = d(p);
39
+ switch (t.type) {
40
+ case "heading":
41
+ return N(t, s, r, n, l);
42
+ case "paragraph":
43
+ return {
44
+ id: s,
45
+ type: "paragraph",
46
+ position: r,
47
+ children: (t.children ?? []).map((a, c) => u(a, s, c, n, l)).filter(o)
48
+ };
49
+ case "blockquote":
50
+ return {
51
+ id: s,
52
+ type: "blockquote",
53
+ position: r,
54
+ children: (t.children ?? []).map((a, c) => u(a, s, c, n, l)).filter(o)
55
+ };
56
+ case "list":
57
+ return q(t, s, r, n, l);
58
+ case "listItem":
59
+ return F(t, s, r, n, l);
60
+ case "code":
61
+ return {
62
+ id: s,
63
+ type: "codeBlock",
64
+ position: r,
65
+ text: t.value,
66
+ attrs: {
67
+ language: t.lang ?? void 0,
68
+ meta: t.meta ?? void 0
69
+ }
70
+ };
71
+ case "inlineCode":
72
+ return {
73
+ id: s,
74
+ type: "inlineCode",
75
+ position: r,
76
+ text: t.value
77
+ };
78
+ case "break":
79
+ return {
80
+ id: s,
81
+ type: "lineBreak",
82
+ position: r
83
+ };
84
+ case "text":
85
+ return {
86
+ id: s,
87
+ type: "text",
88
+ position: r,
89
+ text: t.value
90
+ };
91
+ case "emphasis":
92
+ return {
93
+ id: s,
94
+ type: "emphasis",
95
+ position: r,
96
+ children: (t.children ?? []).map((a, c) => u(a, s, c, n, l)).filter(o)
97
+ };
98
+ case "strong":
99
+ return {
100
+ id: s,
101
+ type: "strong",
102
+ position: r,
103
+ children: (t.children ?? []).map((a, c) => u(a, s, c, n, l)).filter(o)
104
+ };
105
+ case "delete":
106
+ return {
107
+ id: s,
108
+ type: "strikethrough",
109
+ position: r,
110
+ children: (t.children ?? []).map((a, c) => u(a, s, c, n, l)).filter(o)
111
+ };
112
+ case "link":
113
+ return P(t, s, r, n, l);
114
+ case "linkReference": {
115
+ const a = t, c = typeof a.identifier == "string" ? a.identifier : "", f = c.length > 0 ? l.get(c) : void 0;
116
+ if (!f?.url)
117
+ return {
118
+ id: s,
119
+ type: "text",
120
+ position: r,
121
+ text: g(t)
122
+ };
123
+ const y = Array.isArray(a.children) ? a.children : [];
124
+ return {
125
+ id: s,
126
+ type: "link",
127
+ position: r,
128
+ attrs: {
129
+ url: f.url,
130
+ title: f.title ?? void 0
131
+ },
132
+ children: y.map((b, m) => u(b, s, m, n, l)).filter(o)
133
+ };
134
+ }
135
+ case "image": {
136
+ const a = t, c = typeof a.url == "string" ? a.url : "", f = typeof a.title == "string" ? a.title : void 0, y = typeof a.alt == "string" ? a.alt : "";
137
+ return c.length === 0 ? {
138
+ id: s,
139
+ type: "text",
140
+ position: r,
141
+ text: y
142
+ } : {
143
+ id: s,
144
+ type: "image",
145
+ position: r,
146
+ attrs: {
147
+ url: c,
148
+ title: f,
149
+ alt: y
150
+ }
151
+ };
152
+ }
153
+ case "imageReference": {
154
+ const a = t, c = typeof a.identifier == "string" ? a.identifier : "", f = c.length > 0 ? l.get(c) : void 0, y = typeof a.alt == "string" ? a.alt : "";
155
+ return f?.url ? {
156
+ id: s,
157
+ type: "image",
158
+ position: r,
159
+ attrs: {
160
+ url: f.url,
161
+ title: f.title ?? void 0,
162
+ alt: y
163
+ }
164
+ } : {
165
+ id: s,
166
+ type: "text",
167
+ position: r,
168
+ text: y
169
+ };
170
+ }
171
+ case "thematicBreak":
172
+ return {
173
+ id: s,
174
+ type: "thematicBreak",
175
+ position: r
176
+ };
177
+ case "table":
178
+ return L(t, s, r, n, l);
179
+ case "tableRow":
180
+ return _(t, s, r, n, l);
181
+ case "tableCell":
182
+ return H(t, s, r, n, l);
183
+ // Reference-style definitions should not render as visible content.
184
+ case "definition":
185
+ return null;
186
+ // Footnotes are supported by remark-gfm but not rendered as interactive footnotes in v1.
187
+ // Convert them to readable content instead of emitting unsupported placeholders.
188
+ case "footnoteReference": {
189
+ const a = t, c = typeof a.identifier == "string" ? a.identifier : typeof a.label == "string" ? a.label : "", f = c.length > 0 ? c : "?";
190
+ return {
191
+ id: s,
192
+ type: "text",
193
+ position: r,
194
+ text: `[^${f}]`
195
+ };
196
+ }
197
+ case "footnoteDefinition": {
198
+ const a = t, c = typeof a.identifier == "string" ? a.identifier : typeof a.label == "string" ? a.label : "", f = c.length > 0 ? c : "?", y = d(`${p}|footnote-label-text`), m = {
199
+ id: d(`${p}|footnote-label-paragraph`),
200
+ type: "paragraph",
201
+ position: r,
202
+ children: [
203
+ {
204
+ id: y,
205
+ type: "text",
206
+ position: r,
207
+ text: `[^${f}]: `
208
+ }
209
+ ]
210
+ }, x = Array.isArray(a.children) ? a.children : [];
211
+ return {
212
+ id: s,
213
+ type: "blockquote",
214
+ position: r,
215
+ children: [
216
+ m,
217
+ ...x.map(($, w) => u($, s, w, n, l)).filter(o)
218
+ ]
219
+ };
220
+ }
221
+ // Raw HTML is intentionally unsupported in v1.
222
+ case "html":
223
+ return {
224
+ id: s,
225
+ type: "unsupported",
226
+ position: r,
227
+ attrs: { originalType: "html" },
228
+ text: t.value
229
+ };
230
+ default:
231
+ return {
232
+ id: s,
233
+ // Preserve the original type string for better diagnostics.
234
+ type: "unsupported",
235
+ position: r,
236
+ attrs: { originalType: t.type }
237
+ };
238
+ }
239
+ }
240
+ function N(t, e, i, n, l) {
241
+ const r = g(t), p = r.length > 0 ? n.slug(r) : void 0;
242
+ return {
243
+ id: e,
244
+ type: "heading",
245
+ position: i,
246
+ attrs: { depth: t.depth, anchor: p },
247
+ children: (t.children ?? []).map((s, a) => u(s, e, a, n, l)).filter(o)
248
+ };
249
+ }
250
+ function P(t, e, i, n, l) {
251
+ return {
252
+ id: e,
253
+ type: "link",
254
+ position: i,
255
+ attrs: {
256
+ url: t.url,
257
+ title: t.title ?? void 0
258
+ },
259
+ children: (t.children ?? []).map((r, p) => u(r, e, p, n, l)).filter(o)
260
+ };
261
+ }
262
+ function q(t, e, i, n, l) {
263
+ return {
264
+ id: e,
265
+ type: "list",
266
+ position: i,
267
+ attrs: {
268
+ ordered: t.ordered ?? !1,
269
+ start: t.start ?? void 0,
270
+ spread: t.spread ?? void 0
271
+ },
272
+ children: (t.children ?? []).map((r, p) => u(r, e, p, n, l)).filter(o)
273
+ };
274
+ }
275
+ function F(t, e, i, n, l) {
276
+ return {
277
+ id: e,
278
+ type: "listItem",
279
+ position: i,
280
+ attrs: {
281
+ checked: t.checked ?? void 0,
282
+ spread: t.spread ?? void 0
283
+ },
284
+ children: (t.children ?? []).map((r, p) => u(r, e, p, n, l)).filter(o)
285
+ };
286
+ }
287
+ function L(t, e, i, n, l) {
288
+ return {
289
+ id: e,
290
+ type: "table",
291
+ position: i,
292
+ attrs: {
293
+ align: t.align ?? void 0
294
+ },
295
+ children: (t.children ?? []).map((r, p) => u(r, e, p, n, l)).filter(o)
296
+ };
297
+ }
298
+ function _(t, e, i, n, l) {
299
+ return {
300
+ id: e,
301
+ type: "tableRow",
302
+ position: i,
303
+ children: (t.children ?? []).map((r, p) => u(r, e, p, n, l)).filter(o)
304
+ };
305
+ }
306
+ function H(t, e, i, n, l) {
307
+ return {
308
+ id: e,
309
+ type: "tableCell",
310
+ position: i,
311
+ children: (t.children ?? []).map((r, p) => u(r, e, p, n, l)).filter(o)
312
+ };
313
+ }
314
+ function z() {
315
+ const t = /* @__PURE__ */ new Map();
316
+ return {
317
+ slug(e) {
318
+ const i = D(e), n = t.get(i) ?? 0;
319
+ return t.set(i, n + 1), n === 0 ? i : `${i}-${n}`;
320
+ }
321
+ };
322
+ }
323
+ function D(t) {
324
+ const i = t.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]+/gu, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
325
+ return i.length > 0 ? i : "section";
326
+ }
327
+ function g(t) {
328
+ if (!t || typeof t != "object") return "";
329
+ const e = t;
330
+ return typeof e.type != "string" ? "" : e.type === "text" || e.type === "inlineCode" ? typeof e.value == "string" ? e.value : "" : (Array.isArray(e.children) ? e.children : []).map((n) => g(n)).join("");
331
+ }
332
+ function O(t) {
333
+ const e = t;
334
+ if (!e?.start || !e?.end)
335
+ return;
336
+ const i = e.start.offset, n = e.end.offset, l = e.start.line, r = e.start.column;
337
+ if (!(typeof i != "number" || typeof n != "number" || typeof l != "number" || typeof r != "number"))
338
+ return {
339
+ start: i,
340
+ end: n,
341
+ line: l,
342
+ column: r
343
+ };
344
+ }
345
+ function Q(t, e = {}) {
346
+ const i = V(t), n = k().use(I);
347
+ return (e.gfm ?? !0) && n.use(v), String(n.stringify(i));
348
+ }
349
+ function V(t) {
350
+ return {
351
+ type: "root",
352
+ children: t.nodes.map((e) => h(e))
353
+ };
354
+ }
355
+ function h(t) {
356
+ switch (t.type) {
357
+ case "heading":
358
+ return {
359
+ type: "heading",
360
+ depth: j(t.attrs?.depth),
361
+ children: (t.children ?? []).map(h)
362
+ };
363
+ case "paragraph":
364
+ return {
365
+ type: "paragraph",
366
+ children: (t.children ?? []).map(h)
367
+ };
368
+ case "blockquote":
369
+ return {
370
+ type: "blockquote",
371
+ children: (t.children ?? []).map(h)
372
+ };
373
+ case "list":
374
+ return {
375
+ type: "list",
376
+ ordered: !!t.attrs?.ordered,
377
+ start: typeof t.attrs?.start == "number" ? t.attrs.start : void 0,
378
+ spread: typeof t.attrs?.spread == "boolean" ? t.attrs.spread : void 0,
379
+ children: (t.children ?? []).map(h)
380
+ };
381
+ case "listItem":
382
+ return {
383
+ type: "listItem",
384
+ checked: typeof t.attrs?.checked == "boolean" ? t.attrs.checked : null,
385
+ spread: typeof t.attrs?.spread == "boolean" ? t.attrs.spread : void 0,
386
+ children: (t.children ?? []).map(h)
387
+ };
388
+ case "codeBlock":
389
+ return {
390
+ type: "code",
391
+ lang: typeof t.attrs?.language == "string" ? t.attrs.language : null,
392
+ meta: typeof t.attrs?.meta == "string" ? t.attrs.meta : null,
393
+ value: t.text ?? ""
394
+ };
395
+ case "inlineCode":
396
+ return {
397
+ type: "inlineCode",
398
+ value: t.text ?? ""
399
+ };
400
+ case "text":
401
+ return {
402
+ type: "text",
403
+ value: t.text ?? ""
404
+ };
405
+ case "emphasis":
406
+ return {
407
+ type: "emphasis",
408
+ children: (t.children ?? []).map(h)
409
+ };
410
+ case "strong":
411
+ return {
412
+ type: "strong",
413
+ children: (t.children ?? []).map(h)
414
+ };
415
+ case "strikethrough":
416
+ return {
417
+ type: "delete",
418
+ children: (t.children ?? []).map(h)
419
+ };
420
+ case "link":
421
+ return {
422
+ type: "link",
423
+ url: typeof t.attrs?.url == "string" ? t.attrs.url : "",
424
+ title: typeof t.attrs?.title == "string" ? t.attrs.title : null,
425
+ children: (t.children ?? []).map(h)
426
+ };
427
+ case "image":
428
+ return {
429
+ type: "image",
430
+ url: typeof t.attrs?.url == "string" ? t.attrs.url : "",
431
+ title: typeof t.attrs?.title == "string" ? t.attrs.title : null,
432
+ alt: typeof t.attrs?.alt == "string" ? t.attrs.alt : ""
433
+ };
434
+ case "thematicBreak":
435
+ return {
436
+ type: "thematicBreak"
437
+ };
438
+ case "lineBreak":
439
+ return {
440
+ type: "break"
441
+ };
442
+ case "table":
443
+ return {
444
+ type: "table",
445
+ align: Array.isArray(t.attrs?.align) ? t.attrs.align : void 0,
446
+ children: (t.children ?? []).map(h)
447
+ };
448
+ case "tableRow":
449
+ return {
450
+ type: "tableRow",
451
+ children: (t.children ?? []).map(h)
452
+ };
453
+ case "tableCell":
454
+ return {
455
+ type: "tableCell",
456
+ children: (t.children ?? []).map(h)
457
+ };
458
+ case "unsupported":
459
+ return {
460
+ type: "html",
461
+ value: `<!-- Unsupported node: ${String(t.attrs?.originalType ?? "unknown")} -->`
462
+ };
463
+ default:
464
+ return {
465
+ type: "html",
466
+ value: `<!-- Unsupported node: ${String(t.type)} -->`
467
+ };
468
+ }
469
+ }
470
+ function j(t) {
471
+ const e = typeof t == "number" ? Math.trunc(t) : 1;
472
+ return e <= 1 ? 1 : e === 2 ? 2 : e === 3 ? 3 : e === 4 ? 4 : e === 5 ? 5 : 6;
473
+ }
474
+ function W(t, ...e) {
475
+ return e.reduce((i, n) => n(i), t);
476
+ }
477
+ export {
478
+ d as createNodeId,
479
+ B as hashStringFNV1a32,
480
+ K as parse,
481
+ Q as serialize,
482
+ W as transform
483
+ };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@cocoar/vue-markdown-core",
3
+ "version": "0.1.0-beta.23",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "scripts": {
19
+ "build": "vite build",
20
+ "test": "vitest run",
21
+ "lint": "eslint src/"
22
+ },
23
+ "dependencies": {
24
+ "unified": "^11.0.5",
25
+ "remark-parse": "^11.0.0",
26
+ "remark-stringify": "^11.0.0",
27
+ "remark-gfm": "^4.0.1"
28
+ },
29
+ "devDependencies": {
30
+ "@types/mdast": "^4.0.4"
31
+ }
32
+ }