tia-gpc-widget 1.1.0 → 1.1.1

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/dist/loader.js CHANGED
@@ -1,271 +1,271 @@
1
- /**
2
- * TIA GPC Widget Loader
3
- * @version 1.0.0
4
- */
5
-
6
- (function() {
7
- 'use strict';
8
-
9
- const CONFIG = {
10
- versionUrl: 'https://cdn.jsdelivr.net/npm/tia-gpc-widget@latest/dist/version.json',
11
- defaultChannel: 'stable',
12
- timeout: 15000,
13
- maxRetries: 3,
14
- retryDelay: 2000,
15
- fallbackVersion: '1.0.9',
16
- fallbackCdn: 'https://cdn.jsdelivr.net/npm/tia-gpc-widget'
17
- };
18
-
19
- let loadAttempts = 0;
20
- let loadStartTime = Date.now();
21
-
22
- const log = {
23
- info: function(msg, data) {
24
- console.log('[TIA GPC Loader]', msg, data || '');
25
- },
26
- warn: function(msg, data) {
27
- console.warn('[TIA GPC Loader]', msg, data || '');
28
- },
29
- error: function(msg, data) {
30
- console.error('[TIA GPC Loader]', msg, data || '');
31
- }
32
- };
33
-
34
- function isAlreadyLoaded() {
35
- return window.TiaGPCWidgetLoaded === true || window.TiaGPC !== undefined;
36
- }
37
-
38
- function getLoaderConfig() {
39
- const scriptTag = document.currentScript ||
40
- document.querySelector('script[src*="loader"]');
41
-
42
- if (!scriptTag) return {};
43
-
44
- return {
45
- channel: scriptTag.getAttribute('data-channel') || CONFIG.defaultChannel,
46
- version: scriptTag.getAttribute('data-version') || null,
47
- debug: scriptTag.getAttribute('data-debug') === 'true',
48
- apiUrl: scriptTag.getAttribute('data-api-url') || null
49
- };
50
- }
51
-
52
- function emit(eventName, detail) {
53
- window.dispatchEvent(new CustomEvent(eventName, { detail }));
54
- }
55
-
56
- function loadScript(url, timeout) {
57
- return new Promise((resolve, reject) => {
58
- const script = document.createElement('script');
59
- script.src = url;
60
- script.async = true;
61
- script.crossOrigin = 'anonymous';
62
-
63
- let timeoutId;
64
-
65
- script.onload = function() {
66
- clearTimeout(timeoutId);
67
- resolve();
68
- };
69
-
70
- script.onerror = function() {
71
- clearTimeout(timeoutId);
72
- reject(new Error(`Failed to load script: ${url}`));
73
- };
74
-
75
- timeoutId = setTimeout(() => {
76
- reject(new Error(`Timeout loading script: ${url}`));
77
- }, timeout || CONFIG.timeout);
78
-
79
- document.head.appendChild(script);
80
- });
81
- }
82
-
83
- function loadStyles(url) {
84
- return new Promise((resolve, reject) => {
85
- const existingLink = document.querySelector(`link[href*="${url}"]`);
86
- if (existingLink) {
87
- resolve();
88
- return;
89
- }
90
-
91
- const link = document.createElement('link');
92
- link.rel = 'stylesheet';
93
- link.href = url;
94
- link.crossOrigin = 'anonymous';
95
-
96
- link.onload = resolve;
97
- link.onerror = () => reject(new Error(`Failed to load CSS: ${url}`));
98
-
99
- document.head.appendChild(link);
100
- });
101
- }
102
-
103
- async function fetchVersionInfo(loaderConfig) {
104
- try {
105
- if (loaderConfig.version) {
106
- return buildFallbackUrls(loaderConfig.version);
107
- }
108
-
109
- const response = await fetch(CONFIG.versionUrl, {
110
- cache: 'no-cache',
111
- headers: {
112
- 'Cache-Control': 'no-cache, no-store, must-revalidate',
113
- 'Pragma': 'no-cache',
114
- 'Expires': '0'
115
- }
116
- });
117
-
118
- if (!response.ok) {
119
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
120
- }
121
-
122
- const data = await response.json();
123
- const channelData = data[loaderConfig.channel] || data.stable;
124
-
125
- return {
126
- version: data.version,
127
- js: channelData.js,
128
- css: channelData.css,
129
- timestamp: data.timestamp
130
- };
131
-
132
- } catch (error) {
133
- log.warn('Failed to fetch version info, using fallback', error.message);
134
- return buildFallbackUrls(CONFIG.fallbackVersion);
135
- }
136
- }
137
-
138
- function buildFallbackUrls(version) {
139
- const baseUrl = CONFIG.fallbackCdn;
140
- return {
141
- version: version,
142
- js: `${baseUrl}@${version}/dist/tia-gpc-widget.standalone.js`,
143
- css: `${baseUrl}@${version}/dist/tia-gpc-widget.standalone.css`,
144
- timestamp: null
145
- };
146
- }
147
-
148
- async function loadWidgetWithRetry(versionInfo, loaderConfig) {
149
- loadAttempts++;
150
-
151
- try {
152
- log.info(`Loading widget v${versionInfo.version} (attempt ${loadAttempts}/${CONFIG.maxRetries})...`);
153
-
154
- loadStyles(versionInfo.css).catch(err => {
155
- log.warn('CSS loading failed, continuing anyway', err);
156
- });
157
-
158
- await loadScript(versionInfo.js, CONFIG.timeout);
159
-
160
- if (!window.TiaGPC) {
161
- throw new Error('Widget loaded but TiaGPC global not found');
162
- }
163
-
164
- const loadTime = Date.now() - loadStartTime;
165
-
166
- log.info(`Widget v${versionInfo.version} loaded successfully in ${loadTime}ms`);
167
-
168
- window.TiaGPCWidgetLoaded = true;
169
- window.TiaGPCWidgetVersion = versionInfo.version;
170
-
171
- emit('tia-gpc-loader-ready', {
172
- version: versionInfo.version,
173
- loadTime: loadTime,
174
- attempts: loadAttempts,
175
- channel: loaderConfig.channel
176
- });
177
-
178
- if (loaderConfig.apiUrl) {
179
- sendAnalytics(loaderConfig.apiUrl, {
180
- event: 'widget_loaded',
181
- version: versionInfo.version,
182
- loadTime: loadTime,
183
- url: window.location.href
184
- });
185
- }
186
-
187
- return true;
188
-
189
- } catch (error) {
190
- log.error(`Failed to load widget (attempt ${loadAttempts})`, error.message);
191
-
192
- if (loadAttempts < CONFIG.maxRetries) {
193
- log.info(`Retrying in ${CONFIG.retryDelay}ms...`);
194
- await new Promise(resolve => setTimeout(resolve, CONFIG.retryDelay));
195
- return loadWidgetWithRetry(versionInfo, loaderConfig);
196
- } else {
197
- emit('tia-gpc-loader-error', {
198
- error: error.message,
199
- attempts: loadAttempts,
200
- version: versionInfo.version
201
- });
202
-
203
- throw new Error(`Failed to load widget after ${loadAttempts} attempts: ${error.message}`);
204
- }
205
- }
206
- }
207
-
208
- function sendAnalytics(apiUrl, data) {
209
- try {
210
- fetch(apiUrl, {
211
- method: 'POST',
212
- headers: { 'Content-Type': 'application/json' },
213
- body: JSON.stringify(data)
214
- }).catch(() => {});
215
- } catch (e) {
216
- }
217
- }
218
-
219
- async function init() {
220
- try {
221
- if (isAlreadyLoaded()) {
222
- log.warn('Widget already loaded, skipping');
223
- return;
224
- }
225
-
226
- log.info('Initializing TIA GPC Widget Loader...');
227
-
228
- const loaderConfig = getLoaderConfig();
229
-
230
- if (loaderConfig.debug) {
231
- log.info('Loader config:', loaderConfig);
232
- }
233
-
234
- const versionInfo = await fetchVersionInfo(loaderConfig);
235
-
236
- if (loaderConfig.debug) {
237
- log.info('Version info:', versionInfo);
238
- }
239
-
240
- await loadWidgetWithRetry(versionInfo, loaderConfig);
241
-
242
- } catch (error) {
243
- log.error('Fatal error initializing widget', error);
244
-
245
- const widgets = document.querySelectorAll('tia-gpc-widget');
246
- if (widgets.length > 0) {
247
- widgets.forEach(widget => {
248
- widget.innerHTML = `
249
- <div style="padding: 20px; background: #fee; border: 2px solid #c00; border-radius: 8px; font-family: sans-serif;">
250
- <strong>Error loading TIA GPC Widget</strong>
251
- <p style="margin: 10px 0 0 0; font-size: 14px;">${error.message}</p>
252
- </div>
253
- `;
254
- });
255
- }
256
- }
257
- }
258
-
259
- if (document.readyState === 'loading') {
260
- document.addEventListener('DOMContentLoaded', init);
261
- } else {
262
- init();
263
- }
264
-
265
- window.TiaGPCLoader = {
266
- version: '1.0.0',
267
- reload: init,
268
- config: CONFIG
269
- };
270
-
271
- })();
1
+ /**
2
+ * TIA GPC Widget Loader
3
+ * @version 1.0.0
4
+ */
5
+
6
+ (function() {
7
+ 'use strict';
8
+
9
+ const CONFIG = {
10
+ versionUrl: 'https://cdn.jsdelivr.net/npm/tia-gpc-widget@latest/dist/version.json',
11
+ defaultChannel: 'stable',
12
+ timeout: 15000,
13
+ maxRetries: 3,
14
+ retryDelay: 2000,
15
+ fallbackVersion: '1.1.1',
16
+ fallbackCdn: 'https://cdn.jsdelivr.net/npm/tia-gpc-widget'
17
+ };
18
+
19
+ let loadAttempts = 0;
20
+ let loadStartTime = Date.now();
21
+
22
+ const log = {
23
+ info: function(msg, data) {
24
+ console.log('[TIA GPC Loader]', msg, data || '');
25
+ },
26
+ warn: function(msg, data) {
27
+ console.warn('[TIA GPC Loader]', msg, data || '');
28
+ },
29
+ error: function(msg, data) {
30
+ console.error('[TIA GPC Loader]', msg, data || '');
31
+ }
32
+ };
33
+
34
+ function isAlreadyLoaded() {
35
+ return window.TiaGPCWidgetLoaded === true || window.TiaGPC !== undefined;
36
+ }
37
+
38
+ function getLoaderConfig() {
39
+ const scriptTag = document.currentScript ||
40
+ document.querySelector('script[src*="loader"]');
41
+
42
+ if (!scriptTag) return {};
43
+
44
+ return {
45
+ channel: scriptTag.getAttribute('data-channel') || CONFIG.defaultChannel,
46
+ version: scriptTag.getAttribute('data-version') || null,
47
+ debug: scriptTag.getAttribute('data-debug') === 'true',
48
+ apiUrl: scriptTag.getAttribute('data-api-url') || null
49
+ };
50
+ }
51
+
52
+ function emit(eventName, detail) {
53
+ window.dispatchEvent(new CustomEvent(eventName, { detail }));
54
+ }
55
+
56
+ function loadScript(url, timeout) {
57
+ return new Promise((resolve, reject) => {
58
+ const script = document.createElement('script');
59
+ script.src = url;
60
+ script.async = true;
61
+ script.crossOrigin = 'anonymous';
62
+
63
+ let timeoutId;
64
+
65
+ script.onload = function() {
66
+ clearTimeout(timeoutId);
67
+ resolve();
68
+ };
69
+
70
+ script.onerror = function() {
71
+ clearTimeout(timeoutId);
72
+ reject(new Error(`Failed to load script: ${url}`));
73
+ };
74
+
75
+ timeoutId = setTimeout(() => {
76
+ reject(new Error(`Timeout loading script: ${url}`));
77
+ }, timeout || CONFIG.timeout);
78
+
79
+ document.head.appendChild(script);
80
+ });
81
+ }
82
+
83
+ function loadStyles(url) {
84
+ return new Promise((resolve, reject) => {
85
+ const existingLink = document.querySelector(`link[href*="${url}"]`);
86
+ if (existingLink) {
87
+ resolve();
88
+ return;
89
+ }
90
+
91
+ const link = document.createElement('link');
92
+ link.rel = 'stylesheet';
93
+ link.href = url;
94
+ link.crossOrigin = 'anonymous';
95
+
96
+ link.onload = resolve;
97
+ link.onerror = () => reject(new Error(`Failed to load CSS: ${url}`));
98
+
99
+ document.head.appendChild(link);
100
+ });
101
+ }
102
+
103
+ async function fetchVersionInfo(loaderConfig) {
104
+ try {
105
+ if (loaderConfig.version) {
106
+ return buildFallbackUrls(loaderConfig.version);
107
+ }
108
+
109
+ const response = await fetch(CONFIG.versionUrl, {
110
+ cache: 'no-cache',
111
+ headers: {
112
+ 'Cache-Control': 'no-cache, no-store, must-revalidate',
113
+ 'Pragma': 'no-cache',
114
+ 'Expires': '0'
115
+ }
116
+ });
117
+
118
+ if (!response.ok) {
119
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
120
+ }
121
+
122
+ const data = await response.json();
123
+ const channelData = data[loaderConfig.channel] || data.stable;
124
+
125
+ return {
126
+ version: data.version,
127
+ js: channelData.js,
128
+ css: channelData.css,
129
+ timestamp: data.timestamp
130
+ };
131
+
132
+ } catch (error) {
133
+ log.warn('Failed to fetch version info, using fallback', error.message);
134
+ return buildFallbackUrls(CONFIG.fallbackVersion);
135
+ }
136
+ }
137
+
138
+ function buildFallbackUrls(version) {
139
+ const baseUrl = CONFIG.fallbackCdn;
140
+ return {
141
+ version: version,
142
+ js: `${baseUrl}@${version}/dist/tia-gpc-widget.standalone.js`,
143
+ css: `${baseUrl}@${version}/dist/tia-gpc-widget.standalone.css`,
144
+ timestamp: null
145
+ };
146
+ }
147
+
148
+ async function loadWidgetWithRetry(versionInfo, loaderConfig) {
149
+ loadAttempts++;
150
+
151
+ try {
152
+ log.info(`Loading widget v${versionInfo.version} (attempt ${loadAttempts}/${CONFIG.maxRetries})...`);
153
+
154
+ loadStyles(versionInfo.css).catch(err => {
155
+ log.warn('CSS loading failed, continuing anyway', err);
156
+ });
157
+
158
+ await loadScript(versionInfo.js, CONFIG.timeout);
159
+
160
+ if (!window.TiaGPC) {
161
+ throw new Error('Widget loaded but TiaGPC global not found');
162
+ }
163
+
164
+ const loadTime = Date.now() - loadStartTime;
165
+
166
+ log.info(`Widget v${versionInfo.version} loaded successfully in ${loadTime}ms`);
167
+
168
+ window.TiaGPCWidgetLoaded = true;
169
+ window.TiaGPCWidgetVersion = versionInfo.version;
170
+
171
+ emit('tia-gpc-loader-ready', {
172
+ version: versionInfo.version,
173
+ loadTime: loadTime,
174
+ attempts: loadAttempts,
175
+ channel: loaderConfig.channel
176
+ });
177
+
178
+ if (loaderConfig.apiUrl) {
179
+ sendAnalytics(loaderConfig.apiUrl, {
180
+ event: 'widget_loaded',
181
+ version: versionInfo.version,
182
+ loadTime: loadTime,
183
+ url: window.location.href
184
+ });
185
+ }
186
+
187
+ return true;
188
+
189
+ } catch (error) {
190
+ log.error(`Failed to load widget (attempt ${loadAttempts})`, error.message);
191
+
192
+ if (loadAttempts < CONFIG.maxRetries) {
193
+ log.info(`Retrying in ${CONFIG.retryDelay}ms...`);
194
+ await new Promise(resolve => setTimeout(resolve, CONFIG.retryDelay));
195
+ return loadWidgetWithRetry(versionInfo, loaderConfig);
196
+ } else {
197
+ emit('tia-gpc-loader-error', {
198
+ error: error.message,
199
+ attempts: loadAttempts,
200
+ version: versionInfo.version
201
+ });
202
+
203
+ throw new Error(`Failed to load widget after ${loadAttempts} attempts: ${error.message}`);
204
+ }
205
+ }
206
+ }
207
+
208
+ function sendAnalytics(apiUrl, data) {
209
+ try {
210
+ fetch(apiUrl, {
211
+ method: 'POST',
212
+ headers: { 'Content-Type': 'application/json' },
213
+ body: JSON.stringify(data)
214
+ }).catch(() => {});
215
+ } catch (e) {
216
+ }
217
+ }
218
+
219
+ async function init() {
220
+ try {
221
+ if (isAlreadyLoaded()) {
222
+ log.warn('Widget already loaded, skipping');
223
+ return;
224
+ }
225
+
226
+ log.info('Initializing TIA GPC Widget Loader...');
227
+
228
+ const loaderConfig = getLoaderConfig();
229
+
230
+ if (loaderConfig.debug) {
231
+ log.info('Loader config:', loaderConfig);
232
+ }
233
+
234
+ const versionInfo = await fetchVersionInfo(loaderConfig);
235
+
236
+ if (loaderConfig.debug) {
237
+ log.info('Version info:', versionInfo);
238
+ }
239
+
240
+ await loadWidgetWithRetry(versionInfo, loaderConfig);
241
+
242
+ } catch (error) {
243
+ log.error('Fatal error initializing widget', error);
244
+
245
+ const widgets = document.querySelectorAll('tia-gpc-widget');
246
+ if (widgets.length > 0) {
247
+ widgets.forEach(widget => {
248
+ widget.innerHTML = `
249
+ <div style="padding: 20px; background: #fee; border: 2px solid #c00; border-radius: 8px; font-family: sans-serif;">
250
+ <strong>Error loading TIA GPC Widget</strong>
251
+ <p style="margin: 10px 0 0 0; font-size: 14px;">${error.message}</p>
252
+ </div>
253
+ `;
254
+ });
255
+ }
256
+ }
257
+ }
258
+
259
+ if (document.readyState === 'loading') {
260
+ document.addEventListener('DOMContentLoaded', init);
261
+ } else {
262
+ init();
263
+ }
264
+
265
+ window.TiaGPCLoader = {
266
+ version: '1.0.0',
267
+ reload: init,
268
+ config: CONFIG
269
+ };
270
+
271
+ })();
@@ -1,3 +1,3 @@
1
1
  /*! TIA GPC Widget Loader v1.0.0 | (c) 2025 TIA | UNLICENSED */
