@pfmcodes/caret 0.2.7 → 0.2.8
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 +4 -1
- package/editor.js +5 -11
- package/langauges.js +6 -0
- package/package.json +1 -1
- package/types/langauges.ts +6 -7
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Caret
|
|
2
|
-
|
|
2
|
+

|
|
3
3
|
[](https://opensource.org/licenses/MIT)
|
|
4
4
|
[](https://github.com/PFMCODES/lexius-edior)
|
|
5
5
|
[](https://github.com/PFMCODES/lexius-edior)
|
|
@@ -33,6 +33,9 @@ A lightweight, feature-rich code editor with real-time syntax highlighting and c
|
|
|
33
33
|
|
|
34
34
|
## What's-New?
|
|
35
35
|
|
|
36
|
+
### v0.2.8
|
|
37
|
+
- just mistake i made has been fixed
|
|
38
|
+
|
|
36
39
|
### v0.2.7
|
|
37
40
|
- another cleanup but this time, with file optimizations and updated comments at the end of each containing short summaries of each function and variables(only some important variables)
|
|
38
41
|
|
package/editor.js
CHANGED
|
@@ -71,8 +71,10 @@ async function createEditor(editor, data) {
|
|
|
71
71
|
editor.style = "position: relative; width: 600px; height: 300px; overflow: hidden; /* 👈 CRITICAL */ font-size: 14px;"
|
|
72
72
|
if (code && editor && editor1 && language && highlighted) {
|
|
73
73
|
editor1.style.paddingTop = "-9px";
|
|
74
|
-
editor1.value =
|
|
75
|
-
|
|
74
|
+
editor1.value = code;
|
|
75
|
+
let h = await _render(code, language, editor1);
|
|
76
|
+
highlighted.innerHTML = h;
|
|
77
|
+
console.log({h: h, code: code})
|
|
76
78
|
}
|
|
77
79
|
const keyDown = async (e) => {
|
|
78
80
|
if (e.key !== "Tab") return;
|
|
@@ -396,13 +398,6 @@ function getWrapMap(code, wrapAt = 71) {
|
|
|
396
398
|
return wrapMap;
|
|
397
399
|
}
|
|
398
400
|
|
|
399
|
-
function escapeHtml(str) {
|
|
400
|
-
return str
|
|
401
|
-
.replace(/&/g, "&")
|
|
402
|
-
.replace(/</g, "<")
|
|
403
|
-
.replace(/>/g, ">");
|
|
404
|
-
}
|
|
405
|
-
|
|
406
401
|
async function _render(code, language, editor) {
|
|
407
402
|
// If no editor context provided, just highlight everything (initial load)
|
|
408
403
|
if (!editor) {
|
|
@@ -440,7 +435,7 @@ async function _render(code, language, editor) {
|
|
|
440
435
|
const highlightedVisible = hljs.highlight(wrappedCode, { language }).value;
|
|
441
436
|
// Plain text for non-visible areas (no highlighting = faster)
|
|
442
437
|
if (highlightedVisible.trim() === "") {
|
|
443
|
-
return hljs.highlight(
|
|
438
|
+
return hljs.highlight(code, { language }).value;
|
|
444
439
|
}
|
|
445
440
|
const beforeHTML = "\n".repeat(beforeLines.length);
|
|
446
441
|
const afterHTML = "\n".repeat(afterLines.length);
|
|
@@ -467,7 +462,6 @@ Internal functions:
|
|
|
467
462
|
_render(code, language, editor) -> virtual renderer, only highlights visible lines for performance
|
|
468
463
|
wrapCode(code, wrapAt) -> wraps long lines at word boundaries
|
|
469
464
|
getWrapMap(code, wrapAt) -> returns an array mapping each line to its visual line count
|
|
470
|
-
escapeHtml(str) -> escapes HTML special characters
|
|
471
465
|
updateCaret() -> updates the caret position using canvas font metrics
|
|
472
466
|
updateLineNumbers() -> re-renders line numbers, accounting for wrapped lines
|
|
473
467
|
updateFontMetrics() -> updates the canvas font to match the textarea's computed style
|
package/langauges.js
CHANGED
|
@@ -69,6 +69,10 @@ function init() {
|
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
export function registerAliases(a, b) {
|
|
73
|
+
hljs.registerAliases(a, b)
|
|
74
|
+
}
|
|
75
|
+
|
|
72
76
|
function registerLanguage(name, definition) {
|
|
73
77
|
if (!registeredLanguages.includes(name)) {
|
|
74
78
|
hljs.registerLanguage(name, definition);
|
|
@@ -84,6 +88,7 @@ const languages = {
|
|
|
84
88
|
init,
|
|
85
89
|
registeredLanguages,
|
|
86
90
|
registerLanguage,
|
|
91
|
+
registerAliases,
|
|
87
92
|
hljs
|
|
88
93
|
}
|
|
89
94
|
|
|
@@ -93,4 +98,5 @@ export default languages;
|
|
|
93
98
|
registeredLannguage: added for the editor.js can check if the langauge provided already is regsitered or not
|
|
94
99
|
init: just registers some languages and updates the registeredLangauges variable
|
|
95
100
|
registerLanguage: just registers a language
|
|
101
|
+
registerAliases: basically registers a nickname or second name for an language
|
|
96
102
|
*/
|
package/package.json
CHANGED
package/types/langauges.ts
CHANGED
|
@@ -37,8 +37,7 @@ import plaintext from "https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/languages/
|
|
|
37
37
|
// @ts-ignore
|
|
38
38
|
import hljs from "https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/core.js";
|
|
39
39
|
|
|
40
|
-
let registeredLanguages: Array<
|
|
41
|
-
type T = any
|
|
40
|
+
let registeredLanguages: Array<any> = [];
|
|
42
41
|
|
|
43
42
|
function init() {
|
|
44
43
|
// Register all languages
|
|
@@ -89,6 +88,10 @@ function init() {
|
|
|
89
88
|
]
|
|
90
89
|
}
|
|
91
90
|
|
|
91
|
+
export function registerAliases(a: any, b: any) {
|
|
92
|
+
hljs.registerAliases(a, b)
|
|
93
|
+
}
|
|
94
|
+
|
|
92
95
|
function registerLanguage(name: string, definition: any) {
|
|
93
96
|
hljs.registerLanguage(name, definition);
|
|
94
97
|
if (!registeredLanguages.includes(name)) {
|
|
@@ -106,12 +109,8 @@ const languages = {
|
|
|
106
109
|
export default languages;
|
|
107
110
|
|
|
108
111
|
/*
|
|
109
|
-
|
|
110
112
|
registeredLannguage: added for the editor.js can check if the langauge provided already is regsitered or not
|
|
111
|
-
|
|
112
|
-
|
|
113
113
|
init: just registers some languages and updates the registeredLangauges variable
|
|
114
|
-
|
|
115
114
|
registerLanguage: just registers a language
|
|
116
|
-
|
|
115
|
+
registerAliases: basically registers a nickname or second name for an language
|
|
117
116
|
*/
|