@weldsuite/helpdesk-widget-sdk 1.0.15 → 1.0.16

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.
@@ -512,14 +512,16 @@ class IframeManager {
512
512
  const container = document.createElement('div');
513
513
  container.className = 'weld-launcher-frame';
514
514
  container.setAttribute('data-state', 'visible');
515
+ // Container is larger than the button to allow hover animations (scale, shadow) without clipping
516
+ const launcherPadding = 10;
515
517
  container.style.cssText = `
516
518
  position: fixed;
517
- bottom: ${launcher.position.bottom};
518
- right: ${launcher.position.right};
519
- width: ${launcher.size};
520
- height: ${launcher.size};
519
+ bottom: calc(${launcher.position.bottom} - ${launcherPadding}px);
520
+ right: calc(${launcher.position.right} - ${launcherPadding}px);
521
+ width: calc(${launcher.size} + ${launcherPadding * 2}px);
522
+ height: calc(${launcher.size} + ${launcherPadding * 2}px);
521
523
  z-index: 2147483003;
522
- pointer-events: auto;
524
+ pointer-events: none;
523
525
  display: block;
524
526
  `;
525
527
  // Create iframe
@@ -533,6 +535,7 @@ class IframeManager {
533
535
  border: none;
534
536
  background: transparent;
535
537
  display: block;
538
+ pointer-events: auto;
536
539
  `;
537
540
  iframe.setAttribute('allow', 'clipboard-write');
538
541
  iframe.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-forms allow-popups');
@@ -653,43 +656,10 @@ class IframeManager {
653
656
  this.logger.debug('Widget iframe created');
654
657
  }
655
658
  /**
656
- * Create backdrop iframe
659
+ * Create backdrop iframe — disabled, widget stays non-modal so users can interact with the page
657
660
  */
658
661
  async createBackdropIframe() {
659
- if (!this.config.iframes.backdrop?.enabled) {
660
- this.logger.debug('Backdrop disabled, skipping creation');
661
- return;
662
- }
663
- // Create container
664
- const container = document.createElement('div');
665
- container.className = 'weld-backdrop-frame';
666
- container.setAttribute('data-state', 'hidden');
667
- container.style.cssText = `
668
- position: fixed;
669
- top: 0;
670
- left: 0;
671
- right: 0;
672
- bottom: 0;
673
- z-index: 2147483000;
674
- background: transparent;
675
- pointer-events: none;
676
- opacity: 0;
677
- transition: opacity 200ms ease;
678
- `;
679
- this.appContainer?.appendChild(container);
680
- // Store metadata (backdrop doesn't have an iframe, just a div)
681
- // We'll create a minimal "iframe" reference for consistency
682
- const dummyIframe = document.createElement('iframe');
683
- dummyIframe.style.display = 'none';
684
- this.iframes.set(IframeType.BACKDROP, {
685
- type: IframeType.BACKDROP,
686
- element: dummyIframe,
687
- container,
688
- ready: true, // Backdrop is always ready
689
- visible: false,
690
- createdAt: Date.now(),
691
- });
692
- this.logger.debug('Backdrop created');
662
+ this.logger.debug('Backdrop disabled, skipping creation');
693
663
  }
694
664
  /**
695
665
  * Build iframe URL with parameters
@@ -2190,7 +2160,7 @@ class StateCoordinator {
2190
2160
  }
2191
2161
  }
2192
2162
 
2193
- var version = "1.0.15";
2163
+ var version = "1.0.16";
2194
2164
  var packageJson = {
2195
2165
  version: version};
2196
2166
 
@@ -2273,6 +2243,242 @@ class WeldSDK {
2273
2243
  console.log('[Weld SDK] Widget close requested');
2274
2244
  this.close();
2275
2245
  }
2246
+ if (event.data?.type === 'weld:image:open' && event.data?.url) {
2247
+ this.showImageLightbox(event.data.url);
2248
+ }
2249
+ }
2250
+ /**
2251
+ * Show fullscreen image lightbox on the parent page
2252
+ */
2253
+ showImageLightbox(url) {
2254
+ // Remove existing lightbox if any
2255
+ const existing = document.getElementById('weld-image-lightbox');
2256
+ if (existing)
2257
+ existing.remove();
2258
+ // Zoom / pan state
2259
+ let scale = 1;
2260
+ let translateX = 0;
2261
+ let translateY = 0;
2262
+ let isDragging = false;
2263
+ let dragStartX = 0;
2264
+ let dragStartY = 0;
2265
+ let lastTranslateX = 0;
2266
+ let lastTranslateY = 0;
2267
+ const applyTransform = () => {
2268
+ img.style.transform = `translate(${translateX}px, ${translateY}px) scale(${scale})`;
2269
+ };
2270
+ const resetTransform = () => {
2271
+ scale = 1;
2272
+ translateX = 0;
2273
+ translateY = 0;
2274
+ applyTransform();
2275
+ img.style.cursor = 'zoom-in';
2276
+ };
2277
+ const overlay = document.createElement('div');
2278
+ overlay.id = 'weld-image-lightbox';
2279
+ overlay.style.cssText = `
2280
+ position: fixed;
2281
+ inset: 0;
2282
+ z-index: 2147483647;
2283
+ background: rgba(0, 0, 0, 0.92);
2284
+ display: flex;
2285
+ align-items: center;
2286
+ justify-content: center;
2287
+ padding: 16px;
2288
+ cursor: pointer;
2289
+ overflow: hidden;
2290
+ `;
2291
+ // Close button
2292
+ const closeBtn = document.createElement('button');
2293
+ closeBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>`;
2294
+ closeBtn.style.cssText = `
2295
+ position: absolute;
2296
+ top: 16px;
2297
+ right: 16px;
2298
+ width: 40px;
2299
+ height: 40px;
2300
+ border-radius: 50%;
2301
+ border: none;
2302
+ background: rgba(255, 255, 255, 0.1);
2303
+ color: white;
2304
+ cursor: pointer;
2305
+ display: flex;
2306
+ align-items: center;
2307
+ justify-content: center;
2308
+ transition: background 0.15s;
2309
+ `;
2310
+ closeBtn.onmouseenter = () => { closeBtn.style.background = 'rgba(255, 255, 255, 0.2)'; };
2311
+ closeBtn.onmouseleave = () => { closeBtn.style.background = 'rgba(255, 255, 255, 0.1)'; };
2312
+ // Download button
2313
+ const downloadBtn = document.createElement('a');
2314
+ downloadBtn.href = url;
2315
+ downloadBtn.download = '';
2316
+ downloadBtn.target = '_blank';
2317
+ downloadBtn.rel = 'noopener noreferrer';
2318
+ downloadBtn.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>`;
2319
+ downloadBtn.style.cssText = `
2320
+ position: absolute;
2321
+ top: 16px;
2322
+ right: 64px;
2323
+ width: 40px;
2324
+ height: 40px;
2325
+ border-radius: 50%;
2326
+ border: none;
2327
+ background: rgba(255, 255, 255, 0.1);
2328
+ color: white;
2329
+ cursor: pointer;
2330
+ display: flex;
2331
+ align-items: center;
2332
+ justify-content: center;
2333
+ transition: background 0.15s;
2334
+ text-decoration: none;
2335
+ `;
2336
+ downloadBtn.onmouseenter = () => { downloadBtn.style.background = 'rgba(255, 255, 255, 0.2)'; };
2337
+ downloadBtn.onmouseleave = () => { downloadBtn.style.background = 'rgba(255, 255, 255, 0.1)'; };
2338
+ // Image
2339
+ const img = document.createElement('img');
2340
+ img.src = url;
2341
+ img.alt = 'Full size';
2342
+ img.draggable = false;
2343
+ img.style.cssText = `
2344
+ max-width: 100%;
2345
+ max-height: 100%;
2346
+ object-fit: contain;
2347
+ border-radius: 8px;
2348
+ cursor: zoom-in;
2349
+ transition: transform 0.2s ease;
2350
+ user-select: none;
2351
+ `;
2352
+ // Click to toggle zoom
2353
+ img.addEventListener('click', (e) => {
2354
+ e.stopPropagation();
2355
+ if (scale === 1) {
2356
+ // Zoom in to 2.5x centered on click position
2357
+ const rect = img.getBoundingClientRect();
2358
+ const clickX = e.clientX - rect.left - rect.width / 2;
2359
+ const clickY = e.clientY - rect.top - rect.height / 2;
2360
+ scale = 2.5;
2361
+ translateX = -clickX * 1.5;
2362
+ translateY = -clickY * 1.5;
2363
+ applyTransform();
2364
+ img.style.cursor = 'zoom-out';
2365
+ }
2366
+ else {
2367
+ // Zoom out - reset
2368
+ resetTransform();
2369
+ }
2370
+ });
2371
+ // Mouse wheel zoom
2372
+ overlay.addEventListener('wheel', (e) => {
2373
+ e.preventDefault();
2374
+ const delta = e.deltaY > 0 ? -0.25 : 0.25;
2375
+ const newScale = Math.min(Math.max(scale + delta, 1), 5);
2376
+ if (newScale === 1) {
2377
+ resetTransform();
2378
+ }
2379
+ else {
2380
+ scale = newScale;
2381
+ applyTransform();
2382
+ img.style.cursor = 'zoom-out';
2383
+ }
2384
+ }, { passive: false });
2385
+ // Drag to pan when zoomed
2386
+ img.addEventListener('mousedown', (e) => {
2387
+ if (scale <= 1)
2388
+ return;
2389
+ e.preventDefault();
2390
+ isDragging = true;
2391
+ dragStartX = e.clientX;
2392
+ dragStartY = e.clientY;
2393
+ lastTranslateX = translateX;
2394
+ lastTranslateY = translateY;
2395
+ img.style.cursor = 'grabbing';
2396
+ img.style.transition = 'none';
2397
+ });
2398
+ window.addEventListener('mousemove', (e) => {
2399
+ if (!isDragging)
2400
+ return;
2401
+ translateX = lastTranslateX + (e.clientX - dragStartX);
2402
+ translateY = lastTranslateY + (e.clientY - dragStartY);
2403
+ applyTransform();
2404
+ });
2405
+ window.addEventListener('mouseup', () => {
2406
+ if (!isDragging)
2407
+ return;
2408
+ isDragging = false;
2409
+ img.style.cursor = scale > 1 ? 'zoom-out' : 'zoom-in';
2410
+ img.style.transition = 'transform 0.2s ease';
2411
+ });
2412
+ // Touch: pinch to zoom + drag to pan
2413
+ let lastTouchDist = 0;
2414
+ let lastTouchScale = 1;
2415
+ overlay.addEventListener('touchstart', (e) => {
2416
+ if (e.touches.length === 2) {
2417
+ e.preventDefault();
2418
+ const dx = e.touches[0].clientX - e.touches[1].clientX;
2419
+ const dy = e.touches[0].clientY - e.touches[1].clientY;
2420
+ lastTouchDist = Math.hypot(dx, dy);
2421
+ lastTouchScale = scale;
2422
+ }
2423
+ else if (e.touches.length === 1 && scale > 1) {
2424
+ isDragging = true;
2425
+ dragStartX = e.touches[0].clientX;
2426
+ dragStartY = e.touches[0].clientY;
2427
+ lastTranslateX = translateX;
2428
+ lastTranslateY = translateY;
2429
+ img.style.transition = 'none';
2430
+ }
2431
+ }, { passive: false });
2432
+ overlay.addEventListener('touchmove', (e) => {
2433
+ if (e.touches.length === 2) {
2434
+ e.preventDefault();
2435
+ const dx = e.touches[0].clientX - e.touches[1].clientX;
2436
+ const dy = e.touches[0].clientY - e.touches[1].clientY;
2437
+ const dist = Math.hypot(dx, dy);
2438
+ scale = Math.min(Math.max(lastTouchScale * (dist / lastTouchDist), 1), 5);
2439
+ if (scale === 1) {
2440
+ translateX = 0;
2441
+ translateY = 0;
2442
+ }
2443
+ applyTransform();
2444
+ }
2445
+ else if (e.touches.length === 1 && isDragging) {
2446
+ e.preventDefault();
2447
+ translateX = lastTranslateX + (e.touches[0].clientX - dragStartX);
2448
+ translateY = lastTranslateY + (e.touches[0].clientY - dragStartY);
2449
+ applyTransform();
2450
+ }
2451
+ }, { passive: false });
2452
+ overlay.addEventListener('touchend', (e) => {
2453
+ if (e.touches.length < 2) {
2454
+ lastTouchDist = 0;
2455
+ }
2456
+ if (e.touches.length === 0) {
2457
+ isDragging = false;
2458
+ img.style.transition = 'transform 0.2s ease';
2459
+ }
2460
+ });
2461
+ const close = () => {
2462
+ document.removeEventListener('keydown', handleKeyDown);
2463
+ overlay.remove();
2464
+ };
2465
+ // Only close on backdrop click when not zoomed (prevent accidental close while panning)
2466
+ overlay.addEventListener('click', (e) => {
2467
+ if (e.target === overlay && scale <= 1)
2468
+ close();
2469
+ });
2470
+ downloadBtn.addEventListener('click', (e) => e.stopPropagation());
2471
+ closeBtn.addEventListener('click', (e) => { e.stopPropagation(); close(); });
2472
+ // Close on Escape
2473
+ const handleKeyDown = (e) => {
2474
+ if (e.key === 'Escape')
2475
+ close();
2476
+ };
2477
+ document.addEventListener('keydown', handleKeyDown);
2478
+ overlay.appendChild(closeBtn);
2479
+ overlay.appendChild(downloadBtn);
2480
+ overlay.appendChild(img);
2481
+ document.body.appendChild(overlay);
2276
2482
  }
2277
2483
  /**
2278
2484
  * Initialize the SDK and render widget
@@ -2384,8 +2590,6 @@ class WeldSDK {
2384
2590
  console.log('[Weld SDK] Opening widget...');
2385
2591
  this.stateCoordinator.openWidget();
2386
2592
  this.iframeManager.showIframe(IframeType.WIDGET);
2387
- this.iframeManager.showIframe(IframeType.BACKDROP);
2388
- // Keep launcher visible so user can click it to close the widget
2389
2593
  // Send open message to the widget iframe
2390
2594
  const widgetIframe = this.iframeManager.getIframe(IframeType.WIDGET);
2391
2595
  if (widgetIframe?.element?.contentWindow) {
@@ -2406,8 +2610,6 @@ class WeldSDK {
2406
2610
  console.log('[Weld SDK] Closing widget...');
2407
2611
  this.stateCoordinator.closeWidget();
2408
2612
  this.iframeManager.hideIframe(IframeType.WIDGET);
2409
- this.iframeManager.hideIframe(IframeType.BACKDROP);
2410
- // Launcher stays visible
2411
2613
  // Send close message to the widget iframe
2412
2614
  const widgetIframe = this.iframeManager.getIframe(IframeType.WIDGET);
2413
2615
  if (widgetIframe?.element?.contentWindow) {