tia-gpc-widget 1.0.6 → 1.0.8

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/README.md CHANGED
@@ -1,1071 +1,1092 @@
1
- # TIA GPC Widget
2
-
3
- Widget de chat inteligente para integración con TIA GPC. Compatible con **React, HTML puro, Angular, ASP.NET, Vue, y cualquier otro framework**.
4
-
5
- [![Version](https://img.shields.io/badge/version-1.0.0-blue.svg)](https://www.npmjs.com/package/tia-gpc-widget)
6
- [![License](https://img.shields.io/badge/license-UNLICENSED-red.svg)](LICENSE)
7
-
8
- ---
9
-
10
- ## 📋 Tabla de Contenidos
11
-
12
- - [Características](#-características)
13
- - [Instalación](#-instalación)
14
- - [Opción 1: NPM (Para proyectos React/Node)](#opción-1-npm-para-proyectos-reactnode)
15
- - [Opción 2: CDN / Script directo (Para HTML, Angular, ASP.NET, etc.)](#opción-2-cdn--script-directo-para-html-angular-aspnet-etc)
16
- - [Uso Rápido](#-uso-rápido)
17
- - [Ejemplos por Framework](#-ejemplos-por-framework)
18
- - [React](#1-react)
19
- - [HTML Puro / Vanilla JavaScript](#2-html-puro--vanilla-javascript)
20
- - [Angular](#3-angular)
21
- - [ASP.NET / ASPX](#4-aspnet--aspx)
22
- - [Vue.js](#5-vuejs)
23
- - [Next.js](#6-nextjs)
24
- - [PHP](#7-php)
25
- - [API y Configuración](#-api-y-configuración)
26
- - [Props/Atributos](#propsatributos)
27
- - [Eventos](#eventos)
28
- - [API Programática (JavaScript)](#api-programática-javascript)
29
- - [Personalización](#-personalización)
30
- - [Temas](#temas)
31
- - [Posiciones](#posiciones)
32
- - [Idiomas](#idiomas)
33
- - [Colores](#colores)
34
- - [Build y Desarrollo](#-build-y-desarrollo)
35
- - [Publicación](#-publicación)
36
- - [Soporte](#-soporte)
37
-
38
- ---
39
-
40
- ## 🚀 Características
41
-
42
- - ✅ **Framework Agnostic**: Funciona en React, Angular, Vue, ASP.NET, HTML puro, etc.
43
- - ✅ **Web Component**: Basado en estándares web nativos
44
- - ✅ **Temas**: Modo claro, oscuro o automático
45
- - ✅ **Internacionalización**: Español, Inglés, Francés
46
- - ✅ **Responsive**: Diseño adaptable para móviles y escritorio
47
- - ✅ **Personalizable**: Colores, posiciones, dimensiones
48
- - ✅ **TypeScript Ready**: Tipos incluidos
49
- - ✅ **Zero Dependencies**: El bundle standalone incluye todo lo necesario
50
-
51
- ---
52
-
53
- ## 📦 Instalación
54
-
55
- ### Opción 1: NPM (Para proyectos React/Node)
56
-
57
- ```bash
58
- npm install tia-gpc-widget
59
- ```
60
-
61
- o con yarn:
62
-
63
- ```bash
64
- yarn add tia-gpc-widget
65
- ```
66
-
67
- o con pnpm:
68
-
69
- ```bash
70
- pnpm add tia-gpc-widget
71
- ```
72
-
73
- ### Opción 2: CDN / Script directo (Para HTML, Angular, ASP.NET, etc.)
74
-
75
- Puedes incluir el widget directamente desde un CDN o desde tu servidor:
76
-
77
- ```html
78
- <!-- Incluir JavaScript -->
79
- <script src="https://cdn.tu-dominio.com/tia-gpc-widget.standalone.js"></script>
80
-
81
- <!-- Incluir CSS -->
82
- <link rel="stylesheet" href="https://cdn.tu-dominio.com/tia-gpc-widget.standalone.css">
83
- ```
84
-
85
- O si instalaste vía NPM, copia los archivos desde `node_modules/tia-gpc-widget/dist/`:
86
-
87
- - `tia-gpc-widget.standalone.js`
88
- - `tia-gpc-widget.standalone.css`
89
-
90
- ---
91
-
92
- ## ⚡ Uso Rápido
93
-
94
- ### En HTML Puro
95
-
96
- ```html
97
- <!DOCTYPE html>
98
- <html lang="es">
99
- <head>
100
- <meta charset="UTF-8">
101
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
102
- <title>Mi Aplicación con TIA GPC</title>
103
-
104
- <!-- CSS del widget -->
105
- <link rel="stylesheet" href="./tia-gpc-widget.standalone.css">
106
- </head>
107
- <body>
108
- <h1>Mi Aplicación</h1>
109
-
110
- <!-- Widget TIA GPC -->
111
- <tia-gpc-widget
112
- token="tu-license-token-aqui"
113
- theme="auto"
114
- position="bottom-right"
115
- language="es"
116
- ></tia-gpc-widget>
117
-
118
- <!-- JavaScript del widget -->
119
- <script src="./tia-gpc-widget.standalone.js"></script>
120
- </body>
121
- </html>
122
- ```
123
-
124
- ### En React
125
-
126
- ```jsx
127
- import { TiaGPCWidget } from 'tia-gpc-widget';
128
- import 'tia-gpc-widget/styles';
129
-
130
- function App() {
131
- return (
132
- <div>
133
- <h1>Mi Aplicación</h1>
134
- <TiaGPCWidget
135
- token="tu-license-token-aqui"
136
- theme="auto"
137
- position="bottom-right"
138
- language="es"
139
- />
140
- </div>
141
- );
142
- }
143
-
144
- export default App;
145
- ```
146
-
147
- ---
148
-
149
- ## 📚 Ejemplos por Framework
150
-
151
- ### 1. React
152
-
153
- #### Instalación
154
-
155
- ```bash
156
- npm install tia-gpc-widget
157
- ```
158
-
159
- #### Uso Básico
160
-
161
- ```jsx
162
- import { TiaGPCWidget } from 'tia-gpc-widget';
163
- import 'tia-gpc-widget/styles';
164
-
165
- function App() {
166
- return (
167
- <TiaGPCWidget
168
- token="tu-license-token"
169
- theme="auto"
170
- position="bottom-right"
171
- language="es"
172
- primaryColor="#2563eb"
173
- onReady={() => console.log('Widget listo')}
174
- onError={(error) => console.error('Error:', error)}
175
- />
176
- );
177
- }
178
- ```
179
-
180
- #### Con Configuración Avanzada
181
-
182
- ```jsx
183
- import { TiaGPCWidget, WIDGET_POSITIONS, THEMES, LANGUAGES } from 'tia-gpc-widget';
184
- import 'tia-gpc-widget/styles';
185
-
186
- function App() {
187
- const handleReady = () => {
188
- console.log('✅ Widget inicializado correctamente');
189
- };
190
-
191
- const handleError = (error) => {
192
- console.error('❌ Error en el widget:', error);
193
- };
194
-
195
- return (
196
- <TiaGPCWidget
197
- token="tu-license-token"
198
- theme={THEMES.AUTO}
199
- position={WIDGET_POSITIONS.BOTTOM_RIGHT}
200
- language={LANGUAGES.ES}
201
- primaryColor="#10b981"
202
- width="450px"
203
- height="650px"
204
- autoOpen={false}
205
- showBranding={true}
206
- mobileFullscreen={true}
207
- onReady={handleReady}
208
- onError={handleError}
209
- onClose={() => console.log('Widget cerrado')}
210
- />
211
- );
212
- }
213
- ```
214
-
215
- ---
216
-
217
- ### 2. HTML Puro / Vanilla JavaScript
218
-
219
- #### Método 1: Usando el elemento HTML directamente
220
-
221
- ```html
222
- <!DOCTYPE html>
223
- <html lang="es">
224
- <head>
225
- <meta charset="UTF-8">
226
- <title>TIA GPC Widget - HTML Puro</title>
227
- <link rel="stylesheet" href="./tia-gpc-widget.standalone.css">
228
- </head>
229
- <body>
230
- <h1>Mi Sitio Web</h1>
231
-
232
- <!-- Widget como elemento HTML -->
233
- <tia-gpc-widget
234
- token="tu-license-token"
235
- theme="light"
236
- position="bottom-right"
237
- language="es"
238
- primary-color="#3b82f6"
239
- width="400px"
240
- height="600px"
241
- auto-open="false"
242
- show-branding="true"
243
- ></tia-gpc-widget>
244
-
245
- <script src="./tia-gpc-widget.standalone.js"></script>
246
-
247
- <!-- Eventos opcionales -->
248
- <script>
249
- const widget = document.querySelector('tia-gpc-widget');
250
-
251
- widget.addEventListener('ready', () => {
252
- console.log('Widget listo');
253
- });
254
-
255
- widget.addEventListener('error', (e) => {
256
- console.error('Error:', e.detail);
257
- });
258
-
259
- widget.addEventListener('close', () => {
260
- console.log('Widget cerrado');
261
- });
262
- </script>
263
- </body>
264
- </html>
265
- ```
266
-
267
- #### Método 2: Creación programática con JavaScript
268
-
269
- ```html
270
- <!DOCTYPE html>
271
- <html lang="es">
272
- <head>
273
- <meta charset="UTF-8">
274
- <title>TIA GPC Widget - Programático</title>
275
- <link rel="stylesheet" href="./tia-gpc-widget.standalone.css">
276
- </head>
277
- <body>
278
- <h1>Mi Sitio Web</h1>
279
- <button id="crear-widget">Crear Widget</button>
280
-
281
- <script src="./tia-gpc-widget.standalone.js"></script>
282
- <script>
283
- document.getElementById('crear-widget').addEventListener('click', () => {
284
- // Usar la API global TiaGPC
285
- const widget = TiaGPC.create({
286
- token: 'tu-license-token',
287
- theme: 'auto',
288
- position: TiaGPC.POSITIONS.BOTTOM_RIGHT,
289
- language: TiaGPC.LANGUAGES.ES,
290
- primaryColor: '#3b82f6',
291
- autoOpen: false,
292
- onReady: () => console.log('✅ Widget listo'),
293
- onError: (error) => console.error('❌ Error:', error),
294
- onClose: () => console.log('Widget cerrado')
295
- });
296
-
297
- console.log('Widget creado:', widget);
298
- });
299
-
300
- // Ver información del widget
301
- TiaGPC.info();
302
- </script>
303
- </body>
304
- </html>
305
- ```
306
-
307
- ---
308
-
309
- ### 3. Angular
310
-
311
- #### Paso 1: Instalar el widget
312
-
313
- ```bash
314
- npm install tia-gpc-widget
315
- ```
316
-
317
- #### Paso 2: Configurar Angular para Web Components
318
-
319
- En `src/main.ts` o `src/polyfills.ts`, agrega:
320
-
321
- ```typescript
322
- // Habilitar Custom Elements (Web Components)
323
- import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
324
- ```
325
-
326
- En tu módulo principal (`app.module.ts`):
327
-
328
- ```typescript
329
- import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
330
- import { BrowserModule } from '@angular/platform-browser';
331
- import { AppComponent } from './app.component';
332
-
333
- @NgModule({
334
- declarations: [AppComponent],
335
- imports: [BrowserModule],
336
- schemas: [CUSTOM_ELEMENTS_SCHEMA], // ← Importante
337
- bootstrap: [AppComponent]
338
- })
339
- export class AppModule { }
340
- ```
341
-
342
- #### Paso 3: Importar los archivos del widget
343
-
344
- En `angular.json`, agrega los archivos CSS y JS:
345
-
346
- ```json
347
- {
348
- "projects": {
349
- "tu-proyecto": {
350
- "architect": {
351
- "build": {
352
- "options": {
353
- "styles": [
354
- "src/styles.css",
355
- "node_modules/tia-gpc-widget/dist/tia-gpc-widget.standalone.css"
356
- ],
357
- "scripts": [
358
- "node_modules/tia-gpc-widget/dist/tia-gpc-widget.standalone.js"
359
- ]
360
- }
361
- }
362
- }
363
- }
364
- }
365
- }
366
- ```
367
-
368
- #### Paso 4: Usar el widget en tu componente
369
-
370
- ```typescript
371
- // app.component.ts
372
- import { Component, OnInit } from '@angular/core';
373
-
374
- declare global {
375
- interface Window {
376
- TiaGPC: any;
377
- }
378
- }
379
-
380
- @Component({
381
- selector: 'app-root',
382
- template: `
383
- <h1>Mi Aplicación Angular</h1>
384
-
385
- <!-- Opción 1: Elemento HTML directo -->
386
- <tia-gpc-widget
387
- [attr.token]="widgetToken"
388
- [attr.theme]="theme"
389
- [attr.position]="position"
390
- [attr.language]="language"
391
- (ready)="onWidgetReady()"
392
- (error)="onWidgetError($event)"
393
- ></tia-gpc-widget>
394
- `
395
- })
396
- export class AppComponent implements OnInit {
397
- widgetToken = 'tu-license-token';
398
- theme = 'auto';
399
- position = 'bottom-right';
400
- language = 'es';
401
-
402
- ngOnInit() {
403
- console.log('TiaGPC disponible:', window.TiaGPC);
404
- }
405
-
406
- onWidgetReady() {
407
- console.log('✅ Widget de TIA GPC listo');
408
- }
409
-
410
- onWidgetError(event: any) {
411
- console.error('❌ Error en widget:', event.detail);
412
- }
413
- }
414
- ```
415
-
416
- #### Opción alternativa: Creación programática
417
-
418
- ```typescript
419
- // app.component.ts
420
- import { Component, OnInit } from '@angular/core';
421
-
422
- @Component({
423
- selector: 'app-root',
424
- template: `
425
- <h1>Mi Aplicación Angular</h1>
426
- <button (click)="createWidget()">Crear Widget</button>
427
- <div #widgetContainer></div>
428
- `
429
- })
430
- export class AppComponent implements OnInit {
431
- ngOnInit() {
432
- this.createWidget();
433
- }
434
-
435
- createWidget() {
436
- if (window.TiaGPC) {
437
- window.TiaGPC.create({
438
- token: 'tu-license-token',
439
- theme: 'auto',
440
- language: 'es',
441
- onReady: () => console.log('Widget listo'),
442
- onError: (err: any) => console.error(err)
443
- });
444
- }
445
- }
446
- }
447
- ```
448
-
449
- ---
450
-
451
- ### 4. ASP.NET / ASPX
452
-
453
- #### Opción 1: En una página ASPX
454
-
455
- ```aspx
456
- <%@ Page Language="C#" AutoEventWireup="true" %>
457
-
458
- <!DOCTYPE html>
459
- <html>
460
- <head>
461
- <title>TIA GPC Widget - ASP.NET</title>
462
- <link rel="stylesheet" href="/assets/tia-gpc-widget.standalone.css" />
463
- </head>
464
- <body>
465
- <form id="form1" runat="server">
466
- <h1>Mi Aplicación ASP.NET</h1>
467
-
468
- <!-- Widget TIA GPC -->
469
- <tia-gpc-widget
470
- token="<%= ConfigurationManager.AppSettings["TiaGpcToken"] %>"
471
- theme="auto"
472
- position="bottom-right"
473
- language="es"
474
- primary-color="#2563eb"
475
- ></tia-gpc-widget>
476
- </form>
477
-
478
- <script src="/assets/tia-gpc-widget.standalone.js"></script>
479
- <script>
480
- // Eventos opcionales
481
- document.querySelector('tia-gpc-widget').addEventListener('ready', function() {
482
- console.log('Widget TIA GPC inicializado');
483
- });
484
- </script>
485
- </body>
486
- </html>
487
- ```
488
-
489
- #### Opción 2: Con Master Page
490
-
491
- En tu `Site.Master`:
492
-
493
- ```aspx
494
- <head runat="server">
495
- <link rel="stylesheet" href="/Scripts/tia-gpc-widget.standalone.css" />
496
- </head>
497
- <body>
498
- <asp:ContentPlaceHolder ID="MainContent" runat="server">
499
- </asp:ContentPlaceHolder>
500
-
501
- <!-- Widget global -->
502
- <tia-gpc-widget
503
- token="<%= GetTiaGpcToken() %>"
504
- theme="auto"
505
- language="es"
506
- ></tia-gpc-widget>
507
-
508
- <script src="/Scripts/tia-gpc-widget.standalone.js"></script>
509
- </body>
510
- ```
511
-
512
- En tu `Site.Master.cs`:
513
-
514
- ```csharp
515
- public partial class SiteMaster : MasterPage
516
- {
517
- protected string GetTiaGpcToken()
518
- {
519
- return ConfigurationManager.AppSettings["TiaGpcToken"];
520
- }
521
- }
522
- ```
523
-
524
- #### Opción 3: MVC / Razor
525
-
526
- En tu layout `_Layout.cshtml`:
527
-
528
- ```html
529
- <!DOCTYPE html>
530
- <html>
531
- <head>
532
- <link rel="stylesheet" href="~/Content/tia-gpc-widget.standalone.css" />
533
- </head>
534
- <body>
535
- @RenderBody()
536
-
537
- <!-- Widget TIA GPC -->
538
- <tia-gpc-widget
539
- token="@ViewBag.TiaGpcToken"
540
- theme="auto"
541
- language="es"
542
- ></tia-gpc-widget>
543
-
544
- <script src="~/Scripts/tia-gpc-widget.standalone.js"></script>
545
- </body>
546
- </html>
547
- ```
548
-
549
- En tu `Controller`:
550
-
551
- ```csharp
552
- public class HomeController : Controller
553
- {
554
- public ActionResult Index()
555
- {
556
- ViewBag.TiaGpcToken = ConfigurationManager.AppSettings["TiaGpcToken"];
557
- return View();
558
- }
559
- }
560
- ```
561
-
562
- ---
563
-
564
- ### 5. Vue.js
565
-
566
- #### Instalación
567
-
568
- ```bash
569
- npm install tia-gpc-widget
570
- ```
571
-
572
- #### Configuración
573
-
574
- En `main.js` o `main.ts`:
575
-
576
- ```javascript
577
- import { createApp } from 'vue';
578
- import App from './App.vue';
579
-
580
- // Importar el widget standalone
581
- import 'tia-gpc-widget/dist/tia-gpc-widget.standalone.js';
582
- import 'tia-gpc-widget/dist/tia-gpc-widget.standalone.css';
583
-
584
- const app = createApp(App);
585
-
586
- // Configurar Vue para ignorar custom elements
587
- app.config.compilerOptions.isCustomElement = (tag) => tag === 'tia-gpc-widget';
588
-
589
- app.mount('#app');
590
- ```
591
-
592
- #### Uso en componentes
593
-
594
- ```vue
595
- <template>
596
- <div>
597
- <h1>Mi Aplicación Vue</h1>
598
-
599
- <!-- Widget TIA GPC -->
600
- <tia-gpc-widget
601
- :token="widgetToken"
602
- :theme="theme"
603
- :language="language"
604
- position="bottom-right"
605
- @ready="onReady"
606
- @error="onError"
607
- ></tia-gpc-widget>
608
- </div>
609
- </template>
610
-
611
- <script setup>
612
- import { ref, onMounted } from 'vue';
613
-
614
- const widgetToken = ref('tu-license-token');
615
- const theme = ref('auto');
616
- const language = ref('es');
617
-
618
- const onReady = () => {
619
- console.log('✅ Widget TIA GPC listo');
620
- };
621
-
622
- const onError = (event) => {
623
- console.error('❌ Error:', event.detail);
624
- };
625
-
626
- onMounted(() => {
627
- console.log('TiaGPC disponible:', window.TiaGPC);
628
- });
629
- </script>
630
- ```
631
-
632
- ---
633
-
634
- ### 6. Next.js
635
-
636
- #### Instalación
637
-
638
- ```bash
639
- npm install tia-gpc-widget
640
- ```
641
-
642
- #### Uso (con Client Component)
643
-
644
- ```jsx
645
- // components/TiaWidget.jsx
646
- 'use client'; // ← Importante: Client Component
647
-
648
- import { useEffect } from 'react';
649
-
650
- export default function TiaWidget() {
651
- useEffect(() => {
652
- // Importar el widget solo en el cliente
653
- import('tia-gpc-widget/dist/tia-gpc-widget.standalone.js');
654
- }, []);
655
-
656
- return (
657
- <>
658
- {/* CSS */}
659
- <link rel="stylesheet" href="/tia-gpc-widget.standalone.css" />
660
-
661
- {/* Widget */}
662
- <tia-gpc-widget
663
- token={process.env.NEXT_PUBLIC_TIA_GPC_TOKEN}
664
- theme="auto"
665
- language="es"
666
- ></tia-gpc-widget>
667
- </>
668
- );
669
- }
670
- ```
671
-
672
- En tu página:
673
-
674
- ```jsx
675
- // app/page.jsx
676
- import TiaWidget from '@/components/TiaWidget';
677
-
678
- export default function Home() {
679
- return (
680
- <main>
681
- <h1>Mi App Next.js</h1>
682
- <TiaWidget />
683
- </main>
684
- );
685
- }
686
- ```
687
-
688
- ---
689
-
690
- ### 7. PHP
691
-
692
- ```php
693
- <!DOCTYPE html>
694
- <html lang="es">
695
- <head>
696
- <meta charset="UTF-8">
697
- <title>TIA GPC Widget - PHP</title>
698
- <link rel="stylesheet" href="/assets/tia-gpc-widget.standalone.css">
699
- </head>
700
- <body>
701
- <h1>Mi Aplicación PHP</h1>
702
-
703
- <?php
704
- // Obtener token desde variables de entorno o config
705
- $tiaGpcToken = getenv('TIA_GPC_TOKEN') ?: 'tu-license-token';
706
- $userLanguage = $_SESSION['user_language'] ?? 'es';
707
- ?>
708
-
709
- <!-- Widget TIA GPC -->
710
- <tia-gpc-widget
711
- token="<?php echo htmlspecialchars($tiaGpcToken); ?>"
712
- theme="auto"
713
- position="bottom-right"
714
- language="<?php echo htmlspecialchars($userLanguage); ?>"
715
- ></tia-gpc-widget>
716
-
717
- <script src="/assets/tia-gpc-widget.standalone.js"></script>
718
- </body>
719
- </html>
720
- ```
721
-
722
- ---
723
-
724
- ## 🎛️ API y Configuración
725
-
726
- ### Props/Atributos
727
-
728
- Todos los frameworks soportan los mismos atributos:
729
-
730
- | Atributo | Tipo | Por Defecto | Descripción |
731
- |----------|------|-------------|-------------|
732
- | `token` | `string` | **Requerido** | Token de licencia de TIA GPC |
733
- | `theme` | `'auto' \| 'light' \| 'dark'` | `'auto'` | Tema del widget |
734
- | `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` | Posición en la pantalla |
735
- | `language` | `'es' \| 'en' \| 'fr'` | `'es'` | Idioma del widget |
736
- | `primary-color` | `string` | `'#2563eb'` | Color primario (hexadecimal) |
737
- | `width` | `string` | `'400px'` | Ancho del widget |
738
- | `height` | `string` | `'600px'` | Alto del widget |
739
- | `api-url` | `string` | API por defecto | URL de la API personalizada |
740
- | `turnstile-site-key` | `string` | - | Clave del sitio Cloudflare Turnstile |
741
- | `auto-open` | `boolean` | `false` | Abrir automáticamente al cargar |
742
- | `show-branding` | `boolean` | `true` | Mostrar marca de TIA GPC |
743
- | `mobile-fullscreen` | `boolean` | `true` | Pantalla completa en móviles |
744
-
745
- ### Eventos
746
-
747
- | Evento | Descripción | Payload |
748
- |--------|-------------|---------|
749
- | `ready` | Se dispara cuando el widget está listo | - |
750
- | `error` | Se dispara cuando ocurre un error | `{ detail: ErrorObject }` |
751
- | `close` | Se dispara cuando el widget se cierra | - |
752
-
753
- #### Ejemplo de uso de eventos
754
-
755
- ```html
756
- <script>
757
- const widget = document.querySelector('tia-gpc-widget');
758
-
759
- widget.addEventListener('ready', () => {
760
- console.log('Widget listo');
761
- });
762
-
763
- widget.addEventListener('error', (e) => {
764
- console.error('Error:', e.detail);
765
- // Enviar a sistema de logging
766
- });
767
-
768
- widget.addEventListener('close', () => {
769
- console.log('Usuario cerró el widget');
770
- // Analytics o tracking
771
- });
772
- </script>
773
- ```
774
-
775
- ### API Programática (JavaScript)
776
-
777
- El widget expone una API global `TiaGPC` para control programático:
778
-
779
- ```javascript
780
- // Crear widget programáticamente
781
- const widget = TiaGPC.create({
782
- token: 'tu-token',
783
- theme: 'dark',
784
- language: 'en',
785
- position: TiaGPC.POSITIONS.BOTTOM_LEFT,
786
- onReady: () => console.log('Listo'),
787
- onError: (err) => console.error(err)
788
- });
789
-
790
- // Abrir el widget
791
- widget.open();
792
-
793
- // Cerrar el widget
794
- widget.close();
795
-
796
- // Ver información
797
- TiaGPC.info();
798
-
799
- // Constantes disponibles
800
- console.log(TiaGPC.POSITIONS); // { BOTTOM_RIGHT, BOTTOM_LEFT, ... }
801
- console.log(TiaGPC.THEMES); // { AUTO, LIGHT, DARK }
802
- console.log(TiaGPC.LANGUAGES); // { ES, EN, FR }
803
- ```
804
-
805
- ---
806
-
807
- ## 🎨 Personalización
808
-
809
- ### Temas
810
-
811
- ```html
812
- <!-- Automático (sigue preferencias del sistema) -->
813
- <tia-gpc-widget theme="auto"></tia-gpc-widget>
814
-
815
- <!-- Claro -->
816
- <tia-gpc-widget theme="light"></tia-gpc-widget>
817
-
818
- <!-- Oscuro -->
819
- <tia-gpc-widget theme="dark"></tia-gpc-widget>
820
- ```
821
-
822
- ### Posiciones
823
-
824
- ```html
825
- <!-- Esquina inferior derecha (por defecto) -->
826
- <tia-gpc-widget position="bottom-right"></tia-gpc-widget>
827
-
828
- <!-- Esquina inferior izquierda -->
829
- <tia-gpc-widget position="bottom-left"></tia-gpc-widget>
830
-
831
- <!-- Esquina superior derecha -->
832
- <tia-gpc-widget position="top-right"></tia-gpc-widget>
833
-
834
- <!-- Esquina superior izquierda -->
835
- <tia-gpc-widget position="top-left"></tia-gpc-widget>
836
- ```
837
-
838
- ### Idiomas
839
-
840
- ```html
841
- <!-- Español -->
842
- <tia-gpc-widget language="es"></tia-gpc-widget>
843
-
844
- <!-- Inglés -->
845
- <tia-gpc-widget language="en"></tia-gpc-widget>
846
-
847
- <!-- Francés -->
848
- <tia-gpc-widget language="fr"></tia-gpc-widget>
849
- ```
850
-
851
- ### Colores
852
-
853
- ```html
854
- <!-- Color personalizado -->
855
- <tia-gpc-widget
856
- primary-color="#10b981"
857
- ></tia-gpc-widget>
858
-
859
- <!-- Azul (por defecto) -->
860
- <tia-gpc-widget primary-color="#2563eb"></tia-gpc-widget>
861
-
862
- <!-- Verde -->
863
- <tia-gpc-widget primary-color="#16a34a"></tia-gpc-widget>
864
-
865
- <!-- Morado -->
866
- <tia-gpc-widget primary-color="#9333ea"></tia-gpc-widget>
867
- ```
868
-
869
- ---
870
-
871
- ## 🛠️ Build y Desarrollo
872
-
873
- ### Scripts disponibles
874
-
875
- ```bash
876
- # Desarrollo (modo dev con hot reload)
877
- npm run dev
878
-
879
- # Build completo (NPM + Standalone)
880
- npm run build
881
-
882
- # Build solo para NPM (sin React incluido)
883
- npm run build:npm
884
-
885
- # Build Standalone (con React incluido)
886
- npm run build:standalone
887
-
888
- # Lint
889
- npm run lint
890
-
891
- # Preview
892
- npm run preview
893
- ```
894
-
895
- ### Estructura de archivos generados
896
-
897
- ```
898
- dist/
899
- ├── tia-gpc.es.js # Build ESM para NPM
900
- ├── tia-gpc.cjs.js # Build CommonJS para NPM
901
- ├── tia-gpc.css # CSS para build NPM
902
- ├── tia-gpc-widget.standalone.js # Build standalone (IIFE con React)
903
- └── tia-gpc-widget.standalone.css # CSS para standalone
904
- ```
905
-
906
- ### ¿Cuál archivo usar?
907
-
908
- | Entorno | Archivo a usar |
909
- |---------|----------------|
910
- | React, Vue (con build system) | `tia-gpc.es.js` + `tia-gpc.css` |
911
- | Node.js CommonJS | `tia-gpc.cjs.js` + `tia-gpc.css` |
912
- | HTML puro, Angular, ASP.NET, PHP | `tia-gpc-widget.standalone.js` + `tia-gpc-widget.standalone.css` |
913
-
914
- ---
915
-
916
- ## 📤 Publicación
917
-
918
- ### Publicar en NPM (Público)
919
-
920
- ```bash
921
- # 1. Login en NPM
922
- npm login
923
-
924
- # 2. Construir el proyecto
925
- npm run build
926
-
927
- # 3. Publicar
928
- npm publish
929
- ```
930
-
931
- ### Publicar en NPM Privado / GitLab Package Registry
932
-
933
- #### Configurar `.npmrc`
934
-
935
- Crea un archivo `.npmrc` en la raíz del proyecto:
936
-
937
- ```ini
938
- # Para GitLab Package Registry
939
- @tu-scope:registry=https://gitlab.com/api/v4/projects/YOUR_PROJECT_ID/packages/npm/
940
- //gitlab.com/api/v4/projects/YOUR_PROJECT_ID/packages/npm/:_authToken=${CI_JOB_TOKEN}
941
- ```
942
-
943
- #### Actualizar `package.json`
944
-
945
- ```json
946
- {
947
- "name": "@tu-scope/tia-gpc-widget",
948
- "publishConfig": {
949
- "@tu-scope:registry": "https://gitlab.com/api/v4/projects/YOUR_PROJECT_ID/packages/npm/"
950
- }
951
- }
952
- ```
953
-
954
- #### Publicar
955
-
956
- ```bash
957
- npm run build
958
- npm publish
959
- ```
960
-
961
- ### Publicar en CDN
962
-
963
- 1. Hacer build del proyecto:
964
- ```bash
965
- npm run build
966
- ```
967
-
968
- 2. Subir archivos al CDN:
969
- ```
970
- dist/tia-gpc-widget.standalone.js → https://cdn.tu-dominio.com/tia-gpc-widget.standalone.js
971
- dist/tia-gpc-widget.standalone.css → https://cdn.tu-dominio.com/tia-gpc-widget.standalone.css
972
- ```
973
-
974
- 3. Usuarios pueden incluir directamente:
975
- ```html
976
- <script src="https://cdn.tu-dominio.com/tia-gpc-widget.standalone.js"></script>
977
- <link rel="stylesheet" href="https://cdn.tu-dominio.com/tia-gpc-widget.standalone.css">
978
- ```
979
-
980
- ### Distribución Manual
981
-
982
- Copia los archivos del `dist/` a tu servidor web:
983
-
984
- ```bash
985
- # Copiar archivos standalone al servidor
986
- cp dist/tia-gpc-widget.standalone.* /var/www/html/assets/
987
- ```
988
-
989
- ---
990
-
991
- ## 🔐 Obtener Token de Licencia
992
-
993
- Para usar este widget necesitas un token de licencia de TIA GPC. Contacta con el equipo de TIA para obtener tu token:
994
-
995
- - **Email**: soporte@tia.com
996
- - **Web**: https://tia.com/gpc
997
-
998
- ---
999
-
1000
- ## 📊 Tamaño de los Bundles
1001
-
1002
- | Archivo | Tamaño (gzip) | Descripción |
1003
- |---------|---------------|-------------|
1004
- | `tia-gpc.es.js` | ~45 KB | Build NPM (sin React) |
1005
- | `tia-gpc-widget.standalone.js` | ~180 KB | Build standalone (con React) |
1006
- | `*.css` | ~15 KB | Estilos |
1007
-
1008
- El bundle standalone es más grande porque incluye React y todas las dependencias.
1009
-
1010
- ---
1011
-
1012
- ## 🐛 Troubleshooting
1013
-
1014
- ### El widget no aparece
1015
-
1016
- 1. Verifica que incluiste ambos archivos (JS y CSS)
1017
- 2. Revisa la consola del navegador para errores
1018
- 3. Asegúrate de que el token es válido
1019
-
1020
- ### Error: "customElements.define() called with incorrect arguments"
1021
-
1022
- - En Angular: Agrega `CUSTOM_ELEMENTS_SCHEMA` a tu módulo
1023
- - En Vue: Configura `isCustomElement` en el compiler options
1024
-
1025
- ### Conflictos de CSS
1026
-
1027
- El widget usa prefijos `gpc-` en todas las clases para evitar conflictos. Si aún hay problemas, puedes aumentar la especificidad:
1028
-
1029
- ```css
1030
- .tu-contenedor tia-gpc-widget {
1031
- /* tus estilos personalizados */
1032
- }
1033
- ```
1034
-
1035
- ### React no está definido (en build standalone)
1036
-
1037
- Si ves este error, asegúrate de estar usando el archivo `standalone.js` y no el build NPM regular.
1038
-
1039
- ---
1040
-
1041
- ## 📝 Licencia
1042
-
1043
- UNLICENSED - Uso interno de TIA
1044
-
1045
- ---
1046
-
1047
- ## 👥 Soporte
1048
-
1049
- Para soporte técnico:
1050
-
1051
- - **Email**: soporte@tia.com
1052
- - **GitLab Issues**: https://gitlab.com/softia/tiagpc-frontend/issues
1053
- - **Documentación**: Este README
1054
-
1055
- ---
1056
-
1057
- ## 🚀 Changelog
1058
-
1059
- ### v1.0.0 (2025-01-10)
1060
-
1061
- - ✨ Versión inicial
1062
- - Soporte para React
1063
- - ✅ Build standalone para HTML/Angular/ASP.NET
1064
- - Web Component API
1065
- - ✅ Temas claro/oscuro
1066
- - Internacionalización (ES/EN/FR)
1067
- - Personalización completa
1068
-
1069
- ---
1070
-
1071
- **Desarrollado con ❤️ por el equipo de TIA**
1
+ # TIA GPC Widget
2
+
3
+ Intelligent chat widget for TIA GPC integration. Compatible with **React, HTML, Angular, ASP.NET, Vue, and any other framework**.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/tia-gpc-widget.svg)](https://www.npmjs.com/package/tia-gpc-widget)
6
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tia-gpc-widget/badge)](https://www.jsdelivr.com/package/npm/tia-gpc-widget)
7
+ [![License](https://img.shields.io/badge/license-UNLICENSED-red.svg)](LICENSE)
8
+
9
+ ---
10
+
11
+ ## 📋 Table of Contents
12
+
13
+ - [Features](#-features)
14
+ - [Installation](#-installation)
15
+ - [Option 1: NPM (For React/Node Projects)](#option-1-npm-for-reactnode-projects)
16
+ - [Option 2: CDN (For HTML, Angular, ASP.NET, etc.)](#option-2-cdn-for-html-angular-aspnet-etc)
17
+ - [Quick Start](#-quick-start)
18
+ - [Framework Examples](#-framework-examples)
19
+ - [React](#1-react)
20
+ - [HTML / Vanilla JavaScript](#2-html--vanilla-javascript)
21
+ - [Angular](#3-angular)
22
+ - [ASP.NET / ASPX](#4-aspnet--aspx)
23
+ - [Vue.js](#5-vuejs)
24
+ - [Next.js](#6-nextjs)
25
+ - [PHP](#7-php)
26
+ - [API & Configuration](#-api--configuration)
27
+ - [Props/Attributes](#propsattributes)
28
+ - [Events](#events)
29
+ - [Programmatic API (JavaScript)](#programmatic-api-javascript)
30
+ - [Customization](#-customization)
31
+ - [Themes](#themes)
32
+ - [Positions](#positions)
33
+ - [Languages](#languages)
34
+ - [Colors](#colors)
35
+ - [Build & Development](#-build--development)
36
+ - [Publishing](#-publishing)
37
+ - [Support](#-support)
38
+
39
+ ---
40
+
41
+ ## 🚀 Features
42
+
43
+ - ✅ **Framework Agnostic**: Works in React, Angular, Vue, ASP.NET, plain HTML, etc.
44
+ - ✅ **Web Component**: Based on native web standards
45
+ - ✅ **Themes**: Light, dark, or automatic mode
46
+ - ✅ **Internationalization**: Spanish, English, French
47
+ - ✅ **Responsive**: Adaptive design for mobile and desktop
48
+ - ✅ **Customizable**: Colors, positions, dimensions
49
+ - ✅ **TypeScript Ready**: Types included
50
+ - ✅ **Zero Dependencies**: Standalone bundle includes everything needed
51
+
52
+ ---
53
+
54
+ ## 📦 Installation
55
+
56
+ ### Option 1: NPM (For React/Node Projects)
57
+
58
+ ```bash
59
+ npm install tia-gpc-widget
60
+ ```
61
+
62
+ or with yarn:
63
+
64
+ ```bash
65
+ yarn add tia-gpc-widget
66
+ ```
67
+
68
+ or with pnpm:
69
+
70
+ ```bash
71
+ pnpm add tia-gpc-widget
72
+ ```
73
+
74
+ ### Option 2: CDN (For HTML, Angular, ASP.NET, etc.)
75
+
76
+ You can include the widget directly from a CDN:
77
+
78
+ #### jsDelivr (Recommended)
79
+
80
+ ```html
81
+ <!-- JavaScript -->
82
+ <script src="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.js"></script>
83
+
84
+ <!-- CSS -->
85
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.css">
86
+ ```
87
+
88
+ #### unpkg
89
+
90
+ ```html
91
+ <!-- JavaScript -->
92
+ <script src="https://unpkg.com/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.js"></script>
93
+
94
+ <!-- CSS -->
95
+ <link rel="stylesheet" href="https://unpkg.com/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.css">
96
+ ```
97
+
98
+ #### Latest Version (Development Only)
99
+
100
+ ```html
101
+ <!-- Always use specific versions in production! -->
102
+ <script src="https://cdn.jsdelivr.net/npm/tia-gpc-widget/dist/tia-gpc-widget.standalone.js"></script>
103
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tia-gpc-widget/dist/tia-gpc-widget.standalone.css">
104
+ ```
105
+
106
+ ---
107
+
108
+ ## ⚡ Quick Start
109
+
110
+ ### In Plain HTML
111
+
112
+ ```html
113
+ <!DOCTYPE html>
114
+ <html lang="en">
115
+ <head>
116
+ <meta charset="UTF-8">
117
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
118
+ <title>My App with TIA GPC</title>
119
+
120
+ <!-- Widget CSS -->
121
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.css">
122
+ </head>
123
+ <body>
124
+ <h1>My Application</h1>
125
+
126
+ <!-- TIA GPC Widget -->
127
+ <tia-gpc-widget
128
+ token="your-license-token-here"
129
+ theme="auto"
130
+ position="bottom-right"
131
+ language="en"
132
+ ></tia-gpc-widget>
133
+
134
+ <!-- Widget JavaScript -->
135
+ <script src="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.js"></script>
136
+ </body>
137
+ </html>
138
+ ```
139
+
140
+ ### In React
141
+
142
+ ```jsx
143
+ import { TiaGPCWidget } from 'tia-gpc-widget';
144
+ import 'tia-gpc-widget/styles';
145
+
146
+ function App() {
147
+ return (
148
+ <div>
149
+ <h1>My Application</h1>
150
+ <TiaGPCWidget
151
+ token="your-license-token-here"
152
+ theme="auto"
153
+ position="bottom-right"
154
+ language="en"
155
+ />
156
+ </div>
157
+ );
158
+ }
159
+
160
+ export default App;
161
+ ```
162
+
163
+ ---
164
+
165
+ ## 📚 Framework Examples
166
+
167
+ ### 1. React
168
+
169
+ #### Installation
170
+
171
+ ```bash
172
+ npm install tia-gpc-widget
173
+ ```
174
+
175
+ #### Basic Usage
176
+
177
+ ```jsx
178
+ import { TiaGPCWidget } from 'tia-gpc-widget';
179
+ import 'tia-gpc-widget/styles';
180
+
181
+ function App() {
182
+ return (
183
+ <TiaGPCWidget
184
+ token="your-license-token"
185
+ theme="auto"
186
+ position="bottom-right"
187
+ language="en"
188
+ primaryColor="#2563eb"
189
+ onReady={() => console.log('Widget ready')}
190
+ onError={(error) => console.error('Error:', error)}
191
+ />
192
+ );
193
+ }
194
+ ```
195
+
196
+ #### Advanced Configuration
197
+
198
+ ```jsx
199
+ import { TiaGPCWidget, WIDGET_POSITIONS, THEMES, LANGUAGES } from 'tia-gpc-widget';
200
+ import 'tia-gpc-widget/styles';
201
+
202
+ function App() {
203
+ const handleReady = () => {
204
+ console.log('✅ Widget initialized successfully');
205
+ };
206
+
207
+ const handleError = (error) => {
208
+ console.error('❌ Widget error:', error);
209
+ };
210
+
211
+ return (
212
+ <TiaGPCWidget
213
+ token="your-license-token"
214
+ theme={THEMES.AUTO}
215
+ position={WIDGET_POSITIONS.BOTTOM_RIGHT}
216
+ language={LANGUAGES.EN}
217
+ primaryColor="#10b981"
218
+ width="450px"
219
+ height="650px"
220
+ autoOpen={false}
221
+ showBranding={true}
222
+ mobileFullscreen={true}
223
+ onReady={handleReady}
224
+ onError={handleError}
225
+ onClose={() => console.log('Widget closed')}
226
+ />
227
+ );
228
+ }
229
+ ```
230
+
231
+ ---
232
+
233
+ ### 2. HTML / Vanilla JavaScript
234
+
235
+ #### Method 1: Using HTML element directly
236
+
237
+ ```html
238
+ <!DOCTYPE html>
239
+ <html lang="en">
240
+ <head>
241
+ <meta charset="UTF-8">
242
+ <title>TIA GPC Widget - Plain HTML</title>
243
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.css">
244
+ </head>
245
+ <body>
246
+ <h1>My Website</h1>
247
+
248
+ <!-- Widget as HTML element -->
249
+ <tia-gpc-widget
250
+ token="your-license-token"
251
+ theme="light"
252
+ position="bottom-right"
253
+ language="en"
254
+ primary-color="#3b82f6"
255
+ width="400px"
256
+ height="600px"
257
+ auto-open="false"
258
+ show-branding="true"
259
+ ></tia-gpc-widget>
260
+
261
+ <script src="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.js"></script>
262
+
263
+ <!-- Optional events -->
264
+ <script>
265
+ const widget = document.querySelector('tia-gpc-widget');
266
+
267
+ widget.addEventListener('ready', () => {
268
+ console.log('Widget ready');
269
+ });
270
+
271
+ widget.addEventListener('error', (e) => {
272
+ console.error('Error:', e.detail);
273
+ });
274
+
275
+ widget.addEventListener('close', () => {
276
+ console.log('Widget closed');
277
+ });
278
+ </script>
279
+ </body>
280
+ </html>
281
+ ```
282
+
283
+ #### Method 2: Programmatic creation with JavaScript
284
+
285
+ ```html
286
+ <!DOCTYPE html>
287
+ <html lang="en">
288
+ <head>
289
+ <meta charset="UTF-8">
290
+ <title>TIA GPC Widget - Programmatic</title>
291
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.css">
292
+ </head>
293
+ <body>
294
+ <h1>My Website</h1>
295
+ <button id="create-widget">Create Widget</button>
296
+
297
+ <script src="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.js"></script>
298
+ <script>
299
+ document.getElementById('create-widget').addEventListener('click', () => {
300
+ // Use the global TiaGPC API
301
+ const widget = TiaGPC.create({
302
+ token: 'your-license-token',
303
+ theme: 'auto',
304
+ position: TiaGPC.POSITIONS.BOTTOM_RIGHT,
305
+ language: TiaGPC.LANGUAGES.EN,
306
+ primaryColor: '#3b82f6',
307
+ autoOpen: false,
308
+ onReady: () => console.log('✅ Widget ready'),
309
+ onError: (error) => console.error('❌ Error:', error),
310
+ onClose: () => console.log('Widget closed')
311
+ });
312
+
313
+ console.log('Widget created:', widget);
314
+ });
315
+
316
+ // View widget information
317
+ TiaGPC.info();
318
+ </script>
319
+ </body>
320
+ </html>
321
+ ```
322
+
323
+ ---
324
+
325
+ ### 3. Angular
326
+
327
+ #### Step 1: Install the widget
328
+
329
+ ```bash
330
+ npm install tia-gpc-widget
331
+ ```
332
+
333
+ #### Step 2: Configure Angular for Web Components
334
+
335
+ In `src/main.ts` or `src/polyfills.ts`, add:
336
+
337
+ ```typescript
338
+ // Enable Custom Elements (Web Components)
339
+ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
340
+ ```
341
+
342
+ In your main module (`app.module.ts`):
343
+
344
+ ```typescript
345
+ import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
346
+ import { BrowserModule } from '@angular/platform-browser';
347
+ import { AppComponent } from './app.component';
348
+
349
+ @NgModule({
350
+ declarations: [AppComponent],
351
+ imports: [BrowserModule],
352
+ schemas: [CUSTOM_ELEMENTS_SCHEMA], // ← Important
353
+ bootstrap: [AppComponent]
354
+ })
355
+ export class AppModule { }
356
+ ```
357
+
358
+ #### Step 3: Import widget files
359
+
360
+ In `angular.json`, add the CSS and JS files:
361
+
362
+ ```json
363
+ {
364
+ "projects": {
365
+ "your-project": {
366
+ "architect": {
367
+ "build": {
368
+ "options": {
369
+ "styles": [
370
+ "src/styles.css",
371
+ "node_modules/tia-gpc-widget/dist/tia-gpc-widget.standalone.css"
372
+ ],
373
+ "scripts": [
374
+ "node_modules/tia-gpc-widget/dist/tia-gpc-widget.standalone.js"
375
+ ]
376
+ }
377
+ }
378
+ }
379
+ }
380
+ }
381
+ }
382
+ ```
383
+
384
+ #### Step 4: Use the widget in your component
385
+
386
+ ```typescript
387
+ // app.component.ts
388
+ import { Component, OnInit } from '@angular/core';
389
+
390
+ declare global {
391
+ interface Window {
392
+ TiaGPC: any;
393
+ }
394
+ }
395
+
396
+ @Component({
397
+ selector: 'app-root',
398
+ template: `
399
+ <h1>My Angular Application</h1>
400
+
401
+ <!-- Option 1: Direct HTML element -->
402
+ <tia-gpc-widget
403
+ [attr.token]="widgetToken"
404
+ [attr.theme]="theme"
405
+ [attr.position]="position"
406
+ [attr.language]="language"
407
+ (ready)="onWidgetReady()"
408
+ (error)="onWidgetError($event)"
409
+ ></tia-gpc-widget>
410
+ `
411
+ })
412
+ export class AppComponent implements OnInit {
413
+ widgetToken = 'your-license-token';
414
+ theme = 'auto';
415
+ position = 'bottom-right';
416
+ language = 'en';
417
+
418
+ ngOnInit() {
419
+ console.log('TiaGPC available:', window.TiaGPC);
420
+ }
421
+
422
+ onWidgetReady() {
423
+ console.log('✅ TIA GPC widget ready');
424
+ }
425
+
426
+ onWidgetError(event: any) {
427
+ console.error('❌ Widget error:', event.detail);
428
+ }
429
+ }
430
+ ```
431
+
432
+ #### Alternative option: Programmatic creation
433
+
434
+ ```typescript
435
+ // app.component.ts
436
+ import { Component, OnInit } from '@angular/core';
437
+
438
+ @Component({
439
+ selector: 'app-root',
440
+ template: `
441
+ <h1>My Angular Application</h1>
442
+ <button (click)="createWidget()">Create Widget</button>
443
+ <div #widgetContainer></div>
444
+ `
445
+ })
446
+ export class AppComponent implements OnInit {
447
+ ngOnInit() {
448
+ this.createWidget();
449
+ }
450
+
451
+ createWidget() {
452
+ if (window.TiaGPC) {
453
+ window.TiaGPC.create({
454
+ token: 'your-license-token',
455
+ theme: 'auto',
456
+ language: 'en',
457
+ onReady: () => console.log('Widget ready'),
458
+ onError: (err: any) => console.error(err)
459
+ });
460
+ }
461
+ }
462
+ }
463
+ ```
464
+
465
+ ---
466
+
467
+ ### 4. ASP.NET / ASPX
468
+
469
+ #### Option 1: In an ASPX page
470
+
471
+ ```aspx
472
+ <%@ Page Language="C#" AutoEventWireup="true" %>
473
+
474
+ <!DOCTYPE html>
475
+ <html>
476
+ <head>
477
+ <title>TIA GPC Widget - ASP.NET</title>
478
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.css" />
479
+ </head>
480
+ <body>
481
+ <form id="form1" runat="server">
482
+ <h1>My ASP.NET Application</h1>
483
+
484
+ <!-- TIA GPC Widget -->
485
+ <tia-gpc-widget
486
+ token="<%= ConfigurationManager.AppSettings["TiaGpcToken"] %>"
487
+ theme="auto"
488
+ position="bottom-right"
489
+ language="en"
490
+ primary-color="#2563eb"
491
+ ></tia-gpc-widget>
492
+ </form>
493
+
494
+ <script src="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.js"></script>
495
+ <script>
496
+ // Optional events
497
+ document.querySelector('tia-gpc-widget').addEventListener('ready', function() {
498
+ console.log('TIA GPC Widget initialized');
499
+ });
500
+ </script>
501
+ </body>
502
+ </html>
503
+ ```
504
+
505
+ #### Option 2: With Master Page
506
+
507
+ In your `Site.Master`:
508
+
509
+ ```aspx
510
+ <head runat="server">
511
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.css" />
512
+ </head>
513
+ <body>
514
+ <asp:ContentPlaceHolder ID="MainContent" runat="server">
515
+ </asp:ContentPlaceHolder>
516
+
517
+ <!-- Global widget -->
518
+ <tia-gpc-widget
519
+ token="<%= GetTiaGpcToken() %>"
520
+ theme="auto"
521
+ language="en"
522
+ ></tia-gpc-widget>
523
+
524
+ <script src="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.js"></script>
525
+ </body>
526
+ ```
527
+
528
+ In your `Site.Master.cs`:
529
+
530
+ ```csharp
531
+ public partial class SiteMaster : MasterPage
532
+ {
533
+ protected string GetTiaGpcToken()
534
+ {
535
+ return ConfigurationManager.AppSettings["TiaGpcToken"];
536
+ }
537
+ }
538
+ ```
539
+
540
+ #### Option 3: MVC / Razor
541
+
542
+ In your layout `_Layout.cshtml`:
543
+
544
+ ```html
545
+ <!DOCTYPE html>
546
+ <html>
547
+ <head>
548
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.css" />
549
+ </head>
550
+ <body>
551
+ @RenderBody()
552
+
553
+ <!-- TIA GPC Widget -->
554
+ <tia-gpc-widget
555
+ token="@ViewBag.TiaGpcToken"
556
+ theme="auto"
557
+ language="en"
558
+ ></tia-gpc-widget>
559
+
560
+ <script src="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.js"></script>
561
+ </body>
562
+ </html>
563
+ ```
564
+
565
+ In your `Controller`:
566
+
567
+ ```csharp
568
+ public class HomeController : Controller
569
+ {
570
+ public ActionResult Index()
571
+ {
572
+ ViewBag.TiaGpcToken = ConfigurationManager.AppSettings["TiaGpcToken"];
573
+ return View();
574
+ }
575
+ }
576
+ ```
577
+
578
+ ---
579
+
580
+ ### 5. Vue.js
581
+
582
+ #### Installation
583
+
584
+ ```bash
585
+ npm install tia-gpc-widget
586
+ ```
587
+
588
+ #### Configuration
589
+
590
+ In `main.js` or `main.ts`:
591
+
592
+ ```javascript
593
+ import { createApp } from 'vue';
594
+ import App from './App.vue';
595
+
596
+ // Import the standalone widget
597
+ import 'tia-gpc-widget/dist/tia-gpc-widget.standalone.js';
598
+ import 'tia-gpc-widget/dist/tia-gpc-widget.standalone.css';
599
+
600
+ const app = createApp(App);
601
+
602
+ // Configure Vue to ignore custom elements
603
+ app.config.compilerOptions.isCustomElement = (tag) => tag === 'tia-gpc-widget';
604
+
605
+ app.mount('#app');
606
+ ```
607
+
608
+ #### Usage in components
609
+
610
+ ```vue
611
+ <template>
612
+ <div>
613
+ <h1>My Vue Application</h1>
614
+
615
+ <!-- TIA GPC Widget -->
616
+ <tia-gpc-widget
617
+ :token="widgetToken"
618
+ :theme="theme"
619
+ :language="language"
620
+ position="bottom-right"
621
+ @ready="onReady"
622
+ @error="onError"
623
+ ></tia-gpc-widget>
624
+ </div>
625
+ </template>
626
+
627
+ <script setup>
628
+ import { ref, onMounted } from 'vue';
629
+
630
+ const widgetToken = ref('your-license-token');
631
+ const theme = ref('auto');
632
+ const language = ref('en');
633
+
634
+ const onReady = () => {
635
+ console.log('✅ TIA GPC Widget ready');
636
+ };
637
+
638
+ const onError = (event) => {
639
+ console.error('❌ Error:', event.detail);
640
+ };
641
+
642
+ onMounted(() => {
643
+ console.log('TiaGPC available:', window.TiaGPC);
644
+ });
645
+ </script>
646
+ ```
647
+
648
+ ---
649
+
650
+ ### 6. Next.js
651
+
652
+ #### Installation
653
+
654
+ ```bash
655
+ npm install tia-gpc-widget
656
+ ```
657
+
658
+ #### Usage (with Client Component)
659
+
660
+ ```jsx
661
+ // components/TiaWidget.jsx
662
+ 'use client'; // ← Important: Client Component
663
+
664
+ import { useEffect } from 'react';
665
+
666
+ export default function TiaWidget() {
667
+ useEffect(() => {
668
+ // Import widget only on client side
669
+ import('tia-gpc-widget/dist/tia-gpc-widget.standalone.js');
670
+ }, []);
671
+
672
+ return (
673
+ <>
674
+ {/* CSS */}
675
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.css" />
676
+
677
+ {/* Widget */}
678
+ <tia-gpc-widget
679
+ token={process.env.NEXT_PUBLIC_TIA_GPC_TOKEN}
680
+ theme="auto"
681
+ language="en"
682
+ ></tia-gpc-widget>
683
+ </>
684
+ );
685
+ }
686
+ ```
687
+
688
+ In your page:
689
+
690
+ ```jsx
691
+ // app/page.jsx
692
+ import TiaWidget from '@/components/TiaWidget';
693
+
694
+ export default function Home() {
695
+ return (
696
+ <main>
697
+ <h1>My Next.js App</h1>
698
+ <TiaWidget />
699
+ </main>
700
+ );
701
+ }
702
+ ```
703
+
704
+ ---
705
+
706
+ ### 7. PHP
707
+
708
+ ```php
709
+ <!DOCTYPE html>
710
+ <html lang="en">
711
+ <head>
712
+ <meta charset="UTF-8">
713
+ <title>TIA GPC Widget - PHP</title>
714
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.css">
715
+ </head>
716
+ <body>
717
+ <h1>My PHP Application</h1>
718
+
719
+ <?php
720
+ // Get token from environment variables or config
721
+ $tiaGpcToken = getenv('TIA_GPC_TOKEN') ?: 'your-license-token';
722
+ $userLanguage = $_SESSION['user_language'] ?? 'en';
723
+ ?>
724
+
725
+ <!-- TIA GPC Widget -->
726
+ <tia-gpc-widget
727
+ token="<?php echo htmlspecialchars($tiaGpcToken); ?>"
728
+ theme="auto"
729
+ position="bottom-right"
730
+ language="<?php echo htmlspecialchars($userLanguage); ?>"
731
+ ></tia-gpc-widget>
732
+
733
+ <script src="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.js"></script>
734
+ </body>
735
+ </html>
736
+ ```
737
+
738
+ ---
739
+
740
+ ## 🎛️ API & Configuration
741
+
742
+ ### Props/Attributes
743
+
744
+ All frameworks support the same attributes:
745
+
746
+ | Attribute | Type | Default | Description |
747
+ |----------|------|-------------|-------------|
748
+ | `token` | `string` | **Required** | TIA GPC license token |
749
+ | `theme` | `'auto' \| 'light' \| 'dark'` | `'auto'` | Widget theme |
750
+ | `position` | `'bottom-right' \| 'bottom-left' \| 'top-right' \| 'top-left'` | `'bottom-right'` | Screen position |
751
+ | `language` | `'es' \| 'en' \| 'fr'` | `'es'` | Widget language |
752
+ | `primary-color` | `string` | `'#2563eb'` | Primary color (hexadecimal) |
753
+ | `width` | `string` | `'400px'` | Widget width |
754
+ | `height` | `string` | `'600px'` | Widget height |
755
+ | `api-url` | `string` | Default API | Custom API URL |
756
+ | `turnstile-site-key` | `string` | - | Cloudflare Turnstile site key |
757
+ | `auto-open` | `boolean` | `false` | Auto-open on load |
758
+ | `show-branding` | `boolean` | `true` | Show TIA GPC branding |
759
+ | `mobile-fullscreen` | `boolean` | `true` | Fullscreen on mobile |
760
+
761
+ ### Events
762
+
763
+ | Event | Description | Payload |
764
+ |--------|-------------|---------|
765
+ | `ready` | Fired when widget is ready | - |
766
+ | `error` | Fired when an error occurs | `{ detail: ErrorObject }` |
767
+ | `close` | Fired when widget closes | - |
768
+
769
+ #### Event usage example
770
+
771
+ ```html
772
+ <script>
773
+ const widget = document.querySelector('tia-gpc-widget');
774
+
775
+ widget.addEventListener('ready', () => {
776
+ console.log('Widget ready');
777
+ });
778
+
779
+ widget.addEventListener('error', (e) => {
780
+ console.error('Error:', e.detail);
781
+ // Send to logging system
782
+ });
783
+
784
+ widget.addEventListener('close', () => {
785
+ console.log('User closed the widget');
786
+ // Analytics or tracking
787
+ });
788
+ </script>
789
+ ```
790
+
791
+ ### Programmatic API (JavaScript)
792
+
793
+ The widget exposes a global `TiaGPC` API for programmatic control:
794
+
795
+ ```javascript
796
+ // Create widget programmatically
797
+ const widget = TiaGPC.create({
798
+ token: 'your-token',
799
+ theme: 'dark',
800
+ language: 'en',
801
+ position: TiaGPC.POSITIONS.BOTTOM_LEFT,
802
+ onReady: () => console.log('Ready'),
803
+ onError: (err) => console.error(err)
804
+ });
805
+
806
+ // Open widget
807
+ widget.open();
808
+
809
+ // Close widget
810
+ widget.close();
811
+
812
+ // View information
813
+ TiaGPC.info();
814
+
815
+ // Available constants
816
+ console.log(TiaGPC.POSITIONS); // { BOTTOM_RIGHT, BOTTOM_LEFT, ... }
817
+ console.log(TiaGPC.THEMES); // { AUTO, LIGHT, DARK }
818
+ console.log(TiaGPC.LANGUAGES); // { ES, EN, FR }
819
+ ```
820
+
821
+ ---
822
+
823
+ ## 🎨 Customization
824
+
825
+ ### Themes
826
+
827
+ ```html
828
+ <!-- Automatic (follows system preferences) -->
829
+ <tia-gpc-widget theme="auto"></tia-gpc-widget>
830
+
831
+ <!-- Light -->
832
+ <tia-gpc-widget theme="light"></tia-gpc-widget>
833
+
834
+ <!-- Dark -->
835
+ <tia-gpc-widget theme="dark"></tia-gpc-widget>
836
+ ```
837
+
838
+ ### Positions
839
+
840
+ ```html
841
+ <!-- Bottom right corner (default) -->
842
+ <tia-gpc-widget position="bottom-right"></tia-gpc-widget>
843
+
844
+ <!-- Bottom left corner -->
845
+ <tia-gpc-widget position="bottom-left"></tia-gpc-widget>
846
+
847
+ <!-- Top right corner -->
848
+ <tia-gpc-widget position="top-right"></tia-gpc-widget>
849
+
850
+ <!-- Top left corner -->
851
+ <tia-gpc-widget position="top-left"></tia-gpc-widget>
852
+ ```
853
+
854
+ ### Languages
855
+
856
+ ```html
857
+ <!-- Spanish -->
858
+ <tia-gpc-widget language="es"></tia-gpc-widget>
859
+
860
+ <!-- English -->
861
+ <tia-gpc-widget language="en"></tia-gpc-widget>
862
+
863
+ <!-- French -->
864
+ <tia-gpc-widget language="fr"></tia-gpc-widget>
865
+ ```
866
+
867
+ ### Colors
868
+
869
+ ```html
870
+ <!-- Custom color -->
871
+ <tia-gpc-widget
872
+ primary-color="#10b981"
873
+ ></tia-gpc-widget>
874
+
875
+ <!-- Blue (default) -->
876
+ <tia-gpc-widget primary-color="#2563eb"></tia-gpc-widget>
877
+
878
+ <!-- Green -->
879
+ <tia-gpc-widget primary-color="#16a34a"></tia-gpc-widget>
880
+
881
+ <!-- Purple -->
882
+ <tia-gpc-widget primary-color="#9333ea"></tia-gpc-widget>
883
+ ```
884
+
885
+ ---
886
+
887
+ ## 🛠️ Build & Development
888
+
889
+ ### Available scripts
890
+
891
+ ```bash
892
+ # Development (dev mode with hot reload)
893
+ npm run dev
894
+
895
+ # Complete build (NPM + Standalone)
896
+ npm run build
897
+
898
+ # Build only for NPM (without bundled React)
899
+ npm run build:npm
900
+
901
+ # Standalone build (with bundled React)
902
+ npm run build:standalone
903
+
904
+ # Lint
905
+ npm run lint
906
+
907
+ # Preview
908
+ npm run preview
909
+ ```
910
+
911
+ ### Generated file structure
912
+
913
+ ```
914
+ dist/
915
+ ├── tia-gpc.es.js # ESM build for NPM
916
+ ├── tia-gpc.cjs.js # CommonJS build for NPM
917
+ ├── tia-gpc.css # CSS for NPM build
918
+ ├── tia-gpc-widget.standalone.js # Standalone build (IIFE with React)
919
+ └── tia-gpc-widget.standalone.css # CSS for standalone
920
+ ```
921
+
922
+ ### Which file to use?
923
+
924
+ | Environment | File to use |
925
+ |---------|----------------|
926
+ | React, Vue (with build system) | `tia-gpc.es.js` + `tia-gpc.css` |
927
+ | Node.js CommonJS | `tia-gpc.cjs.js` + `tia-gpc.css` |
928
+ | Plain HTML, Angular, ASP.NET, PHP | `tia-gpc-widget.standalone.js` + `tia-gpc-widget.standalone.css` |
929
+
930
+ ---
931
+
932
+ ## 📤 Publishing
933
+
934
+ ### Publish to NPM (Public)
935
+
936
+ ```bash
937
+ # 1. Login to NPM
938
+ npm login
939
+
940
+ # 2. Build the project
941
+ npm run build
942
+
943
+ # 3. Publish
944
+ npm publish
945
+ ```
946
+
947
+ ### Publish to Private NPM / GitLab Package Registry
948
+
949
+ #### Configure `.npmrc`
950
+
951
+ Create an `.npmrc` file in the project root:
952
+
953
+ ```ini
954
+ # For GitLab Package Registry
955
+ @your-scope:registry=https://gitlab.com/api/v4/projects/YOUR_PROJECT_ID/packages/npm/
956
+ //gitlab.com/api/v4/projects/YOUR_PROJECT_ID/packages/npm/:_authToken=${CI_JOB_TOKEN}
957
+ ```
958
+
959
+ #### Update `package.json`
960
+
961
+ ```json
962
+ {
963
+ "name": "@your-scope/tia-gpc-widget",
964
+ "publishConfig": {
965
+ "@your-scope:registry": "https://gitlab.com/api/v4/projects/YOUR_PROJECT_ID/packages/npm/"
966
+ }
967
+ }
968
+ ```
969
+
970
+ #### Publish
971
+
972
+ ```bash
973
+ npm run build
974
+ npm publish
975
+ ```
976
+
977
+ ### CDN Distribution
978
+
979
+ After publishing to npm, your package is automatically available on these CDNs:
980
+
981
+ #### jsDelivr
982
+ ```html
983
+ <script src="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.js"></script>
984
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.css">
985
+ ```
986
+
987
+ #### unpkg
988
+ ```html
989
+ <script src="https://unpkg.com/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.js"></script>
990
+ <link rel="stylesheet" href="https://unpkg.com/tia-gpc-widget@1.0.6/dist/tia-gpc-widget.standalone.css">
991
+ ```
992
+
993
+ **Note:** CDNs may take 5-10 minutes to sync after publishing to npm.
994
+
995
+ ### Manual Distribution
996
+
997
+ Copy files from `dist/` to your web server:
998
+
999
+ ```bash
1000
+ # Copy standalone files to server
1001
+ cp dist/tia-gpc-widget.standalone.* /var/www/html/assets/
1002
+ ```
1003
+
1004
+ ---
1005
+
1006
+ ## 🔐 Getting a License Token
1007
+
1008
+ To use this widget you need a TIA GPC license token. Contact the TIA team to get your token:
1009
+
1010
+ - **Email**: support@tia.com
1011
+ - **Web**: https://tia.com/gpc
1012
+
1013
+ ---
1014
+
1015
+ ## 📊 Bundle Sizes
1016
+
1017
+ | File | Size (gzip) | Description |
1018
+ |---------|---------------|-------------|
1019
+ | `tia-gpc.es.js` | ~45 KB | NPM build (without React) |
1020
+ | `tia-gpc-widget.standalone.js` | ~180 KB | Standalone build (with React) |
1021
+ | `*.css` | ~15 KB | Styles |
1022
+
1023
+ The standalone bundle is larger because it includes React and all dependencies.
1024
+
1025
+ ---
1026
+
1027
+ ## 🐛 Troubleshooting
1028
+
1029
+ ### Widget doesn't appear
1030
+
1031
+ 1. Verify you included both files (JS and CSS)
1032
+ 2. Check browser console for errors
1033
+ 3. Make sure the token is valid
1034
+
1035
+ ### Error: "customElements.define() called with incorrect arguments"
1036
+
1037
+ - In Angular: Add `CUSTOM_ELEMENTS_SCHEMA` to your module
1038
+ - In Vue: Configure `isCustomElement` in compiler options
1039
+
1040
+ ### CSS Conflicts
1041
+
1042
+ The widget uses `gpc-` prefixes on all classes to avoid conflicts. If there are still issues, you can increase specificity:
1043
+
1044
+ ```css
1045
+ .your-container tia-gpc-widget {
1046
+ /* your custom styles */
1047
+ }
1048
+ ```
1049
+
1050
+ ### React is not defined (in standalone build)
1051
+
1052
+ If you see this error, make sure you're using the `standalone.js` file and not the regular NPM build.
1053
+
1054
+ ---
1055
+
1056
+ ## 📝 License
1057
+
1058
+ UNLICENSED - Internal use by TIA
1059
+
1060
+ ---
1061
+
1062
+ ## 👥 Support
1063
+
1064
+ For technical support:
1065
+
1066
+ - **Email**: support@tia.com
1067
+ - **GitLab Issues**: https://gitlab.com/softia/tiagpc-frontend/issues
1068
+ - **Documentation**: This README
1069
+
1070
+ ---
1071
+
1072
+ ## 🚀 Changelog
1073
+
1074
+ ### v1.0.6 (2025-01-11)
1075
+
1076
+ - ✨ Added CDN support via jsDelivr and unpkg
1077
+ - 📝 Updated documentation to English
1078
+ - 🔧 Added `unpkg` and `jsdelivr` fields to package.json
1079
+
1080
+ ### v1.0.0 (2025-01-10)
1081
+
1082
+ - ✨ Initial release
1083
+ - ✅ React support
1084
+ - ✅ Standalone build for HTML/Angular/ASP.NET
1085
+ - ✅ Web Component API
1086
+ - ✅ Light/dark themes
1087
+ - ✅ Internationalization (ES/EN/FR)
1088
+ - ✅ Full customization
1089
+
1090
+ ---
1091
+
1092
+ **Built with ❤️ by the TIA team**