@duct-sdk/sdk 0.3.4 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  Public release notes for the Duct SDK. Versioning follows [semver](https://semver.org).
4
4
 
5
+ ## [0.3.6] — 2026-06-10
6
+
7
+ ### Fixed
8
+ - **Launcher drag UX** — closed bubble drags from the icon itself (4px threshold); no grab cursor or extra handle on hover. Tap still opens.
9
+ - **Panel drag handle** — grab bar only renders while the panel is open; themed “Drag to move” tooltip replaces the native browser title.
10
+
11
+ ## [0.3.5] — 2026-06-10
12
+
13
+ ### Fixed
14
+ - **Explicit drag handles** — `DuctShell` launcher and open panel no longer treat the whole chrome as a drag target. A small grab handle is the only drag surface; the bubble uses a normal click to open and the panel header stays fully interactive.
15
+
5
16
  ## [0.3.4] — 2026-06-10
6
17
 
7
18
  ### Fixed
@@ -62,6 +62,53 @@ function clampBubble(x, y) {
62
62
  y: Math.min(Math.max(margin, y), Math.max(margin, maxY)),
63
63
  };
64
64
  }
65
+ /** Top grab handle for the open panel — with theme-aware hover tooltip. */
66
+ function ShellDragHandle({ onPointerDown, isDragging, isDark, label = "Drag to move", style, }) {
67
+ const [hovered, setHovered] = useState(false);
68
+ const barColor = isDark ? "rgba(255,255,255,0.28)" : "rgba(12,11,9,0.20)";
69
+ const showTip = hovered && !isDragging;
70
+ return (_jsxs("div", { role: "button", tabIndex: -1, onPointerDown: onPointerDown, "aria-label": label, onMouseEnter: () => setHovered(true), onMouseLeave: () => setHovered(false), style: {
71
+ position: "absolute",
72
+ top: 6,
73
+ left: "50%",
74
+ transform: "translateX(-50%)",
75
+ zIndex: 2,
76
+ width: 44,
77
+ height: 22,
78
+ display: "flex",
79
+ alignItems: "center",
80
+ justifyContent: "center",
81
+ cursor: isDragging ? "grabbing" : "grab",
82
+ touchAction: "none",
83
+ borderRadius: 11,
84
+ ...style,
85
+ }, children: [_jsx("div", { "aria-hidden": "true", style: {
86
+ width: 32,
87
+ height: 4,
88
+ borderRadius: 2,
89
+ backgroundColor: barColor,
90
+ } }), showTip && (_jsx("div", { role: "tooltip", style: {
91
+ position: "absolute",
92
+ top: "100%",
93
+ left: "50%",
94
+ transform: "translateX(-50%)",
95
+ marginTop: 6,
96
+ padding: "5px 10px",
97
+ fontSize: 11,
98
+ fontWeight: 500,
99
+ lineHeight: 1.3,
100
+ letterSpacing: "0.01em",
101
+ whiteSpace: "nowrap",
102
+ pointerEvents: "none",
103
+ borderRadius: 8,
104
+ backgroundColor: isDark ? "#1A1816" : "#FFFFFF",
105
+ color: isDark ? "#9C9790" : "#635F59",
106
+ border: isDark ? "1px solid rgba(255,255,255,0.08)" : "1px solid rgba(12,11,9,0.10)",
107
+ boxShadow: isDark
108
+ ? "0 8px 24px rgba(0,0,0,0.45)"
109
+ : "0 8px 24px rgba(12,11,9,0.12)",
110
+ }, children: label }))] }));
111
+ }
65
112
  /** Keep a dragged panel visible inside the viewport. */
66
113
  function clampPanel(x, y, width, height) {
67
114
  if (typeof window === "undefined")
@@ -341,44 +388,6 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
341
388
  }
342
389
  catch { /* ignore corrupt storage */ }
343
390
  }, [shellId, draggable]);
344
- // Free drag — pointer move/up handlers attached to window during a drag.
345
- useEffect(() => {
346
- if (!isDragging)
347
- return;
348
- const onMove = (e) => {
349
- const st = dragState.current;
350
- if (!st)
351
- return;
352
- if (Math.abs(e.clientX - st.startX) > 4 || Math.abs(e.clientY - st.startY) > 4) {
353
- st.moved = true;
354
- }
355
- setBubblePos(clampBubble(e.clientX - st.dx, e.clientY - st.dy));
356
- };
357
- const onUp = () => {
358
- setIsDragging(false);
359
- const st = dragState.current;
360
- dragState.current = null;
361
- if (st && !st.moved) {
362
- // Treat as a click → open the panel.
363
- openPanel();
364
- }
365
- else if (bubblePos) {
366
- try {
367
- window.localStorage.setItem(`duct-shell-pos:${shellId}`, JSON.stringify(bubblePos));
368
- }
369
- catch { /* ignore */ }
370
- // Bubble moved to a new location — clear any panel position so the panel
371
- // re-anchors near the bubble on the next open instead of the old dragged spot.
372
- setPanelPos(null);
373
- }
374
- };
375
- window.addEventListener("pointermove", onMove);
376
- window.addEventListener("pointerup", onUp);
377
- return () => {
378
- window.removeEventListener("pointermove", onMove);
379
- window.removeEventListener("pointerup", onUp);
380
- };
381
- }, [isDragging, bubblePos, openPanel, shellId]);
382
391
  // Free-drag the open panel using a top handle. The handle sits outside the
