@pfmcodes/caret 0.2.6 → 0.2.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 +3 -0
- package/editor.js +20 -12
- package/index.js +13 -1
- package/langauges.js +30 -31
- package/package.json +1 -1
- package/theme.js +5 -9
- package/types/editor.ts +24 -13
- package/types/index.d.ts +12 -0
- package/types/index.ts +14 -2
- package/types/theme.ts +5 -9
- package/types/esm-highlight.d.ts +0 -4
- /package/types/{languages.ts → langauges.ts} +0 -0
package/README.md
CHANGED
|
@@ -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.7
|
|
37
|
+
- 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
|
+
|
|
36
39
|
### v0.2.6
|
|
37
40
|
|
|
38
41
|
- CommonJs support has been removed to reduce package size
|
package/editor.js
CHANGED
|
@@ -453,16 +453,24 @@ const editor = {
|
|
|
453
453
|
|
|
454
454
|
export default editor;
|
|
455
455
|
|
|
456
|
-
/*
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
456
|
+
/*
|
|
457
|
+
createEditor(editor, data): creates the main editor using HTML elements like textarea, pre, div etc.
|
|
458
|
+
Returns an object with the following methods:
|
|
459
|
+
getValue() -> returns the current value from the editor
|
|
460
|
+
setValue(val) -> sets a value to the editor
|
|
461
|
+
focus() -> focuses the editor
|
|
462
|
+
setLanguage(lang) -> changes the syntax highlighting language
|
|
463
|
+
destroy() -> destroys the editor and removes all event listeners
|
|
464
|
+
onDidChangeModelContent(fn) -> fires a callback whenever the editor content changes
|
|
465
|
+
|
|
466
|
+
Internal functions:
|
|
467
|
+
_render(code, language, editor) -> virtual renderer, only highlights visible lines for performance
|
|
468
|
+
wrapCode(code, wrapAt) -> wraps long lines at word boundaries
|
|
469
|
+
getWrapMap(code, wrapAt) -> returns an array mapping each line to its visual line count
|
|
470
|
+
escapeHtml(str) -> escapes HTML special characters
|
|
471
|
+
updateCaret() -> updates the caret position using canvas font metrics
|
|
472
|
+
updateLineNumbers() -> re-renders line numbers, accounting for wrapped lines
|
|
473
|
+
updateFontMetrics() -> updates the canvas font to match the textarea's computed style
|
|
474
|
+
getFontMetrics() -> returns ascent, descent and height of the current font
|
|
475
|
+
getVisualRow(text, wrapAt) -> returns which visual row and remaining text the caret is on
|
|
468
476
|
*/
|
package/index.js
CHANGED
|
@@ -7,4 +7,16 @@ const Caret = {
|
|
|
7
7
|
theme,
|
|
8
8
|
language
|
|
9
9
|
}
|
|
10
|
-
export default Caret;
|
|
10
|
+
export default Caret;
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
Caret.editor:
|
|
14
|
+
createEditor() -> backbone of caret, handles ui and abstractions
|
|
15
|
+
Caret.theme:
|
|
16
|
+
setTheme() -> changes the current highlight.js theme
|
|
17
|
+
Caret.langauge:
|
|
18
|
+
init() -> initializes default avaible languages
|
|
19
|
+
registerLanguage() -> registers a new languages
|
|
20
|
+
registeredLangauges[List]: has all the langauges registered
|
|
21
|
+
hljs: the highlight.js module
|
|
22
|
+
*/
|
package/langauges.js
CHANGED
|
@@ -22,31 +22,31 @@ let registeredLanguages = [];
|
|
|
22
22
|
|
|
23
23
|
function init() {
|
|
24
24
|
// Register all languages
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
25
|
+
registerLanguage("javascript", javascript);
|
|
26
|
+
registerLanguage("xml", xml);
|
|
27
|
+
registerLanguage("typescript", typescript);
|
|
28
|
+
registerAliases(["jsx"], { languageName: "javascript" });
|
|
29
|
+
registerAliases(["js"], { languageName: "javascript" });
|
|
30
|
+
registerAliases(["ts"], { languageName: "typescript" });
|
|
31
|
+
registerAliases(["html"], { languageName: "xml" });
|
|
32
|
+
registerAliases(["svg"], { languageName: "xml" });
|
|
33
|
+
registerLanguage("css", css);
|
|
34
|
+
registerLanguage("python", python);
|
|
35
|
+
registerLanguage("java", java);
|
|
36
|
+
registerLanguage("csharp", csharp);
|
|
37
|
+
registerLanguage("cpp", cpp);
|
|
38
|
+
registerLanguage("ruby", ruby);
|
|
39
|
+
registerLanguage("php", php);
|
|
40
|
+
registerLanguage("go", go);
|
|
41
|
+
registerLanguage("c", c);
|
|
42
|
+
registerLanguage("rust", rust);
|
|
43
|
+
registerLanguage("kotlin", kotlin);
|
|
44
|
+
registerLanguage("swift", swift);
|
|
45
|
+
registerLanguage("json", json);
|
|
46
|
+
registerLanguage("bash", bash);
|
|
47
|
+
registerLanguage("shell", bash);
|
|
48
|
+
registerLanguage("sh", bash);
|
|
49
|
+
registerLanguage("plaintext", plaintext);
|
|
50
50
|
registeredLanguages.push(
|
|
51
51
|
"javascript", "js",
|
|
52
52
|
"xml", "html", "svg",
|
|
@@ -70,9 +70,13 @@ function init() {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
function registerLanguage(name, definition) {
|
|
73
|
-
hljs.registerLanguage(name, definition);
|
|
74
73
|
if (!registeredLanguages.includes(name)) {
|
|
74
|
+
hljs.registerLanguage(name, definition);
|
|
75
75
|
registeredLanguages.push(name);
|
|
76
|
+
return;
|
|
77
|
+
} else {
|
|
78
|
+
console.warn(`Caret: Language ${name} already registered, aborting`);
|
|
79
|
+
return;
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -86,12 +90,7 @@ const languages = {
|
|
|
86
90
|
export default languages;
|
|
87
91
|
|
|
88
92
|
/*
|
|
89
|
-
|
|
90
93
|
registeredLannguage: added for the editor.js can check if the langauge provided already is regsitered or not
|
|
91
|
-
|
|
92
|
-
|
|
93
94
|
init: just registers some languages and updates the registeredLangauges variable
|
|
94
|
-
|
|
95
95
|
registerLanguage: just registers a language
|
|
96
|
-
|
|
97
96
|
*/
|
package/package.json
CHANGED
package/theme.js
CHANGED
|
@@ -3,16 +3,12 @@ function setTheme(name) {
|
|
|
3
3
|
link.href = `https://esm.sh/@pfmcodes/highlight.js@1.0.0/styles/${name}.css`;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
function removeTheme() {
|
|
7
|
-
const link = document.getElementById("Caret-theme");
|
|
8
|
-
if (link) {
|
|
9
|
-
link.parentNode.removeChild(link);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
6
|
const theme = {
|
|
14
|
-
removeTheme,
|
|
15
7
|
setTheme
|
|
16
8
|
}
|
|
17
9
|
|
|
18
|
-
export default theme;
|
|
10
|
+
export default theme;
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
setTheme() -> changes the current highlight.js theme
|
|
14
|
+
*/
|
package/types/editor.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
import hljs from "https://esm.sh/@pfmcodes/highlight.js@1.0.0/es/core.js"; // Use default export
|
|
2
|
-
import languages from "./
|
|
3
|
+
import languages from "./langauges.ts";
|
|
3
4
|
|
|
4
5
|
languages.init();
|
|
5
6
|
|
|
@@ -49,6 +50,7 @@ async function createEditor(editor: HTMLElement, data: any) {
|
|
|
49
50
|
link.href = `https://esm.sh/@pfmcodes/highlight.js@1.0.0/styles/${theme}.css`;
|
|
50
51
|
document.head.appendChild(link);
|
|
51
52
|
} else {
|
|
53
|
+
// @ts-ignore
|
|
52
54
|
themeLink.href = `https://esm.sh/@pfmcodes/highlight.js@1.0.0/styles/${theme}.css`;
|
|
53
55
|
}
|
|
54
56
|
} else {
|
|
@@ -60,6 +62,7 @@ async function createEditor(editor: HTMLElement, data: any) {
|
|
|
60
62
|
link.href = `https://esm.sh/@pfmcodes/highlight.js@1.0.0/styles/hybrid.css`;
|
|
61
63
|
document.head.appendChild(link);
|
|
62
64
|
} else {
|
|
65
|
+
// @ts-ignore
|
|
63
66
|
themeLink.href = `./highlight.js/styles/hybrid.css`;
|
|
64
67
|
}
|
|
65
68
|
}
|
|
@@ -455,16 +458,24 @@ const editor = {
|
|
|
455
458
|
|
|
456
459
|
export default editor;
|
|
457
460
|
|
|
458
|
-
/*
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
461
|
+
/*
|
|
462
|
+
createEditor(editor, data): creates the main editor using HTML elements like textarea, pre, div etc.
|
|
463
|
+
Returns an object with the following methods:
|
|
464
|
+
getValue() -> returns the current value from the editor
|
|
465
|
+
setValue(val) -> sets a value to the editor
|
|
466
|
+
focus() -> focuses the editor
|
|
467
|
+
setLanguage(lang) -> changes the syntax highlighting language
|
|
468
|
+
destroy() -> destroys the editor and removes all event listeners
|
|
469
|
+
onDidChangeModelContent(fn) -> fires a callback whenever the editor content changes
|
|
470
|
+
|
|
471
|
+
Internal functions:
|
|
472
|
+
_render(code, language, editor) -> virtual renderer, only highlights visible lines for performance
|
|
473
|
+
wrapCode(code, wrapAt) -> wraps long lines at word boundaries
|
|
474
|
+
getWrapMap(code, wrapAt) -> returns an array mapping each line to its visual line count
|
|
475
|
+
escapeHtml(str) -> escapes HTML special characters
|
|
476
|
+
updateCaret() -> updates the caret position using canvas font metrics
|
|
477
|
+
updateLineNumbers() -> re-renders line numbers, accounting for wrapped lines
|
|
478
|
+
updateFontMetrics() -> updates the canvas font to match the textarea's computed style
|
|
479
|
+
getFontMetrics() -> returns ascent, descent and height of the current font
|
|
480
|
+
getVisualRow(text, wrapAt) -> returns which visual row and remaining text the caret is on
|
|
470
481
|
*/
|
package/types/index.d.ts
CHANGED
|
@@ -32,3 +32,15 @@ declare module "@pfmcodes/caret" {
|
|
|
32
32
|
|
|
33
33
|
export default Caret;
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
Caret.editor:
|
|
38
|
+
createEditor() -> backbone of caret, handles ui and abstractions
|
|
39
|
+
Caret.theme:
|
|
40
|
+
setTheme() -> changes the current highlight.js theme
|
|
41
|
+
Caret.langauge:
|
|
42
|
+
init() -> initializes default avaible languages
|
|
43
|
+
registerLanguage() -> registers a new languages
|
|
44
|
+
registeredLangauges[List]: has all the langauges registered
|
|
45
|
+
hljs: the highlight.js module
|
|
46
|
+
*/
|
package/types/index.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import editor from "./editor.ts";
|
|
2
2
|
import theme from "./theme.ts";
|
|
3
|
-
import language from "./
|
|
3
|
+
import language from "./langauges.ts";
|
|
4
4
|
|
|
5
5
|
const Caret = {
|
|
6
6
|
editor,
|
|
7
7
|
theme,
|
|
8
8
|
language
|
|
9
9
|
}
|
|
10
|
-
export default Caret;
|
|
10
|
+
export default Caret;
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
Caret.editor:
|
|
14
|
+
createEditor() -> backbone of caret, handles ui and abstractions
|
|
15
|
+
Caret.theme:
|
|
16
|
+
setTheme() -> changes the current highlight.js theme
|
|
17
|
+
Caret.langauge:
|
|
18
|
+
init() -> initializes default avaible languages
|
|
19
|
+
registerLanguage() -> registers a new languages
|
|
20
|
+
registeredLangauges[List]: has all the langauges registered
|
|
21
|
+
hljs: the highlight.js module
|
|
22
|
+
*/
|
package/types/theme.ts
CHANGED
|
@@ -3,16 +3,12 @@ function setTheme(name: string) {
|
|
|
3
3
|
link.href = `./highlight.js/styles/${name}.css`;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
function removeTheme() {
|
|
7
|
-
const link = document.getElementById("Caret-theme") as HTMLLinkElement;
|
|
8
|
-
if (link && link.parentNode) {
|
|
9
|
-
link.parentNode.removeChild(link);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
6
|
const theme = {
|
|
14
|
-
removeTheme,
|
|
15
7
|
setTheme
|
|
16
8
|
}
|
|
17
9
|
|
|
18
|
-
export default theme;
|
|
10
|
+
export default theme;
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
setTheme() -> changes the current highlight.js theme
|
|
14
|
+
*/
|
package/types/esm-highlight.d.ts
DELETED
|
File without changes
|