2
- !function(){"use strict";const e={versionUrl:"https://cdn.jsdelivr.net/npm/tia-gpc-widget@latest/dist/version.json",defaultChannel:"stable",timeout:15e3,maxRetries:3,retryDelay:2e3,fallbackVersion:"1.0.9",fallbackCdn:"https://cdn.jsdelivr.net/npm/tia-gpc-widget"};let t=0,n=Date.now();const o=function(e,t){console.log("[TIA GPC Loader]",e,t||"")},i=function(e,t){console.warn("[TIA GPC Loader]",e,t||"")},r=function(e,t){console.error("[TIA GPC Loader]",e,t||"")};function a(e,t){window.dispatchEvent(new CustomEvent(e,{detail:t}))}function s(t){const n=e.fallbackCdn;return{version:t,js:`${n}@${t}/dist/tia-gpc-widget.standalone.js`,css:`${n}@${t}/dist/tia-gpc-widget.standalone.css`,timestamp:null}}async function d(s,c){t++;try{if(o(`Loading widget v${s.version} (attempt ${t}/${e.maxRetries})...`),(l=s.css,new Promise((e,t)=>{if(document.querySelector(`link[href*="${l}"]`))return void e();const n=document.createElement("link");n.rel="stylesheet",n.href=l,n.crossOrigin="anonymous",n.onload=e,n.onerror=()=>t(new Error(`Failed to load CSS: ${l}`)),document.head.appendChild(n)})).catch(e=>{i("CSS loading failed, continuing anyway",e)}),await function(t,n){return new Promise((o,i)=>{const r=document.createElement("script");let a;r.src=t,r.async=!0,r.crossOrigin="anonymous",r.onload=function(){clearTimeout(a),o()},r.onerror=function(){clearTimeout(a),i(new Error(`Failed to load script: ${t}`))},a=setTimeout(()=>{i(new Error(`Timeout loading script: ${t}`))},n||e.timeout),document.head.appendChild(r)})}(s.js,e.timeout),!window.TiaGPC)throw new Error("Widget loaded but TiaGPC global not found");const r=Date.now()-n;return o(`Widget v${s.version} loaded successfully in ${r}ms`),window.TiaGPCWidgetLoaded=!0,window.TiaGPCWidgetVersion=s.version,a("tia-gpc-loader-ready",{version:s.version,loadTime:r,attempts:t,channel:c.channel}),c.apiUrl&&function(e,t){try{fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).catch(()=>{})}catch(e){}}(c.apiUrl,{event:"widget_loaded",version:s.version,loadTime:r,url:window.location.href}),!0}catch(n){if(r(`Failed to load widget (attempt ${t})`,n.message),t<e.maxRetries)return o(`Retrying in ${e.retryDelay}ms...`),await new Promise(t=>setTimeout(t,e.retryDelay)),d(s,c);throw a("tia-gpc-loader-error",{error:n.message,attempts:t,version:s.version}),new Error(`Failed to load widget after ${t} attempts: ${n.message}`)}var l}async function c(){try{if(!0===window.TiaGPCWidgetLoaded||void 0!==window.TiaGPC)return void i("Widget already loaded, skipping");o("Initializing TIA GPC Widget Loader...");const t=function(){const t=document.currentScript||document.querySelector('script[src*="loader"]');return t?{channel:t.getAttribute("data-channel")||e.defaultChannel,version:t.getAttribute("data-version")||null,debug:"true"===t.getAttribute("data-debug"),apiUrl:t.getAttribute("data-api-url")||null}:{}}();t.debug&&o("Loader config:",t);const n=await async function(t){try{if(t.version)return s(t.version);const n=await fetch(e.versionUrl,{cache:"no-cache",headers:{"Cache-Control":"no-cache, no-store, must-revalidate",Pragma:"no-cache",Expires:"0"}});if(!n.ok)throw new Error(`HTTP ${n.status}: ${n.statusText}`);const o=await n.json(),i=o[t.channel]||o.stable;return{version:o.version,js:i.js,css:i.css,timestamp:o.timestamp}}catch(t){return i("Failed to fetch version info, using fallback",t.message),s(e.fallbackVersion)}}(t);t.debug&&o("Version info:",n),await d(n,t)}catch(e){r("Fatal error initializing widget",e);const t=document.querySelectorAll("tia-gpc-widget");t.length>0&&t.forEach(t=>{t.innerHTML=`\n <div style="padding: 20px; background: #fee; border: 2px solid #c00; border-radius: 8px; font-family: sans-serif;">\n <strong>Error loading TIA GPC Widget</strong>\n <p style="margin: 10px 0 0 0; font-size: 14px;">${e.message}</p>\n </div>\n `})}}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",c):c(),window.TiaGPCLoader={version:"1.0.0",reload:c,config:e}}();
2
+ !function(){"use strict";const e={versionUrl:"https://cdn.jsdelivr.net/npm/tia-gpc-widget@latest/dist/version.json",defaultChannel:"stable",timeout:15e3,maxRetries:3,retryDelay:2e3,fallbackVersion:"1.1.1",fallbackCdn:"https://cdn.jsdelivr.net/npm/tia-gpc-widget"};let t=0,n=Date.now();const o=function(e,t){console.log("[TIA GPC Loader]",e,t||"")},i=function(e,t){console.warn("[TIA GPC Loader]",e,t||"")},r=function(e,t){console.error("[TIA GPC Loader]",e,t||"")};function a(e,t){window.dispatchEvent(new CustomEvent(e,{detail:t}))}function s(t){const n=e.fallbackCdn;return{version:t,js:`${n}@${t}/dist/tia-gpc-widget.standalone.js`,css:`${n}@${t}/dist/tia-gpc-widget.standalone.css`,timestamp:null}}async function d(s,c){t++;try{if(o(`Loading widget v${s.version} (attempt ${t}/${e.maxRetries})...`),(l=s.css,new Promise((e,t)=>{if(document.querySelector(`link[href*="${l}"]`))return void e();const n=document.createElement("link");n.rel="stylesheet",n.href=l,n.crossOrigin="anonymous",n.onload=e,n.onerror=()=>t(new Error(`Failed to load CSS: ${l}`)),document.head.appendChild(n)})).catch(e=>{i("CSS loading failed, continuing anyway",e)}),await function(t,n){return new Promise((o,i)=>{const r=document.createElement("script");let a;r.src=t,r.async=!0,r.crossOrigin="anonymous",r.onload=function(){clearTimeout(a),o()},r.onerror=function(){clearTimeout(a),i(new Error(`Failed to load script: ${t}`))},a=setTimeout(()=>{i(new Error(`Timeout loading script: ${t}`))},n||e.timeout),document.head.appendChild(r)})}(s.js,e.timeout),!window.TiaGPC)throw new Error("Widget loaded but TiaGPC global not found");const r=Date.now()-n;return o(`Widget v${s.version} loaded successfully in ${r}ms`),window.TiaGPCWidgetLoaded=!0,window.TiaGPCWidgetVersion=s.version,a("tia-gpc-loader-ready",{version:s.version,loadTime:r,attempts:t,channel:c.channel}),c.apiUrl&&function(e,t){try{fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).catch(()=>{})}catch(e){}}(c.apiUrl,{event:"widget_loaded",version:s.version,loadTime:r,url:window.location.href}),!0}catch(n){if(r(`Failed to load widget (attempt ${t})`,n.message),t<e.maxRetries)return o(`Retrying in ${e.retryDelay}ms...`),await new Promise(t=>setTimeout(t,e.retryDelay)),d(s,c);throw a("tia-gpc-loader-error",{error:n.message,attempts:t,version:s.version}),new Error(`Failed to load widget after ${t} attempts: ${n.message}`)}var l}async function c(){try{if(!0===window.TiaGPCWidgetLoaded||void 0!==window.TiaGPC)return void i("Widget already loaded, skipping");o("Initializing TIA GPC Widget Loader...");const t=function(){const t=document.currentScript||document.querySelector('script[src*="loader"]');return t?{channel:t.getAttribute("data-channel")||e.defaultChannel,version:t.getAttribute("data-version")||null,debug:"true"===t.getAttribute("data-debug"),apiUrl:t.getAttribute("data-api-url")||null}:{}}();t.debug&&o("Loader config:",t);const n=await async function(t){try{if(t.version)return s(t.version);const n=await fetch(e.versionUrl,{cache:"no-cache",headers:{"Cache-Control":"no-cache, no-store, must-revalidate",Pragma:"no-cache",Expires:"0"}});if(!n.ok)throw new Error(`HTTP ${n.status}: ${n.statusText}`);const o=await n.json(),i=o[t.channel]||o.stable;return{version:o.version,js:i.js,css:i.css,timestamp:o.timestamp}}catch(t){return i("Failed to fetch version info, using fallback",t.message),s(e.fallbackVersion)}}(t);t.debug&&o("Version info:",n),await d(n,t)}catch(e){r("Fatal error initializing widget",e);const t=document.querySelectorAll("tia-gpc-widget");t.length>0&&t.forEach(t=>{t.innerHTML=`\n <div style="padding: 20px; background: #fee; border: 2px solid #c00; border-radius: 8px; font-family: sans-serif;">\n <strong>Error loading TIA GPC Widget</strong>\n <p style="margin: 10px 0 0 0; font-size: 14px;">${e.message}</p>\n </div>\n `})}}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",c):c(),window.TiaGPCLoader={version:"1.0.0",reload:c,config:e}}();
3
3
  //# sourceMappingURL=loader.min.js.map