slicejs-web-framework 1.0.6 → 1.0.9

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.
Files changed (137) hide show
  1. package/Slice/Components/Structural/Router/Router.js +59 -33
  2. package/api/index.js +99 -0
  3. package/package.json +1 -1
  4. package/src/App/index.html +22 -0
  5. package/src/App/index.js +63 -0
  6. package/src/App/style.css +40 -0
  7. package/src/Components/AppComponents/ButtonDocumentation/ButtonDocumentation.css +16 -0
  8. package/src/Components/AppComponents/ButtonDocumentation/ButtonDocumentation.html +22 -0
  9. package/src/Components/AppComponents/ButtonDocumentation/ButtonDocumentation.js +102 -0
  10. package/src/Components/AppComponents/CardDocumentation/CardDocumentation.css +15 -0
  11. package/src/Components/AppComponents/CardDocumentation/CardDocumentation.html +38 -0
  12. package/src/Components/AppComponents/CardDocumentation/CardDocumentation.js +113 -0
  13. package/src/Components/AppComponents/CheckboxDocumentation/CheckboxDocumentation.css +21 -0
  14. package/src/Components/AppComponents/CheckboxDocumentation/CheckboxDocumentation.html +35 -0
  15. package/src/Components/AppComponents/CheckboxDocumentation/CheckboxDocumentation.js +103 -0
  16. package/src/Components/AppComponents/CodeVisualizer/CodeVisualizer.css +130 -0
  17. package/src/Components/AppComponents/CodeVisualizer/CodeVisualizer.html +4 -0
  18. package/src/Components/AppComponents/CodeVisualizer/CodeVisualizer.js +263 -0
  19. package/src/Components/AppComponents/Documentation/Documentation.css +0 -0
  20. package/src/Components/AppComponents/Documentation/Documentation.html +30 -0
  21. package/src/Components/AppComponents/Documentation/Documentation.js +75 -0
  22. package/src/Components/AppComponents/DocumentationPage/DocumentationPage.css +62 -0
  23. package/src/Components/AppComponents/DocumentationPage/DocumentationPage.html +0 -0
  24. package/src/Components/AppComponents/DocumentationPage/DocumentationPage.js +283 -0
  25. package/src/Components/AppComponents/InputDocumentation/InputDocumentation.css +41 -0
  26. package/src/Components/AppComponents/InputDocumentation/InputDocumentation.html +95 -0
  27. package/src/Components/AppComponents/InputDocumentation/InputDocumentation.js +315 -0
  28. package/src/Components/AppComponents/LandingMenu/LandingMenu.css +108 -0
  29. package/src/Components/AppComponents/LandingMenu/LandingMenu.html +16 -0
  30. package/src/Components/AppComponents/LandingMenu/LandingMenu.js +33 -0
  31. package/src/Components/AppComponents/LandingPage/LandingPage.css +14 -0
  32. package/src/Components/AppComponents/LandingPage/LandingPage.html +0 -0
  33. package/src/Components/AppComponents/LandingPage/LandingPage.js +53 -0
  34. package/src/Components/AppComponents/MainMenu/MainMenu.css +80 -0
  35. package/src/Components/AppComponents/MainMenu/MainMenu.html +39 -0
  36. package/src/Components/AppComponents/MainMenu/MainMenu.js +42 -0
  37. package/src/Components/AppComponents/MyLayout/MyLayout.css +0 -0
  38. package/src/Components/AppComponents/MyLayout/MyLayout.html +0 -0
  39. package/src/Components/AppComponents/MyLayout/MyLayout.js +13 -0
  40. package/src/Components/AppComponents/MyNavigation/MyNavigation.css +49 -0
  41. package/src/Components/AppComponents/MyNavigation/MyNavigation.html +1 -0
  42. package/src/Components/AppComponents/MyNavigation/MyNavigation.js +60 -0
  43. package/src/Components/AppComponents/Playground/Playground.css +12 -0
  44. package/src/Components/AppComponents/Playground/Playground.html +0 -0
  45. package/src/Components/AppComponents/Playground/Playground.js +126 -0
  46. package/src/Components/AppComponents/RoutingDocumentation/RoutingDocumentation.css +89 -0
  47. package/src/Components/AppComponents/RoutingDocumentation/RoutingDocumentation.html +108 -0
  48. package/src/Components/AppComponents/RoutingDocumentation/RoutingDocumentation.js +177 -0
  49. package/src/Components/AppComponents/SliceTeamCard/SliceTeamCard.css +104 -0
  50. package/src/Components/AppComponents/SliceTeamCard/SliceTeamCard.html +12 -0
  51. package/src/Components/AppComponents/SliceTeamCard/SliceTeamCard.js +74 -0
  52. package/src/Components/AppComponents/SwitchDocumentation/SwitchDocumentation.css +21 -0
  53. package/src/Components/AppComponents/SwitchDocumentation/SwitchDocumentation.html +35 -0
  54. package/src/Components/AppComponents/SwitchDocumentation/SwitchDocumentation.js +103 -0
  55. package/src/Components/AppComponents/TheBuildMethod/TheBuildMethod.css +122 -0
  56. package/src/Components/AppComponents/TheBuildMethod/TheBuildMethod.html +70 -0
  57. package/src/Components/AppComponents/TheBuildMethod/TheBuildMethod.js +86 -0
  58. package/src/Components/AppComponents/TheSliceTeam/TheSliceTeam.css +23 -0
  59. package/src/Components/AppComponents/TheSliceTeam/TheSliceTeam.html +6 -0
  60. package/src/Components/AppComponents/TheSliceTeam/TheSliceTeam.js +129 -0
  61. package/src/Components/AppComponents/WhatIsSlice/WhatIsSlice.css +0 -0
  62. package/src/Components/AppComponents/WhatIsSlice/WhatIsSlice.html +7 -0
  63. package/src/Components/AppComponents/WhatIsSlice/WhatIsSlice.js +15 -0
  64. package/src/Components/Service/FetchManager/FetchManager.js +133 -0
  65. package/src/Components/Service/IndexedDbManager/IndexedDbManager.js +141 -0
  66. package/src/Components/Service/Link/Link.js +26 -0
  67. package/src/Components/Service/LocalStorageManager/LocalStorageManager.js +45 -0
  68. package/src/Components/Service/Translator/Translator.js +45 -0
  69. package/src/Components/Service/Translator/messages.json +58 -0
  70. package/src/Components/Visual/Button/Button.css +47 -0
  71. package/src/Components/Visual/Button/Button.html +5 -0
  72. package/src/Components/Visual/Button/Button.js +70 -0
  73. package/src/Components/Visual/Card/Card.css +68 -0
  74. package/src/Components/Visual/Card/Card.html +7 -0
  75. package/src/Components/Visual/Card/Card.js +107 -0
  76. package/src/Components/Visual/Checkbox/Checkbox.css +87 -0
  77. package/src/Components/Visual/Checkbox/Checkbox.html +8 -0
  78. package/src/Components/Visual/Checkbox/Checkbox.js +86 -0
  79. package/src/Components/Visual/Details/Details.css +70 -0
  80. package/src/Components/Visual/Details/Details.html +9 -0
  81. package/src/Components/Visual/Details/Details.js +76 -0
  82. package/src/Components/Visual/DropDown/DropDown.css +60 -0
  83. package/src/Components/Visual/DropDown/DropDown.html +5 -0
  84. package/src/Components/Visual/DropDown/DropDown.js +63 -0
  85. package/src/Components/Visual/Grid/Grid.css +7 -0
  86. package/src/Components/Visual/Grid/Grid.html +1 -0
  87. package/src/Components/Visual/Grid/Grid.js +57 -0
  88. package/src/Components/Visual/Icon/Icon.css +510 -0
  89. package/src/Components/Visual/Icon/Icon.html +1 -0
  90. package/src/Components/Visual/Icon/Icon.js +89 -0
  91. package/src/Components/Visual/Icon/slc.eot +0 -0
  92. package/src/Components/Visual/Icon/slc.json +555 -0
  93. package/src/Components/Visual/Icon/slc.styl +507 -0
  94. package/src/Components/Visual/Icon/slc.svg +1485 -0
  95. package/src/Components/Visual/Icon/slc.symbol.svg +1059 -0
  96. package/src/Components/Visual/Icon/slc.ttf +0 -0
  97. package/src/Components/Visual/Icon/slc.woff +0 -0
  98. package/src/Components/Visual/Icon/slc.woff2 +0 -0
  99. package/src/Components/Visual/Input/Input.css +91 -0
  100. package/src/Components/Visual/Input/Input.html +4 -0
  101. package/src/Components/Visual/Input/Input.js +215 -0
  102. package/src/Components/Visual/Layout/Layout.css +0 -0
  103. package/src/Components/Visual/Layout/Layout.html +0 -0
  104. package/src/Components/Visual/Layout/Layout.js +49 -0
  105. package/src/Components/Visual/Loading/Loading.css +56 -0
  106. package/src/Components/Visual/Loading/Loading.html +83 -0
  107. package/src/Components/Visual/Loading/Loading.js +38 -0
  108. package/src/Components/Visual/MultiRoute/MultiRoute.js +93 -0
  109. package/src/Components/Visual/Navbar/Navbar.css +115 -0
  110. package/src/Components/Visual/Navbar/Navbar.html +44 -0
  111. package/src/Components/Visual/Navbar/Navbar.js +141 -0
  112. package/src/Components/Visual/NotFound/NotFound.css +117 -0
  113. package/src/Components/Visual/NotFound/NotFound.html +24 -0
  114. package/src/Components/Visual/NotFound/NotFound.js +16 -0
  115. package/src/Components/Visual/Route/Route.js +93 -0
  116. package/src/Components/Visual/Select/Select.css +84 -0
  117. package/src/Components/Visual/Select/Select.html +8 -0
  118. package/src/Components/Visual/Select/Select.js +195 -0
  119. package/src/Components/Visual/Switch/Switch.css +76 -0
  120. package/src/Components/Visual/Switch/Switch.html +8 -0
  121. package/src/Components/Visual/Switch/Switch.js +102 -0
  122. package/src/Components/Visual/TreeItem/TreeItem.css +36 -0
  123. package/src/Components/Visual/TreeItem/TreeItem.html +1 -0
  124. package/src/Components/Visual/TreeItem/TreeItem.js +126 -0
  125. package/src/Components/Visual/TreeView/TreeView.css +8 -0
  126. package/src/Components/Visual/TreeView/TreeView.html +1 -0
  127. package/src/Components/Visual/TreeView/TreeView.js +48 -0
  128. package/src/Components/components.js +45 -0
  129. package/src/Styles/sliceStyles.css +34 -0
  130. package/src/Themes/Dark.css +42 -0
  131. package/src/Themes/Light.css +31 -0
  132. package/src/Themes/Slice.css +47 -0
  133. package/src/images/Slice.js-logo.png +0 -0
  134. package/src/images/favicon.ico +0 -0
  135. package/src/images/im2/Slice.js-logo.png +0 -0
  136. package/src/routes.js +77 -0
  137. package/src/sliceConfig.json +58 -0
