@owomark/react 0.1.5 → 0.1.7
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/README.md +57 -1
- package/dist/.build-manifest.json +58 -0
- package/dist/highlight.worker.js +113 -0
- package/dist/index.d.ts +133 -35
- package/dist/index.js +1723 -219
- package/dist/mdx.worker.js +97 -0
- package/package.json +6 -4
- package/dist/index.css +0 -32
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/mdx.worker.ts
|
|
2
|
+
import { compile } from "@mdx-js/mdx";
|
|
3
|
+
import {
|
|
4
|
+
getOwoMarkPlugins,
|
|
5
|
+
inspectMdxSource,
|
|
6
|
+
remapMdxErrorDetails
|
|
7
|
+
} from "@owomark/processor";
|
|
8
|
+
|
|
9
|
+
// src/mdx-error.ts
|
|
10
|
+
function parseMdxErrorDetails(error) {
|
|
11
|
+
if (error && typeof error === "object") {
|
|
12
|
+
const value = error;
|
|
13
|
+
if (typeof value.line === "number") {
|
|
14
|
+
return {
|
|
15
|
+
message: value.message ?? String(error),
|
|
16
|
+
line: value.line,
|
|
17
|
+
column: typeof value.column === "number" ? value.column : void 0
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const text = value.message ?? String(error);
|
|
21
|
+
const match = text.match(/\((\d+):(\d+)/);
|
|
22
|
+
if (match) {
|
|
23
|
+
return {
|
|
24
|
+
message: text,
|
|
25
|
+
line: Number(match[1]),
|
|
26
|
+
column: Number(match[2])
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return { message: text };
|
|
30
|
+
}
|
|
31
|
+
return { message: String(error) };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// src/mdx.worker.ts
|
|
35
|
+
var cancelledIds = /* @__PURE__ */ new Set();
|
|
36
|
+
self.onmessage = (e) => {
|
|
37
|
+
const msg = e.data;
|
|
38
|
+
if (msg.type === "cancel") {
|
|
39
|
+
cancelledIds.add(msg.id);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
void handleCompile(msg);
|
|
43
|
+
};
|
|
44
|
+
async function handleCompile(data) {
|
|
45
|
+
const { id, markdown, options } = data;
|
|
46
|
+
const inspection = options.preparedSource && options.sourceMap ? null : inspectMdxSource(markdown, {
|
|
47
|
+
enableMath: options.enableMath,
|
|
48
|
+
enableSideAnnotation: options.enableSideAnnotation,
|
|
49
|
+
extraRemarkDescriptors: options.extraRemarkDescriptors
|
|
50
|
+
});
|
|
51
|
+
const preparedSource = options.preparedSource ?? inspection.compileSource;
|
|
52
|
+
const sourceMap = options.sourceMap ?? inspection.sourceMap;
|
|
53
|
+
try {
|
|
54
|
+
if (cancelledIds.has(id)) {
|
|
55
|
+
cancelledIds.delete(id);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const { remarkPlugins, rehypePlugins } = getOwoMarkPlugins({
|
|
59
|
+
mode: "production",
|
|
60
|
+
enableMath: options.enableMath,
|
|
61
|
+
enableSideAnnotation: options.enableSideAnnotation,
|
|
62
|
+
enableCodeHighlight: false,
|
|
63
|
+
sourceAnchors: options.sourceAnchors,
|
|
64
|
+
extraRemarkDescriptors: options.extraRemarkDescriptors,
|
|
65
|
+
extraRehypeDescriptors: options.extraRehypeDescriptors,
|
|
66
|
+
mdxSourceMap: sourceMap
|
|
67
|
+
});
|
|
68
|
+
if (cancelledIds.has(id)) {
|
|
69
|
+
cancelledIds.delete(id);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const result = await compile(preparedSource, {
|
|
73
|
+
outputFormat: "function-body",
|
|
74
|
+
remarkPlugins,
|
|
75
|
+
rehypePlugins
|
|
76
|
+
});
|
|
77
|
+
if (cancelledIds.has(id)) {
|
|
78
|
+
cancelledIds.delete(id);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
self.postMessage({
|
|
82
|
+
id,
|
|
83
|
+
ok: true,
|
|
84
|
+
code: String(result)
|
|
85
|
+
});
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (cancelledIds.has(id)) {
|
|
88
|
+
cancelledIds.delete(id);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
self.postMessage({
|
|
92
|
+
id,
|
|
93
|
+
ok: false,
|
|
94
|
+
error: parseMdxErrorDetails(remapMdxErrorDetails(error, sourceMap))
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owomark/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "React bindings and components for the OwoMark editor stack.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,9 +33,11 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@owomark/
|
|
38
|
-
"@owomark/
|
|
36
|
+
"@mdx-js/mdx": "^3.0.0",
|
|
37
|
+
"@owomark/core": "^0.1.7",
|
|
38
|
+
"@owomark/processor": "^0.1.7",
|
|
39
|
+
"@owomark/view": "^0.1.7",
|
|
40
|
+
"shiki": "^3.23.0"
|
|
39
41
|
},
|
|
40
42
|
"peerDependencies": {
|
|
41
43
|
"react": ">=18",
|
package/dist/index.css
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/* src/MdxSkeleton.css */
|
|
2
|
-
.owo-mdx-skeleton {
|
|
3
|
-
background:
|
|
4
|
-
linear-gradient(
|
|
5
|
-
90deg,
|
|
6
|
-
var(--owo-skeleton-base, #e5e7eb) 25%,
|
|
7
|
-
var(--owo-skeleton-shine, #f3f4f6) 50%,
|
|
8
|
-
var(--owo-skeleton-base, #e5e7eb) 75%);
|
|
9
|
-
background-size: 200% 100%;
|
|
10
|
-
animation: owo-mdx-skeleton-shimmer 1.5s ease-in-out infinite;
|
|
11
|
-
border-radius: 4px;
|
|
12
|
-
}
|
|
13
|
-
@keyframes owo-mdx-skeleton-shimmer {
|
|
14
|
-
0% {
|
|
15
|
-
background-position: 200% 0;
|
|
16
|
-
}
|
|
17
|
-
100% {
|
|
18
|
-
background-position: -200% 0;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
.owo-mdx-skeleton-block {
|
|
22
|
-
display: flex;
|
|
23
|
-
flex-direction: column;
|
|
24
|
-
gap: 8px;
|
|
25
|
-
padding: 12px 0;
|
|
26
|
-
}
|
|
27
|
-
.owo-mdx-skeleton-line {
|
|
28
|
-
height: 14px;
|
|
29
|
-
}
|
|
30
|
-
.owo-mdx-skeleton-line:last-child {
|
|
31
|
-
width: 60%;
|
|
32
|
-
}
|