@particle-academy/fancy-code 0.9.0 → 0.9.3
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/CHANGELOG.md +68 -0
- package/README.md +9 -0
- package/dist/index.cjs +44 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -24
- package/dist/index.js.map +1 -1
- package/package.json +9 -4
package/dist/index.js
CHANGED
|
@@ -42,26 +42,12 @@ function CodeEditorPanel({ className }) {
|
|
|
42
42
|
_maxHeight,
|
|
43
43
|
_minHeight
|
|
44
44
|
} = useCodeEditor();
|
|
45
|
-
if (!engine) return null;
|
|
46
|
-
const {
|
|
47
|
-
textareaRef,
|
|
48
|
-
highlightedHtml,
|
|
49
|
-
lineCount,
|
|
50
|
-
activeLine,
|
|
51
|
-
themeColors,
|
|
52
|
-
handleKeyDown,
|
|
53
|
-
handleInput,
|
|
54
|
-
handleScroll,
|
|
55
|
-
handleSelect,
|
|
56
|
-
scrollTop,
|
|
57
|
-
scrollLeft
|
|
58
|
-
} = engine;
|
|
59
|
-
const gutterWidth = lineNumbers ? `${Math.max(String(lineCount).length, 2) * 0.75 + 1.5}em` : "0";
|
|
60
45
|
const lineNumberElements = useMemo(() => {
|
|
61
|
-
if (!lineNumbers) return null;
|
|
62
|
-
const
|
|
46
|
+
if (!engine || !lineNumbers) return null;
|
|
47
|
+
const { themeColors: themeColors2, lineCount: lineCount2, activeLine: activeLine2 } = engine;
|
|
48
|
+
const removed = diffRemovedColor(themeColors2);
|
|
63
49
|
const lines = [];
|
|
64
|
-
for (let i = 1; i <=
|
|
50
|
+
for (let i = 1; i <= lineCount2; i++) {
|
|
65
51
|
const mark = gutterDiffMark(diffAnnotations, i);
|
|
66
52
|
lines.push(
|
|
67
53
|
/* @__PURE__ */ jsxs(
|
|
@@ -71,8 +57,8 @@ function CodeEditorPanel({ className }) {
|
|
|
71
57
|
"data-diff-deleted-above": mark?.deletedAbove ? "" : void 0,
|
|
72
58
|
style: {
|
|
73
59
|
position: "relative",
|
|
74
|
-
color: i ===
|
|
75
|
-
backgroundColor: i ===
|
|
60
|
+
color: i === activeLine2 ? themeColors2.foreground : themeColors2.gutterForeground,
|
|
61
|
+
backgroundColor: i === activeLine2 ? themeColors2.activeLineBackground : void 0
|
|
76
62
|
},
|
|
77
63
|
className: "pr-3 text-right text-[13px] leading-[1.5] select-none",
|
|
78
64
|
children: [
|
|
@@ -87,7 +73,7 @@ function CodeEditorPanel({ className }) {
|
|
|
87
73
|
bottom: 0,
|
|
88
74
|
width: 3,
|
|
89
75
|
borderRadius: 2,
|
|
90
|
-
backgroundColor: diffMarkColor(mark.type,
|
|
76
|
+
backgroundColor: diffMarkColor(mark.type, themeColors2)
|
|
91
77
|
}
|
|
92
78
|
}
|
|
93
79
|
),
|
|
@@ -108,7 +94,7 @@ function CodeEditorPanel({ className }) {
|
|
|
108
94
|
}
|
|
109
95
|
),
|
|
110
96
|
i,
|
|
111
|
-
i ===
|
|
97
|
+
i === lineCount2 && hasDeletedAtEnd(diffAnnotations) && /* @__PURE__ */ jsx(
|
|
112
98
|
"span",
|
|
113
99
|
{
|
|
114
100
|
"aria-hidden": "true",
|
|
@@ -132,7 +118,22 @@ function CodeEditorPanel({ className }) {
|
|
|
132
118
|
);
|
|
133
119
|
}
|
|
134
120
|
return lines;
|
|
135
|
-
}, [
|
|
121
|
+
}, [engine, lineNumbers, diffAnnotations]);
|
|
122
|
+
if (!engine) return null;
|
|
123
|
+
const {
|
|
124
|
+
textareaRef,
|
|
125
|
+
highlightedHtml,
|
|
126
|
+
lineCount,
|
|
127
|
+
activeLine,
|
|
128
|
+
themeColors,
|
|
129
|
+
handleKeyDown,
|
|
130
|
+
handleInput,
|
|
131
|
+
handleScroll,
|
|
132
|
+
handleSelect,
|
|
133
|
+
scrollTop,
|
|
134
|
+
scrollLeft
|
|
135
|
+
} = engine;
|
|
136
|
+
const gutterWidth = lineNumbers ? `${Math.max(String(lineCount).length, 2) * 0.75 + 1.5}em` : "0";
|
|
136
137
|
const containerStyle = {
|
|
137
138
|
backgroundColor: themeColors.background,
|
|
138
139
|
color: themeColors.foreground,
|
|
@@ -1641,8 +1642,27 @@ function escapeHtml(s) {
|
|
|
1641
1642
|
function escapeAttr(s) {
|
|
1642
1643
|
return s.replace(/"/g, """).replace(/'/g, "'");
|
|
1643
1644
|
}
|
|
1645
|
+
var LINK_SCHEMES = /* @__PURE__ */ new Set(["http", "https", "mailto", "tel"]);
|
|
1646
|
+
function schemeOf(url) {
|
|
1647
|
+
let s = "";
|
|
1648
|
+
for (const ch of url) {
|
|
1649
|
+
const code = ch.codePointAt(0) ?? 0;
|
|
1650
|
+
if (code === 9 || code === 10 || code === 13) continue;
|
|
1651
|
+
if (s === "" && code <= 32) continue;
|
|
1652
|
+
s += ch;
|
|
1653
|
+
}
|
|
1654
|
+
const m = /^([a-zA-Z][a-zA-Z0-9+.-]*):/.exec(s);
|
|
1655
|
+
return m ? m[1].toLowerCase() : null;
|
|
1656
|
+
}
|
|
1657
|
+
function safeUrl(url, kind) {
|
|
1658
|
+
const scheme = schemeOf(url);
|
|
1659
|
+
if (scheme === null) return true;
|
|
1660
|
+
if (scheme === "http" || scheme === "https") return true;
|
|
1661
|
+
if (kind === "link") return LINK_SCHEMES.has(scheme);
|
|
1662
|
+
return scheme === "data" && /^data:image\/(png|jpe?g|gif|webp|avif|bmp);/i.test(url.trim());
|
|
1663
|
+
}
|
|
1644
1664
|
function inline(text) {
|
|
1645
|
-
return text.replace(/!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (_m, alt, src, title) => `<img src="${escapeAttr(src)}" alt="${escapeAttr(alt)}"${title ? ` title="${escapeAttr(title)}"` : ""}>`).replace(/\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (_m, t, href, title) => `<a href="${escapeAttr(href)}"${title ? ` title="${escapeAttr(title)}"` : ""} rel="noopener">${t}</a>`).replace(/`([^`]+)`/g, (_m, c) => `<code>${c}</code>`).replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g, "<strong>$2</strong>").replace(/(\*|_)(?=\S)([\s\S]*?\S)\1/g, "<em>$2</em>");
|
|
1665
|
+
return text.replace(/!\[([^\]]*)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (_m, alt, src, title) => safeUrl(src, "image") ? `<img src="${escapeAttr(src)}" alt="${escapeAttr(alt)}"${title ? ` title="${escapeAttr(title)}"` : ""}>` : alt).replace(/\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)/g, (_m, t, href, title) => safeUrl(href, "link") ? `<a href="${escapeAttr(href)}"${title ? ` title="${escapeAttr(title)}"` : ""} rel="noopener">${t}</a>` : t).replace(/`([^`]+)`/g, (_m, c) => `<code>${c}</code>`).replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g, "<strong>$2</strong>").replace(/(\*|_)(?=\S)([\s\S]*?\S)\1/g, "<em>$2</em>");
|
|
1646
1666
|
}
|
|
1647
1667
|
function renderMarkdown(markdown) {
|
|
1648
1668
|
const lines = markdown.replace(/\r\n?/g, "\n").split("\n");
|