@widergy/energy-ui 3.97.0 → 3.98.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [3.98.0](https://github.com/widergy/energy-ui/compare/v3.97.0...v3.98.0) (2025-08-12)
2
+
3
+
4
+ ### Features
5
+
6
+ * [PDI-149] duplicated styles fix ([#662](https://github.com/widergy/energy-ui/issues/662)) ([427e41d](https://github.com/widergy/energy-ui/commit/427e41d5b4bf5e2be12b904386bc86a5814cceb5))
7
+
1
8
  # [3.97.0](https://github.com/widergy/energy-ui/compare/v3.96.7...v3.97.0) (2025-08-11)
2
9
 
3
10
 
package/dist/index.js CHANGED
@@ -477,6 +477,12 @@ Object.defineProperty(exports, "keyboardUtils", {
477
477
  return _keyboardUtils.default;
478
478
  }
479
479
  });
480
+ Object.defineProperty(exports, "stylesDeduplicationUtils", {
481
+ enumerable: true,
482
+ get: function () {
483
+ return _styleDeduplication.default;
484
+ }
485
+ });
480
486
  var _AlertHandler = _interopRequireDefault(require("./components/UTAlert/AlertHandler"));
481
487
  var _componentUtils = _interopRequireDefault(require("./utils/componentUtils"));
482
488
  var _EnergyThemeProvider = _interopRequireDefault(require("./components/EnergyThemeProvider"));
@@ -556,4 +562,5 @@ var _UTVirtualKeyboard = _interopRequireDefault(require("./components/UTVirtualK
556
562
  var _UTWorkflowContainer = _interopRequireDefault(require("./components/UTWorkflowContainer"));
557
563
  var _WithLoading = _interopRequireDefault(require("./components/WithLoading"));
558
564
  var _WithTouch = _interopRequireDefault(require("./components/WithTouch"));
565
+ var _styleDeduplication = _interopRequireDefault(require("./utils/styleDeduplication"));
559
566
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useStyleDeduplication = exports.setupStyleDeduplication = exports.isStyleDeduplicationConfigured = exports.getDeduplicationStats = exports.default = void 0;
7
+ var _react = require("react");
8
+ /**
9
+ * Sistema de deduplicación de estilos para Energy UI
10
+ * Evita que los estilos se carguen múltiples veces cuando la librería se importa desde diferentes proyectos
11
+ */
12
+
13
+ // Cache global para estilos ya cargados
14
+ const loadedStyles = new Set();
15
+ const styleElements = new Map();
16
+
17
+ /**
18
+ * Genera un hash único para un conjunto de estilos
19
+ */
20
+ const generateStyleHash = content => {
21
+ let hash = 0;
22
+ for (let i = 0; i < content.length; i++) {
23
+ const char = content.charCodeAt(i);
24
+ hash = (hash << 5) - hash + char;
25
+ hash = hash & hash; // Convertir a entero de 32 bits
26
+ }
27
+ return hash.toString(36);
28
+ };
29
+
30
+ /**
31
+ * Verifica si un estilo ya está cargado
32
+ */
33
+ const isStyleAlreadyLoaded = content => {
34
+ const hash = generateStyleHash(content);
35
+ return loadedStyles.has(hash);
36
+ };
37
+
38
+ /**
39
+ * Marca un estilo como cargado
40
+ */
41
+ const markStyleAsLoaded = (content, element) => {
42
+ const hash = generateStyleHash(content);
43
+ loadedStyles.add(hash);
44
+ styleElements.set(hash, element);
45
+ };
46
+
47
+ /**
48
+ * Intercepta la creación de elementos <style> para evitar duplicados
49
+ */
50
+ const interceptStyleCreation = () => {
51
+ if (window.__energyUI_styleDeduplicationConfigured) {
52
+ return;
53
+ }
54
+
55
+ // Crear el punto de inserción si no existe
56
+ let insertionPoint = document.getElementById('energyui-insertion-point');
57
+ if (!insertionPoint) {
58
+ insertionPoint = document.createElement('div');
59
+ insertionPoint.id = 'energyui-insertion-point';
60
+ insertionPoint.setAttribute('data-energy-ui', 'deduplication-insertion-point');
61
+ document.head.appendChild(insertionPoint);
62
+ }
63
+
64
+ // Usar un enfoque más simple: solo observar el DOM
65
+ const observer = new MutationObserver(mutations => {
66
+ mutations.forEach(mutation => {
67
+ mutation.addedNodes.forEach(node => {
68
+ if (node.nodeType === Node.ELEMENT_NODE && node.tagName === 'STYLE') {
69
+ const content = node.textContent || '';
70
+ if (content && (content.includes('UT') || content.includes('energy-ui') || content.includes('energyui') || content.includes('__'))) {
71
+ if (isStyleAlreadyLoaded(content)) {
72
+ console.log('Energy UI: Estilo duplicado detectado en DOM, removiendo...');
73
+ node.remove();
74
+ } else {
75
+ markStyleAsLoaded(content, node);
76
+ }
77
+ }
78
+ }
79
+ });
80
+ });
81
+ });
82
+ observer.observe(document.head, {
83
+ childList: true,
84
+ subtree: true
85
+ });
86
+
87
+ // Interceptar la inserción de reglas CSS para JSS
88
+ const originalInsertRule = CSSStyleSheet.prototype.insertRule;
89
+ CSSStyleSheet.prototype.insertRule = function (rule, index) {
90
+ // Verificar si la regla ya existe en otra hoja de estilos
91
+ if (rule && typeof rule === 'string') {
92
+ const existingSheets = Array.from(document.styleSheets);
93
+ for (const sheet of existingSheets) {
94
+ try {
95
+ const rules = Array.from(sheet.cssRules || []);
96
+ for (const existingRule of rules) {
97
+ if (existingRule.cssText === rule) {
98
+ console.log('Energy UI: Regla CSS duplicada detectada y evitada');
99
+ return 0; // Retornar índice 0 para evitar errores
100
+ }
101
+ }
102
+ } catch (e) {
103
+ // Ignorar errores de CORS
104
+ }
105
+ }
106
+ }
107
+ return originalInsertRule.call(this, rule, index);
108
+ };
109
+
110
+ // Marcar como configurado
111
+ window.__energyUI_styleDeduplicationConfigured = true;
112
+ console.log('Energy UI: Sistema de deduplicación de estilos configurado');
113
+ };
114
+
115
+ /**
116
+ * Función para limpiar estilos duplicados existentes
117
+ */
118
+ const cleanupDuplicateStyles = () => {
119
+ const styleElements = document.querySelectorAll('style');
120
+ const seenContents = new Set();
121
+ styleElements.forEach(style => {
122
+ const content = style.textContent || '';
123
+ if (content && (content.includes('UT') || content.includes('energy-ui') || content.includes('energyui') || content.includes('__'))) {
124
+ const hash = generateStyleHash(content);
125
+ if (seenContents.has(hash)) {
126
+ console.log('Energy UI: Removiendo estilo duplicado existente');
127
+ style.remove();
128
+ } else {
129
+ seenContents.add(hash);
130
+ markStyleAsLoaded(content, style);
131
+ }
132
+ }
133
+ });
134
+ };
135
+
136
+ /**
137
+ * Hook para React
138
+ */
139
+ const useStyleDeduplication = function () {
140
+ let enableStyleDeduplication = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
141
+ (0, _react.useEffect)(() => {
142
+ if (enableStyleDeduplication) {
143
+ interceptStyleCreation();
144
+ cleanupDuplicateStyles();
145
+ }
146
+ }, [enableStyleDeduplication]);
147
+ };
148
+
149
+ /**
150
+ * Función para configuración manual
151
+ */
152
+ exports.useStyleDeduplication = useStyleDeduplication;
153
+ const setupStyleDeduplication = () => {
154
+ interceptStyleCreation();
155
+ cleanupDuplicateStyles();
156
+ };
157
+
158
+ /**
159
+ * Función para verificar si está configurado
160
+ */
161
+ exports.setupStyleDeduplication = setupStyleDeduplication;
162
+ const isStyleDeduplicationConfigured = () => {
163
+ return window.__energyUI_styleDeduplicationConfigured === true;
164
+ };
165
+
166
+ /**
167
+ * Función para obtener estadísticas de deduplicación
168
+ */
169
+ exports.isStyleDeduplicationConfigured = isStyleDeduplicationConfigured;
170
+ const getDeduplicationStats = () => {
171
+ return {
172
+ loadedStylesCount: loadedStyles.size,
173
+ styleElementsCount: styleElements.size,
174
+ isConfigured: isStyleDeduplicationConfigured()
175
+ };
176
+ };
177
+ exports.getDeduplicationStats = getDeduplicationStats;
178
+ var _default = exports.default = {
179
+ getDeduplicationStats,
180
+ isStyleDeduplicationConfigured,
181
+ setupStyleDeduplication,
182
+ useStyleDeduplication
183
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widergy/energy-ui",
3
- "version": "3.97.0",
3
+ "version": "3.98.0",
4
4
  "description": "Widergy Web Components",
5
5
  "author": "widergy",
6
6
  "license": "MIT",