@pfmcodes/caret 0.2.1 → 0.2.6
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 +42 -45
- package/{esm/editor.js → editor.js} +174 -37
- package/index.css +27 -20
- package/{esm/index.js → index.js} +1 -1
- package/{esm/languages.js → langauges.js} +12 -12
- package/package.json +8 -8
- package/types/editor.ts +189 -53
- package/commonjs/editor.js +0 -332
- package/commonjs/index.js +0 -10
- package/commonjs/languages.js +0 -97
- package/commonjs/theme.js +0 -18
- /package/{esm/theme.js → theme.js} +0 -0
package/commonjs/editor.js
DELETED
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
const hljs = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/core.js"); // Use default export
|
|
2
|
-
const languages = require("./languages.js");
|
|
3
|
-
|
|
4
|
-
languages.init();
|
|
5
|
-
|
|
6
|
-
async function createEditor(editor, data) {
|
|
7
|
-
const editor1 = document.createElement("textarea");
|
|
8
|
-
const highlighted = document.createElement("pre");
|
|
9
|
-
const caret = document.createElement("div");
|
|
10
|
-
const measureCanvas = document.createElement("canvas");
|
|
11
|
-
const measureCtx = measureCanvas.getContext("2d");
|
|
12
|
-
const isDark = data.theme && (data.theme.includes("dark") || data.theme.includes("night"));
|
|
13
|
-
const caretColor = isDark ? "#fff" : "#7116d8";
|
|
14
|
-
const lineColor = isDark ? "#fff" : "#000";
|
|
15
|
-
const lineCounter = document.createElement("div");
|
|
16
|
-
|
|
17
|
-
editor1.id = "Caret-textarea";
|
|
18
|
-
highlighted.id = "Caret-highlighted";
|
|
19
|
-
caret.id = "Caret-caret";
|
|
20
|
-
lineCounter.id = "Caret-lineCounter";
|
|
21
|
-
editor1.className = 'dark';
|
|
22
|
-
highlighted.className = 'dark';
|
|
23
|
-
caret.className = 'dark';
|
|
24
|
-
lineCounter.className = 'dark';
|
|
25
|
-
editor1.style.backgroundColor = isDark ? "#222" : "#fff";
|
|
26
|
-
let code = data.value || "";
|
|
27
|
-
let language = data.language;
|
|
28
|
-
let theme = data.theme;
|
|
29
|
-
if (!languages.registeredLanguages.includes(language)) {
|
|
30
|
-
const mod = await import(`https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/${language}.js`);
|
|
31
|
-
languages.registerLanguage(language, mod.default);
|
|
32
|
-
languages.registeredLanguages.push(language);
|
|
33
|
-
}
|
|
34
|
-
if (theme) {
|
|
35
|
-
let themeLink = document.getElementById("Caret-theme")
|
|
36
|
-
if (!themeLink) {
|
|
37
|
-
const link = document.createElement("link");
|
|
38
|
-
link.rel = "stylesheet";
|
|
39
|
-
link.id = "Caret-theme";
|
|
40
|
-
link.href = `https://esm.sh/@pfmcodes/highlight.js@1.0.0/styles/${theme}.css`;
|
|
41
|
-
document.head.appendChild(link);
|
|
42
|
-
} else {
|
|
43
|
-
themeLink.href = `https://esm.sh/@pfmcodes/highlight.js@1.0.0/styles/${theme}.css`;
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
let themeLink = document.getElementById("Caret-theme");
|
|
47
|
-
if (!themeLink) {
|
|
48
|
-
const link = document.createElement("link");
|
|
49
|
-
link.rel = "stylesheet";
|
|
50
|
-
link.id = "Caret-theme";
|
|
51
|
-
link.href = `https://esm.sh/@pfmcodes/highlight.js@1.0.0/styles/hybrid.css`;
|
|
52
|
-
document.head.appendChild(link);
|
|
53
|
-
} else {
|
|
54
|
-
themeLink.href = `./highlight.js/styles/hybrid.css`;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
editor1.spellcheck = false;
|
|
58
|
-
editor1.autocapitalize = "off";
|
|
59
|
-
editor1.autocomplete = "off";
|
|
60
|
-
editor1.autocorrect = "off";
|
|
61
|
-
editor.style = "position: relative; width: 600px; height: 300px; overflow: hidden; /* 👈 CRITICAL */ font-size: 14px;"
|
|
62
|
-
if (code && editor && editor1 && language && highlighted) {
|
|
63
|
-
editor1.style.paddingTop = "-9px";
|
|
64
|
-
console.log(data.value + " data.value");
|
|
65
|
-
editor1.value = data.value;
|
|
66
|
-
highlighted.innerHTML = await _render(data.value, language, editor1);
|
|
67
|
-
}
|
|
68
|
-
const keyDown = async (e) => {
|
|
69
|
-
if (e.key !== "Tab") return;
|
|
70
|
-
|
|
71
|
-
e.preventDefault();
|
|
72
|
-
|
|
73
|
-
const value = editor1.value;
|
|
74
|
-
const start = editor1.selectionStart;
|
|
75
|
-
const end = editor1.selectionEnd;
|
|
76
|
-
|
|
77
|
-
const indent = " ";
|
|
78
|
-
|
|
79
|
-
// Find line start & end
|
|
80
|
-
const lineStart = value.lastIndexOf("\n", start - 1) + 1;
|
|
81
|
-
const lineEnd = value.indexOf("\n", end);
|
|
82
|
-
const finalLineEnd = lineEnd === -1 ? value.length : lineEnd;
|
|
83
|
-
|
|
84
|
-
const block = value.slice(lineStart, finalLineEnd);
|
|
85
|
-
const lines = block.split("\n");
|
|
86
|
-
|
|
87
|
-
let newLines;
|
|
88
|
-
let delta = 0;
|
|
89
|
-
|
|
90
|
-
if (e.shiftKey) {
|
|
91
|
-
// UNINDENT
|
|
92
|
-
newLines = lines.map(line => {
|
|
93
|
-
if (line.startsWith(indent)) {
|
|
94
|
-
delta -= indent.length;
|
|
95
|
-
return line.slice(indent.length);
|
|
96
|
-
}
|
|
97
|
-
if (line.startsWith("\t")) {
|
|
98
|
-
delta -= 1;
|
|
99
|
-
return line.slice(1);
|
|
100
|
-
}
|
|
101
|
-
return line;
|
|
102
|
-
});
|
|
103
|
-
} else {
|
|
104
|
-
// INDENT
|
|
105
|
-
newLines = lines.map(line => indent + line);
|
|
106
|
-
delta = indent.length;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const newBlock = newLines.join("\n");
|
|
110
|
-
|
|
111
|
-
editor1.value =
|
|
112
|
-
value.slice(0, lineStart) +
|
|
113
|
-
newBlock +
|
|
114
|
-
value.slice(finalLineEnd);
|
|
115
|
-
|
|
116
|
-
// Fix selection
|
|
117
|
-
editor1.selectionStart = start + delta;
|
|
118
|
-
editor1.selectionEnd =
|
|
119
|
-
end + delta * newLines.length;
|
|
120
|
-
|
|
121
|
-
highlighted.innerHTML = await _render(editor1.value, language, editor1);
|
|
122
|
-
updateLineNumbers();
|
|
123
|
-
updateCaret();
|
|
124
|
-
}
|
|
125
|
-
editor1.addEventListener("keydown", keyDown);
|
|
126
|
-
editor.appendChild(lineCounter);
|
|
127
|
-
editor.appendChild(highlighted);
|
|
128
|
-
editor.appendChild(editor1);
|
|
129
|
-
editor.appendChild(caret);
|
|
130
|
-
|
|
131
|
-
function updateFontMetrics() {
|
|
132
|
-
const style = getComputedStyle(editor1);
|
|
133
|
-
measureCtx.font = `${style.fontSize} ${style.fontFamily}`;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function updateLineNumbers() {
|
|
137
|
-
const lineCount = editor1.value.split("\n").length;
|
|
138
|
-
|
|
139
|
-
let html = "";
|
|
140
|
-
for (let i = 1; i <= lineCount; i++) {
|
|
141
|
-
html += `<div class="Caret-lineCounter-number" style="color: ${lineColor}">${i}</div>`;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
lineCounter.innerHTML = html;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
highlighted.style.paddingTop = "12px"
|
|
148
|
-
|
|
149
|
-
function getFontMetrics() {
|
|
150
|
-
const metrics = measureCtx.measureText("Mg");
|
|
151
|
-
return {
|
|
152
|
-
ascent: metrics.actualBoundingBoxAscent,
|
|
153
|
-
descent: metrics.actualBoundingBoxDescent,
|
|
154
|
-
height: metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
const focus = () => {
|
|
158
|
-
caret.style.opacity = "1";
|
|
159
|
-
caret.style.background = caretColor;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
editor1.addEventListener("focus", focus);
|
|
163
|
-
|
|
164
|
-
const blur = () => {
|
|
165
|
-
caret.style.opacity = "0";
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
editor1.addEventListener("blur", blur);
|
|
169
|
-
|
|
170
|
-
function updateCaret() {
|
|
171
|
-
const start = editor1.selectionStart;
|
|
172
|
-
const text = editor1.value.slice(0, start);
|
|
173
|
-
|
|
174
|
-
const lines = text.split("\n");
|
|
175
|
-
const lineIndex = lines.length - 1;
|
|
176
|
-
const lineText = lines[lineIndex].replace(/\t/g, " ");
|
|
177
|
-
|
|
178
|
-
const style = getComputedStyle(editor1);
|
|
179
|
-
const paddingLeft = parseFloat(style.paddingLeft);
|
|
180
|
-
const paddingTop = parseFloat(style.paddingTop);
|
|
181
|
-
const lineHeight = parseFloat(style.lineHeight);
|
|
182
|
-
|
|
183
|
-
updateFontMetrics();
|
|
184
|
-
const metrics = measureCtx.measureText("Mg");
|
|
185
|
-
const ascent = metrics.actualBoundingBoxAscent;
|
|
186
|
-
|
|
187
|
-
caret.style.left =
|
|
188
|
-
paddingLeft + measureCtx.measureText(lineText).width + "px";
|
|
189
|
-
caret.style.top =
|
|
190
|
-
-9 +
|
|
191
|
-
paddingTop +
|
|
192
|
-
lineIndex * lineHeight +
|
|
193
|
-
(lineHeight - ascent) +
|
|
194
|
-
"px";
|
|
195
|
-
|
|
196
|
-
caret.style.height = `${lineHeight - 5}px`;
|
|
197
|
-
}
|
|
198
|
-
const input = async () => {
|
|
199
|
-
caret.style.opacity = "1";
|
|
200
|
-
highlighted.innerHTML = await _render(editor1.value, language, editor1);
|
|
201
|
-
updateLineNumbers();
|
|
202
|
-
updateCaret();
|
|
203
|
-
};
|
|
204
|
-
editor1.addEventListener("input", input);
|
|
205
|
-
const scroll = async () => {
|
|
206
|
-
const x = -editor1.scrollLeft;
|
|
207
|
-
const y = -editor1.scrollTop;
|
|
208
|
-
highlighted.innerHTML = await _render(editor1.value, language, editor1);
|
|
209
|
-
highlighted.style.transform = `translate(${x}px, ${y}px)`;
|
|
210
|
-
caret.style.transform = `translate(${x}px, ${y}px)`;
|
|
211
|
-
lineCounter.style.transform = `translateY(${y}px)`;
|
|
212
|
-
};
|
|
213
|
-
editor1.addEventListener("scroll", scroll);
|
|
214
|
-
|
|
215
|
-
updateFontMetrics();
|
|
216
|
-
getFontMetrics();
|
|
217
|
-
|
|
218
|
-
editor1.addEventListener("click", updateCaret);
|
|
219
|
-
editor1.addEventListener("keyup", updateCaret);
|
|
220
|
-
|
|
221
|
-
// Initial caret position
|
|
222
|
-
updateLineNumbers();
|
|
223
|
-
updateCaret();
|
|
224
|
-
|
|
225
|
-
// Focus the editor
|
|
226
|
-
editor1.focus();
|
|
227
|
-
function destroy() {
|
|
228
|
-
editor1.removeEventListener('click', updateCaret);
|
|
229
|
-
editor1.removeEventListener('keyup', updateCaret);
|
|
230
|
-
editor1.removeEventListener('scroll', scroll);
|
|
231
|
-
editor1.removeEventListener('keydown', keyDown);
|
|
232
|
-
editor.innerHTML = "";
|
|
233
|
-
}
|
|
234
|
-
async function refresh() {
|
|
235
|
-
highlighted.innerHTML = await _render(editor1.value, language, editor1);
|
|
236
|
-
updateLineNumbers();
|
|
237
|
-
updateCaret();
|
|
238
|
-
}
|
|
239
|
-
function getValue() {
|
|
240
|
-
return editor1.value;
|
|
241
|
-
}
|
|
242
|
-
function setValue(i) {
|
|
243
|
-
editor1.value = i;
|
|
244
|
-
refresh();
|
|
245
|
-
}
|
|
246
|
-
async function setLanguage(l) {
|
|
247
|
-
if (!languages.registeredLanguages.includes(l)) {
|
|
248
|
-
if (l === "html" || l === "svg") {
|
|
249
|
-
language = "xml";
|
|
250
|
-
l = "xml";
|
|
251
|
-
}
|
|
252
|
-
const mod = await import(`https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/${l}.js`);
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
language = l;
|
|
256
|
-
refresh();
|
|
257
|
-
}
|
|
258
|
-
return {
|
|
259
|
-
getValue,
|
|
260
|
-
setValue,
|
|
261
|
-
focus,
|
|
262
|
-
setLanguage,
|
|
263
|
-
destroy
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function escapeHtml(str) {
|
|
268
|
-
return str
|
|
269
|
-
.replace(/&/g, "&")
|
|
270
|
-
.replace(/</g, "<")
|
|
271
|
-
.replace(/>/g, ">");
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
async function _render(code, language, editor) {
|
|
275
|
-
// If no editor context provided, just highlight everything (initial load)
|
|
276
|
-
if (!editor) {
|
|
277
|
-
return hljs.highlight(code, { language }).value;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const scrollTop = editor.scrollTop;
|
|
281
|
-
const scrollBottom = scrollTop + editor.clientHeight;
|
|
282
|
-
const style = getComputedStyle(editor);
|
|
283
|
-
const lineHeight = parseFloat(style.lineHeight);
|
|
284
|
-
|
|
285
|
-
// Calculate visible line range
|
|
286
|
-
const startLine = Math.floor(scrollTop / lineHeight);
|
|
287
|
-
const endLine = Math.ceil(scrollBottom / lineHeight);
|
|
288
|
-
|
|
289
|
-
const lines = code.split("\n");
|
|
290
|
-
|
|
291
|
-
// Add buffer (render extra lines above/below for smooth scrolling)
|
|
292
|
-
const bufferLines = 10;
|
|
293
|
-
const visibleStart = Math.max(0, startLine - bufferLines) || 0;
|
|
294
|
-
const visibleEnd = Math.min(lines.length, endLine + bufferLines) || 0;
|
|
295
|
-
|
|
296
|
-
// Split into three sections
|
|
297
|
-
const beforeLines = lines.slice(0, visibleStart);
|
|
298
|
-
const visibleLines = lines.slice(visibleStart, visibleEnd);
|
|
299
|
-
const afterLines = lines.slice(visibleEnd);
|
|
300
|
-
|
|
301
|
-
// Only highlight visible portion
|
|
302
|
-
|
|
303
|
-
const highlightedVisible = hljs.highlight(visibleLines.join("\n"), { language }).value;
|
|
304
|
-
// Plain text for non-visible areas (no highlighting = faster)
|
|
305
|
-
if (highlightedVisible.trim() === "") {
|
|
306
|
-
return hljs.highlight(escapeHtml(code), { language }).value;
|
|
307
|
-
}
|
|
308
|
-
const beforeHTML = "\n".repeat(beforeLines.length);
|
|
309
|
-
const afterHTML = "\n".repeat(afterLines.length);
|
|
310
|
-
return beforeHTML + highlightedVisible + afterHTML;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
const editor = {
|
|
314
|
-
createEditor
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
module.exports = editor;
|
|
318
|
-
|
|
319
|
-
/*
|
|
320
|
-
|
|
321
|
-
createEditor: creates the main editor, using html Elements like, textarea and etc.
|
|
322
|
-
refresh: refreshs the editor
|
|
323
|
-
getValue: return the current value from the editor
|
|
324
|
-
setValue: sets a certain value to the editor's value
|
|
325
|
-
focus: focusses the editor
|
|
326
|
-
destroy: destroys and removeEventListeners
|
|
327
|
-
updateCaret: updates the caret positon, height and other metrics using math
|
|
328
|
-
updateLineNumbers: just add new line numbers
|
|
329
|
-
getFontMetrics: returns back the font's metrics like height
|
|
330
|
-
updateFontMetrics: update the fontMetrics
|
|
331
|
-
|
|
332
|
-
*/
|
package/commonjs/index.js
DELETED
package/commonjs/languages.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
const javascript = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/javascript.js");
|
|
2
|
-
const xml = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/xml.js");
|
|
3
|
-
const css = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/css.js");
|
|
4
|
-
const python = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/python.js");
|
|
5
|
-
const java = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/java.js");
|
|
6
|
-
const csharp = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/csharp.js");
|
|
7
|
-
const cpp = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/cpp.js");
|
|
8
|
-
const ruby = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/ruby.js");
|
|
9
|
-
const php = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/php.js");
|
|
10
|
-
const go = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/go.js");
|
|
11
|
-
const c = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/c.js");
|
|
12
|
-
const rust = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/rust.js");
|
|
13
|
-
const kotlin = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/kotlin.js");
|
|
14
|
-
const swift = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/swift.js");
|
|
15
|
-
const typescript = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/typescript.js");
|
|
16
|
-
const json = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/json.js");
|
|
17
|
-
const bash = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/bash.js");
|
|
18
|
-
const plaintext = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/plaintext.js");
|
|
19
|
-
const hljs = require("https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/core.js");
|
|
20
|
-
|
|
21
|
-
let registeredLanguages = [];
|
|
22
|
-
|
|
23
|
-
function init() {
|
|
24
|
-
// Register all languages
|
|
25
|
-
hljs.registerLanguage("javascript", javascript);
|
|
26
|
-
hljs.registerLanguage("xml", xml);
|
|
27
|
-
hljs.registerLanguage("css", css);
|
|
28
|
-
hljs.registerLanguage("html", xml);
|
|
29
|
-
hljs.registerLanguage("python", python);
|
|
30
|
-
hljs.registerLanguage("java", java);
|
|
31
|
-
hljs.registerLanguage("csharp", csharp);
|
|
32
|
-
hljs.registerLanguage("cpp", cpp);
|
|
33
|
-
hljs.registerLanguage("ruby", ruby);
|
|
34
|
-
hljs.registerLanguage("php", php);
|
|
35
|
-
hljs.registerLanguage("go", go);
|
|
36
|
-
hljs.registerLanguage("c", c);
|
|
37
|
-
hljs.registerLanguage("rust", rust);
|
|
38
|
-
hljs.registerLanguage("kotlin", kotlin);
|
|
39
|
-
hljs.registerLanguage("swift", swift);
|
|
40
|
-
hljs.registerLanguage("typescript", typescript);
|
|
41
|
-
hljs.registerLanguage("json", json);
|
|
42
|
-
hljs.registerLanguage("bash", bash);
|
|
43
|
-
hljs.registerLanguage("shell", bash);
|
|
44
|
-
hljs.registerLanguage("sh", bash);
|
|
45
|
-
hljs.registerLanguage("plaintext", plaintext);
|
|
46
|
-
registeredLanguages = [
|
|
47
|
-
"javascript",
|
|
48
|
-
"js",
|
|
49
|
-
"xml",
|
|
50
|
-
"html",
|
|
51
|
-
"svg",
|
|
52
|
-
"python",
|
|
53
|
-
"java",
|
|
54
|
-
"csharp",
|
|
55
|
-
"cpp",
|
|
56
|
-
"ruby",
|
|
57
|
-
"php",
|
|
58
|
-
"go",
|
|
59
|
-
"c",
|
|
60
|
-
"rust",
|
|
61
|
-
"kotlin",
|
|
62
|
-
"swift",
|
|
63
|
-
"typescript",
|
|
64
|
-
"json",
|
|
65
|
-
"bash",
|
|
66
|
-
"shell",
|
|
67
|
-
"sh",
|
|
68
|
-
"plaintext"
|
|
69
|
-
]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function registerLanguage(name, definition) {
|
|
73
|
-
hljs.registerLanguage(name, definition);
|
|
74
|
-
if (!registeredLanguages.includes(name)) {
|
|
75
|
-
registeredLanguages.push(name);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const languages = {
|
|
80
|
-
init,
|
|
81
|
-
registeredLanguages,
|
|
82
|
-
registerLanguage,
|
|
83
|
-
hljs
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
module.exports = languages;
|
|
87
|
-
|
|
88
|
-
/*
|
|
89
|
-
|
|
90
|
-
registeredLannguage: added for the editor.js can check if the langauge provided already is regsitered or not
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
init: just registers some languages and updates the registeredLangauges variable
|
|
94
|
-
|
|
95
|
-
registerLanguage: just registers a language
|
|
96
|
-
|
|
97
|
-
*/
|
package/commonjs/theme.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
function setTheme(name) {
|
|
2
|
-
const link = document.getElementById("Caret-theme");
|
|
3
|
-
link.href = `https://esm.sh/@pfmcodes/highlight.js@1.0.0/styles/${name}.css`;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
function removeTheme() {
|
|
7
|
-
const link = document.getElementById("Caret-theme");
|
|
8
|
-
if (link) {
|
|
9
|
-
link.parentNode.removeChild(link);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const theme = {
|
|
14
|
-
removeTheme,
|
|
15
|
-
setTheme
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
module.exports = theme;
|
|
File without changes
|