@@ -0,0 +1,113 @@
1
+ export default class CardDocumentation extends HTMLElement {
2
+ constructor(props) {
3
+ super();
4
+ slice.attachTemplate(this);
5
+
6
+ slice.controller.setComponentProps(this, props);
7
+ this.debuggerProps = [];
8
+ }
9
+
10
+ async init() {
11
+ await this.createCard(this.querySelector('.sliceCard'), {});
12
+ await this.createCard(
13
+ this.querySelector('.myCard'),
14
+ {
15
+ title: 'My Slice Card',
16
+ text: "My Slice Card's information.",
17
+ },
18
+ `{
19
+ title: "My Slice Card",
20
+ text: "My Slice Card's information.",
21
+ }`
22
+ );
23
+ await this.createCard(
24
+ this.querySelector('.cardClick'),
25
+ {
26
+ title: 'Uncover Slice Card',
27
+ text: 'isOpen is true.',
28
+ isOpen: true,
29
+ },
30
+ `{
31
+ title: "Uncover Slice Card",
32
+ text: "isOpen is true",
33
+ isOpen: true
34
+ }`
35
+ );
36
+ await this.createCard(
37
+ this.querySelector('.cardIcon'),
38
+ {
39
+ title: 'Discord',
40
+ text: 'This card has Discord Icon.',
41
+ icon: {
42
+ name: 'discord',
43
+ iconStyle: 'filled',
44
+ },
45
+ },
46
+ `{
47
+ title: "Discord",
48
+ text: "This card has Discord Icon.",
49
+ icon: {
50
+ name: "discord",
51
+ iconStyle: "filled",
52
+ }
53
+ }`
54
+ );
55
+ await this.createCard(
56
+ this.querySelector('.cardColor'),
57
+ {
58
+ title: 'Github',
59
+ text: 'This card has customized colors.',
60
+ icon: {
61
+ name: 'github',
62
+ iconStyle: 'filled',
63
+ },
64
+ customColor: {
65
+ card: 'darkblue',
66
+ icon: 'white',
67
+ },
68
+ },
69
+ `{
70
+ title: "Github",
71
+ text: "This card has customized colors.",
72
+ icon: {
73
+ name: "github",
74
+ iconStyle: "filled",
75
+ },
76
+ customColor: {
77
+ card: "darkblue",
78
+ icon: "white",
79
+ },
80
+ }`
81
+ );
82
+ }
83
+
84
+ async createCard(appendTo, cardProps, codeProps) {
85
+ if (!codeProps) {
86
+ codeProps = '{}';
87
+ }
88
+ const myCard = await slice.build('Card', cardProps);
89
+
90
+ const componentCode = await slice.build('CodeVisualizer', {
91
+ value: `const myCard = await slice.build("Card", ${codeProps});
92
+
93
+ `,
94
+ language: 'javascript',
95
+ });
96
+
97
+ const div = document.createElement('div');
98
+ const cardDiv = document.createElement('div');
99
+ cardDiv.classList.add('cards');
100
+ cardDiv.appendChild(myCard);
101
+ div.classList.add('cards_container');
102
+ div.appendChild(cardDiv);
103
+ div.appendChild(componentCode);
104
+
105
+ if (appendTo) {
106
+ appendTo.appendChild(div);
107
+ }
108
+
109
+ return div;
110
+ }
111
+ }
112
+
113
+ customElements.define('slice-carddocumentation', CardDocumentation);
@@ -0,0 +1,21 @@
1
+ .checkboxs {
2
+ width: 100%;
3
+ display: flex;
4
+ flex-direction: row;
5
+ justify-content: center;
6
+ align-items: center;
7
+ }
8
+ .labelCheckbox {
9
+ display: grid;
10
+ align-items: end;
11
+ grid-template-columns: repeat(2, 1fr);
12
+ grid-template-rows: repeat(1, 1fr);
13
+ gap: 10px;
14
+ margin: 0 auto;
15
+ }
16
+
17
+ @media only screen and (max-width: 770px) {
18
+ .labelCheckbox {
19
+ grid-template-columns: repeat(1, 1fr);
20
+ }
21
+ }
@@ -0,0 +1,35 @@
1
+ <h1 id="sliceCheckbox">Slice CheckBox</h1>
2
+ <div class="myCheckbox">
3
+ <p>This is a Slice Checkbox.</p>
4
+ </div>
5
+ <div class="colorCheckbox">
6
+ <h2 id="customColor">Custom color</h2>
7
+ <p>
8
+ You cand customize your Slice Checkbox by changing it's color with the color
9
+ prop
10
+ </p>
11
+ </div>
12
+ <h1 id="label">Label</h1>
13
+ <div class="label">
14
+ <p>You can set a label to your checkbox.</p>
15
+ </div>
16
+ <h2 id="labelPlacement">Label Placement</h2>
17
+ <p>You can also set in wich position to put the label to.</p>
18
+ <div class="labelCheckbox">
19
+ <div class="labelLeft">
20
+ <h2>Left</h2>
21
+ <p>This label is positioned at left.</p>
22
+ </div>
23
+ <div class="labelTop">
24
+ <h2>Top</h2>
25
+ <p>This label is positioned at top.</p>
26
+ </div>
27
+ <div class="labelRight">
28
+ <h2>Right (default)</h2>
29
+ <p>This label is positioned at right.</p>
30
+ </div>
31
+ <div class="labelBottom">
32
+ <h2>Bottom</h2>
33
+ <p>This label is positioned at bottom.</p>
34
+ </div>
35
+ </div>
@@ -0,0 +1,103 @@
1
+ export default class CheckboxDocumentation extends HTMLElement {
2
+ constructor(props) {
3
+ super();
4
+ slice.attachTemplate(this);
5
+
6
+ slice.controller.setComponentProps(this, props);
7
+ this.debuggerProps = [];
8
+ }
9
+
10
+ async init() {
11
+ await this.createCheckbox(this.querySelector('.myCheckbox'), {}, `{}`);
12
+ await this.createCheckbox(
13
+ this.querySelector('.colorCheckbox'),
14
+ { customColor: 'gold' },
15
+ `{
16
+ customColor: "gold"
17
+ }`
18
+ );
19
+ await this.createCheckbox(
20
+ this.querySelector('.label'),
21
+ {
22
+ label: 'Checkbox',
23
+ },
24
+ `{
25
+ label: "Checkbox",
26
+ }`
27
+ );
28
+ await this.createCheckbox(
29
+ this.querySelector('.labelLeft'),
30
+ {
31
+ label: 'Left',
32
+ labelPlacement: 'left',
33
+ },
34
+ `{
35
+ label: "Left",
36
+ labelPlacement: "left",
37
+ }`
38
+ );
39
+ await this.createCheckbox(
40
+ this.querySelector('.labelTop'),
41
+ {
42
+ label: 'Top',
43
+ labelPlacement: 'top',
44
+ },
45
+ `{
46
+ label: "Top",
47
+ labelPlacement: "top",
48
+ }`
49
+ );
50
+ await this.createCheckbox(
51
+ this.querySelector('.labelRight'),
52
+ {
53
+ label: 'Right',
54
+ labelPlacement: 'right',
55
+ },
56
+ `{
57
+ label: "Right",
58
+ labelPlacement: "right",
59
+ }`
60
+ );
61
+ await this.createCheckbox(
62
+ this.querySelector('.labelBottom'),
63
+ {
64
+ label: 'Bottom',
65
+ labelPlacement: 'bottom',
66
+ },
67
+ `{
68
+ label: "Bottom",
69
+ labelPlacement: "bottom",
70
+ }`
71
+ );
72
+ }
73
+
74
+ async createCheckbox(appendTo, checkboxProps, codeProps) {
75
+ if (!codeProps) {
76
+ codeProps = '{}';
77
+ }
78
+ const myCheckbox = await slice.build('Checkbox', checkboxProps);
79
+
80
+ const componentCode = await slice.build('CodeVisualizer', {
81
+ value: `const myCheckbox = await slice.build("Checkbox", ${codeProps});
82
+
83
+ `,
84
+ language: 'javascript',
85
+ });
86
+
87
+ const div = document.createElement('div');
88
+ const checkboxDiv = document.createElement('div');
89
+ checkboxDiv.classList.add('checkboxs');
90
+ checkboxDiv.appendChild(myCheckbox);
91
+ div.classList.add('checkboxs_container');
92
+ div.appendChild(checkboxDiv);
93
+ div.appendChild(componentCode);
94
+
95
+ if (appendTo) {
96
+ appendTo.appendChild(div);
97
+ }
98
+
99
+ return div;
100
+ }
101
+ }
102
+
103
+ customElements.define('slice-checkboxdocumentation', CheckboxDocumentation);
@@ -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,4 @@
1
+ <div class="codevisualizer_container">
2
+ <button class="copy-button" title="Copy to clipboard">Copy</button>
3
+ <pre class="codevisualizer"><code></code></pre>
4
+ </div>
@@ -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, '&amp;')
91
+ .replace(/</g, '&lt;')
92
+ .replace(/>/g, '&gt;')
93
+ .replace(/"/g, '&quot;')
94
+ .replace(/'/g, '&#039;');
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(/&lt;!--[\s\S]*?--&gt;/g, 'code-comment');
178
+
179
+ // 2. Etiquetas HTML
180
+ extractTokens(/(&lt;\/?[a-zA-Z0-9-]+)(\s|&gt;)/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-]+)=(&quot;|&#039;)/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
+