slicejs-web-framework 1.0.20 → 1.0.22
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/Slice/Components/Structural/Debugger/Debugger.js +119 -3
- package/package.json +1 -1
- package/src/Components/AppComponents/HomePage/HomePage.css +2 -0
- package/src/Components/AppComponents/HomePage/HomePage.js +4 -4
- package/src/Components/AppComponents/Playground/Playground.js +4 -0
- package/src/Components/Visual/CodeVisualizer/CodeVisualizer.css +130 -0
- package/src/Components/Visual/CodeVisualizer/CodeVisualizer.html +4 -0
- package/src/Components/Visual/CodeVisualizer/CodeVisualizer.js +263 -0
- package/src/Components/components.js +2 -24
- package/src/routes.js +4 -0
|
@@ -9,11 +9,127 @@ export default class Debugger extends HTMLElement {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
async enableDebugMode() {
|
|
12
|
-
const html = await slice.controller.fetchText('Debugger', true, true, "/Slice/Components/Structural/Debugger/Debugger.html" );
|
|
12
|
+
//const html = await slice.controller.fetchText('Debugger', true, true, "/Slice/Components/Structural/Debugger/Debugger.html" );
|
|
13
|
+
|
|
14
|
+
const html = `
|
|
15
|
+
<div id="debugger-container">
|
|
16
|
+
<div class="debugger-header">
|
|
17
|
+
<div id="close-debugger">[×]</div>
|
|
18
|
+
<h3>Component Details</h3>
|
|
19
|
+
</div>
|
|
20
|
+
<div id="component-details">
|
|
21
|
+
<ul class="component-details-list"></ul>
|
|
22
|
+
<div class="component-details-table"></div>
|
|
23
|
+
</div>
|
|
24
|
+
</div>`
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
13
30
|
this.innerHTML = html;
|
|
14
|
-
const css = await slice.controller.fetchText('Debugger', true, true, "/Slice/Components/Structural/Debugger/Debugger.css"
|
|
31
|
+
//const css = await slice.controller.fetchText('Debugger', true, true, "/Slice/Components/Structural/Debugger/Debugger.css");
|
|
32
|
+
const css = `
|
|
33
|
+
#debugger-container {
|
|
34
|
+
font-family: var(--font-family);
|
|
35
|
+
display: none;
|
|
36
|
+
position: fixed;
|
|
37
|
+
top: 20px;
|
|
38
|
+
left: 20px;
|
|
39
|
+
padding: 10px;
|
|
40
|
+
border: var(--slice-border) solid var(--primary-color);
|
|
41
|
+
background-color: var(--primary-background-color);
|
|
42
|
+
z-index: 1000;
|
|
43
|
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
44
|
+
border-radius: 8px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
#debugger-container.active {
|
|
48
|
+
display: block;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.slice_thead td {
|
|
52
|
+
font-weight: bold;
|
|
53
|
+
background-color: var(--primary-color);
|
|
54
|
+
color: var(--primary-color-contrast);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#close-debugger {
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
position: absolute;
|
|
60
|
+
top: 10px;
|
|
61
|
+
right: 10px;
|
|
62
|
+
font-size: 14px;
|
|
63
|
+
color: var(--danger-color);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
h3 {
|
|
67
|
+
color: var(--primary-color);
|
|
68
|
+
margin-bottom: 10px;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#component-details {
|
|
72
|
+
color: var(--font-primary-color);
|
|
73
|
+
}
|
|
74
|
+
.component-details-table {
|
|
75
|
+
overflow: scroll;
|
|
76
|
+
input {
|
|
77
|
+
outline: none;
|
|
78
|
+
border-bottom: 1px solid var(--tertiary-background-color);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
.component-details-table::-webkit-scrollbar {
|
|
82
|
+
width: 5px;
|
|
83
|
+
height: 5px;
|
|
84
|
+
}
|
|
85
|
+
.component-details-table::-webkit-scrollbar-thumb {
|
|
86
|
+
background: var(--secondary-color);
|
|
87
|
+
border-radius: var(--border-radius-slice);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#component-details table {
|
|
91
|
+
width: 100%;
|
|
92
|
+
border-collapse: collapse;
|
|
93
|
+
margin-top: 10px;
|
|
94
|
+
/* border: 1px solid var(--primary-color); */
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.debugger-header {
|
|
98
|
+
border-bottom: 1px solid var(--primary-color);
|
|
99
|
+
user-select: none;
|
|
100
|
+
cursor: grab;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.debugger-header:active {
|
|
104
|
+
cursor: grabbing;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
#component-details th,
|
|
108
|
+
#component-details td {
|
|
109
|
+
padding: 10px;
|
|
110
|
+
text-align: left;
|
|
111
|
+
border-bottom: 1px solid var(--primary-color);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
input {
|
|
115
|
+
border: 0px;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.slice_component-details td,
|
|
119
|
+
input {
|
|
120
|
+
background-color: var(--secondary-background-color);
|
|
121
|
+
color: var(--font-primary-color);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* Estilo para las filas impares, solo para mejorar la legibilidad */
|
|
125
|
+
#component-details tr:nth-child(odd) {
|
|
126
|
+
background-color: #f9f9f9;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
`
|
|
130
|
+
|
|
15
131
|
slice.stylesManager.registerComponentStyles('Debugger', css);
|
|
16
|
-
|
|
132
|
+
|
|
17
133
|
this.debuggerContainer = this.querySelector('#debugger-container');
|
|
18
134
|
this.closeDebugger = this.querySelector('#close-debugger');
|
|
19
135
|
this.componentDetails = this.querySelector('#component-details');
|
package/package.json
CHANGED
|
@@ -19,9 +19,8 @@ export default class HomePage extends HTMLElement {
|
|
|
19
19
|
},
|
|
20
20
|
items: [
|
|
21
21
|
{ text: 'Home', path: '/' },
|
|
22
|
-
{ text: 'Documentation', path: '/Documentation' },
|
|
23
22
|
{ text: 'Playground', path: '/Playground' },
|
|
24
|
-
|
|
23
|
+
|
|
25
24
|
],
|
|
26
25
|
buttons: [
|
|
27
26
|
{
|
|
@@ -43,7 +42,8 @@ export default class HomePage extends HTMLElement {
|
|
|
43
42
|
// Crear botones para la sección de llamada a la acción
|
|
44
43
|
const docsButton = await slice.build('Button', {
|
|
45
44
|
value: 'Documentation',
|
|
46
|
-
onClickCallback: () => slice.
|
|
45
|
+
onClickCallback: () => //redirect to https://slice-js-docs.vercel.app/Documentation
|
|
46
|
+
window.open('https://slice-js-docs.vercel.app/Documentation', '_blank'),
|
|
47
47
|
customColor: {
|
|
48
48
|
button: 'var(--primary-color)',
|
|
49
49
|
label: 'var(--primary-color-contrast)'
|
|
@@ -52,7 +52,7 @@ export default class HomePage extends HTMLElement {
|
|
|
52
52
|
|
|
53
53
|
const componentsButton = await slice.build('Button', {
|
|
54
54
|
value: 'Components Library',
|
|
55
|
-
onClickCallback: () => slice.
|
|
55
|
+
onClickCallback: () => window.open('https://slice-js-docs.vercel.app/Documentation/Visual', '_blank'),
|
|
56
56
|
customColor: {
|
|
57
57
|
button: 'var(--secondary-color)',
|
|
58
58
|
label: 'var(--secondary-color-contrast)'
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
slice-codevisualizer {
|
|
2
|
+
display: block;
|
|
3
|
+
width: 100%;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.codevisualizer_container {
|
|
7
|
+
position: relative;
|
|
8
|
+
font-size: smaller;
|
|
9
|
+
max-width: 100%;
|
|
10
|
+
background-color: var(--secondary-background-color);
|
|
11
|
+
border: 1px solid var(--primary-color);
|
|
12
|
+
padding: 15px 10px 10px;
|
|
13
|
+
border-radius: var(--border-radius-slice, 10px);
|
|
14
|
+
overflow-x: auto;
|
|
15
|
+
margin: 15px 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.codevisualizer pre {
|
|
19
|
+
margin: 0;
|
|
20
|
+
padding: 0;
|
|
21
|
+
font-family: 'Courier New', Courier, monospace;
|
|
22
|
+
line-height: 1.5;
|
|
23
|
+
white-space: pre;
|
|
24
|
+
tab-size: 2;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.codevisualizer code {
|
|
28
|
+
display: block;
|
|
29
|
+
color: var(--font-primary-color);
|
|
30
|
+
overflow-wrap: normal;
|
|
31
|
+
word-break: normal;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* Botón de copiar */
|
|
35
|
+
.copy-button {
|
|
36
|
+
position: absolute;
|
|
37
|
+
top: 5px;
|
|
38
|
+
right: 10px;
|
|
39
|
+
padding: 4px 8px;
|
|
40
|
+
font-size: 12px;
|
|
41
|
+
background-color: var(--primary-color);
|
|
42
|
+
color: var(--primary-color-contrast);
|
|
43
|
+
border: none;
|
|
44
|
+
border-radius: var(--border-radius-slice, 4px);
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
opacity: 0.7;
|
|
47
|
+
transition: opacity 0.2s ease, background-color 0.2s ease;
|
|
48
|
+
z-index: 1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.copy-button:hover {
|
|
52
|
+
opacity: 1;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.copy-button.copied {
|
|
56
|
+
background-color: var(--success-color);
|
|
57
|
+
color: var(--success-contrast);
|
|
58
|
+
opacity: 1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* Temas para resaltado de sintaxis adaptados a las variables de Slice */
|
|
62
|
+
.codevisualizer .code-keyword {
|
|
63
|
+
color: var(--primary-color); /* Palabras clave en color primario */
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.codevisualizer .code-string {
|
|
67
|
+
color: var(--success-color); /* Strings en color de éxito */
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.codevisualizer .code-number {
|
|
71
|
+
color: var(--warning-color); /* Números en color de advertencia */
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.codevisualizer .code-comment {
|
|
75
|
+
color: var(--medium-color); /* Comentarios en color medio */
|
|
76
|
+
font-style: italic;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.codevisualizer .code-function {
|
|
80
|
+
color: var(--secondary-color); /* Funciones en color secundario */
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.codevisualizer .code-method {
|
|
84
|
+
color: var(--secondary-color); /* Métodos en color secundario */
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.codevisualizer .code-builtin {
|
|
88
|
+
color: var(--secondary-color); /* Objetos integrados en color secundario */
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.codevisualizer .code-tag {
|
|
92
|
+
color: var(--primary-color); /* Tags HTML en color primario */
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.codevisualizer .code-attribute {
|
|
96
|
+
color: var(--warning-color); /* Atributos HTML en color de advertencia */
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.codevisualizer .code-selector {
|
|
100
|
+
color: var(--primary-color); /* Selectores CSS en color primario */
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.codevisualizer .code-property {
|
|
104
|
+
color: var(--secondary-color); /* Propiedades CSS en color secundario */
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.codevisualizer .code-value {
|
|
108
|
+
color: var(--success-color); /* Valores CSS en color de éxito */
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.codevisualizer .code-unit {
|
|
112
|
+
color: var(--warning-color); /* Unidades CSS en color de advertencia */
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.codevisualizer .code-color {
|
|
116
|
+
color: var(--font-primary-color); /* Colores CSS en color primario */
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/* Media query para diseño responsivo */
|
|
120
|
+
@media screen and (max-width: 768px) {
|
|
121
|
+
.codevisualizer_container {
|
|
122
|
+
font-size: 12px;
|
|
123
|
+
padding: 25px 8px 8px;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.copy-button {
|
|
127
|
+
font-size: 10px;
|
|
128
|
+
padding: 3px 6px;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
export default class CodeVisualizer extends HTMLElement {
|
|
2
|
+
constructor(props) {
|
|
3
|
+
super();
|
|
4
|
+
slice.attachTemplate(this);
|
|
5
|
+
|
|
6
|
+
this.$container = this.querySelector('.codevisualizer_container');
|
|
7
|
+
this.$code = this.querySelector('.codevisualizer');
|
|
8
|
+
this.$copyButton = this.querySelector('.copy-button');
|
|
9
|
+
|
|
10
|
+
// Configurar el botón de copiado
|
|
11
|
+
this.$copyButton.addEventListener('click', () => this.copyCodeToClipboard());
|
|
12
|
+
|
|
13
|
+
slice.controller.setComponentProps(this, props);
|
|
14
|
+
this.debuggerProps = ['language', 'value'];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
set value(value) {
|
|
18
|
+
this._value = value;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get value() {
|
|
22
|
+
return this._value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
set language(value) {
|
|
26
|
+
this._language = value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get language() {
|
|
30
|
+
return this._language;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
init() {
|
|
34
|
+
this.visualizeCode();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
visualizeCode() {
|
|
38
|
+
if (this._value && this._language) {
|
|
39
|
+
const highlightedCode = this.highlightCode(this._value, this._language);
|
|
40
|
+
this.$code.innerHTML = `<pre><code class="language-${this._language}">${highlightedCode}</code></pre>`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
copyCodeToClipboard() {
|
|
45
|
+
// Obtenemos el texto sin formato (sin las etiquetas HTML de resaltado)
|
|
46
|
+
const textToCopy = this._value;
|
|
47
|
+
|
|
48
|
+
// Utilizar el API de clipboard
|
|
49
|
+
navigator.clipboard.writeText(textToCopy)
|
|
50
|
+
.then(() => {
|
|
51
|
+
// Cambiar el texto del botón temporalmente para indicar éxito
|
|
52
|
+
this.$copyButton.textContent = '✓ Copiado!';
|
|
53
|
+
this.$copyButton.classList.add('copied');
|
|
54
|
+
|
|
55
|
+
// Restaurar el texto original después de 1.5 segundos
|
|
56
|
+
setTimeout(() => {
|
|
57
|
+
this.$copyButton.textContent = 'Copiar';
|
|
58
|
+
this.$copyButton.classList.remove('copied');
|
|
59
|
+
}, 1500);
|
|
60
|
+
})
|
|
61
|
+
.catch(err => {
|
|
62
|
+
console.error('Error al copiar al portapapeles: ', err);
|
|
63
|
+
this.$copyButton.textContent = '❌ Error!';
|
|
64
|
+
|
|
65
|
+
setTimeout(() => {
|
|
66
|
+
this.$copyButton.textContent = 'Copiar';
|
|
67
|
+
}, 1500);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
highlightCode(code, language) {
|
|
72
|
+
// Escape HTML to prevent XSS
|
|
73
|
+
const escapedCode = this.escapeHtml(code);
|
|
74
|
+
|
|
75
|
+
switch (language.toLowerCase()) {
|
|
76
|
+
case 'javascript':
|
|
77
|
+
case 'js':
|
|
78
|
+
return this.highlightJavaScript(escapedCode);
|
|
79
|
+
case 'html':
|
|
80
|
+
return this.highlightHtml(escapedCode);
|
|
81
|
+
case 'css':
|
|
82
|
+
return this.highlightCss(escapedCode);
|
|
83
|
+
default:
|
|
84
|
+
return escapedCode;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
escapeHtml(text) {
|
|
89
|
+
return text
|
|
90
|
+
.replace(/&/g, '&')
|
|
91
|
+
.replace(/</g, '<')
|
|
92
|
+
.replace(/>/g, '>')
|
|
93
|
+
.replace(/"/g, '"')
|
|
94
|
+
.replace(/'/g, ''');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
highlightJavaScript(code) {
|
|
98
|
+
// Este método fue rediseñado por completo para evitar problemas de superposición
|
|
99
|
+
let tokenizedCode = code;
|
|
100
|
+
|
|
101
|
+
// Creamos una estructura para almacenar todos los tokens y luego reemplazarlos de una sola vez
|
|
102
|
+
const tokens = [];
|
|
103
|
+
|
|
104
|
+
// Función para generar un ID único para cada token
|
|
105
|
+
const generateTokenId = (index) => `__TOKEN_${index}__`;
|
|
106
|
+
|
|
107
|
+
// Función para extraer tokens y reemplazarlos con marcadores
|
|
108
|
+
const extractTokens = (regex, className) => {
|
|
109
|
+
tokenizedCode = tokenizedCode.replace(regex, (match) => {
|
|
110
|
+
const tokenId = generateTokenId(tokens.length);
|
|
111
|
+
tokens.push({ id: tokenId, content: match, className });
|
|
112
|
+
return tokenId;
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// Extraer los tokens en orden específico para evitar interferencias
|
|
117
|
+
|
|
118
|
+
// 1. Primero los comentarios
|
|
119
|
+
extractTokens(/\/\/.*$/gm, 'code-comment');
|
|
120
|
+
extractTokens(/\/\*[\s\S]*?\*\//g, 'code-comment');
|
|
121
|
+
|
|
122
|
+
// 2. Luego las cadenas de texto
|
|
123
|
+
extractTokens(/(['"`])(?:\\.|[^\\])*?\1/g, 'code-string');
|
|
124
|
+
|
|
125
|
+
// 3. Luego los números
|
|
126
|
+
extractTokens(/\b(\d+(?:\.\d+)?)\b/g, 'code-number');
|
|
127
|
+
|
|
128
|
+
// 4. Palabras clave
|
|
129
|
+
const keywords = [
|
|
130
|
+
'await', 'async', 'break', 'case', 'catch', 'class', 'const', 'continue',
|
|
131
|
+
'debugger', 'default', 'delete', 'do', 'else', 'export', 'extends', 'false',
|
|
132
|
+
'finally', 'for', 'function', 'if', 'import', 'in', 'instanceof', 'new',
|
|
133
|
+
'null', 'return', 'super', 'switch', 'this', 'throw', 'true', 'try',
|
|
134
|
+
'typeof', 'var', 'void', 'while', 'with', 'yield', 'let'
|
|
135
|
+
];
|
|
136
|
+
extractTokens(new RegExp(`\\b(${keywords.join('|')})\\b`, 'g'), 'code-keyword');
|
|
137
|
+
|
|
138
|
+
// 5. Objetos y métodos integrados
|
|
139
|
+
const builtins = [
|
|
140
|
+
'Array', 'Boolean', 'Date', 'Error', 'Function', 'JSON', 'Math',
|
|
141
|
+
'Number', 'Object', 'Promise', 'RegExp', 'String', 'console', 'document',
|
|
142
|
+
'window', 'slice', 'Map', 'Set', 'Symbol', 'setTimeout', 'setInterval'
|
|
143
|
+
];
|
|
144
|
+
extractTokens(new RegExp(`\\b(${builtins.join('|')})\\b`, 'g'), 'code-builtin');
|
|
145
|
+
|
|
146
|
+
// 6. Métodos y llamadas a funciones (esto debe ir después de extraer las palabras clave)
|
|
147
|
+
extractTokens(/(\.)([a-zA-Z_$][\w$]*)\s*(?=\()/g, 'code-method');
|
|
148
|
+
|
|
149
|
+
// Reemplazar los tokens con el HTML resaltado
|
|
150
|
+
tokens.forEach(token => {
|
|
151
|
+
tokenizedCode = tokenizedCode.replace(
|
|
152
|
+
token.id,
|
|
153
|
+
`<span class="${token.className}">${token.content}</span>`
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
return tokenizedCode;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
highlightHtml(code) {
|
|
161
|
+
// Utilizamos un enfoque similar al de JavaScript para HTML
|
|
162
|
+
let tokenizedCode = code;
|
|
163
|
+
const tokens = [];
|
|
164
|
+
const generateTokenId = (index) => `__TOKEN_${index}__`;
|
|
165
|
+
|
|
166
|
+
const extractTokens = (regex, className) => {
|
|
167
|
+
tokenizedCode = tokenizedCode.replace(regex, (match) => {
|
|
168
|
+
const tokenId = generateTokenId(tokens.length);
|
|
169
|
+
tokens.push({ id: tokenId, content: match, className });
|
|
170
|
+
return tokenId;
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// Extraer tokens HTML en orden
|
|
175
|
+
|
|
176
|
+
// 1. Comentarios HTML
|
|
177
|
+
extractTokens(/<!--[\s\S]*?-->/g, 'code-comment');
|
|
178
|
+
|
|
179
|
+
// 2. Etiquetas HTML
|
|
180
|
+
extractTokens(/(<\/?[a-zA-Z0-9-]+)(\s|>)/g, (match, tag, end) => {
|
|
181
|
+
const tokenId = generateTokenId(tokens.length);
|
|
182
|
+
tokens.push({
|
|
183
|
+
id: tokenId,
|
|
184
|
+
content: `<span class="code-tag">${tag}</span>${end}`,
|
|
185
|
+
className: 'no-class' // Ya incluye su propio elemento span
|
|
186
|
+
});
|
|
187
|
+
return tokenId;
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// 3. Atributos HTML
|
|
191
|
+
extractTokens(/\s([a-zA-Z0-9-]+)=("|')/g, (match, attr, quote) => {
|
|
192
|
+
const tokenId = generateTokenId(tokens.length);
|
|
193
|
+
tokens.push({
|
|
194
|
+
id: tokenId,
|
|
195
|
+
content: ` <span class="code-attribute">${attr}</span>=${quote}`,
|
|
196
|
+
className: 'no-class' // Ya incluye su propio elemento span
|
|
197
|
+
});
|
|
198
|
+
return tokenId;
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
// Reemplazar los tokens con el HTML resaltado
|
|
202
|
+
tokens.forEach(token => {
|
|
203
|
+
tokenizedCode = tokenizedCode.replace(
|
|
204
|
+
token.id,
|
|
205
|
+
token.className === 'no-class' ? token.content : `<span class="${token.className}">${token.content}</span>`
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
return tokenizedCode;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
highlightCss(code) {
|
|
213
|
+
// Utilizamos el mismo enfoque para CSS
|
|
214
|
+
let tokenizedCode = code;
|
|
215
|
+
const tokens = [];
|
|
216
|
+
const generateTokenId = (index) => `__TOKEN_${index}__`;
|
|
217
|
+
|
|
218
|
+
const extractTokens = (regex, className, processor = null) => {
|
|
219
|
+
tokenizedCode = tokenizedCode.replace(regex, (match, ...groups) => {
|
|
220
|
+
const tokenId = generateTokenId(tokens.length);
|
|
221
|
+
const content = processor ? processor(match, ...groups) : match;
|
|
222
|
+
tokens.push({ id: tokenId, content, className });
|
|
223
|
+
return tokenId;
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
// Comentarios CSS
|
|
228
|
+
extractTokens(/\/\*[\s\S]*?\*\//g, 'code-comment');
|
|
229
|
+
|
|
230
|
+
// Selectores CSS
|
|
231
|
+
extractTokens(/([^\{\}]+)(?=\{)/g, 'code-selector');
|
|
232
|
+
|
|
233
|
+
// Propiedad y valor CSS (manipulando la coincidencia para preservar la estructura)
|
|
234
|
+
tokenizedCode = tokenizedCode.replace(/(\s*)([a-zA-Z-]+)(\s*):(\s*)([^;\{\}]+)(?=;)/g, (match, space1, prop, space2, space3, value) => {
|
|
235
|
+
const propTokenId = generateTokenId(tokens.length);
|
|
236
|
+
tokens.push({ id: propTokenId, content: prop, className: 'code-property' });
|
|
237
|
+
|
|
238
|
+
const valueTokenId = generateTokenId(tokens.length);
|
|
239
|
+
tokens.push({ id: valueTokenId, content: value, className: 'code-value' });
|
|
240
|
+
|
|
241
|
+
return `${space1}<span class="code-property">${prop}</span>${space2}:${space3}<span class="code-value">${value}</span>`;
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
// Colores CSS
|
|
245
|
+
extractTokens(/#([a-fA-F0-9]{3,6})\b/g, 'code-color');
|
|
246
|
+
|
|
247
|
+
// Reemplazar los tokens restantes
|
|
248
|
+
tokens.forEach(token => {
|
|
249
|
+
if (token.className !== 'no-replace') {
|
|
250
|
+
tokenizedCode = tokenizedCode.replace(
|
|
251
|
+
token.id,
|
|
252
|
+
`<span class="${token.className}">${token.content}</span>`
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
return tokenizedCode;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
customElements.define('slice-codevisualizer', CodeVisualizer);
|
|
262
|
+
|
|
263
|
+
|
|
@@ -1,32 +1,10 @@
|
|
|
1
1
|
const components = {
|
|
2
|
-
"
|
|
3
|
-
"CardDocumentation": "AppComponents",
|
|
4
|
-
"CheckboxDocumentation": "AppComponents",
|
|
5
|
-
"CodeVisualizer": "AppComponents",
|
|
6
|
-
"Documentation": "AppComponents",
|
|
7
|
-
"DocumentationPage": "AppComponents",
|
|
8
|
-
"InputDocumentation": "AppComponents",
|
|
9
|
-
"Installation": "AppComponents",
|
|
10
|
-
"LandingMenu": "AppComponents",
|
|
11
|
-
"LandingPage": "AppComponents",
|
|
12
|
-
"MainMenu": "AppComponents",
|
|
13
|
-
"MyLayout": "AppComponents",
|
|
14
|
-
"MyNavigation": "AppComponents",
|
|
2
|
+
"HomePage": "AppComponents",
|
|
15
3
|
"Playground": "AppComponents",
|
|
16
|
-
"RoutingDocumentation": "AppComponents",
|
|
17
|
-
"ServiceDocumentation": "AppComponents",
|
|
18
|
-
"SliceStylesDocumentation": "AppComponents",
|
|
19
|
-
"SliceTeamCard": "AppComponents",
|
|
20
|
-
"StructuralDocumentation": "AppComponents",
|
|
21
|
-
"SwitchDocumentation": "AppComponents",
|
|
22
|
-
"TheBuildMethod": "AppComponents",
|
|
23
|
-
"ThemesDocumentation": "AppComponents",
|
|
24
|
-
"TheSliceTeam": "AppComponents",
|
|
25
|
-
"VisualDocumentation": "AppComponents",
|
|
26
|
-
"WhatIsSlice": "AppComponents",
|
|
27
4
|
"Button": "Visual",
|
|
28
5
|
"Card": "Visual",
|
|
29
6
|
"Checkbox": "Visual",
|
|
7
|
+
"CodeVisualizer": "Visual",
|
|
30
8
|
"Details": "Visual",
|
|
31
9
|
"DropDown": "Visual",
|
|
32
10
|
"Grid": "Visual",
|