juxscript 1.1.49 → 1.1.51
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/lib/components/code.d.ts.map +1 -1
- package/lib/components/code.js +3 -6
- package/lib/components/code.ts +3 -7
- package/lib/utils/codeparser.d.ts +4 -4
- package/lib/utils/codeparser.d.ts.map +1 -1
- package/lib/utils/codeparser.js +25 -30
- package/lib/utils/codeparser.ts +27 -31
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAOxD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,KAAK,SAAS,GAAG;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,qBAAa,IAAK,SAAQ,aAAa,CAAC,SAAS,CAAC;IAChD,OAAO,CAAC,cAAc,CAA4B;IAClD,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAS;gBAE9B,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB;IAYjD,SAAS,CAAC,gBAAgB,IAAI,SAAS,MAAM,EAAE;IAI/C,SAAS,CAAC,i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C;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,qBAAa,IAAK,SAAQ,aAAa,CAAC,SAAS,CAAC;IAChD,OAAO,CAAC,cAAc,CAA4B;IAClD,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAS;gBAE9B,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB;IAYjD,SAAS,CAAC,gBAAgB,IAAI,SAAS,MAAM,EAAE;IAI/C,SAAS,CAAC,iBAAiB,IAAI,SAAS,MAAM,EAAE;IAIhD,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAsBtC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK5B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK7B,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAKrC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK9B,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI;IASrC;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACH,OAAO,CAAC,aAAa;IAoBrB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA0B1B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAezB,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,IAAI;CA4EnE;AAED,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,GAAG,IAAI,CAEhE"}
|
package/lib/components/code.js
CHANGED
|
@@ -149,9 +149,8 @@ export class Code extends BaseComponent {
|
|
|
149
149
|
wrapper.className += ` ${className}`;
|
|
150
150
|
if (style)
|
|
151
151
|
wrapper.setAttribute('style', style);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const codeEl = document.createElement('code');
|
|
152
|
+
// ✅ Remove <pre>, just use a div with code styling
|
|
153
|
+
const codeEl = document.createElement('div');
|
|
155
154
|
codeEl.className = 'jux-code-lines';
|
|
156
155
|
// Build initial lines with parsed tokens
|
|
157
156
|
const parsedLines = this._parseLines();
|
|
@@ -162,8 +161,7 @@ export class Code extends BaseComponent {
|
|
|
162
161
|
const lineEl = this._createLineElement(parsedLine, lineNumber, isHighlighted);
|
|
163
162
|
codeEl.appendChild(lineEl);
|
|
164
163
|
});
|
|
165
|
-
|
|
166
|
-
wrapper.appendChild(pre);
|
|
164
|
+
wrapper.appendChild(codeEl);
|
|
167
165
|
this._wireStandardEvents(wrapper);
|
|
168
166
|
// Wire sync bindings
|
|
169
167
|
this._syncBindings.forEach(({ property, stateObj, toState, toComponent }) => {
|
|
@@ -180,7 +178,6 @@ export class Code extends BaseComponent {
|
|
|
180
178
|
stateObj.subscribe((val) => {
|
|
181
179
|
const transformed = transform(val);
|
|
182
180
|
this.state.language = transformed;
|
|
183
|
-
pre.className = `language-${transformed}`;
|
|
184
181
|
this._rebuildLines();
|
|
185
182
|
});
|
|
186
183
|
}
|
package/lib/components/code.ts
CHANGED
|
@@ -198,10 +198,8 @@ export class Code extends BaseComponent<CodeState> {
|
|
|
198
198
|
if (className) wrapper.className += ` ${className}`;
|
|
199
199
|
if (style) wrapper.setAttribute('style', style);
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const codeEl = document.createElement('code');
|
|
201
|
+
// ✅ Remove <pre>, just use a div with code styling
|
|
202
|
+
const codeEl = document.createElement('div');
|
|
205
203
|
codeEl.className = 'jux-code-lines';
|
|
206
204
|
|
|
207
205
|
// Build initial lines with parsed tokens
|
|
@@ -215,8 +213,7 @@ export class Code extends BaseComponent<CodeState> {
|
|
|
215
213
|
codeEl.appendChild(lineEl);
|
|
216
214
|
});
|
|
217
215
|
|
|
218
|
-
|
|
219
|
-
wrapper.appendChild(pre);
|
|
216
|
+
wrapper.appendChild(codeEl);
|
|
220
217
|
|
|
221
218
|
this._wireStandardEvents(wrapper);
|
|
222
219
|
|
|
@@ -237,7 +234,6 @@ export class Code extends BaseComponent<CodeState> {
|
|
|
237
234
|
stateObj.subscribe((val: any) => {
|
|
238
235
|
const transformed = transform(val);
|
|
239
236
|
this.state.language = transformed;
|
|
240
|
-
pre.className = `language-${transformed}`;
|
|
241
237
|
this._rebuildLines();
|
|
242
238
|
});
|
|
243
239
|
}
|
|
@@ -3,6 +3,10 @@ export interface ParsedLine {
|
|
|
3
3
|
html: string;
|
|
4
4
|
raw: string;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* Escape HTML entities
|
|
8
|
+
*/
|
|
9
|
+
declare function escapeHtml(text: string): string;
|
|
6
10
|
/**
|
|
7
11
|
* Parse code into lines with simple syntax highlighting
|
|
8
12
|
*/
|
|
@@ -11,10 +15,6 @@ export declare function parseCode(code: string, language?: string): ParsedLine[]
|
|
|
11
15
|
* Render a parsed line (just returns the pre-generated HTML)
|
|
12
16
|
*/
|
|
13
17
|
export declare function renderLineWithTokens(parsedLine: ParsedLine): string;
|
|
14
|
-
/**
|
|
15
|
-
* Escape HTML entities
|
|
16
|
-
*/
|
|
17
|
-
declare function escapeHtml(text: string): string;
|
|
18
18
|
/**
|
|
19
19
|
* Generate CSS for syntax highlighting
|
|
20
20
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeparser.d.ts","sourceRoot":"","sources":["codeparser.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,UAAU;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAqB,GAAG,UAAU,EAAE,CAQrF;
|
|
1
|
+
{"version":3,"file":"codeparser.d.ts","sourceRoot":"","sources":["codeparser.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,UAAU;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOxC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAqB,GAAG,UAAU,EAAE,CAQrF;AAsCD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEnE;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAiE9C;AAED;;GAEG;;;;;;;AACH,wBAKE"}
|
package/lib/utils/codeparser.js
CHANGED
|
@@ -9,6 +9,17 @@ const KEYWORDS = new Set([
|
|
|
9
9
|
'typeof', 'var', 'void', 'while', 'with', 'yield', 'from', 'of',
|
|
10
10
|
'static', 'get', 'set', 'as', 'interface', 'type', 'enum', 'namespace'
|
|
11
11
|
]);
|
|
12
|
+
/**
|
|
13
|
+
* Escape HTML entities
|
|
14
|
+
*/
|
|
15
|
+
function escapeHtml(text) {
|
|
16
|
+
return text
|
|
17
|
+
.replace(/&/g, '&')
|
|
18
|
+
.replace(/</g, '<')
|
|
19
|
+
.replace(/>/g, '>')
|
|
20
|
+
.replace(/"/g, '"')
|
|
21
|
+
.replace(/'/g, ''');
|
|
22
|
+
}
|
|
12
23
|
/**
|
|
13
24
|
* Parse code into lines with simple syntax highlighting
|
|
14
25
|
*/
|
|
@@ -26,26 +37,26 @@ export function parseCode(code, language = 'javascript') {
|
|
|
26
37
|
function highlightLine(line) {
|
|
27
38
|
if (!line.trim())
|
|
28
39
|
return ' ';
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
// Escape the raw line first
|
|
41
|
+
let escaped = escapeHtml(line);
|
|
42
|
+
// Now add spans (on already-escaped text)
|
|
43
|
+
// 1. Comments
|
|
44
|
+
escaped = escaped.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
|
|
45
|
+
escaped = escaped.replace(/(\/\*[\s\S]*?\*\/)/g, '<span class="token-comment">$1</span>');
|
|
46
|
+
// 2. Strings (already escaped, so look for " etc)
|
|
47
|
+
escaped = escaped.replace(/("[^&]*?"|'[^&]*?'|`[^`]*?`)/g, '<span class="token-string">$1</span>');
|
|
37
48
|
// 3. Numbers
|
|
38
|
-
|
|
49
|
+
escaped = escaped.replace(/\b(\d+\.?\d*)\b/g, '<span class="token-number">$1</span>');
|
|
39
50
|
// 4. Keywords (only whole words)
|
|
40
51
|
KEYWORDS.forEach(keyword => {
|
|
41
52
|
const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
|
|
42
|
-
|
|
53
|
+
escaped = escaped.replace(regex, '<span class="token-keyword">$1</span>');
|
|
43
54
|
});
|
|
44
|
-
// 5. Braces, brackets, parentheses
|
|
45
|
-
|
|
55
|
+
// 5. Braces, brackets, parentheses (these are plain text, not escaped)
|
|
56
|
+
escaped = escaped.replace(/([{}[\]()])/g, '<span class="token-punctuation">$1</span>');
|
|
46
57
|
// 6. Operators
|
|
47
|
-
|
|
48
|
-
return
|
|
58
|
+
escaped = escaped.replace(/([+\-*/%=<>!&|^~?:])/g, '<span class="token-operator">$1</span>');
|
|
59
|
+
return escaped || ' ';
|
|
49
60
|
}
|
|
50
61
|
/**
|
|
51
62
|
* Render a parsed line (just returns the pre-generated HTML)
|
|
@@ -53,17 +64,6 @@ function highlightLine(line) {
|
|
|
53
64
|
export function renderLineWithTokens(parsedLine) {
|
|
54
65
|
return parsedLine.html;
|
|
55
66
|
}
|
|
56
|
-
/**
|
|
57
|
-
* Escape HTML entities
|
|
58
|
-
*/
|
|
59
|
-
function escapeHtml(text) {
|
|
60
|
-
return text
|
|
61
|
-
.replace(/&/g, '&')
|
|
62
|
-
.replace(/</g, '<')
|
|
63
|
-
.replace(/>/g, '>')
|
|
64
|
-
.replace(/"/g, '"')
|
|
65
|
-
.replace(/'/g, ''');
|
|
66
|
-
}
|
|
67
67
|
/**
|
|
68
68
|
* Generate CSS for syntax highlighting
|
|
69
69
|
*/
|
|
@@ -78,13 +78,8 @@ export function getSyntaxHighlightCSS() {
|
|
|
78
78
|
border-radius: 8px;
|
|
79
79
|
overflow: hidden;
|
|
80
80
|
margin: 1rem 0;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
.jux-code pre {
|
|
84
|
-
margin: 0;
|
|
85
81
|
padding: 1rem;
|
|
86
82
|
overflow-x: auto;
|
|
87
|
-
background: transparent;
|
|
88
83
|
}
|
|
89
84
|
|
|
90
85
|
.jux-code-lines {
|
package/lib/utils/codeparser.ts
CHANGED
|
@@ -16,6 +16,18 @@ export interface ParsedLine {
|
|
|
16
16
|
raw: string;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Escape HTML entities
|
|
21
|
+
*/
|
|
22
|
+
function escapeHtml(text: string): string {
|
|
23
|
+
return text
|
|
24
|
+
.replace(/&/g, '&')
|
|
25
|
+
.replace(/</g, '<')
|
|
26
|
+
.replace(/>/g, '>')
|
|
27
|
+
.replace(/"/g, '"')
|
|
28
|
+
.replace(/'/g, ''');
|
|
29
|
+
}
|
|
30
|
+
|
|
19
31
|
/**
|
|
20
32
|
* Parse code into lines with simple syntax highlighting
|
|
21
33
|
*/
|
|
@@ -35,33 +47,34 @@ export function parseCode(code: string, language: string = 'javascript'): Parsed
|
|
|
35
47
|
function highlightLine(line: string): string {
|
|
36
48
|
if (!line.trim()) return ' ';
|
|
37
49
|
|
|
38
|
-
|
|
50
|
+
// Escape the raw line first
|
|
51
|
+
let escaped = escapeHtml(line);
|
|
39
52
|
|
|
40
|
-
//
|
|
41
|
-
result = result.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
|
|
42
|
-
result = result.replace(/(\/\*[\s\S]*?\*\/)/g, '<span class="token-comment">$1</span>');
|
|
53
|
+
// Now add spans (on already-escaped text)
|
|
43
54
|
|
|
44
|
-
//
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
// 1. Comments
|
|
56
|
+
escaped = escaped.replace(/(\/\/.*$)/g, '<span class="token-comment">$1</span>');
|
|
57
|
+
escaped = escaped.replace(/(\/\*[\s\S]*?\*\/)/g, '<span class="token-comment">$1</span>');
|
|
58
|
+
|
|
59
|
+
// 2. Strings (already escaped, so look for " etc)
|
|
60
|
+
escaped = escaped.replace(/("[^&]*?"|'[^&]*?'|`[^`]*?`)/g, '<span class="token-string">$1</span>');
|
|
48
61
|
|
|
49
62
|
// 3. Numbers
|
|
50
|
-
|
|
63
|
+
escaped = escaped.replace(/\b(\d+\.?\d*)\b/g, '<span class="token-number">$1</span>');
|
|
51
64
|
|
|
52
65
|
// 4. Keywords (only whole words)
|
|
53
66
|
KEYWORDS.forEach(keyword => {
|
|
54
67
|
const regex = new RegExp(`\\b(${keyword})\\b`, 'g');
|
|
55
|
-
|
|
68
|
+
escaped = escaped.replace(regex, '<span class="token-keyword">$1</span>');
|
|
56
69
|
});
|
|
57
70
|
|
|
58
|
-
// 5. Braces, brackets, parentheses
|
|
59
|
-
|
|
71
|
+
// 5. Braces, brackets, parentheses (these are plain text, not escaped)
|
|
72
|
+
escaped = escaped.replace(/([{}[\]()])/g, '<span class="token-punctuation">$1</span>');
|
|
60
73
|
|
|
61
74
|
// 6. Operators
|
|
62
|
-
|
|
75
|
+
escaped = escaped.replace(/([+\-*/%=<>!&|^~?:])/g, '<span class="token-operator">$1</span>');
|
|
63
76
|
|
|
64
|
-
return
|
|
77
|
+
return escaped || ' ';
|
|
65
78
|
}
|
|
66
79
|
|
|
67
80
|
/**
|
|
@@ -71,18 +84,6 @@ export function renderLineWithTokens(parsedLine: ParsedLine): string {
|
|
|
71
84
|
return parsedLine.html;
|
|
72
85
|
}
|
|
73
86
|
|
|
74
|
-
/**
|
|
75
|
-
* Escape HTML entities
|
|
76
|
-
*/
|
|
77
|
-
function escapeHtml(text: string): string {
|
|
78
|
-
return text
|
|
79
|
-
.replace(/&/g, '&')
|
|
80
|
-
.replace(/</g, '<')
|
|
81
|
-
.replace(/>/g, '>')
|
|
82
|
-
.replace(/"/g, '"')
|
|
83
|
-
.replace(/'/g, ''');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
87
|
/**
|
|
87
88
|
* Generate CSS for syntax highlighting
|
|
88
89
|
*/
|
|
@@ -97,13 +98,8 @@ export function getSyntaxHighlightCSS(): string {
|
|
|
97
98
|
border-radius: 8px;
|
|
98
99
|
overflow: hidden;
|
|
99
100
|
margin: 1rem 0;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
.jux-code pre {
|
|
103
|
-
margin: 0;
|
|
104
101
|
padding: 1rem;
|
|
105
102
|
overflow-x: auto;
|
|
106
|
-
background: transparent;
|
|
107
103
|
}
|
|
108
104
|
|
|
109
105
|
.jux-code-lines {
|