383
392
  // iframe so dragging works without relying on iframe internals.
384
393
  useEffect(() => {
@@ -401,15 +410,57 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
401
410
  window.removeEventListener("pointerup", onUp);
402
411
  };
403
412
  }, [isPanelDragging]);
413
+ // Launcher bubble: pointer stays default until the user actually drags (4px threshold).
414
+ // A tap opens; a drag repositions — no separate handle or grab cursor on hover.
404
415
  const onBubblePointerDown = useCallback((e) => {
405
416
  if (!draggable)
406
417
  return;
407
418
  const rect = e.currentTarget.getBoundingClientRect();
408
- dragState.current = { dx: e.clientX - rect.left, dy: e.clientY - rect.top, startX: e.clientX, startY: e.clientY, moved: false };
409
- // Seed bubblePos from current rect so the first drag frame is smooth.
419
+ const st = {
420
+ dx: e.clientX - rect.left,
421
+ dy: e.clientY - rect.top,
422
+ startX: e.clientX,
423
+ startY: e.clientY,
424
+ moved: false,
425
+ };
426
+ dragState.current = st;
410
427
  setBubblePos((prev) => prev ?? clampBubble(rect.left, rect.top));
411
- setIsDragging(true);
412
- }, [draggable]);
428
+ const onMove = (ev) => {
429
+ if (!dragState.current)
430
+ return;
431
+ if (!st.moved
432
+ && Math.abs(ev.clientX - st.startX) <= 4
433
+ && Math.abs(ev.clientY - st.startY) <= 4) {
434
+ return;
435
+ }
436
+ st.moved = true;
437
+ setIsDragging(true);
438
+ setBubblePos(clampBubble(ev.clientX - st.dx, ev.clientY - st.dy));
439
+ };
440
+ const onUp = () => {
441
+ window.removeEventListener("pointermove", onMove);
442
+ window.removeEventListener("pointerup", onUp);
443
+ dragState.current = null;
444
+ setIsDragging(false);
445
+ if (st.moved) {
446
+ setBubblePos((pos) => {
447
+ if (pos) {
448
+ try {
449
+ window.localStorage.setItem(`duct-shell-pos:${shellId}`, JSON.stringify(pos));
450
+ }
451
+ catch { /* ignore */ }
452
+ }
453
+ return pos;
454
+ });
455
+ setPanelPos(null);
456
+ }
457
+ else {
458
+ openPanel();
459
+ }
460
+ };
461
+ window.addEventListener("pointermove", onMove);
462
+ window.addEventListener("pointerup", onUp);
463
+ }, [draggable, openPanel, shellId]);
413
464
  const onPanelPointerDown = useCallback((e) => {
414
465
  if (!draggable || !panelRef.current)
415
466
  return;
@@ -487,48 +538,38 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
487
538
  const bubbleShadow = isDarkChrome
488
539
  ? "0 4px 16px rgba(0,0,0,0.40), 0 2px 8px rgba(0,0,0,0.20)"
489
540
  : "0 4px 16px rgba(12,11,9,0.16), 0 2px 8px rgba(12,11,9,0.08)";
490
- const buttonStyle = {
491
- ...bubbleStyle,
492
- zIndex: 9999,
493
- width: `${BUBBLE_SIZE}px`,
494
- height: `${BUBBLE_SIZE}px`,
541
+ const bubbleLauncherStyle = {
542
+ position: "relative",
543
+ width: "100%",
544
+ height: "100%",
495
545
  borderRadius: "50%",
496
546
  border: bubbleBorder,
497
- cursor: isDragging ? "grabbing" : "pointer",
547
+ cursor: "pointer",
498
548
  display: "flex",
499
549
  alignItems: "center",
500
550
  justifyContent: "center",
501
551
  backgroundColor: bubbleBg,
502
552
  boxShadow: bubbleShadow,
503
553
  padding: 0,
504
- touchAction: "none",
505
554
  transition: isDragging ? "none" : "transform 150ms ease, box-shadow 150ms ease",
506
555
  };
507
- return (_jsxs(_Fragment, { children: [!panelOpen && (_jsx("button", { type: "button", style: buttonStyle, onClick: (e) => {
508
- // Suppress click when a drag just happened.
509
- if (dragState.current?.moved) {
510
- e.preventDefault();
511
- return;
512
- }
513
- if (!draggable)
514
- openPanel();
515
- }, onPointerDown: onBubblePointerDown, "aria-label": "Open Duct Shell", className: className, onMouseEnter: (e) => {
556
+ const bubbleIcon = !iconLoadFailed ? (_jsx("img", { src: currentIconSrc, alt: "Duct", width: 30, height: 30, draggable: false, onError: handleIconError, style: { width: "30px", height: "30px", objectFit: "contain", pointerEvents: "none" } })) : (_jsx("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M18 12c0-3.3-2.2-5.5-5.5-5.5C9 6.5 7 8.7 7 12s2 5.5 5.5 5.5c2 0 3.6-.8 4.6-2.2l-2.2-1.6c-.6.8-1.4 1.3-2.4 1.3-1.6 0-2.8-1.2-2.8-3s1.2-3 2.8-3c1 0 1.8.5 2.3 1.3L18 12z", fill: "#E8622A" }) }));
557
+ return (_jsxs(_Fragment, { children: [!panelOpen && (_jsx("button", { type: "button", style: {
558
+ ...bubbleStyle,
559
+ ...bubbleLauncherStyle,
560
+ position: "fixed",
561
+ zIndex: 9999,
562
+ width: `${BUBBLE_SIZE}px`,
563
+ height: `${BUBBLE_SIZE}px`,
564
+ cursor: isDragging ? "grabbing" : "pointer",
565
+ touchAction: draggable ? "none" : undefined,
566
+ }, onPointerDown: draggable ? onBubblePointerDown : undefined, onClick: draggable ? undefined : () => openPanel(), "aria-label": "Open Duct Shell", className: className, onMouseEnter: (e) => {
516
567
  if (isDragging)
517
568
  return;
518
569
  e.currentTarget.style.transform = "scale(1.07)";
519
570
  }, onMouseLeave: (e) => {
520
571
  e.currentTarget.style.transform = "scale(1)";
521
- }, children: !iconLoadFailed ? (_jsx("img", { src: currentIconSrc, alt: "Duct", width: 30, height: 30, draggable: false, onError: handleIconError, style: { width: "30px", height: "30px", objectFit: "contain", pointerEvents: "none" } })) : (_jsx("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M18 12c0-3.3-2.2-5.5-5.5-5.5C9 6.5 7 8.7 7 12s2 5.5 5.5 5.5c2 0 3.6-.8 4.6-2.2l-2.2-1.6c-.6.8-1.4 1.3-2.4 1.3-1.6 0-2.8-1.2-2.8-3s1.2-3 2.8-3c1 0 1.8.5 2.3 1.3L18 12z", fill: isDarkChrome ? "#E8622A" : "#E8622A" }) })) })), _jsxs("div", { ref: panelRef, style: panelStyle, "data-duct-shell": shellId, children: [_jsx("div", { onPointerDown: onPanelPointerDown, "aria-hidden": "true", title: "Drag Duct Shell", style: {
522
- position: "absolute",
523
- top: 0,
524
- left: 0,
525
- // Leave the header control cluster (+ New, close) clickable inside the iframe.
526
- right: 140,
527
- height: 44,
528
- zIndex: 2,
529
- cursor: isPanelDragging ? "grabbing" : "grab",
530
- touchAction: "none",
531
- } }), _jsx("iframe", { ref: iframeRef, src: shellUrl, title: "Duct Shell", sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", allow: "clipboard-write", referrerPolicy: "no-referrer-when-downgrade", style: {
572
+ }, children: bubbleIcon })), _jsxs("div", { ref: panelRef, style: panelStyle, "data-duct-shell": shellId, children: [draggable && panelOpen && (_jsx(ShellDragHandle, { onPointerDown: onPanelPointerDown, isDragging: isPanelDragging, isDark: isDarkChrome, label: "Drag to move" })), _jsx("iframe", { ref: iframeRef, src: shellUrl, title: "Duct Shell", sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", allow: "clipboard-write", referrerPolicy: "no-referrer-when-downgrade", style: {
532
573
  width: "100%",
533
574
  height: "100%",
534
575
  border: "none",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duct-sdk/sdk",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "type": "module",
5
5
  "description": "Duct SDK — A shell (like terminal) that knows when to talk, when to show, and when to hand off.",
6
6
  "main": "dist/index.js",