gsap-timeline-viewer 0.1.0 → 0.1.2

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.
@@ -1,13 +1,27 @@
1
- var GSAPTimelineViewer=function(o){"use strict";var C=Object.defineProperty;var D=(o,c,h)=>c in o?C(o,c,{enumerable:!0,configurable:!0,writable:!0,value:h}):o[c]=h;var s=(o,c,h)=>D(o,typeof c!="symbol"?c+"":c,h);let c=0;function h(n){if(!n||n.length===0)return"Unknown";const i=n[0];return i.id?`#${i.id}`:i.classList&&i.classList.length>0?`.${i.classList[0]}`:i.tagName?i.tagName.toLowerCase():"element"}function k(n){const i=["ease","duration","delay","onComplete","onStart","onUpdate","onCompleteParams","onStartParams","onUpdateParams","repeat","repeatDelay","yoyo","stagger","overwrite","immediateRender","lazy","autoAlpha","id","paused","reversed","startAt"];return Object.keys(n).filter(t=>!i.includes(t))}function S(n){const i=[];return n.getChildren(!0,!0,!1).forEach((e,a)=>{if(!("targets"in e))return;const r=e,l=r.targets(),d=r.vars||{},p=k(d);let v="";if(d.id&&typeof d.id=="string")v=d.id;else{const f=h(l),x=p.slice(0,2).join(", ");v=x?`${f} (${x})`:f}const b=e.startTime(),y=e.duration();i.push({id:`tween-${++c}`,label:v,startTime:b,endTime:b+y,duration:y,targets:h(l),properties:p,colorIndex:a%6})}),{duration:n.duration(),tweens:i}}function w(){c=0}function g(n,i=!0){const t=Math.abs(n);return i?t.toFixed(2):t.toFixed(0)}const T=":host{--gtv-bg: #1a1a1a;--gtv-bg-secondary: #252525;--gtv-border: #333;--gtv-text: #e0e0e0;--gtv-text-muted: #888;--gtv-accent: #4a9eff;--gtv-playhead: #4a9eff;--gtv-ruler-bg: #1f1f1f;--gtv-track-height: 28px;--gtv-controls-height: 40px;--gtv-ruler-height: 24px;--gtv-track-1: #3b82f6;--gtv-track-2: #f59e0b;--gtv-track-3: #ec4899;--gtv-track-4: #10b981;--gtv-track-5: #8b5cf6;--gtv-track-6: #ef4444}*{box-sizing:border-box;margin:0;padding:0}.gtv-container{position:fixed;bottom:0;left:0;right:0;background:var(--gtv-bg);border-top:1px solid var(--gtv-border);font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:12px;color:var(--gtv-text);z-index:999999;display:flex;flex-direction:column}.gtv-container.collapsed{height:auto!important}.gtv-container.collapsed .gtv-timeline-area{display:none}.gtv-controls{display:flex;align-items:center;justify-content:space-between;height:var(--gtv-controls-height);padding:0 12px;background:var(--gtv-bg-secondary);border-bottom:1px solid var(--gtv-border);gap:16px}.gtv-controls-left,.gtv-controls-center,.gtv-controls-right{display:flex;align-items:center;gap:8px}.gtv-controls-center{flex:0 0 auto}.gtv-time-display{font-variant-numeric:tabular-nums;min-width:100px;text-align:center}.gtv-time-current{color:var(--gtv-text)}.gtv-time-total{color:var(--gtv-text-muted)}.gtv-btn{display:flex;align-items:center;justify-content:center;width:28px;height:28px;background:transparent;border:none;border-radius:4px;color:var(--gtv-text);cursor:pointer;transition:background .15s}.gtv-btn:hover{background:#ffffff1a}.gtv-btn:active{background:#ffffff26}.gtv-btn.active{color:var(--gtv-accent)}.gtv-btn svg{width:16px;height:16px;fill:currentColor}.gtv-btn-play svg{width:20px;height:20px}.gtv-speed-btn{width:auto;padding:0 8px;font-size:11px;font-weight:500}.gtv-collapse-btn{margin-left:auto}.gtv-timeline-area{display:flex;flex-direction:column;overflow:hidden;flex:1}.gtv-ruler{position:relative;height:var(--gtv-ruler-height);background:var(--gtv-ruler-bg);border-bottom:1px solid var(--gtv-border);overflow:hidden;flex-shrink:0}.gtv-ruler-inner{position:relative;height:100%}.gtv-ruler-marker{position:absolute;top:0;height:100%;display:flex;flex-direction:column;align-items:center}.gtv-ruler-marker-line{width:1px;height:6px;background:var(--gtv-text-muted)}.gtv-ruler-marker-label{font-size:10px;color:var(--gtv-text-muted);margin-top:2px}.gtv-tracks-container{position:relative;overflow-y:auto;overflow-x:hidden;flex:1}.gtv-tracks-scroll{position:relative;min-height:100%}.gtv-track{position:relative;height:var(--gtv-track-height);border-bottom:1px solid var(--gtv-border)}.gtv-track-bar{position:absolute;top:4px;height:calc(var(--gtv-track-height) - 8px);border-radius:4px;display:flex;align-items:center;padding:0 8px;font-size:11px;font-weight:500;color:#fff;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:default;transition:filter .15s}.gtv-track-bar:hover{filter:brightness(1.1)}.gtv-track-bar.is-active{box-shadow:0 0 0 2px var(--gtv-accent)}.gtv-playhead-container{position:absolute;top:0;bottom:0;width:1px;pointer-events:none;z-index:10}.gtv-playhead-head{position:absolute;top:0;left:-5px;width:11px;height:11px;background:var(--gtv-playhead);clip-path:polygon(50% 100%,0 0,100% 0)}.gtv-playhead-line{position:absolute;top:11px;bottom:0;left:0;width:1px;background:var(--gtv-playhead)}.gtv-scrub-area{position:absolute;top:0;left:0;right:0;bottom:0;cursor:pointer}.gtv-empty{display:flex;align-items:center;justify-content:center;padding:24px;color:var(--gtv-text-muted)}",L=["var(--gtv-track-1)","var(--gtv-track-2)","var(--gtv-track-3)","var(--gtv-track-4)","var(--gtv-track-5)","var(--gtv-track-6)"],u=[.25,.5,1,2,4];class m extends HTMLElement{constructor(){super();s(this,"shadow");s(this,"timeline",null);s(this,"timelineData",null);s(this,"isPlaying",!1);s(this,"isLooping",!1);s(this,"speedIndex",2);s(this,"collapsed",!1);s(this,"height",200);s(this,"isDragging",!1);s(this,"container");s(this,"playBtn");s(this,"loopBtn");s(this,"speedBtn");s(this,"timeDisplay");s(this,"rulerInner");s(this,"tracksScroll");s(this,"playhead");s(this,"scrubArea");this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.setupEventListeners()}disconnectedCallback(){this.detachTimeline()}setTimeline(t){this.detachTimeline(),this.timeline=t,w(),this.timelineData=S(t),t.eventCallback("onUpdate",()=>this.onTimelineUpdate()),this.renderTracks(),this.updatePlayhead(),this.updateTimeDisplay(),this.updatePlayState()}detachTimeline(){this.timeline&&(this.timeline.eventCallback("onUpdate",null),this.timeline=null,this.timelineData=null)}render(){this.shadow.innerHTML=`
2
- <style>${T}</style>
1
+ var GSAPTimelineViewer=function(v){"use strict";var j=Object.defineProperty;var V=(v,u,b)=>u in v?j(v,u,{enumerable:!0,configurable:!0,writable:!0,value:b}):v[u]=b;var l=(v,u,b)=>V(v,typeof u!="symbol"?u+"":u,b);let u=0;function b(c){if(!c||c.length===0)return"Unknown";const s=c[0];return s.id?`#${s.id}`:s.classList&&s.classList.length>0?`.${s.classList[0]}`:s.tagName?s.tagName.toLowerCase():"element"}function D(c){const s=["ease","duration","delay","onComplete","onStart","onUpdate","onCompleteParams","onStartParams","onUpdateParams","repeat","repeatDelay","yoyo","stagger","overwrite","immediateRender","lazy","autoAlpha","id","paused","reversed","startAt"];return Object.keys(c).filter(t=>!s.includes(t))}function A(c){const s=[];c.getChildren(!0,!0,!1).forEach((e,i)=>{if(!("targets"in e))return;const a=e,r=a.targets(),n=a.vars||{},g=D(n);let m="";if(n.id&&typeof n.id=="string")m=n.id;else{const w=b(r),S=g.slice(0,2).join(", ");m=S?`${w} (${S})`:w}const p=e.startTime(),d=e.duration();let y="none";n.ease&&(y=typeof n.ease=="string"?n.ease:"custom");let f,M;if(n.stagger&&r.length>1&&(typeof n.stagger=="number"?f=n.stagger:typeof n.stagger=="object"&&(f=n.stagger.each||0),f)){const w=d-f*(r.length-1);M=r.map((S,R)=>{const C=p+R*f;return{targetLabel:b([S]),startTime:C,endTime:C+w}})}s.push({id:`tween-${++u}`,label:m,startTime:p,endTime:p+d,duration:d,targets:b(r),properties:g,colorIndex:i%6,hasStagger:!!n.stagger,ease:y,staggerValue:f,staggerChildren:M})});for(let e=1;e<s.length;e++){const i=s[e-1],a=s[e],r=i.endTime-a.startTime;Math.abs(r)>.001&&(a.overlapWithPrev=Math.round(r*1e3)/1e3)}return{duration:c.duration(),tweens:s}}function E(){u=0}function x(c,s=!0){const t=Math.abs(c);return s?t.toFixed(2):t.toFixed(0)}const H=":host{--gtv-bg: #1a1a1a;--gtv-bg-secondary: #252525;--gtv-border: #333;--gtv-text: #e0e0e0;--gtv-text-muted: #888;--gtv-accent: oklch(65% .15 220);--gtv-playhead: oklch(65% .15 220);--gtv-ruler-bg: #1f1f1f;--gtv-track-height: 28px;--gtv-controls-height: 40px;--gtv-ruler-height: 24px;--gtv-timeline-padding: 16px;--gtv-track-1: oklch(50% .12 220);--gtv-track-1-active: oklch(60% .15 220);--gtv-track-2: oklch(50% .12 70);--gtv-track-2-active: oklch(60% .15 70);--gtv-track-3: oklch(50% .12 350);--gtv-track-3-active: oklch(60% .15 350);--gtv-track-4: oklch(50% .12 160);--gtv-track-4-active: oklch(60% .15 160);--gtv-track-5: oklch(50% .12 290);--gtv-track-5-active: oklch(60% .15 290);--gtv-track-6: oklch(50% .12 25);--gtv-track-6-active: oklch(60% .15 25)}*{box-sizing:border-box;margin:0;padding:0}.gtv-container{position:fixed;bottom:0;left:0;right:0;background:var(--gtv-bg);border-top:1px solid var(--gtv-border);font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:12px;color:var(--gtv-text);z-index:999999;display:flex;flex-direction:column;user-select:none;-webkit-user-select:none}.gtv-container.collapsed{height:auto!important}.gtv-container.collapsed .gtv-timeline-area{display:none}.gtv-controls{position:relative;display:flex;align-items:center;justify-content:center;height:var(--gtv-controls-height);padding:0 12px;background:var(--gtv-bg-secondary);border-bottom:1px solid var(--gtv-border);gap:8px}.gtv-controls-left{position:absolute;left:12px;display:flex;align-items:center;gap:8px}.gtv-controls-center{display:flex;align-items:center;gap:8px}.gtv-controls-right{position:absolute;right:12px;display:flex;align-items:center;gap:8px}.gtv-time-display{font-variant-numeric:tabular-nums;min-width:100px;text-align:center}.gtv-time-current{color:var(--gtv-text)}.gtv-time-total{color:var(--gtv-text-muted)}.gtv-btn{display:flex;align-items:center;justify-content:center;width:28px;height:28px;background:transparent;border:none;border-radius:4px;color:var(--gtv-text);cursor:pointer;transition:background .15s}.gtv-btn:hover{background:#ffffff1a}.gtv-btn:active{background:#ffffff26}.gtv-btn.active{color:var(--gtv-accent)}.gtv-btn svg{width:16px;height:16px;fill:currentColor}.gtv-btn-play svg{width:20px;height:20px}.gtv-speed-btn{width:auto;padding:0 8px;font-size:11px;font-weight:500}.gtv-timeline-select{background:var(--gtv-bg);border:1px solid var(--gtv-border);border-radius:4px;color:var(--gtv-text);font-size:11px;padding:4px 8px;cursor:pointer;max-width:140px}.gtv-timeline-select:focus{outline:none;border-color:var(--gtv-accent)}.gtv-collapse-btn{margin-left:auto}.gtv-timeline-area{position:relative;display:flex;flex-direction:column;overflow:hidden;flex:1}.gtv-resize-handle{position:absolute;top:0;left:0;right:0;height:6px;cursor:ns-resize;z-index:20}.gtv-resize-handle:hover,.gtv-resize-handle:active{background:#ffffff1a}.gtv-ruler{position:relative;height:var(--gtv-ruler-height);background:var(--gtv-ruler-bg);border-bottom:1px solid var(--gtv-border);overflow:visible;flex-shrink:0;padding:0 var(--gtv-timeline-padding)}.gtv-ruler-inner{position:relative;height:100%;width:100%}.gtv-ruler-marker{position:absolute;top:0;display:flex;flex-direction:column;align-items:center}.gtv-ruler-marker-line{width:1px;height:6px;background:var(--gtv-text-muted)}.gtv-ruler-marker-label{font-size:10px;color:var(--gtv-text-muted);margin-top:2px}.gtv-grid-line{position:absolute;top:0;width:1px;height:100%;background:var(--gtv-border);pointer-events:none}.gtv-tracks-container{position:relative;overflow-y:auto;overflow-x:hidden;flex:1;padding:0 var(--gtv-timeline-padding)}.gtv-tracks-scroll{position:relative;min-height:100%;width:100%}.gtv-track{position:relative;padding-top:var(--gtv-track-height)}.gtv-track-bar{position:absolute;top:4px;height:calc(var(--gtv-track-height) - 8px);border-radius:4px;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:0 8px;font-size:11px;font-weight:500;color:#fff;overflow:hidden;cursor:default;transition:filter .15s}.gtv-track-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0}.gtv-track-stagger{opacity:.7;font-size:10px;font-weight:400;flex-shrink:0}.gtv-track-bar:hover{filter:brightness(1.1)}.gtv-playhead-wrapper{position:absolute;top:0;bottom:0;left:var(--gtv-timeline-padding);right:var(--gtv-timeline-padding);pointer-events:none;z-index:15}.gtv-playhead{position:absolute;top:0;bottom:0;width:0;left:0}.gtv-playhead-head{position:absolute;top:6px;left:-5px;width:11px;height:11px;background:var(--gtv-playhead);clip-path:polygon(50% 100%,0 0,100% 0)}.gtv-playhead-line{position:absolute;top:6px;bottom:0;left:0;width:1px;background:var(--gtv-playhead)}.gtv-scrub-area{position:absolute;top:0;left:0;right:0;bottom:0;cursor:ew-resize}.gtv-track[data-expandable=true] .gtv-track-bar{cursor:pointer}.gtv-expand-icon{transition:transform .2s}.gtv-track.expanded .gtv-expand-icon{transform:rotate(180deg)}.gtv-stagger-children{display:none;position:relative;width:100%}.gtv-track.expanded .gtv-stagger-children{display:block}.gtv-stagger-child{position:relative;width:100%;height:calc(var(--gtv-track-height) - 6px)}.gtv-stagger-child-bar{position:absolute;top:2px;height:calc(var(--gtv-track-height) - 12px);border-radius:3px;display:flex;align-items:center;padding:0 6px;font-size:10px;color:#fff;opacity:.7;overflow:hidden}.gtv-stagger-child-bar .gtv-track-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.gtv-overlap-region{position:absolute;top:4px;height:calc(var(--gtv-track-height) - 8px);background:repeating-linear-gradient(-45deg,transparent,transparent 2px,rgba(255,255,255,.15) 2px,rgba(255,255,255,.15) 4px);border-radius:4px;pointer-events:none;z-index:5}.gtv-gap-connector{position:absolute;top:50%;height:1px;border-top:1px dashed var(--gtv-text-muted);pointer-events:none}.gtv-offset-badge{position:absolute;top:50%;transform:translate(-100%,-50%);margin-left:-4px;font-size:9px;font-weight:500;padding:2px 5px;border-radius:3px;white-space:nowrap;pointer-events:none;z-index:10}.gtv-offset-overlap,.gtv-offset-gap{background:var(--gtv-bg-secondary);border:1px solid var(--gtv-border);color:var(--gtv-text-muted)}.gtv-empty{display:flex;align-items:center;justify-content:center;padding:24px;color:var(--gtv-text-muted)}",L=[.25,.5,1,2,4],$=40;class T extends HTMLElement{constructor(){super();l(this,"shadow");l(this,"timeline",null);l(this,"timelineData",null);l(this,"isPlaying",!1);l(this,"isLooping",!1);l(this,"speedIndex",2);l(this,"collapsed",!1);l(this,"height",200);l(this,"isDragging",!1);l(this,"manageBodyPadding",!0);l(this,"isAutofit",!1);l(this,"container");l(this,"playBtn");l(this,"loopBtn");l(this,"speedBtn");l(this,"timeDisplay");l(this,"rulerInner");l(this,"tracksScroll");l(this,"playhead");l(this,"scrubArea");l(this,"resizeHandle");l(this,"timelineSelect");l(this,"isResizing",!1);this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.setupEventListeners(),this.updateBodyPadding()}disconnectedCallback(){this.detachTimeline(),this.clearBodyPadding()}setTimeline(t){this.detachTimeline(),this.timeline=t,E(),this.timelineData=A(t),t.eventCallback("onUpdate",()=>this.onTimelineUpdate()),this.renderTracks(),this.updatePlayhead(),this.updateTimeDisplay(),this.updatePlayState(),requestAnimationFrame(()=>this.applyAutofit())}updateTimelineSelector(){Promise.resolve().then(()=>B).then(({TimelineViewer:t})=>{const e=t.getTimelines(),i=this.timelineSelect.value;this.timelineSelect.innerHTML="",e.forEach((a,r)=>{const n=document.createElement("option");n.value=r,n.textContent=r,this.timelineSelect.appendChild(n)}),i&&e.has(i)&&(this.timelineSelect.value=i)})}setSelectedTimeline(t){this.timelineSelect.value=t}detachTimeline(){this.timeline&&(this.timeline.eventCallback("onUpdate",null),this.timeline=null,this.timelineData=null)}render(){this.shadow.innerHTML=`
2
+ <style>${H}</style>
3
3
  <div class="gtv-container ${this.collapsed?"collapsed":""}" style="height: ${this.height}px;">
4
4
  <!-- Controls Bar -->
5
5
  <div class="gtv-controls">
6
6
  <div class="gtv-controls-left">
7
+ <select class="gtv-timeline-select" title="Select timeline">
8
+ <option value="">No timeline</option>
9
+ </select>
10
+ <button class="gtv-btn" data-action="loop" title="Loop (L)">
11
+ <svg viewBox="0 0 24 24"><path d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z"/></svg>
12
+ </button>
13
+ <button class="gtv-btn gtv-speed-btn" data-action="speed" title="Playback speed">1x</button>
14
+ </div>
15
+
16
+ <div class="gtv-controls-center">
17
+ <span class="gtv-time-display">
18
+ <span class="gtv-time-current">0.00</span>
19
+ <span class="gtv-time-total"> / 0.00</span>
20
+ </span>
7
21
  <button class="gtv-btn" data-action="skip-start" title="Skip to start">
8
22
  <svg viewBox="0 0 24 24"><path d="M6 6h2v12H6V6zm3.5 6l8.5 6V6l-8.5 6z"/></svg>
9
23
  </button>
10
- <button class="gtv-btn gtv-btn-play" data-action="play" title="Play/Pause">
24
+ <button class="gtv-btn gtv-btn-play" data-action="play" title="Play/Pause (Space)">
11
25
  <svg class="play-icon" viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg>
12
26
  <svg class="pause-icon" viewBox="0 0 24 24" style="display: none;"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>
13
27
  </button>
@@ -16,18 +30,10 @@ var GSAPTimelineViewer=function(o){"use strict";var C=Object.defineProperty;var
16
30
  </button>
17
31
  </div>
18
32
 
19
- <div class="gtv-controls-center">
20
- <button class="gtv-btn" data-action="loop" title="Loop">
21
- <svg viewBox="0 0 24 24"><path d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z"/></svg>
22
- </button>
23
- <span class="gtv-time-display">
24
- <span class="gtv-time-current">0.00</span>
25
- <span class="gtv-time-total"> / 0.00</span>
26
- </span>
27
- <button class="gtv-btn gtv-speed-btn" data-action="speed" title="Playback speed">1x</button>
28
- </div>
29
-
30
33
  <div class="gtv-controls-right">
34
+ <button class="gtv-btn" data-action="autofit" title="Auto-fit height">
35
+ <svg viewBox="0 0 24 24"><path d="M4 8h4V4H4v4zm6 12h4v-4h-4v4zm-6 0h4v-4H4v4zm0-6h4v-4H4v4zm6 0h4v-4h-4v4zm6-10v4h4V4h-4zm-6 4h4V4h-4v4zm6 6h4v-4h-4v4zm0 6h4v-4h-4v4z"/></svg>
36
+ </button>
31
37
  <button class="gtv-btn gtv-collapse-btn" data-action="collapse" title="Collapse/Expand">
32
38
  <svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>
33
39
  </button>
@@ -36,37 +42,59 @@ var GSAPTimelineViewer=function(o){"use strict";var C=Object.defineProperty;var
36
42
 
37
43
  <!-- Timeline Area -->
38
44
  <div class="gtv-timeline-area">
45
+ <!-- Resize Handle -->
46
+ <div class="gtv-resize-handle"></div>
47
+
39
48
  <!-- Ruler -->
40
49
  <div class="gtv-ruler">
41
50
  <div class="gtv-ruler-inner"></div>
42
- <div class="gtv-playhead-container">
43
- <div class="gtv-playhead-head"></div>
44
- </div>
45
51
  </div>
46
52
 
47
53
  <!-- Tracks -->
48
54
  <div class="gtv-tracks-container">
49
55
  <div class="gtv-tracks-scroll">
50
56
  <div class="gtv-scrub-area"></div>
51
- <div class="gtv-playhead-container">
52
- <div class="gtv-playhead-line"></div>
53
- </div>
54
57
  </div>
55
58
  <div class="gtv-empty">No timeline attached. Call setTimeline() to visualize a GSAP timeline.</div>
56
59
  </div>
60
+
61
+ <!-- Playhead spans entire timeline area -->
62
+ <div class="gtv-playhead-wrapper">
63
+ <div class="gtv-playhead">
64
+ <div class="gtv-playhead-head"></div>
65
+ <div class="gtv-playhead-line"></div>
66
+ </div>
67
+ </div>
57
68
  </div>
58
69
  </div>
59
- `,this.container=this.shadow.querySelector(".gtv-container"),this.playBtn=this.shadow.querySelector('[data-action="play"]'),this.loopBtn=this.shadow.querySelector('[data-action="loop"]'),this.speedBtn=this.shadow.querySelector('[data-action="speed"]'),this.timeDisplay=this.shadow.querySelector(".gtv-time-display"),this.rulerInner=this.shadow.querySelector(".gtv-ruler-inner"),this.tracksScroll=this.shadow.querySelector(".gtv-tracks-scroll"),this.playhead=this.shadow.querySelector(".gtv-ruler .gtv-playhead-container"),this.scrubArea=this.shadow.querySelector(".gtv-scrub-area")}setupEventListeners(){this.shadow.addEventListener("click",t=>{const a=t.target.closest("[data-action]");if(!a)return;switch(a.dataset.action){case"play":this.togglePlay();break;case"skip-start":this.skipToStart();break;case"skip-end":this.skipToEnd();break;case"loop":this.toggleLoop();break;case"speed":this.cycleSpeed();break;case"collapse":this.toggleCollapse();break}}),this.scrubArea.addEventListener("mousedown",t=>this.startScrub(t)),this.shadow.querySelector(".gtv-ruler").addEventListener("mousedown",t=>this.startScrub(t)),document.addEventListener("mousemove",t=>this.onScrub(t)),document.addEventListener("mouseup",()=>this.endScrub()),document.addEventListener("keydown",t=>{t.target===document.body&&t.code==="Space"&&(t.preventDefault(),this.togglePlay())})}startScrub(t){this.timeline&&(this.isDragging=!0,this.scrubToPosition(t))}onScrub(t){!this.isDragging||!this.timeline||this.scrubToPosition(t)}endScrub(){this.isDragging=!1}scrubToPosition(t){if(!this.timeline||!this.timelineData)return;const e=this.rulerInner.getBoundingClientRect(),r=Math.max(0,Math.min(t.clientX-e.left,e.width))/e.width;this.timeline.progress(r),this.timeline.pause(),this.updatePlayState()}togglePlay(){this.timeline&&(this.timeline.paused()||this.timeline.progress()===1?this.timeline.progress()===1?this.timeline.restart():this.timeline.play():this.timeline.pause(),this.updatePlayState())}skipToStart(){this.timeline&&(this.timeline.progress(0),this.timeline.pause(),this.updatePlayState())}skipToEnd(){this.timeline&&(this.timeline.progress(1),this.timeline.pause(),this.updatePlayState())}toggleLoop(){this.timeline&&(this.isLooping=!this.isLooping,this.timeline.repeat(this.isLooping?-1:0),this.loopBtn.classList.toggle("active",this.isLooping))}cycleSpeed(){if(!this.timeline)return;this.speedIndex=(this.speedIndex+1)%u.length;const t=u[this.speedIndex];this.timeline.timeScale(t),this.speedBtn.textContent=`${t}x`}toggleCollapse(){this.collapsed=!this.collapsed,this.container.classList.toggle("collapsed",this.collapsed);const t=this.shadow.querySelector('[data-action="collapse"]');t.innerHTML=this.collapsed?'<svg viewBox="0 0 24 24"><path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6z"/></svg>':'<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>'}updatePlayState(){if(!this.timeline)return;this.isPlaying=!this.timeline.paused()&&this.timeline.progress()<1;const t=this.playBtn.querySelector(".play-icon"),e=this.playBtn.querySelector(".pause-icon");t.style.display=this.isPlaying?"none":"block",e.style.display=this.isPlaying?"block":"none"}onTimelineUpdate(){this.updatePlayhead(),this.updateTimeDisplay(),this.updateActiveTracks(),this.updatePlayState()}updatePlayhead(){if(!this.timeline||!this.timelineData)return;const e=`${this.timeline.progress()*100}%`;this.playhead.style.left=e;const a=this.tracksScroll.querySelector(".gtv-playhead-container");a&&(a.style.left=e)}updateTimeDisplay(){if(!this.timeline||!this.timelineData)return;const t=this.timeline.time(),e=this.timelineData.duration,a=this.timeDisplay.querySelector(".gtv-time-current"),r=this.timeDisplay.querySelector(".gtv-time-total");a.textContent=g(t),r.textContent=` / ${g(e)}`}updateActiveTracks(){if(!this.timeline||!this.timelineData)return;const t=this.timeline.time();this.tracksScroll.querySelectorAll(".gtv-track-bar").forEach((a,r)=>{const l=this.timelineData.tweens[r],d=t>=l.startTime&&t<=l.endTime;a.classList.toggle("is-active",d)})}renderTracks(){if(!this.timelineData)return;const{duration:t,tweens:e}=this.timelineData,a=this.shadow.querySelector(".gtv-empty");a.style.display=e.length>0?"none":"flex",this.renderRuler(t);const r=e.map(p=>this.renderTrack(p,t)).join(""),l=this.tracksScroll.querySelector(".gtv-scrub-area"),d=this.tracksScroll.querySelector(".gtv-playhead-container");this.tracksScroll.innerHTML=r,this.tracksScroll.prepend(l),this.tracksScroll.appendChild(d),this.scrubArea=l}renderRuler(t){const e=[],a=this.calculateInterval(t);for(let r=0;r<=t;r+=a){const l=r/t*100;e.push(`
60
- <div class="gtv-ruler-marker" style="left: ${l}%;">
70
+ `,this.container=this.shadow.querySelector(".gtv-container"),this.playBtn=this.shadow.querySelector('[data-action="play"]'),this.loopBtn=this.shadow.querySelector('[data-action="loop"]'),this.speedBtn=this.shadow.querySelector('[data-action="speed"]'),this.timeDisplay=this.shadow.querySelector(".gtv-time-display"),this.rulerInner=this.shadow.querySelector(".gtv-ruler-inner"),this.tracksScroll=this.shadow.querySelector(".gtv-tracks-scroll"),this.playhead=this.shadow.querySelector(".gtv-playhead"),this.scrubArea=this.shadow.querySelector(".gtv-scrub-area"),this.resizeHandle=this.shadow.querySelector(".gtv-resize-handle"),this.timelineSelect=this.shadow.querySelector(".gtv-timeline-select")}setupEventListeners(){this.shadow.addEventListener("click",t=>{const i=t.target.closest("[data-action]");if(!i)return;switch(i.dataset.action){case"play":this.togglePlay();break;case"skip-start":this.skipToStart();break;case"skip-end":this.skipToEnd();break;case"loop":this.toggleLoop();break;case"speed":this.cycleSpeed();break;case"collapse":this.toggleCollapse();break;case"autofit":this.toggleAutofit();break}}),this.timelineSelect.addEventListener("change",()=>{const t=this.timelineSelect.value;t&&Promise.resolve().then(()=>B).then(({TimelineViewer:e})=>{var i;(i=e.getInstance())==null||i.select(t)})}),this.shadow.addEventListener("click",t=>{const i=t.target.closest(".gtv-track-bar");if(i){const a=i.closest(".gtv-track");(a==null?void 0:a.dataset.expandable)==="true"&&(t.stopPropagation(),a.classList.toggle("expanded"),requestAnimationFrame(()=>this.applyAutofit()))}}),this.scrubArea.addEventListener("mousedown",t=>this.startScrub(t)),this.shadow.querySelector(".gtv-ruler").addEventListener("mousedown",t=>this.startScrub(t)),this.shadow.querySelector(".gtv-tracks-container").addEventListener("mousedown",t=>{t.target.closest(".gtv-track-bar")||this.startScrub(t)}),document.addEventListener("mousemove",t=>{this.onScrub(t),this.onResize(t)}),document.addEventListener("mouseup",()=>{this.endScrub(),this.endResize()}),this.resizeHandle.addEventListener("mousedown",t=>this.startResize(t)),document.addEventListener("keydown",t=>{if(t.target===document.body)switch(t.code){case"Space":t.preventDefault(),this.togglePlay();break;case"KeyJ":t.preventDefault(),this.jumpToPrevPoint();break;case"KeyK":t.preventDefault(),this.jumpToNextPoint();break;case"KeyL":t.preventDefault(),this.toggleLoop();break}})}startScrub(t){this.timeline&&(t.preventDefault(),this.isDragging=!0,document.body.style.cursor="ew-resize",document.body.style.userSelect="none",this.scrubToPosition(t))}onScrub(t){!this.isDragging||!this.timeline||this.scrubToPosition(t)}endScrub(){this.isDragging=!1,document.body.style.cursor="",document.body.style.userSelect=""}startResize(t){t.preventDefault(),this.isResizing=!0,document.body.style.cursor="ns-resize",document.body.style.userSelect="none"}onResize(t){if(!this.isResizing)return;const e=window.innerHeight,i=e-t.clientY;this.height=Math.max(100,Math.min(i,e-100)),this.container.style.height=`${this.height}px`,this.updateBodyPadding()}endResize(){this.isResizing&&(this.isResizing=!1,document.body.style.cursor="",document.body.style.userSelect="")}updateBodyPadding(){if(!this.manageBodyPadding)return;const t=this.collapsed?$:this.height;document.body.style.paddingBottom=`${t}px`}clearBodyPadding(){this.manageBodyPadding&&(document.body.style.paddingBottom="")}scrubToPosition(t){if(!this.timeline||!this.timelineData)return;const e=this.rulerInner.getBoundingClientRect(),a=Math.max(0,Math.min(t.clientX-e.left,e.width))/e.width;this.timeline.progress(a),this.timeline.pause(),this.updatePlayState()}togglePlay(){this.timeline&&(this.timeline.paused()||this.timeline.progress()===1?this.timeline.progress()===1?this.timeline.restart():this.timeline.play():this.timeline.pause(),this.updatePlayState())}skipToStart(){this.timeline&&(this.timeline.progress(0),this.timeline.pause(),this.updatePlayState())}skipToEnd(){this.timeline&&(this.timeline.progress(1),this.timeline.pause(),this.updatePlayState())}getTimePoints(){if(!this.timelineData)return[0];const t=new Set;return t.add(0),t.add(Math.round(this.timelineData.duration*1e3)/1e3),this.timelineData.tweens.forEach(e=>{t.add(Math.round(e.startTime*1e3)/1e3),t.add(Math.round(e.endTime*1e3)/1e3)}),Array.from(t).sort((e,i)=>e-i)}jumpToPrevPoint(){if(!this.timeline||!this.timelineData)return;const t=Math.round(this.timeline.time()*1e3)/1e3,e=this.getTimePoints();let i=0;for(const a of e)if(a<t-.001)i=a;else break;this.timeline.time(i),this.timeline.pause(),this.updatePlayState()}jumpToNextPoint(){if(!this.timeline||!this.timelineData)return;const t=Math.round(this.timeline.time()*1e3)/1e3,e=this.getTimePoints();let i=this.timelineData.duration;for(const a of e)if(a>t+.001){i=a;break}this.timeline.time(i),this.timeline.pause(),this.updatePlayState()}toggleLoop(){this.timeline&&(this.isLooping=!this.isLooping,this.timeline.repeat(this.isLooping?-1:0),this.loopBtn.classList.toggle("active",this.isLooping))}cycleSpeed(){if(!this.timeline)return;this.speedIndex=(this.speedIndex+1)%L.length;const t=L[this.speedIndex];this.timeline.timeScale(t),this.speedBtn.textContent=`${t}x`}toggleCollapse(){this.collapsed=!this.collapsed,this.container.classList.toggle("collapsed",this.collapsed);const t=this.shadow.querySelector('[data-action="collapse"]');t.innerHTML=this.collapsed?'<svg viewBox="0 0 24 24"><path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6z"/></svg>':'<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>',this.updateBodyPadding()}toggleAutofit(){this.isAutofit=!this.isAutofit,this.shadow.querySelector('[data-action="autofit"]').classList.toggle("active",this.isAutofit),this.isAutofit&&this.applyAutofit()}applyAutofit(){if(!this.isAutofit||this.collapsed)return;const t=this.shadow.querySelectorAll(".gtv-track");let e=0;const i=28,a=22;t.forEach(p=>{if(e+=i,p.classList.contains("expanded")){const d=p.querySelectorAll(".gtv-stagger-child");e+=d.length*a}});const r=24,n=16,g=100,m=window.innerHeight-100;this.height=Math.max(g,Math.min($+r+e+n,m)),this.container.style.height=`${this.height}px`,this.updateBodyPadding()}updatePlayState(){if(!this.timeline)return;this.isPlaying=!this.timeline.paused()&&this.timeline.progress()<1;const t=this.playBtn.querySelector(".play-icon"),e=this.playBtn.querySelector(".pause-icon");t.style.display=this.isPlaying?"none":"block",e.style.display=this.isPlaying?"block":"none"}onTimelineUpdate(){this.updatePlayhead(),this.updateTimeDisplay(),this.updateActiveTracks(),this.updatePlayState()}updatePlayhead(){if(!this.timeline||!this.timelineData)return;const t=this.timeline.progress();this.playhead.style.left=`${t*100}%`}updateTimeDisplay(){if(!this.timeline||!this.timelineData)return;const t=this.timeline.time(),e=this.timelineData.duration,i=this.timeDisplay.querySelector(".gtv-time-current"),a=this.timeDisplay.querySelector(".gtv-time-total");i.textContent=x(t),a.textContent=` / ${x(e)}`}updateActiveTracks(){if(!this.timeline||!this.timelineData)return;const t=this.timeline.time();this.tracksScroll.querySelectorAll(".gtv-track-bar").forEach((i,a)=>{const r=this.timelineData.tweens[a],n=t>=r.startTime&&t<=r.endTime,g=i.dataset.color;n?i.style.background=`var(--gtv-track-${g}-active)`:i.style.background=`var(--gtv-track-${g})`})}renderTracks(){if(!this.timelineData)return;const{duration:t,tweens:e}=this.timelineData,i=this.shadow.querySelector(".gtv-empty");i.style.display=e.length>0?"none":"flex",this.renderRuler(t);const a=this.renderGridLines(t),r=e.map(g=>this.renderTrack(g,t)).join(""),n=this.tracksScroll.querySelector(".gtv-scrub-area");this.tracksScroll.innerHTML=a+r,this.tracksScroll.prepend(n),this.scrubArea=n}renderGridLines(t){const e=[],i=this.calculateInterval(t);for(let a=0;a<=t;a+=i){const r=a/t*100;e.push(`<div class="gtv-grid-line" style="left: ${r}%;"></div>`)}return e.join("")}renderRuler(t){const e=[],i=this.calculateInterval(t);for(let a=0;a<=t;a+=i){const r=a/t*100;e.push(`
71
+ <div class="gtv-ruler-marker" style="left: ${r}%;">
61
72
  <div class="gtv-ruler-marker-line"></div>
62
- <span class="gtv-ruler-marker-label">${g(r,!1)}s</span>
73
+ <span class="gtv-ruler-marker-label">${x(a,!1)}s</span>
63
74
  </div>
64
- `)}this.rulerInner.innerHTML=e.join("")}calculateInterval(t){return t<=1?.25:t<=3?.5:t<=10?1:t<=30?5:10}renderTrack(t,e){const a=t.startTime/e*100,r=t.duration/e*100,l=L[t.colorIndex];return`
65
- <div class="gtv-track">
75
+ `)}this.rulerInner.innerHTML=e.join("")}calculateInterval(t){return t<=1?.25:t<=3?.5:t<=10?1:t<=30?5:10}renderTrack(t,e){const i=t.startTime/e*100,a=t.duration/e*100,r=t.colorIndex+1;let n="";t.hasStagger&&t.staggerChildren&&t.staggerChildren.length>0&&(n='<span class="gtv-track-stagger"><svg class="gtv-expand-icon" viewBox="0 0 24 24" width="10" height="10"><path fill="currentColor" d="M7 10l5 5 5-5z"/></svg> Stagger</span>');let g="";if(t.staggerChildren&&t.staggerChildren.length>0){const p=t.staggerChildren.map(d=>{const y=d.startTime/e*100,f=(d.endTime-d.startTime)/e*100;return`
76
+ <div class="gtv-stagger-child">
77
+ <div class="gtv-stagger-child-bar"
78
+ style="left: ${y}%; width: ${f}%; background: var(--gtv-track-${r});">
79
+ <span class="gtv-track-label">${d.targetLabel}</span>
80
+ </div>
81
+ </div>
82
+ `}).join("");g=`<div class="gtv-stagger-children" data-for="${t.id}">${p}</div>`}let m="";if(t.overlapWithPrev!==void 0){const p=t.overlapWithPrev>0,d=Math.abs(t.overlapWithPrev)/e*100,y=p?`-${x(t.overlapWithPrev)}s`:`+${x(Math.abs(t.overlapWithPrev))}s`;p?m=`
83
+ <div class="gtv-overlap-region" style="left: ${i}%; width: ${d}%;"></div>
84
+ <span class="gtv-offset-badge gtv-offset-overlap" style="left: ${i}%;">${y}</span>
85
+ `:m=`
86
+ <div class="gtv-gap-connector" style="left: ${i-d}%; width: ${d}%;"></div>
87
+ <span class="gtv-offset-badge gtv-offset-gap" style="left: ${i}%;">${y}</span>
88
+ `}return`
89
+ <div class="gtv-track" data-expandable="${t.hasStagger&&t.staggerChildren?"true":"false"}">
90
+ ${m}
66
91
  <div class="gtv-track-bar"
67
- style="left: ${a}%; width: ${r}%; background: ${l};"
68
- title="${t.label} (${g(t.startTime)}s - ${g(t.endTime)}s)">
69
- ${t.label}
92
+ data-color="${r}"
93
+ data-tween-id="${t.id}"
94
+ style="left: ${i}%; width: ${a}%; background: var(--gtv-track-${r});">
95
+ <span class="gtv-track-label">${t.label}</span>
96
+ ${n}
70
97
  </div>
98
+ ${g}
71
99
  </div>
72
- `}}customElements.define("gsap-timeline-viewer",m);class P{constructor(i){s(this,"element");this.element=document.createElement("gsap-timeline-viewer"),i.height&&this.element.style.setProperty("--viewer-height",`${i.height}px`),i.timeline&&setTimeout(()=>{this.element.setTimeline(i.timeline)},0)}attach(i=document.body){i.appendChild(this.element)}detach(){this.element.remove()}setTimeline(i){this.element.setTimeline(i)}get htmlElement(){return this.element}}return o.TimelineViewer=P,o.TimelineViewerElement=m,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),o}({});
100
+ `}}customElements.define("gsap-timeline-viewer",T);const h=new Map;let o=null,z=!0,q=0,P=null;function I(){const c=window.gsap;!c||P||(P=c.timeline.bind(c),c.timeline=function(s){const t=P(s);if(z){let e;s!=null&&s.id&&typeof s.id=="string"?e=s.id:e=`Timeline ${++q}`,h.has(e)||(h.set(e,t),o&&(o.htmlElement.updateTimelineSelector(),h.size===1&&o.select(e)))}return t})}class k{constructor(s={}){l(this,"element");l(this,"currentTimelineName",null);this.element=document.createElement("gsap-timeline-viewer"),s.height&&this.element.style.setProperty("--viewer-height",`${s.height}px`)}static create(s={}){return o||(z=s.autoDetect!==!1,z&&I(),o=new k(s),document.body.appendChild(o.element),setTimeout(()=>{if(o.element.updateTimelineSelector(),s.defaultTimeline&&h.has(s.defaultTimeline))o.select(s.defaultTimeline);else if(h.size>0){const t=h.keys().next().value;t&&o.select(t)}},0),o)}static register(s,t){h.set(s,t),o&&(o.element.updateTimelineSelector(),h.size===1&&o.select(s))}static unregister(s){h.delete(s),o&&o.element.updateTimelineSelector()}static getTimelines(){return h}static getInstance(){return o}select(s){const t=h.get(s);t&&(this.currentTimelineName=s,this.element.setTimeline(t),this.element.setSelectedTimeline(s))}getCurrentTimelineName(){return this.currentTimelineName}destroy(){this.element.remove(),o=null}get htmlElement(){return this.element}}const B=Object.freeze(Object.defineProperty({__proto__:null,TimelineViewer:k,TimelineViewerElement:T},Symbol.toStringTag,{value:"Module"}));return v.TimelineViewer=k,v.TimelineViewerElement=T,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"}),v}({});
@@ -1,14 +1,14 @@
1
- var f = Object.defineProperty;
2
- var x = (a, e, t) => e in a ? f(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t;
3
- var s = (a, e, t) => x(a, typeof e != "symbol" ? e + "" : e, t);
4
- let y = 0;
5
- function m(a) {
6
- if (!a || a.length === 0) return "Unknown";
7
- const e = a[0];
8
- return e.id ? `#${e.id}` : e.classList && e.classList.length > 0 ? `.${e.classList[0]}` : e.tagName ? e.tagName.toLowerCase() : "element";
1
+ var M = Object.defineProperty;
2
+ var A = (o, i, t) => i in o ? M(o, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[i] = t;
3
+ var l = (o, i, t) => A(o, typeof i != "symbol" ? i + "" : i, t);
4
+ let B = 0;
5
+ function x(o) {
6
+ if (!o || o.length === 0) return "Unknown";
7
+ const i = o[0];
8
+ return i.id ? `#${i.id}` : i.classList && i.classList.length > 0 ? `.${i.classList[0]}` : i.tagName ? i.tagName.toLowerCase() : "element";
9
9
  }
10
- function k(a) {
11
- const e = [
10
+ function E(o) {
11
+ const i = [
12
12
  "ease",
13
13
  "duration",
14
14
  "delay",
@@ -31,99 +31,146 @@ function k(a) {
31
31
  "reversed",
32
32
  "startAt"
33
33
  ];
34
- return Object.keys(a).filter((t) => !e.includes(t));
34
+ return Object.keys(o).filter((t) => !i.includes(t));
35
35
  }
36
- function S(a) {
37
- const e = [];
38
- return a.getChildren(!0, !0, !1).forEach((i, r) => {
39
- if (!("targets" in i)) return;
40
- const n = i, l = n.targets(), o = n.vars || {}, d = k(o);
41
- let h = "";
42
- if (o.id && typeof o.id == "string")
43
- h = o.id;
36
+ function H(o) {
37
+ const i = [];
38
+ o.getChildren(!0, !0, !1).forEach((e, s) => {
39
+ if (!("targets" in e)) return;
40
+ const a = e, r = a.targets(), n = a.vars || {}, g = E(n);
41
+ let v = "";
42
+ if (n.id && typeof n.id == "string")
43
+ v = n.id;
44
44
  else {
45
- const v = m(l), u = d.slice(0, 2).join(", ");
46
- h = u ? `${v} (${u})` : v;
45
+ const b = x(r), y = g.slice(0, 2).join(", ");
46
+ v = y ? `${b} (${y})` : b;
47
47
  }
48
- const g = i.startTime(), p = i.duration();
49
- e.push({
50
- id: `tween-${++y}`,
51
- label: h,
52
- startTime: g,
53
- endTime: g + p,
54
- duration: p,
55
- targets: m(l),
56
- properties: d,
57
- colorIndex: r % 6
48
+ const h = e.startTime(), d = e.duration();
49
+ let m = "none";
50
+ n.ease && (m = typeof n.ease == "string" ? n.ease : "custom");
51
+ let u, T;
52
+ if (n.stagger && r.length > 1 && (typeof n.stagger == "number" ? u = n.stagger : typeof n.stagger == "object" && (u = n.stagger.each || 0), u)) {
53
+ const b = d - u * (r.length - 1);
54
+ T = r.map((y, D) => {
55
+ const z = h + D * u;
56
+ return {
57
+ targetLabel: x([y]),
58
+ startTime: z,
59
+ endTime: z + b
60
+ };
61
+ });
62
+ }
63
+ i.push({
64
+ id: `tween-${++B}`,
65
+ label: v,
66
+ startTime: h,
67
+ endTime: h + d,
68
+ duration: d,
69
+ targets: x(r),
70
+ properties: g,
71
+ colorIndex: s % 6,
72
+ hasStagger: !!n.stagger,
73
+ ease: m,
74
+ staggerValue: u,
75
+ staggerChildren: T
58
76
  });
59
- }), {
60
- duration: a.duration(),
61
- tweens: e
77
+ });
78
+ for (let e = 1; e < i.length; e++) {
79
+ const s = i[e - 1], a = i[e], r = s.endTime - a.startTime;
80
+ Math.abs(r) > 1e-3 && (a.overlapWithPrev = Math.round(r * 1e3) / 1e3);
81
+ }
82
+ return {
83
+ duration: o.duration(),
84
+ tweens: i
62
85
  };
63
86
  }
64
- function w() {
65
- y = 0;
87
+ function q() {
88
+ B = 0;
66
89
  }
67
- function c(a, e = !0) {
68
- const t = Math.abs(a);
69
- return e ? t.toFixed(2) : t.toFixed(0);
90
+ function f(o, i = !0) {
91
+ const t = Math.abs(o);
92
+ return i ? t.toFixed(2) : t.toFixed(0);
70
93
  }
71
- const T = ":host{--gtv-bg: #1a1a1a;--gtv-bg-secondary: #252525;--gtv-border: #333;--gtv-text: #e0e0e0;--gtv-text-muted: #888;--gtv-accent: #4a9eff;--gtv-playhead: #4a9eff;--gtv-ruler-bg: #1f1f1f;--gtv-track-height: 28px;--gtv-controls-height: 40px;--gtv-ruler-height: 24px;--gtv-track-1: #3b82f6;--gtv-track-2: #f59e0b;--gtv-track-3: #ec4899;--gtv-track-4: #10b981;--gtv-track-5: #8b5cf6;--gtv-track-6: #ef4444}*{box-sizing:border-box;margin:0;padding:0}.gtv-container{position:fixed;bottom:0;left:0;right:0;background:var(--gtv-bg);border-top:1px solid var(--gtv-border);font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:12px;color:var(--gtv-text);z-index:999999;display:flex;flex-direction:column}.gtv-container.collapsed{height:auto!important}.gtv-container.collapsed .gtv-timeline-area{display:none}.gtv-controls{display:flex;align-items:center;justify-content:space-between;height:var(--gtv-controls-height);padding:0 12px;background:var(--gtv-bg-secondary);border-bottom:1px solid var(--gtv-border);gap:16px}.gtv-controls-left,.gtv-controls-center,.gtv-controls-right{display:flex;align-items:center;gap:8px}.gtv-controls-center{flex:0 0 auto}.gtv-time-display{font-variant-numeric:tabular-nums;min-width:100px;text-align:center}.gtv-time-current{color:var(--gtv-text)}.gtv-time-total{color:var(--gtv-text-muted)}.gtv-btn{display:flex;align-items:center;justify-content:center;width:28px;height:28px;background:transparent;border:none;border-radius:4px;color:var(--gtv-text);cursor:pointer;transition:background .15s}.gtv-btn:hover{background:#ffffff1a}.gtv-btn:active{background:#ffffff26}.gtv-btn.active{color:var(--gtv-accent)}.gtv-btn svg{width:16px;height:16px;fill:currentColor}.gtv-btn-play svg{width:20px;height:20px}.gtv-speed-btn{width:auto;padding:0 8px;font-size:11px;font-weight:500}.gtv-collapse-btn{margin-left:auto}.gtv-timeline-area{display:flex;flex-direction:column;overflow:hidden;flex:1}.gtv-ruler{position:relative;height:var(--gtv-ruler-height);background:var(--gtv-ruler-bg);border-bottom:1px solid var(--gtv-border);overflow:hidden;flex-shrink:0}.gtv-ruler-inner{position:relative;height:100%}.gtv-ruler-marker{position:absolute;top:0;height:100%;display:flex;flex-direction:column;align-items:center}.gtv-ruler-marker-line{width:1px;height:6px;background:var(--gtv-text-muted)}.gtv-ruler-marker-label{font-size:10px;color:var(--gtv-text-muted);margin-top:2px}.gtv-tracks-container{position:relative;overflow-y:auto;overflow-x:hidden;flex:1}.gtv-tracks-scroll{position:relative;min-height:100%}.gtv-track{position:relative;height:var(--gtv-track-height);border-bottom:1px solid var(--gtv-border)}.gtv-track-bar{position:absolute;top:4px;height:calc(var(--gtv-track-height) - 8px);border-radius:4px;display:flex;align-items:center;padding:0 8px;font-size:11px;font-weight:500;color:#fff;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:default;transition:filter .15s}.gtv-track-bar:hover{filter:brightness(1.1)}.gtv-track-bar.is-active{box-shadow:0 0 0 2px var(--gtv-accent)}.gtv-playhead-container{position:absolute;top:0;bottom:0;width:1px;pointer-events:none;z-index:10}.gtv-playhead-head{position:absolute;top:0;left:-5px;width:11px;height:11px;background:var(--gtv-playhead);clip-path:polygon(50% 100%,0 0,100% 0)}.gtv-playhead-line{position:absolute;top:11px;bottom:0;left:0;width:1px;background:var(--gtv-playhead)}.gtv-scrub-area{position:absolute;top:0;left:0;right:0;bottom:0;cursor:pointer}.gtv-empty{display:flex;align-items:center;justify-content:center;padding:24px;color:var(--gtv-text-muted)}", L = [
72
- "var(--gtv-track-1)",
73
- "var(--gtv-track-2)",
74
- "var(--gtv-track-3)",
75
- "var(--gtv-track-4)",
76
- "var(--gtv-track-5)",
77
- "var(--gtv-track-6)"
78
- ], b = [0.25, 0.5, 1, 2, 4];
79
- class P extends HTMLElement {
94
+ const I = ":host{--gtv-bg: #1a1a1a;--gtv-bg-secondary: #252525;--gtv-border: #333;--gtv-text: #e0e0e0;--gtv-text-muted: #888;--gtv-accent: oklch(65% .15 220);--gtv-playhead: oklch(65% .15 220);--gtv-ruler-bg: #1f1f1f;--gtv-track-height: 28px;--gtv-controls-height: 40px;--gtv-ruler-height: 24px;--gtv-timeline-padding: 16px;--gtv-track-1: oklch(50% .12 220);--gtv-track-1-active: oklch(60% .15 220);--gtv-track-2: oklch(50% .12 70);--gtv-track-2-active: oklch(60% .15 70);--gtv-track-3: oklch(50% .12 350);--gtv-track-3-active: oklch(60% .15 350);--gtv-track-4: oklch(50% .12 160);--gtv-track-4-active: oklch(60% .15 160);--gtv-track-5: oklch(50% .12 290);--gtv-track-5-active: oklch(60% .15 290);--gtv-track-6: oklch(50% .12 25);--gtv-track-6-active: oklch(60% .15 25)}*{box-sizing:border-box;margin:0;padding:0}.gtv-container{position:fixed;bottom:0;left:0;right:0;background:var(--gtv-bg);border-top:1px solid var(--gtv-border);font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:12px;color:var(--gtv-text);z-index:999999;display:flex;flex-direction:column;user-select:none;-webkit-user-select:none}.gtv-container.collapsed{height:auto!important}.gtv-container.collapsed .gtv-timeline-area{display:none}.gtv-controls{position:relative;display:flex;align-items:center;justify-content:center;height:var(--gtv-controls-height);padding:0 12px;background:var(--gtv-bg-secondary);border-bottom:1px solid var(--gtv-border);gap:8px}.gtv-controls-left{position:absolute;left:12px;display:flex;align-items:center;gap:8px}.gtv-controls-center{display:flex;align-items:center;gap:8px}.gtv-controls-right{position:absolute;right:12px;display:flex;align-items:center;gap:8px}.gtv-time-display{font-variant-numeric:tabular-nums;min-width:100px;text-align:center}.gtv-time-current{color:var(--gtv-text)}.gtv-time-total{color:var(--gtv-text-muted)}.gtv-btn{display:flex;align-items:center;justify-content:center;width:28px;height:28px;background:transparent;border:none;border-radius:4px;color:var(--gtv-text);cursor:pointer;transition:background .15s}.gtv-btn:hover{background:#ffffff1a}.gtv-btn:active{background:#ffffff26}.gtv-btn.active{color:var(--gtv-accent)}.gtv-btn svg{width:16px;height:16px;fill:currentColor}.gtv-btn-play svg{width:20px;height:20px}.gtv-speed-btn{width:auto;padding:0 8px;font-size:11px;font-weight:500}.gtv-timeline-select{background:var(--gtv-bg);border:1px solid var(--gtv-border);border-radius:4px;color:var(--gtv-text);font-size:11px;padding:4px 8px;cursor:pointer;max-width:140px}.gtv-timeline-select:focus{outline:none;border-color:var(--gtv-accent)}.gtv-collapse-btn{margin-left:auto}.gtv-timeline-area{position:relative;display:flex;flex-direction:column;overflow:hidden;flex:1}.gtv-resize-handle{position:absolute;top:0;left:0;right:0;height:6px;cursor:ns-resize;z-index:20}.gtv-resize-handle:hover,.gtv-resize-handle:active{background:#ffffff1a}.gtv-ruler{position:relative;height:var(--gtv-ruler-height);background:var(--gtv-ruler-bg);border-bottom:1px solid var(--gtv-border);overflow:visible;flex-shrink:0;padding:0 var(--gtv-timeline-padding)}.gtv-ruler-inner{position:relative;height:100%;width:100%}.gtv-ruler-marker{position:absolute;top:0;display:flex;flex-direction:column;align-items:center}.gtv-ruler-marker-line{width:1px;height:6px;background:var(--gtv-text-muted)}.gtv-ruler-marker-label{font-size:10px;color:var(--gtv-text-muted);margin-top:2px}.gtv-grid-line{position:absolute;top:0;width:1px;height:100%;background:var(--gtv-border);pointer-events:none}.gtv-tracks-container{position:relative;overflow-y:auto;overflow-x:hidden;flex:1;padding:0 var(--gtv-timeline-padding)}.gtv-tracks-scroll{position:relative;min-height:100%;width:100%}.gtv-track{position:relative;padding-top:var(--gtv-track-height)}.gtv-track-bar{position:absolute;top:4px;height:calc(var(--gtv-track-height) - 8px);border-radius:4px;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:0 8px;font-size:11px;font-weight:500;color:#fff;overflow:hidden;cursor:default;transition:filter .15s}.gtv-track-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0}.gtv-track-stagger{opacity:.7;font-size:10px;font-weight:400;flex-shrink:0}.gtv-track-bar:hover{filter:brightness(1.1)}.gtv-playhead-wrapper{position:absolute;top:0;bottom:0;left:var(--gtv-timeline-padding);right:var(--gtv-timeline-padding);pointer-events:none;z-index:15}.gtv-playhead{position:absolute;top:0;bottom:0;width:0;left:0}.gtv-playhead-head{position:absolute;top:6px;left:-5px;width:11px;height:11px;background:var(--gtv-playhead);clip-path:polygon(50% 100%,0 0,100% 0)}.gtv-playhead-line{position:absolute;top:6px;bottom:0;left:0;width:1px;background:var(--gtv-playhead)}.gtv-scrub-area{position:absolute;top:0;left:0;right:0;bottom:0;cursor:ew-resize}.gtv-track[data-expandable=true] .gtv-track-bar{cursor:pointer}.gtv-expand-icon{transition:transform .2s}.gtv-track.expanded .gtv-expand-icon{transform:rotate(180deg)}.gtv-stagger-children{display:none;position:relative;width:100%}.gtv-track.expanded .gtv-stagger-children{display:block}.gtv-stagger-child{position:relative;width:100%;height:calc(var(--gtv-track-height) - 6px)}.gtv-stagger-child-bar{position:absolute;top:2px;height:calc(var(--gtv-track-height) - 12px);border-radius:3px;display:flex;align-items:center;padding:0 6px;font-size:10px;color:#fff;opacity:.7;overflow:hidden}.gtv-stagger-child-bar .gtv-track-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.gtv-overlap-region{position:absolute;top:4px;height:calc(var(--gtv-track-height) - 8px);background:repeating-linear-gradient(-45deg,transparent,transparent 2px,rgba(255,255,255,.15) 2px,rgba(255,255,255,.15) 4px);border-radius:4px;pointer-events:none;z-index:5}.gtv-gap-connector{position:absolute;top:50%;height:1px;border-top:1px dashed var(--gtv-text-muted);pointer-events:none}.gtv-offset-badge{position:absolute;top:50%;transform:translate(-100%,-50%);margin-left:-4px;font-size:9px;font-weight:500;padding:2px 5px;border-radius:3px;white-space:nowrap;pointer-events:none;z-index:10}.gtv-offset-overlap,.gtv-offset-gap{background:var(--gtv-bg-secondary);border:1px solid var(--gtv-border);color:var(--gtv-text-muted)}.gtv-empty{display:flex;align-items:center;justify-content:center;padding:24px;color:var(--gtv-text-muted)}", P = [0.25, 0.5, 1, 2, 4], L = 40;
95
+ class C extends HTMLElement {
80
96
  constructor() {
81
97
  super();
82
- s(this, "shadow");
83
- s(this, "timeline", null);
84
- s(this, "timelineData", null);
85
- s(this, "isPlaying", !1);
86
- s(this, "isLooping", !1);
87
- s(this, "speedIndex", 2);
98
+ l(this, "shadow");
99
+ l(this, "timeline", null);
100
+ l(this, "timelineData", null);
101
+ l(this, "isPlaying", !1);
102
+ l(this, "isLooping", !1);
103
+ l(this, "speedIndex", 2);
88
104
  // 1x
89
- s(this, "collapsed", !1);
90
- s(this, "height", 200);
91
- s(this, "isDragging", !1);
105
+ l(this, "collapsed", !1);
106
+ l(this, "height", 200);
107
+ l(this, "isDragging", !1);
108
+ l(this, "manageBodyPadding", !0);
109
+ l(this, "isAutofit", !1);
92
110
  // DOM references
93
- s(this, "container");
94
- s(this, "playBtn");
95
- s(this, "loopBtn");
96
- s(this, "speedBtn");
97
- s(this, "timeDisplay");
98
- s(this, "rulerInner");
99
- s(this, "tracksScroll");
100
- s(this, "playhead");
101
- s(this, "scrubArea");
111
+ l(this, "container");
112
+ l(this, "playBtn");
113
+ l(this, "loopBtn");
114
+ l(this, "speedBtn");
115
+ l(this, "timeDisplay");
116
+ l(this, "rulerInner");
117
+ l(this, "tracksScroll");
118
+ l(this, "playhead");
119
+ l(this, "scrubArea");
120
+ l(this, "resizeHandle");
121
+ l(this, "timelineSelect");
122
+ l(this, "isResizing", !1);
102
123
  this.shadow = this.attachShadow({ mode: "open" });
103
124
  }
104
125
  connectedCallback() {
105
- this.render(), this.setupEventListeners();
126
+ this.render(), this.setupEventListeners(), this.updateBodyPadding();
106
127
  }
107
128
  disconnectedCallback() {
108
- this.detachTimeline();
129
+ this.detachTimeline(), this.clearBodyPadding();
109
130
  }
110
131
  setTimeline(t) {
111
- this.detachTimeline(), this.timeline = t, w(), this.timelineData = S(t), t.eventCallback("onUpdate", () => this.onTimelineUpdate()), this.renderTracks(), this.updatePlayhead(), this.updateTimeDisplay(), this.updatePlayState();
132
+ this.detachTimeline(), this.timeline = t, q(), this.timelineData = H(t), t.eventCallback("onUpdate", () => this.onTimelineUpdate()), this.renderTracks(), this.updatePlayhead(), this.updateTimeDisplay(), this.updatePlayState(), requestAnimationFrame(() => this.applyAutofit());
133
+ }
134
+ updateTimelineSelector() {
135
+ Promise.resolve().then(() => $).then(({ TimelineViewer: t }) => {
136
+ const e = t.getTimelines(), s = this.timelineSelect.value;
137
+ this.timelineSelect.innerHTML = "", e.forEach((a, r) => {
138
+ const n = document.createElement("option");
139
+ n.value = r, n.textContent = r, this.timelineSelect.appendChild(n);
140
+ }), s && e.has(s) && (this.timelineSelect.value = s);
141
+ });
142
+ }
143
+ setSelectedTimeline(t) {
144
+ this.timelineSelect.value = t;
112
145
  }
113
146
  detachTimeline() {
114
147
  this.timeline && (this.timeline.eventCallback("onUpdate", null), this.timeline = null, this.timelineData = null);
115
148
  }
116
149
  render() {
117
150
  this.shadow.innerHTML = `
118
- <style>${T}</style>
151
+ <style>${I}</style>
119
152
  <div class="gtv-container ${this.collapsed ? "collapsed" : ""}" style="height: ${this.height}px;">
120
153
  <!-- Controls Bar -->
121
154
  <div class="gtv-controls">
122
155
  <div class="gtv-controls-left">
156
+ <select class="gtv-timeline-select" title="Select timeline">
157
+ <option value="">No timeline</option>
158
+ </select>
159
+ <button class="gtv-btn" data-action="loop" title="Loop (L)">
160
+ <svg viewBox="0 0 24 24"><path d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z"/></svg>
161
+ </button>
162
+ <button class="gtv-btn gtv-speed-btn" data-action="speed" title="Playback speed">1x</button>
163
+ </div>
164
+
165
+ <div class="gtv-controls-center">
166
+ <span class="gtv-time-display">
167
+ <span class="gtv-time-current">0.00</span>
168
+ <span class="gtv-time-total"> / 0.00</span>
169
+ </span>
123
170
  <button class="gtv-btn" data-action="skip-start" title="Skip to start">
124
171
  <svg viewBox="0 0 24 24"><path d="M6 6h2v12H6V6zm3.5 6l8.5 6V6l-8.5 6z"/></svg>
125
172
  </button>
126
- <button class="gtv-btn gtv-btn-play" data-action="play" title="Play/Pause">
173
+ <button class="gtv-btn gtv-btn-play" data-action="play" title="Play/Pause (Space)">
127
174
  <svg class="play-icon" viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg>
128
175
  <svg class="pause-icon" viewBox="0 0 24 24" style="display: none;"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>
129
176
  </button>
@@ -132,18 +179,10 @@ class P extends HTMLElement {
132
179
  </button>
133
180
  </div>
134
181
 
135
- <div class="gtv-controls-center">
136
- <button class="gtv-btn" data-action="loop" title="Loop">
137
- <svg viewBox="0 0 24 24"><path d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z"/></svg>
138
- </button>
139
- <span class="gtv-time-display">
140
- <span class="gtv-time-current">0.00</span>
141
- <span class="gtv-time-total"> / 0.00</span>
142
- </span>
143
- <button class="gtv-btn gtv-speed-btn" data-action="speed" title="Playback speed">1x</button>
144
- </div>
145
-
146
182
  <div class="gtv-controls-right">
183
+ <button class="gtv-btn" data-action="autofit" title="Auto-fit height">
184
+ <svg viewBox="0 0 24 24"><path d="M4 8h4V4H4v4zm6 12h4v-4h-4v4zm-6 0h4v-4H4v4zm0-6h4v-4H4v4zm6 0h4v-4h-4v4zm6-10v4h4V4h-4zm-6 4h4V4h-4v4zm6 6h4v-4h-4v4zm0 6h4v-4h-4v4z"/></svg>
185
+ </button>
147
186
  <button class="gtv-btn gtv-collapse-btn" data-action="collapse" title="Collapse/Expand">
148
187
  <svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>
149
188
  </button>
@@ -152,33 +191,38 @@ class P extends HTMLElement {
152
191
 
153
192
  <!-- Timeline Area -->
154
193
  <div class="gtv-timeline-area">
194
+ <!-- Resize Handle -->
195
+ <div class="gtv-resize-handle"></div>
196
+
155
197
  <!-- Ruler -->
156
198
  <div class="gtv-ruler">
157
199
  <div class="gtv-ruler-inner"></div>
158
- <div class="gtv-playhead-container">
159
- <div class="gtv-playhead-head"></div>
160
- </div>
161
200
  </div>
162
201
 
163
202
  <!-- Tracks -->
164
203
  <div class="gtv-tracks-container">
165
204
  <div class="gtv-tracks-scroll">
166
205
  <div class="gtv-scrub-area"></div>
167
- <div class="gtv-playhead-container">
168
- <div class="gtv-playhead-line"></div>
169
- </div>
170
206
  </div>
171
207
  <div class="gtv-empty">No timeline attached. Call setTimeline() to visualize a GSAP timeline.</div>
172
208
  </div>
209
+
210
+ <!-- Playhead spans entire timeline area -->
211
+ <div class="gtv-playhead-wrapper">
212
+ <div class="gtv-playhead">
213
+ <div class="gtv-playhead-head"></div>
214
+ <div class="gtv-playhead-line"></div>
215
+ </div>
216
+ </div>
173
217
  </div>
174
218
  </div>
175
- `, this.container = this.shadow.querySelector(".gtv-container"), this.playBtn = this.shadow.querySelector('[data-action="play"]'), this.loopBtn = this.shadow.querySelector('[data-action="loop"]'), this.speedBtn = this.shadow.querySelector('[data-action="speed"]'), this.timeDisplay = this.shadow.querySelector(".gtv-time-display"), this.rulerInner = this.shadow.querySelector(".gtv-ruler-inner"), this.tracksScroll = this.shadow.querySelector(".gtv-tracks-scroll"), this.playhead = this.shadow.querySelector(".gtv-ruler .gtv-playhead-container"), this.scrubArea = this.shadow.querySelector(".gtv-scrub-area");
219
+ `, this.container = this.shadow.querySelector(".gtv-container"), this.playBtn = this.shadow.querySelector('[data-action="play"]'), this.loopBtn = this.shadow.querySelector('[data-action="loop"]'), this.speedBtn = this.shadow.querySelector('[data-action="speed"]'), this.timeDisplay = this.shadow.querySelector(".gtv-time-display"), this.rulerInner = this.shadow.querySelector(".gtv-ruler-inner"), this.tracksScroll = this.shadow.querySelector(".gtv-tracks-scroll"), this.playhead = this.shadow.querySelector(".gtv-playhead"), this.scrubArea = this.shadow.querySelector(".gtv-scrub-area"), this.resizeHandle = this.shadow.querySelector(".gtv-resize-handle"), this.timelineSelect = this.shadow.querySelector(".gtv-timeline-select");
176
220
  }
177
221
  setupEventListeners() {
178
222
  this.shadow.addEventListener("click", (t) => {
179
- const r = t.target.closest("[data-action]");
180
- if (!r) return;
181
- switch (r.dataset.action) {
223
+ const s = t.target.closest("[data-action]");
224
+ if (!s) return;
225
+ switch (s.dataset.action) {
182
226
  case "play":
183
227
  this.togglePlay();
184
228
  break;
@@ -197,24 +241,78 @@ class P extends HTMLElement {
197
241
  case "collapse":
198
242
  this.toggleCollapse();
199
243
  break;
244
+ case "autofit":
245
+ this.toggleAutofit();
246
+ break;
200
247
  }
201
- }), this.scrubArea.addEventListener("mousedown", (t) => this.startScrub(t)), this.shadow.querySelector(".gtv-ruler").addEventListener("mousedown", (t) => this.startScrub(t)), document.addEventListener("mousemove", (t) => this.onScrub(t)), document.addEventListener("mouseup", () => this.endScrub()), document.addEventListener("keydown", (t) => {
202
- t.target === document.body && t.code === "Space" && (t.preventDefault(), this.togglePlay());
248
+ }), this.timelineSelect.addEventListener("change", () => {
249
+ const t = this.timelineSelect.value;
250
+ t && Promise.resolve().then(() => $).then(({ TimelineViewer: e }) => {
251
+ var s;
252
+ (s = e.getInstance()) == null || s.select(t);
253
+ });
254
+ }), this.shadow.addEventListener("click", (t) => {
255
+ const s = t.target.closest(".gtv-track-bar");
256
+ if (s) {
257
+ const a = s.closest(".gtv-track");
258
+ (a == null ? void 0 : a.dataset.expandable) === "true" && (t.stopPropagation(), a.classList.toggle("expanded"), requestAnimationFrame(() => this.applyAutofit()));
259
+ }
260
+ }), this.scrubArea.addEventListener("mousedown", (t) => this.startScrub(t)), this.shadow.querySelector(".gtv-ruler").addEventListener("mousedown", (t) => this.startScrub(t)), this.shadow.querySelector(".gtv-tracks-container").addEventListener("mousedown", (t) => {
261
+ t.target.closest(".gtv-track-bar") || this.startScrub(t);
262
+ }), document.addEventListener("mousemove", (t) => {
263
+ this.onScrub(t), this.onResize(t);
264
+ }), document.addEventListener("mouseup", () => {
265
+ this.endScrub(), this.endResize();
266
+ }), this.resizeHandle.addEventListener("mousedown", (t) => this.startResize(t)), document.addEventListener("keydown", (t) => {
267
+ if (t.target === document.body)
268
+ switch (t.code) {
269
+ case "Space":
270
+ t.preventDefault(), this.togglePlay();
271
+ break;
272
+ case "KeyJ":
273
+ t.preventDefault(), this.jumpToPrevPoint();
274
+ break;
275
+ case "KeyK":
276
+ t.preventDefault(), this.jumpToNextPoint();
277
+ break;
278
+ case "KeyL":
279
+ t.preventDefault(), this.toggleLoop();
280
+ break;
281
+ }
203
282
  });
204
283
  }
205
284
  startScrub(t) {
206
- this.timeline && (this.isDragging = !0, this.scrubToPosition(t));
285
+ this.timeline && (t.preventDefault(), this.isDragging = !0, document.body.style.cursor = "ew-resize", document.body.style.userSelect = "none", this.scrubToPosition(t));
207
286
  }
208
287
  onScrub(t) {
209
288
  !this.isDragging || !this.timeline || this.scrubToPosition(t);
210
289
  }
211
290
  endScrub() {
212
- this.isDragging = !1;
291
+ this.isDragging = !1, document.body.style.cursor = "", document.body.style.userSelect = "";
292
+ }
293
+ startResize(t) {
294
+ t.preventDefault(), this.isResizing = !0, document.body.style.cursor = "ns-resize", document.body.style.userSelect = "none";
295
+ }
296
+ onResize(t) {
297
+ if (!this.isResizing) return;
298
+ const e = window.innerHeight, s = e - t.clientY;
299
+ this.height = Math.max(100, Math.min(s, e - 100)), this.container.style.height = `${this.height}px`, this.updateBodyPadding();
300
+ }
301
+ endResize() {
302
+ this.isResizing && (this.isResizing = !1, document.body.style.cursor = "", document.body.style.userSelect = "");
303
+ }
304
+ updateBodyPadding() {
305
+ if (!this.manageBodyPadding) return;
306
+ const t = this.collapsed ? L : this.height;
307
+ document.body.style.paddingBottom = `${t}px`;
308
+ }
309
+ clearBodyPadding() {
310
+ this.manageBodyPadding && (document.body.style.paddingBottom = "");
213
311
  }
214
312
  scrubToPosition(t) {
215
313
  if (!this.timeline || !this.timelineData) return;
216
- const i = this.rulerInner.getBoundingClientRect(), n = Math.max(0, Math.min(t.clientX - i.left, i.width)) / i.width;
217
- this.timeline.progress(n), this.timeline.pause(), this.updatePlayState();
314
+ const e = this.rulerInner.getBoundingClientRect(), a = Math.max(0, Math.min(t.clientX - e.left, e.width)) / e.width;
315
+ this.timeline.progress(a), this.timeline.pause(), this.updatePlayState();
218
316
  }
219
317
  togglePlay() {
220
318
  this.timeline && (this.timeline.paused() || this.timeline.progress() === 1 ? this.timeline.progress() === 1 ? this.timeline.restart() : this.timeline.play() : this.timeline.pause(), this.updatePlayState());
@@ -225,107 +323,256 @@ class P extends HTMLElement {
225
323
  skipToEnd() {
226
324
  this.timeline && (this.timeline.progress(1), this.timeline.pause(), this.updatePlayState());
227
325
  }
326
+ getTimePoints() {
327
+ if (!this.timelineData) return [0];
328
+ const t = /* @__PURE__ */ new Set();
329
+ return t.add(0), t.add(Math.round(this.timelineData.duration * 1e3) / 1e3), this.timelineData.tweens.forEach((e) => {
330
+ t.add(Math.round(e.startTime * 1e3) / 1e3), t.add(Math.round(e.endTime * 1e3) / 1e3);
331
+ }), Array.from(t).sort((e, s) => e - s);
332
+ }
333
+ jumpToPrevPoint() {
334
+ if (!this.timeline || !this.timelineData) return;
335
+ const t = Math.round(this.timeline.time() * 1e3) / 1e3, e = this.getTimePoints();
336
+ let s = 0;
337
+ for (const a of e)
338
+ if (a < t - 1e-3)
339
+ s = a;
340
+ else
341
+ break;
342
+ this.timeline.time(s), this.timeline.pause(), this.updatePlayState();
343
+ }
344
+ jumpToNextPoint() {
345
+ if (!this.timeline || !this.timelineData) return;
346
+ const t = Math.round(this.timeline.time() * 1e3) / 1e3, e = this.getTimePoints();
347
+ let s = this.timelineData.duration;
348
+ for (const a of e)
349
+ if (a > t + 1e-3) {
350
+ s = a;
351
+ break;
352
+ }
353
+ this.timeline.time(s), this.timeline.pause(), this.updatePlayState();
354
+ }
228
355
  toggleLoop() {
229
356
  this.timeline && (this.isLooping = !this.isLooping, this.timeline.repeat(this.isLooping ? -1 : 0), this.loopBtn.classList.toggle("active", this.isLooping));
230
357
  }
231
358
  cycleSpeed() {
232
359
  if (!this.timeline) return;
233
- this.speedIndex = (this.speedIndex + 1) % b.length;
234
- const t = b[this.speedIndex];
360
+ this.speedIndex = (this.speedIndex + 1) % P.length;
361
+ const t = P[this.speedIndex];
235
362
  this.timeline.timeScale(t), this.speedBtn.textContent = `${t}x`;
236
363
  }
237
364
  toggleCollapse() {
238
365
  this.collapsed = !this.collapsed, this.container.classList.toggle("collapsed", this.collapsed);
239
366
  const t = this.shadow.querySelector('[data-action="collapse"]');
240
- t.innerHTML = this.collapsed ? '<svg viewBox="0 0 24 24"><path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6z"/></svg>' : '<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>';
367
+ t.innerHTML = this.collapsed ? '<svg viewBox="0 0 24 24"><path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6z"/></svg>' : '<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>', this.updateBodyPadding();
368
+ }
369
+ toggleAutofit() {
370
+ this.isAutofit = !this.isAutofit, this.shadow.querySelector('[data-action="autofit"]').classList.toggle("active", this.isAutofit), this.isAutofit && this.applyAutofit();
371
+ }
372
+ applyAutofit() {
373
+ if (!this.isAutofit || this.collapsed) return;
374
+ const t = this.shadow.querySelectorAll(".gtv-track");
375
+ let e = 0;
376
+ const s = 28, a = 22;
377
+ t.forEach((h) => {
378
+ if (e += s, h.classList.contains("expanded")) {
379
+ const d = h.querySelectorAll(".gtv-stagger-child");
380
+ e += d.length * a;
381
+ }
382
+ });
383
+ const r = 24, n = 16, g = 100, v = window.innerHeight - 100;
384
+ this.height = Math.max(g, Math.min(L + r + e + n, v)), this.container.style.height = `${this.height}px`, this.updateBodyPadding();
241
385
  }
242
386
  updatePlayState() {
243
387
  if (!this.timeline) return;
244
388
  this.isPlaying = !this.timeline.paused() && this.timeline.progress() < 1;
245
- const t = this.playBtn.querySelector(".play-icon"), i = this.playBtn.querySelector(".pause-icon");
246
- t.style.display = this.isPlaying ? "none" : "block", i.style.display = this.isPlaying ? "block" : "none";
389
+ const t = this.playBtn.querySelector(".play-icon"), e = this.playBtn.querySelector(".pause-icon");
390
+ t.style.display = this.isPlaying ? "none" : "block", e.style.display = this.isPlaying ? "block" : "none";
247
391
  }
248
392
  onTimelineUpdate() {
249
393
  this.updatePlayhead(), this.updateTimeDisplay(), this.updateActiveTracks(), this.updatePlayState();
250
394
  }
251
395
  updatePlayhead() {
252
396
  if (!this.timeline || !this.timelineData) return;
253
- const i = `${this.timeline.progress() * 100}%`;
254
- this.playhead.style.left = i;
255
- const r = this.tracksScroll.querySelector(".gtv-playhead-container");
256
- r && (r.style.left = i);
397
+ const t = this.timeline.progress();
398
+ this.playhead.style.left = `${t * 100}%`;
257
399
  }
258
400
  updateTimeDisplay() {
259
401
  if (!this.timeline || !this.timelineData) return;
260
- const t = this.timeline.time(), i = this.timelineData.duration, r = this.timeDisplay.querySelector(".gtv-time-current"), n = this.timeDisplay.querySelector(".gtv-time-total");
261
- r.textContent = c(t), n.textContent = ` / ${c(i)}`;
402
+ const t = this.timeline.time(), e = this.timelineData.duration, s = this.timeDisplay.querySelector(".gtv-time-current"), a = this.timeDisplay.querySelector(".gtv-time-total");
403
+ s.textContent = f(t), a.textContent = ` / ${f(e)}`;
262
404
  }
263
405
  updateActiveTracks() {
264
406
  if (!this.timeline || !this.timelineData) return;
265
407
  const t = this.timeline.time();
266
- this.tracksScroll.querySelectorAll(".gtv-track-bar").forEach((r, n) => {
267
- const l = this.timelineData.tweens[n], o = t >= l.startTime && t <= l.endTime;
268
- r.classList.toggle("is-active", o);
408
+ this.tracksScroll.querySelectorAll(".gtv-track-bar").forEach((s, a) => {
409
+ const r = this.timelineData.tweens[a], n = t >= r.startTime && t <= r.endTime, g = s.dataset.color;
410
+ n ? s.style.background = `var(--gtv-track-${g}-active)` : s.style.background = `var(--gtv-track-${g})`;
269
411
  });
270
412
  }
271
413
  renderTracks() {
272
414
  if (!this.timelineData) return;
273
- const { duration: t, tweens: i } = this.timelineData, r = this.shadow.querySelector(".gtv-empty");
274
- r.style.display = i.length > 0 ? "none" : "flex", this.renderRuler(t);
275
- const n = i.map((d) => this.renderTrack(d, t)).join(""), l = this.tracksScroll.querySelector(".gtv-scrub-area"), o = this.tracksScroll.querySelector(".gtv-playhead-container");
276
- this.tracksScroll.innerHTML = n, this.tracksScroll.prepend(l), this.tracksScroll.appendChild(o), this.scrubArea = l;
415
+ const { duration: t, tweens: e } = this.timelineData, s = this.shadow.querySelector(".gtv-empty");
416
+ s.style.display = e.length > 0 ? "none" : "flex", this.renderRuler(t);
417
+ const a = this.renderGridLines(t), r = e.map((g) => this.renderTrack(g, t)).join(""), n = this.tracksScroll.querySelector(".gtv-scrub-area");
418
+ this.tracksScroll.innerHTML = a + r, this.tracksScroll.prepend(n), this.scrubArea = n;
419
+ }
420
+ renderGridLines(t) {
421
+ const e = [], s = this.calculateInterval(t);
422
+ for (let a = 0; a <= t; a += s) {
423
+ const r = a / t * 100;
424
+ e.push(`<div class="gtv-grid-line" style="left: ${r}%;"></div>`);
425
+ }
426
+ return e.join("");
277
427
  }
278
428
  renderRuler(t) {
279
- const i = [], r = this.calculateInterval(t);
280
- for (let n = 0; n <= t; n += r) {
281
- const l = n / t * 100;
282
- i.push(`
283
- <div class="gtv-ruler-marker" style="left: ${l}%;">
429
+ const e = [], s = this.calculateInterval(t);
430
+ for (let a = 0; a <= t; a += s) {
431
+ const r = a / t * 100;
432
+ e.push(`
433
+ <div class="gtv-ruler-marker" style="left: ${r}%;">
284
434
  <div class="gtv-ruler-marker-line"></div>
285
- <span class="gtv-ruler-marker-label">${c(n, !1)}s</span>
435
+ <span class="gtv-ruler-marker-label">${f(a, !1)}s</span>
286
436
  </div>
287
437
  `);
288
438
  }
289
- this.rulerInner.innerHTML = i.join("");
439
+ this.rulerInner.innerHTML = e.join("");
290
440
  }
291
441
  calculateInterval(t) {
292
442
  return t <= 1 ? 0.25 : t <= 3 ? 0.5 : t <= 10 ? 1 : t <= 30 ? 5 : 10;
293
443
  }
294
- renderTrack(t, i) {
295
- const r = t.startTime / i * 100, n = t.duration / i * 100, l = L[t.colorIndex];
444
+ renderTrack(t, e) {
445
+ const s = t.startTime / e * 100, a = t.duration / e * 100, r = t.colorIndex + 1;
446
+ let n = "";
447
+ t.hasStagger && t.staggerChildren && t.staggerChildren.length > 0 && (n = '<span class="gtv-track-stagger"><svg class="gtv-expand-icon" viewBox="0 0 24 24" width="10" height="10"><path fill="currentColor" d="M7 10l5 5 5-5z"/></svg> Stagger</span>');
448
+ let g = "";
449
+ if (t.staggerChildren && t.staggerChildren.length > 0) {
450
+ const h = t.staggerChildren.map((d) => {
451
+ const m = d.startTime / e * 100, u = (d.endTime - d.startTime) / e * 100;
452
+ return `
453
+ <div class="gtv-stagger-child">
454
+ <div class="gtv-stagger-child-bar"
455
+ style="left: ${m}%; width: ${u}%; background: var(--gtv-track-${r});">
456
+ <span class="gtv-track-label">${d.targetLabel}</span>
457
+ </div>
458
+ </div>
459
+ `;
460
+ }).join("");
461
+ g = `<div class="gtv-stagger-children" data-for="${t.id}">${h}</div>`;
462
+ }
463
+ let v = "";
464
+ if (t.overlapWithPrev !== void 0) {
465
+ const h = t.overlapWithPrev > 0, d = Math.abs(t.overlapWithPrev) / e * 100, m = h ? `-${f(t.overlapWithPrev)}s` : `+${f(Math.abs(t.overlapWithPrev))}s`;
466
+ h ? v = `
467
+ <div class="gtv-overlap-region" style="left: ${s}%; width: ${d}%;"></div>
468
+ <span class="gtv-offset-badge gtv-offset-overlap" style="left: ${s}%;">${m}</span>
469
+ ` : v = `
470
+ <div class="gtv-gap-connector" style="left: ${s - d}%; width: ${d}%;"></div>
471
+ <span class="gtv-offset-badge gtv-offset-gap" style="left: ${s}%;">${m}</span>
472
+ `;
473
+ }
296
474
  return `
297
- <div class="gtv-track">
475
+ <div class="gtv-track" data-expandable="${t.hasStagger && t.staggerChildren ? "true" : "false"}">
476
+ ${v}
298
477
  <div class="gtv-track-bar"
299
- style="left: ${r}%; width: ${n}%; background: ${l};"
300
- title="${t.label} (${c(t.startTime)}s - ${c(t.endTime)}s)">
301
- ${t.label}
478
+ data-color="${r}"
479
+ data-tween-id="${t.id}"
480
+ style="left: ${s}%; width: ${a}%; background: var(--gtv-track-${r});">
481
+ <span class="gtv-track-label">${t.label}</span>
482
+ ${n}
302
483
  </div>
484
+ ${g}
303
485
  </div>
304
486
  `;
305
487
  }
306
488
  }
307
- customElements.define("gsap-timeline-viewer", P);
308
- class D {
309
- constructor(e) {
310
- s(this, "element");
311
- this.element = document.createElement("gsap-timeline-viewer"), e.height && this.element.style.setProperty("--viewer-height", `${e.height}px`), e.timeline && setTimeout(() => {
312
- this.element.setTimeline(e.timeline);
313
- }, 0);
489
+ customElements.define("gsap-timeline-viewer", C);
490
+ const p = /* @__PURE__ */ new Map();
491
+ let c = null, w = !0, R = 0, k = null;
492
+ function j() {
493
+ const o = window.gsap;
494
+ !o || k || (k = o.timeline.bind(o), o.timeline = function(i) {
495
+ const t = k(i);
496
+ if (w) {
497
+ let e;
498
+ i != null && i.id && typeof i.id == "string" ? e = i.id : e = `Timeline ${++R}`, p.has(e) || (p.set(e, t), c && (c.htmlElement.updateTimelineSelector(), p.size === 1 && c.select(e)));
499
+ }
500
+ return t;
501
+ });
502
+ }
503
+ class S {
504
+ constructor(i = {}) {
505
+ l(this, "element");
506
+ l(this, "currentTimelineName", null);
507
+ this.element = document.createElement("gsap-timeline-viewer"), i.height && this.element.style.setProperty("--viewer-height", `${i.height}px`);
508
+ }
509
+ /**
510
+ * Create and attach the timeline viewer to the page.
511
+ * Call this once - subsequent calls return the existing instance.
512
+ */
513
+ static create(i = {}) {
514
+ return c || (w = i.autoDetect !== !1, w && j(), c = new S(i), document.body.appendChild(c.element), setTimeout(() => {
515
+ if (c.element.updateTimelineSelector(), i.defaultTimeline && p.has(i.defaultTimeline))
516
+ c.select(i.defaultTimeline);
517
+ else if (p.size > 0) {
518
+ const t = p.keys().next().value;
519
+ t && c.select(t);
520
+ }
521
+ }, 0), c);
522
+ }
523
+ /**
524
+ * Register a timeline with a name so it appears in the dropdown.
525
+ */
526
+ static register(i, t) {
527
+ p.set(i, t), c && (c.element.updateTimelineSelector(), p.size === 1 && c.select(i));
528
+ }
529
+ /**
530
+ * Unregister a timeline.
531
+ */
532
+ static unregister(i) {
533
+ p.delete(i), c && c.element.updateTimelineSelector();
534
+ }
535
+ /**
536
+ * Get all registered timelines.
537
+ */
538
+ static getTimelines() {
539
+ return p;
540
+ }
541
+ /**
542
+ * Get the viewer instance (if created).
543
+ */
544
+ static getInstance() {
545
+ return c;
314
546
  }
315
- attach(e = document.body) {
316
- e.appendChild(this.element);
547
+ /**
548
+ * Select a timeline by name.
549
+ */
550
+ select(i) {
551
+ const t = p.get(i);
552
+ t && (this.currentTimelineName = i, this.element.setTimeline(t), this.element.setSelectedTimeline(i));
317
553
  }
318
- detach() {
319
- this.element.remove();
554
+ /**
555
+ * Get current timeline name.
556
+ */
557
+ getCurrentTimelineName() {
558
+ return this.currentTimelineName;
320
559
  }
321
- setTimeline(e) {
322
- this.element.setTimeline(e);
560
+ /**
561
+ * Remove the viewer from the page.
562
+ */
563
+ destroy() {
564
+ this.element.remove(), c = null;
323
565
  }
324
566
  get htmlElement() {
325
567
  return this.element;
326
568
  }
327
569
  }
570
+ const $ = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
571
+ __proto__: null,
572
+ TimelineViewer: S,
573
+ TimelineViewerElement: C
574
+ }, Symbol.toStringTag, { value: "Module" }));
328
575
  export {
329
- D as TimelineViewer,
330
- P as TimelineViewerElement
576
+ S as TimelineViewer,
577
+ C as TimelineViewerElement
331
578
  };
@@ -1,13 +1,27 @@
1
- (function(l,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(l=typeof globalThis<"u"?globalThis:l||self,n(l.GSAPTimelineViewer={}))})(this,function(l){"use strict";var C=Object.defineProperty;var D=(l,n,h)=>n in l?C(l,n,{enumerable:!0,configurable:!0,writable:!0,value:h}):l[n]=h;var s=(l,n,h)=>D(l,typeof n!="symbol"?n+"":n,h);let n=0;function h(o){if(!o||o.length===0)return"Unknown";const i=o[0];return i.id?`#${i.id}`:i.classList&&i.classList.length>0?`.${i.classList[0]}`:i.tagName?i.tagName.toLowerCase():"element"}function k(o){const i=["ease","duration","delay","onComplete","onStart","onUpdate","onCompleteParams","onStartParams","onUpdateParams","repeat","repeatDelay","yoyo","stagger","overwrite","immediateRender","lazy","autoAlpha","id","paused","reversed","startAt"];return Object.keys(o).filter(t=>!i.includes(t))}function S(o){const i=[];return o.getChildren(!0,!0,!1).forEach((e,a)=>{if(!("targets"in e))return;const r=e,c=r.targets(),d=r.vars||{},p=k(d);let v="";if(d.id&&typeof d.id=="string")v=d.id;else{const y=h(c),x=p.slice(0,2).join(", ");v=x?`${y} (${x})`:y}const f=e.startTime(),b=e.duration();i.push({id:`tween-${++n}`,label:v,startTime:f,endTime:f+b,duration:b,targets:h(c),properties:p,colorIndex:a%6})}),{duration:o.duration(),tweens:i}}function w(){n=0}function g(o,i=!0){const t=Math.abs(o);return i?t.toFixed(2):t.toFixed(0)}const T=":host{--gtv-bg: #1a1a1a;--gtv-bg-secondary: #252525;--gtv-border: #333;--gtv-text: #e0e0e0;--gtv-text-muted: #888;--gtv-accent: #4a9eff;--gtv-playhead: #4a9eff;--gtv-ruler-bg: #1f1f1f;--gtv-track-height: 28px;--gtv-controls-height: 40px;--gtv-ruler-height: 24px;--gtv-track-1: #3b82f6;--gtv-track-2: #f59e0b;--gtv-track-3: #ec4899;--gtv-track-4: #10b981;--gtv-track-5: #8b5cf6;--gtv-track-6: #ef4444}*{box-sizing:border-box;margin:0;padding:0}.gtv-container{position:fixed;bottom:0;left:0;right:0;background:var(--gtv-bg);border-top:1px solid var(--gtv-border);font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:12px;color:var(--gtv-text);z-index:999999;display:flex;flex-direction:column}.gtv-container.collapsed{height:auto!important}.gtv-container.collapsed .gtv-timeline-area{display:none}.gtv-controls{display:flex;align-items:center;justify-content:space-between;height:var(--gtv-controls-height);padding:0 12px;background:var(--gtv-bg-secondary);border-bottom:1px solid var(--gtv-border);gap:16px}.gtv-controls-left,.gtv-controls-center,.gtv-controls-right{display:flex;align-items:center;gap:8px}.gtv-controls-center{flex:0 0 auto}.gtv-time-display{font-variant-numeric:tabular-nums;min-width:100px;text-align:center}.gtv-time-current{color:var(--gtv-text)}.gtv-time-total{color:var(--gtv-text-muted)}.gtv-btn{display:flex;align-items:center;justify-content:center;width:28px;height:28px;background:transparent;border:none;border-radius:4px;color:var(--gtv-text);cursor:pointer;transition:background .15s}.gtv-btn:hover{background:#ffffff1a}.gtv-btn:active{background:#ffffff26}.gtv-btn.active{color:var(--gtv-accent)}.gtv-btn svg{width:16px;height:16px;fill:currentColor}.gtv-btn-play svg{width:20px;height:20px}.gtv-speed-btn{width:auto;padding:0 8px;font-size:11px;font-weight:500}.gtv-collapse-btn{margin-left:auto}.gtv-timeline-area{display:flex;flex-direction:column;overflow:hidden;flex:1}.gtv-ruler{position:relative;height:var(--gtv-ruler-height);background:var(--gtv-ruler-bg);border-bottom:1px solid var(--gtv-border);overflow:hidden;flex-shrink:0}.gtv-ruler-inner{position:relative;height:100%}.gtv-ruler-marker{position:absolute;top:0;height:100%;display:flex;flex-direction:column;align-items:center}.gtv-ruler-marker-line{width:1px;height:6px;background:var(--gtv-text-muted)}.gtv-ruler-marker-label{font-size:10px;color:var(--gtv-text-muted);margin-top:2px}.gtv-tracks-container{position:relative;overflow-y:auto;overflow-x:hidden;flex:1}.gtv-tracks-scroll{position:relative;min-height:100%}.gtv-track{position:relative;height:var(--gtv-track-height);border-bottom:1px solid var(--gtv-border)}.gtv-track-bar{position:absolute;top:4px;height:calc(var(--gtv-track-height) - 8px);border-radius:4px;display:flex;align-items:center;padding:0 8px;font-size:11px;font-weight:500;color:#fff;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:default;transition:filter .15s}.gtv-track-bar:hover{filter:brightness(1.1)}.gtv-track-bar.is-active{box-shadow:0 0 0 2px var(--gtv-accent)}.gtv-playhead-container{position:absolute;top:0;bottom:0;width:1px;pointer-events:none;z-index:10}.gtv-playhead-head{position:absolute;top:0;left:-5px;width:11px;height:11px;background:var(--gtv-playhead);clip-path:polygon(50% 100%,0 0,100% 0)}.gtv-playhead-line{position:absolute;top:11px;bottom:0;left:0;width:1px;background:var(--gtv-playhead)}.gtv-scrub-area{position:absolute;top:0;left:0;right:0;bottom:0;cursor:pointer}.gtv-empty{display:flex;align-items:center;justify-content:center;padding:24px;color:var(--gtv-text-muted)}",L=["var(--gtv-track-1)","var(--gtv-track-2)","var(--gtv-track-3)","var(--gtv-track-4)","var(--gtv-track-5)","var(--gtv-track-6)"],u=[.25,.5,1,2,4];class m extends HTMLElement{constructor(){super();s(this,"shadow");s(this,"timeline",null);s(this,"timelineData",null);s(this,"isPlaying",!1);s(this,"isLooping",!1);s(this,"speedIndex",2);s(this,"collapsed",!1);s(this,"height",200);s(this,"isDragging",!1);s(this,"container");s(this,"playBtn");s(this,"loopBtn");s(this,"speedBtn");s(this,"timeDisplay");s(this,"rulerInner");s(this,"tracksScroll");s(this,"playhead");s(this,"scrubArea");this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.setupEventListeners()}disconnectedCallback(){this.detachTimeline()}setTimeline(t){this.detachTimeline(),this.timeline=t,w(),this.timelineData=S(t),t.eventCallback("onUpdate",()=>this.onTimelineUpdate()),this.renderTracks(),this.updatePlayhead(),this.updateTimeDisplay(),this.updatePlayState()}detachTimeline(){this.timeline&&(this.timeline.eventCallback("onUpdate",null),this.timeline=null,this.timelineData=null)}render(){this.shadow.innerHTML=`
2
- <style>${T}</style>
1
+ (function(h,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(h=typeof globalThis<"u"?globalThis:h||self,d(h.GSAPTimelineViewer={}))})(this,function(h){"use strict";var R=Object.defineProperty;var V=(h,d,b)=>d in h?R(h,d,{enumerable:!0,configurable:!0,writable:!0,value:b}):h[d]=b;var l=(h,d,b)=>V(h,typeof d!="symbol"?d+"":d,b);let d=0;function b(c){if(!c||c.length===0)return"Unknown";const s=c[0];return s.id?`#${s.id}`:s.classList&&s.classList.length>0?`.${s.classList[0]}`:s.tagName?s.tagName.toLowerCase():"element"}function D(c){const s=["ease","duration","delay","onComplete","onStart","onUpdate","onCompleteParams","onStartParams","onUpdateParams","repeat","repeatDelay","yoyo","stagger","overwrite","immediateRender","lazy","autoAlpha","id","paused","reversed","startAt"];return Object.keys(c).filter(t=>!s.includes(t))}function A(c){const s=[];c.getChildren(!0,!0,!1).forEach((e,i)=>{if(!("targets"in e))return;const a=e,r=a.targets(),n=a.vars||{},p=D(n);let m="";if(n.id&&typeof n.id=="string")m=n.id;else{const w=b(r),S=p.slice(0,2).join(", ");m=S?`${w} (${S})`:w}const u=e.startTime(),g=e.duration();let y="none";n.ease&&(y=typeof n.ease=="string"?n.ease:"custom");let f,M;if(n.stagger&&r.length>1&&(typeof n.stagger=="number"?f=n.stagger:typeof n.stagger=="object"&&(f=n.stagger.each||0),f)){const w=g-f*(r.length-1);M=r.map((S,j)=>{const C=u+j*f;return{targetLabel:b([S]),startTime:C,endTime:C+w}})}s.push({id:`tween-${++d}`,label:m,startTime:u,endTime:u+g,duration:g,targets:b(r),properties:p,colorIndex:i%6,hasStagger:!!n.stagger,ease:y,staggerValue:f,staggerChildren:M})});for(let e=1;e<s.length;e++){const i=s[e-1],a=s[e],r=i.endTime-a.startTime;Math.abs(r)>.001&&(a.overlapWithPrev=Math.round(r*1e3)/1e3)}return{duration:c.duration(),tweens:s}}function E(){d=0}function x(c,s=!0){const t=Math.abs(c);return s?t.toFixed(2):t.toFixed(0)}const H=":host{--gtv-bg: #1a1a1a;--gtv-bg-secondary: #252525;--gtv-border: #333;--gtv-text: #e0e0e0;--gtv-text-muted: #888;--gtv-accent: oklch(65% .15 220);--gtv-playhead: oklch(65% .15 220);--gtv-ruler-bg: #1f1f1f;--gtv-track-height: 28px;--gtv-controls-height: 40px;--gtv-ruler-height: 24px;--gtv-timeline-padding: 16px;--gtv-track-1: oklch(50% .12 220);--gtv-track-1-active: oklch(60% .15 220);--gtv-track-2: oklch(50% .12 70);--gtv-track-2-active: oklch(60% .15 70);--gtv-track-3: oklch(50% .12 350);--gtv-track-3-active: oklch(60% .15 350);--gtv-track-4: oklch(50% .12 160);--gtv-track-4-active: oklch(60% .15 160);--gtv-track-5: oklch(50% .12 290);--gtv-track-5-active: oklch(60% .15 290);--gtv-track-6: oklch(50% .12 25);--gtv-track-6-active: oklch(60% .15 25)}*{box-sizing:border-box;margin:0;padding:0}.gtv-container{position:fixed;bottom:0;left:0;right:0;background:var(--gtv-bg);border-top:1px solid var(--gtv-border);font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:12px;color:var(--gtv-text);z-index:999999;display:flex;flex-direction:column;user-select:none;-webkit-user-select:none}.gtv-container.collapsed{height:auto!important}.gtv-container.collapsed .gtv-timeline-area{display:none}.gtv-controls{position:relative;display:flex;align-items:center;justify-content:center;height:var(--gtv-controls-height);padding:0 12px;background:var(--gtv-bg-secondary);border-bottom:1px solid var(--gtv-border);gap:8px}.gtv-controls-left{position:absolute;left:12px;display:flex;align-items:center;gap:8px}.gtv-controls-center{display:flex;align-items:center;gap:8px}.gtv-controls-right{position:absolute;right:12px;display:flex;align-items:center;gap:8px}.gtv-time-display{font-variant-numeric:tabular-nums;min-width:100px;text-align:center}.gtv-time-current{color:var(--gtv-text)}.gtv-time-total{color:var(--gtv-text-muted)}.gtv-btn{display:flex;align-items:center;justify-content:center;width:28px;height:28px;background:transparent;border:none;border-radius:4px;color:var(--gtv-text);cursor:pointer;transition:background .15s}.gtv-btn:hover{background:#ffffff1a}.gtv-btn:active{background:#ffffff26}.gtv-btn.active{color:var(--gtv-accent)}.gtv-btn svg{width:16px;height:16px;fill:currentColor}.gtv-btn-play svg{width:20px;height:20px}.gtv-speed-btn{width:auto;padding:0 8px;font-size:11px;font-weight:500}.gtv-timeline-select{background:var(--gtv-bg);border:1px solid var(--gtv-border);border-radius:4px;color:var(--gtv-text);font-size:11px;padding:4px 8px;cursor:pointer;max-width:140px}.gtv-timeline-select:focus{outline:none;border-color:var(--gtv-accent)}.gtv-collapse-btn{margin-left:auto}.gtv-timeline-area{position:relative;display:flex;flex-direction:column;overflow:hidden;flex:1}.gtv-resize-handle{position:absolute;top:0;left:0;right:0;height:6px;cursor:ns-resize;z-index:20}.gtv-resize-handle:hover,.gtv-resize-handle:active{background:#ffffff1a}.gtv-ruler{position:relative;height:var(--gtv-ruler-height);background:var(--gtv-ruler-bg);border-bottom:1px solid var(--gtv-border);overflow:visible;flex-shrink:0;padding:0 var(--gtv-timeline-padding)}.gtv-ruler-inner{position:relative;height:100%;width:100%}.gtv-ruler-marker{position:absolute;top:0;display:flex;flex-direction:column;align-items:center}.gtv-ruler-marker-line{width:1px;height:6px;background:var(--gtv-text-muted)}.gtv-ruler-marker-label{font-size:10px;color:var(--gtv-text-muted);margin-top:2px}.gtv-grid-line{position:absolute;top:0;width:1px;height:100%;background:var(--gtv-border);pointer-events:none}.gtv-tracks-container{position:relative;overflow-y:auto;overflow-x:hidden;flex:1;padding:0 var(--gtv-timeline-padding)}.gtv-tracks-scroll{position:relative;min-height:100%;width:100%}.gtv-track{position:relative;padding-top:var(--gtv-track-height)}.gtv-track-bar{position:absolute;top:4px;height:calc(var(--gtv-track-height) - 8px);border-radius:4px;display:flex;align-items:center;justify-content:space-between;gap:8px;padding:0 8px;font-size:11px;font-weight:500;color:#fff;overflow:hidden;cursor:default;transition:filter .15s}.gtv-track-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0}.gtv-track-stagger{opacity:.7;font-size:10px;font-weight:400;flex-shrink:0}.gtv-track-bar:hover{filter:brightness(1.1)}.gtv-playhead-wrapper{position:absolute;top:0;bottom:0;left:var(--gtv-timeline-padding);right:var(--gtv-timeline-padding);pointer-events:none;z-index:15}.gtv-playhead{position:absolute;top:0;bottom:0;width:0;left:0}.gtv-playhead-head{position:absolute;top:6px;left:-5px;width:11px;height:11px;background:var(--gtv-playhead);clip-path:polygon(50% 100%,0 0,100% 0)}.gtv-playhead-line{position:absolute;top:6px;bottom:0;left:0;width:1px;background:var(--gtv-playhead)}.gtv-scrub-area{position:absolute;top:0;left:0;right:0;bottom:0;cursor:ew-resize}.gtv-track[data-expandable=true] .gtv-track-bar{cursor:pointer}.gtv-expand-icon{transition:transform .2s}.gtv-track.expanded .gtv-expand-icon{transform:rotate(180deg)}.gtv-stagger-children{display:none;position:relative;width:100%}.gtv-track.expanded .gtv-stagger-children{display:block}.gtv-stagger-child{position:relative;width:100%;height:calc(var(--gtv-track-height) - 6px)}.gtv-stagger-child-bar{position:absolute;top:2px;height:calc(var(--gtv-track-height) - 12px);border-radius:3px;display:flex;align-items:center;padding:0 6px;font-size:10px;color:#fff;opacity:.7;overflow:hidden}.gtv-stagger-child-bar .gtv-track-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.gtv-overlap-region{position:absolute;top:4px;height:calc(var(--gtv-track-height) - 8px);background:repeating-linear-gradient(-45deg,transparent,transparent 2px,rgba(255,255,255,.15) 2px,rgba(255,255,255,.15) 4px);border-radius:4px;pointer-events:none;z-index:5}.gtv-gap-connector{position:absolute;top:50%;height:1px;border-top:1px dashed var(--gtv-text-muted);pointer-events:none}.gtv-offset-badge{position:absolute;top:50%;transform:translate(-100%,-50%);margin-left:-4px;font-size:9px;font-weight:500;padding:2px 5px;border-radius:3px;white-space:nowrap;pointer-events:none;z-index:10}.gtv-offset-overlap,.gtv-offset-gap{background:var(--gtv-bg-secondary);border:1px solid var(--gtv-border);color:var(--gtv-text-muted)}.gtv-empty{display:flex;align-items:center;justify-content:center;padding:24px;color:var(--gtv-text-muted)}",L=[.25,.5,1,2,4],$=40;class T extends HTMLElement{constructor(){super();l(this,"shadow");l(this,"timeline",null);l(this,"timelineData",null);l(this,"isPlaying",!1);l(this,"isLooping",!1);l(this,"speedIndex",2);l(this,"collapsed",!1);l(this,"height",200);l(this,"isDragging",!1);l(this,"manageBodyPadding",!0);l(this,"isAutofit",!1);l(this,"container");l(this,"playBtn");l(this,"loopBtn");l(this,"speedBtn");l(this,"timeDisplay");l(this,"rulerInner");l(this,"tracksScroll");l(this,"playhead");l(this,"scrubArea");l(this,"resizeHandle");l(this,"timelineSelect");l(this,"isResizing",!1);this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.setupEventListeners(),this.updateBodyPadding()}disconnectedCallback(){this.detachTimeline(),this.clearBodyPadding()}setTimeline(t){this.detachTimeline(),this.timeline=t,E(),this.timelineData=A(t),t.eventCallback("onUpdate",()=>this.onTimelineUpdate()),this.renderTracks(),this.updatePlayhead(),this.updateTimeDisplay(),this.updatePlayState(),requestAnimationFrame(()=>this.applyAutofit())}updateTimelineSelector(){Promise.resolve().then(()=>B).then(({TimelineViewer:t})=>{const e=t.getTimelines(),i=this.timelineSelect.value;this.timelineSelect.innerHTML="",e.forEach((a,r)=>{const n=document.createElement("option");n.value=r,n.textContent=r,this.timelineSelect.appendChild(n)}),i&&e.has(i)&&(this.timelineSelect.value=i)})}setSelectedTimeline(t){this.timelineSelect.value=t}detachTimeline(){this.timeline&&(this.timeline.eventCallback("onUpdate",null),this.timeline=null,this.timelineData=null)}render(){this.shadow.innerHTML=`
2
+ <style>${H}</style>
3
3
  <div class="gtv-container ${this.collapsed?"collapsed":""}" style="height: ${this.height}px;">
4
4
  <!-- Controls Bar -->
5
5
  <div class="gtv-controls">
6
6
  <div class="gtv-controls-left">
7
+ <select class="gtv-timeline-select" title="Select timeline">
8
+ <option value="">No timeline</option>
9
+ </select>
10
+ <button class="gtv-btn" data-action="loop" title="Loop (L)">
11
+ <svg viewBox="0 0 24 24"><path d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z"/></svg>
12
+ </button>
13
+ <button class="gtv-btn gtv-speed-btn" data-action="speed" title="Playback speed">1x</button>
14
+ </div>
15
+
16
+ <div class="gtv-controls-center">
17
+ <span class="gtv-time-display">
18
+ <span class="gtv-time-current">0.00</span>
19
+ <span class="gtv-time-total"> / 0.00</span>
20
+ </span>
7
21
  <button class="gtv-btn" data-action="skip-start" title="Skip to start">
8
22
  <svg viewBox="0 0 24 24"><path d="M6 6h2v12H6V6zm3.5 6l8.5 6V6l-8.5 6z"/></svg>
9
23
  </button>
10
- <button class="gtv-btn gtv-btn-play" data-action="play" title="Play/Pause">
24
+ <button class="gtv-btn gtv-btn-play" data-action="play" title="Play/Pause (Space)">
11
25
  <svg class="play-icon" viewBox="0 0 24 24"><path d="M8 5v14l11-7z"/></svg>
12
26
  <svg class="pause-icon" viewBox="0 0 24 24" style="display: none;"><path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/></svg>
13
27
  </button>
@@ -16,18 +30,10 @@
16
30
  </button>
17
31
  </div>
18
32
 
19
- <div class="gtv-controls-center">
20
- <button class="gtv-btn" data-action="loop" title="Loop">
21
- <svg viewBox="0 0 24 24"><path d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z"/></svg>
22
- </button>
23
- <span class="gtv-time-display">
24
- <span class="gtv-time-current">0.00</span>
25
- <span class="gtv-time-total"> / 0.00</span>
26
- </span>
27
- <button class="gtv-btn gtv-speed-btn" data-action="speed" title="Playback speed">1x</button>
28
- </div>
29
-
30
33
  <div class="gtv-controls-right">
34
+ <button class="gtv-btn" data-action="autofit" title="Auto-fit height">
35
+ <svg viewBox="0 0 24 24"><path d="M4 8h4V4H4v4zm6 12h4v-4h-4v4zm-6 0h4v-4H4v4zm0-6h4v-4H4v4zm6 0h4v-4h-4v4zm6-10v4h4V4h-4zm-6 4h4V4h-4v4zm6 6h4v-4h-4v4zm0 6h4v-4h-4v4z"/></svg>
36
+ </button>
31
37
  <button class="gtv-btn gtv-collapse-btn" data-action="collapse" title="Collapse/Expand">
32
38
  <svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>
33
39
  </button>
@@ -36,37 +42,59 @@
36
42
 
37
43
  <!-- Timeline Area -->
38
44
  <div class="gtv-timeline-area">
45
+ <!-- Resize Handle -->
46
+ <div class="gtv-resize-handle"></div>
47
+
39
48
  <!-- Ruler -->
40
49
  <div class="gtv-ruler">
41
50
  <div class="gtv-ruler-inner"></div>
42
- <div class="gtv-playhead-container">
43
- <div class="gtv-playhead-head"></div>
44
- </div>
45
51
  </div>
46
52
 
47
53
  <!-- Tracks -->
48
54
  <div class="gtv-tracks-container">
49
55
  <div class="gtv-tracks-scroll">
50
56
  <div class="gtv-scrub-area"></div>
51
- <div class="gtv-playhead-container">
52
- <div class="gtv-playhead-line"></div>
53
- </div>
54
57
  </div>
55
58
  <div class="gtv-empty">No timeline attached. Call setTimeline() to visualize a GSAP timeline.</div>
56
59
  </div>
60
+
61
+ <!-- Playhead spans entire timeline area -->
62
+ <div class="gtv-playhead-wrapper">
63
+ <div class="gtv-playhead">
64
+ <div class="gtv-playhead-head"></div>
65
+ <div class="gtv-playhead-line"></div>
66
+ </div>
67
+ </div>
57
68
  </div>
58
69
  </div>
59
- `,this.container=this.shadow.querySelector(".gtv-container"),this.playBtn=this.shadow.querySelector('[data-action="play"]'),this.loopBtn=this.shadow.querySelector('[data-action="loop"]'),this.speedBtn=this.shadow.querySelector('[data-action="speed"]'),this.timeDisplay=this.shadow.querySelector(".gtv-time-display"),this.rulerInner=this.shadow.querySelector(".gtv-ruler-inner"),this.tracksScroll=this.shadow.querySelector(".gtv-tracks-scroll"),this.playhead=this.shadow.querySelector(".gtv-ruler .gtv-playhead-container"),this.scrubArea=this.shadow.querySelector(".gtv-scrub-area")}setupEventListeners(){this.shadow.addEventListener("click",t=>{const a=t.target.closest("[data-action]");if(!a)return;switch(a.dataset.action){case"play":this.togglePlay();break;case"skip-start":this.skipToStart();break;case"skip-end":this.skipToEnd();break;case"loop":this.toggleLoop();break;case"speed":this.cycleSpeed();break;case"collapse":this.toggleCollapse();break}}),this.scrubArea.addEventListener("mousedown",t=>this.startScrub(t)),this.shadow.querySelector(".gtv-ruler").addEventListener("mousedown",t=>this.startScrub(t)),document.addEventListener("mousemove",t=>this.onScrub(t)),document.addEventListener("mouseup",()=>this.endScrub()),document.addEventListener("keydown",t=>{t.target===document.body&&t.code==="Space"&&(t.preventDefault(),this.togglePlay())})}startScrub(t){this.timeline&&(this.isDragging=!0,this.scrubToPosition(t))}onScrub(t){!this.isDragging||!this.timeline||this.scrubToPosition(t)}endScrub(){this.isDragging=!1}scrubToPosition(t){if(!this.timeline||!this.timelineData)return;const e=this.rulerInner.getBoundingClientRect(),r=Math.max(0,Math.min(t.clientX-e.left,e.width))/e.width;this.timeline.progress(r),this.timeline.pause(),this.updatePlayState()}togglePlay(){this.timeline&&(this.timeline.paused()||this.timeline.progress()===1?this.timeline.progress()===1?this.timeline.restart():this.timeline.play():this.timeline.pause(),this.updatePlayState())}skipToStart(){this.timeline&&(this.timeline.progress(0),this.timeline.pause(),this.updatePlayState())}skipToEnd(){this.timeline&&(this.timeline.progress(1),this.timeline.pause(),this.updatePlayState())}toggleLoop(){this.timeline&&(this.isLooping=!this.isLooping,this.timeline.repeat(this.isLooping?-1:0),this.loopBtn.classList.toggle("active",this.isLooping))}cycleSpeed(){if(!this.timeline)return;this.speedIndex=(this.speedIndex+1)%u.length;const t=u[this.speedIndex];this.timeline.timeScale(t),this.speedBtn.textContent=`${t}x`}toggleCollapse(){this.collapsed=!this.collapsed,this.container.classList.toggle("collapsed",this.collapsed);const t=this.shadow.querySelector('[data-action="collapse"]');t.innerHTML=this.collapsed?'<svg viewBox="0 0 24 24"><path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6z"/></svg>':'<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>'}updatePlayState(){if(!this.timeline)return;this.isPlaying=!this.timeline.paused()&&this.timeline.progress()<1;const t=this.playBtn.querySelector(".play-icon"),e=this.playBtn.querySelector(".pause-icon");t.style.display=this.isPlaying?"none":"block",e.style.display=this.isPlaying?"block":"none"}onTimelineUpdate(){this.updatePlayhead(),this.updateTimeDisplay(),this.updateActiveTracks(),this.updatePlayState()}updatePlayhead(){if(!this.timeline||!this.timelineData)return;const e=`${this.timeline.progress()*100}%`;this.playhead.style.left=e;const a=this.tracksScroll.querySelector(".gtv-playhead-container");a&&(a.style.left=e)}updateTimeDisplay(){if(!this.timeline||!this.timelineData)return;const t=this.timeline.time(),e=this.timelineData.duration,a=this.timeDisplay.querySelector(".gtv-time-current"),r=this.timeDisplay.querySelector(".gtv-time-total");a.textContent=g(t),r.textContent=` / ${g(e)}`}updateActiveTracks(){if(!this.timeline||!this.timelineData)return;const t=this.timeline.time();this.tracksScroll.querySelectorAll(".gtv-track-bar").forEach((a,r)=>{const c=this.timelineData.tweens[r],d=t>=c.startTime&&t<=c.endTime;a.classList.toggle("is-active",d)})}renderTracks(){if(!this.timelineData)return;const{duration:t,tweens:e}=this.timelineData,a=this.shadow.querySelector(".gtv-empty");a.style.display=e.length>0?"none":"flex",this.renderRuler(t);const r=e.map(p=>this.renderTrack(p,t)).join(""),c=this.tracksScroll.querySelector(".gtv-scrub-area"),d=this.tracksScroll.querySelector(".gtv-playhead-container");this.tracksScroll.innerHTML=r,this.tracksScroll.prepend(c),this.tracksScroll.appendChild(d),this.scrubArea=c}renderRuler(t){const e=[],a=this.calculateInterval(t);for(let r=0;r<=t;r+=a){const c=r/t*100;e.push(`
60
- <div class="gtv-ruler-marker" style="left: ${c}%;">
70
+ `,this.container=this.shadow.querySelector(".gtv-container"),this.playBtn=this.shadow.querySelector('[data-action="play"]'),this.loopBtn=this.shadow.querySelector('[data-action="loop"]'),this.speedBtn=this.shadow.querySelector('[data-action="speed"]'),this.timeDisplay=this.shadow.querySelector(".gtv-time-display"),this.rulerInner=this.shadow.querySelector(".gtv-ruler-inner"),this.tracksScroll=this.shadow.querySelector(".gtv-tracks-scroll"),this.playhead=this.shadow.querySelector(".gtv-playhead"),this.scrubArea=this.shadow.querySelector(".gtv-scrub-area"),this.resizeHandle=this.shadow.querySelector(".gtv-resize-handle"),this.timelineSelect=this.shadow.querySelector(".gtv-timeline-select")}setupEventListeners(){this.shadow.addEventListener("click",t=>{const i=t.target.closest("[data-action]");if(!i)return;switch(i.dataset.action){case"play":this.togglePlay();break;case"skip-start":this.skipToStart();break;case"skip-end":this.skipToEnd();break;case"loop":this.toggleLoop();break;case"speed":this.cycleSpeed();break;case"collapse":this.toggleCollapse();break;case"autofit":this.toggleAutofit();break}}),this.timelineSelect.addEventListener("change",()=>{const t=this.timelineSelect.value;t&&Promise.resolve().then(()=>B).then(({TimelineViewer:e})=>{var i;(i=e.getInstance())==null||i.select(t)})}),this.shadow.addEventListener("click",t=>{const i=t.target.closest(".gtv-track-bar");if(i){const a=i.closest(".gtv-track");(a==null?void 0:a.dataset.expandable)==="true"&&(t.stopPropagation(),a.classList.toggle("expanded"),requestAnimationFrame(()=>this.applyAutofit()))}}),this.scrubArea.addEventListener("mousedown",t=>this.startScrub(t)),this.shadow.querySelector(".gtv-ruler").addEventListener("mousedown",t=>this.startScrub(t)),this.shadow.querySelector(".gtv-tracks-container").addEventListener("mousedown",t=>{t.target.closest(".gtv-track-bar")||this.startScrub(t)}),document.addEventListener("mousemove",t=>{this.onScrub(t),this.onResize(t)}),document.addEventListener("mouseup",()=>{this.endScrub(),this.endResize()}),this.resizeHandle.addEventListener("mousedown",t=>this.startResize(t)),document.addEventListener("keydown",t=>{if(t.target===document.body)switch(t.code){case"Space":t.preventDefault(),this.togglePlay();break;case"KeyJ":t.preventDefault(),this.jumpToPrevPoint();break;case"KeyK":t.preventDefault(),this.jumpToNextPoint();break;case"KeyL":t.preventDefault(),this.toggleLoop();break}})}startScrub(t){this.timeline&&(t.preventDefault(),this.isDragging=!0,document.body.style.cursor="ew-resize",document.body.style.userSelect="none",this.scrubToPosition(t))}onScrub(t){!this.isDragging||!this.timeline||this.scrubToPosition(t)}endScrub(){this.isDragging=!1,document.body.style.cursor="",document.body.style.userSelect=""}startResize(t){t.preventDefault(),this.isResizing=!0,document.body.style.cursor="ns-resize",document.body.style.userSelect="none"}onResize(t){if(!this.isResizing)return;const e=window.innerHeight,i=e-t.clientY;this.height=Math.max(100,Math.min(i,e-100)),this.container.style.height=`${this.height}px`,this.updateBodyPadding()}endResize(){this.isResizing&&(this.isResizing=!1,document.body.style.cursor="",document.body.style.userSelect="")}updateBodyPadding(){if(!this.manageBodyPadding)return;const t=this.collapsed?$:this.height;document.body.style.paddingBottom=`${t}px`}clearBodyPadding(){this.manageBodyPadding&&(document.body.style.paddingBottom="")}scrubToPosition(t){if(!this.timeline||!this.timelineData)return;const e=this.rulerInner.getBoundingClientRect(),a=Math.max(0,Math.min(t.clientX-e.left,e.width))/e.width;this.timeline.progress(a),this.timeline.pause(),this.updatePlayState()}togglePlay(){this.timeline&&(this.timeline.paused()||this.timeline.progress()===1?this.timeline.progress()===1?this.timeline.restart():this.timeline.play():this.timeline.pause(),this.updatePlayState())}skipToStart(){this.timeline&&(this.timeline.progress(0),this.timeline.pause(),this.updatePlayState())}skipToEnd(){this.timeline&&(this.timeline.progress(1),this.timeline.pause(),this.updatePlayState())}getTimePoints(){if(!this.timelineData)return[0];const t=new Set;return t.add(0),t.add(Math.round(this.timelineData.duration*1e3)/1e3),this.timelineData.tweens.forEach(e=>{t.add(Math.round(e.startTime*1e3)/1e3),t.add(Math.round(e.endTime*1e3)/1e3)}),Array.from(t).sort((e,i)=>e-i)}jumpToPrevPoint(){if(!this.timeline||!this.timelineData)return;const t=Math.round(this.timeline.time()*1e3)/1e3,e=this.getTimePoints();let i=0;for(const a of e)if(a<t-.001)i=a;else break;this.timeline.time(i),this.timeline.pause(),this.updatePlayState()}jumpToNextPoint(){if(!this.timeline||!this.timelineData)return;const t=Math.round(this.timeline.time()*1e3)/1e3,e=this.getTimePoints();let i=this.timelineData.duration;for(const a of e)if(a>t+.001){i=a;break}this.timeline.time(i),this.timeline.pause(),this.updatePlayState()}toggleLoop(){this.timeline&&(this.isLooping=!this.isLooping,this.timeline.repeat(this.isLooping?-1:0),this.loopBtn.classList.toggle("active",this.isLooping))}cycleSpeed(){if(!this.timeline)return;this.speedIndex=(this.speedIndex+1)%L.length;const t=L[this.speedIndex];this.timeline.timeScale(t),this.speedBtn.textContent=`${t}x`}toggleCollapse(){this.collapsed=!this.collapsed,this.container.classList.toggle("collapsed",this.collapsed);const t=this.shadow.querySelector('[data-action="collapse"]');t.innerHTML=this.collapsed?'<svg viewBox="0 0 24 24"><path d="M7.41 8.59L12 13.17l4.59-4.58L18 10l-6 6-6-6z"/></svg>':'<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>',this.updateBodyPadding()}toggleAutofit(){this.isAutofit=!this.isAutofit,this.shadow.querySelector('[data-action="autofit"]').classList.toggle("active",this.isAutofit),this.isAutofit&&this.applyAutofit()}applyAutofit(){if(!this.isAutofit||this.collapsed)return;const t=this.shadow.querySelectorAll(".gtv-track");let e=0;const i=28,a=22;t.forEach(u=>{if(e+=i,u.classList.contains("expanded")){const g=u.querySelectorAll(".gtv-stagger-child");e+=g.length*a}});const r=24,n=16,p=100,m=window.innerHeight-100;this.height=Math.max(p,Math.min($+r+e+n,m)),this.container.style.height=`${this.height}px`,this.updateBodyPadding()}updatePlayState(){if(!this.timeline)return;this.isPlaying=!this.timeline.paused()&&this.timeline.progress()<1;const t=this.playBtn.querySelector(".play-icon"),e=this.playBtn.querySelector(".pause-icon");t.style.display=this.isPlaying?"none":"block",e.style.display=this.isPlaying?"block":"none"}onTimelineUpdate(){this.updatePlayhead(),this.updateTimeDisplay(),this.updateActiveTracks(),this.updatePlayState()}updatePlayhead(){if(!this.timeline||!this.timelineData)return;const t=this.timeline.progress();this.playhead.style.left=`${t*100}%`}updateTimeDisplay(){if(!this.timeline||!this.timelineData)return;const t=this.timeline.time(),e=this.timelineData.duration,i=this.timeDisplay.querySelector(".gtv-time-current"),a=this.timeDisplay.querySelector(".gtv-time-total");i.textContent=x(t),a.textContent=` / ${x(e)}`}updateActiveTracks(){if(!this.timeline||!this.timelineData)return;const t=this.timeline.time();this.tracksScroll.querySelectorAll(".gtv-track-bar").forEach((i,a)=>{const r=this.timelineData.tweens[a],n=t>=r.startTime&&t<=r.endTime,p=i.dataset.color;n?i.style.background=`var(--gtv-track-${p}-active)`:i.style.background=`var(--gtv-track-${p})`})}renderTracks(){if(!this.timelineData)return;const{duration:t,tweens:e}=this.timelineData,i=this.shadow.querySelector(".gtv-empty");i.style.display=e.length>0?"none":"flex",this.renderRuler(t);const a=this.renderGridLines(t),r=e.map(p=>this.renderTrack(p,t)).join(""),n=this.tracksScroll.querySelector(".gtv-scrub-area");this.tracksScroll.innerHTML=a+r,this.tracksScroll.prepend(n),this.scrubArea=n}renderGridLines(t){const e=[],i=this.calculateInterval(t);for(let a=0;a<=t;a+=i){const r=a/t*100;e.push(`<div class="gtv-grid-line" style="left: ${r}%;"></div>`)}return e.join("")}renderRuler(t){const e=[],i=this.calculateInterval(t);for(let a=0;a<=t;a+=i){const r=a/t*100;e.push(`
71
+ <div class="gtv-ruler-marker" style="left: ${r}%;">
61
72
  <div class="gtv-ruler-marker-line"></div>
62
- <span class="gtv-ruler-marker-label">${g(r,!1)}s</span>
73
+ <span class="gtv-ruler-marker-label">${x(a,!1)}s</span>
63
74
  </div>
64
- `)}this.rulerInner.innerHTML=e.join("")}calculateInterval(t){return t<=1?.25:t<=3?.5:t<=10?1:t<=30?5:10}renderTrack(t,e){const a=t.startTime/e*100,r=t.duration/e*100,c=L[t.colorIndex];return`
65
- <div class="gtv-track">
75
+ `)}this.rulerInner.innerHTML=e.join("")}calculateInterval(t){return t<=1?.25:t<=3?.5:t<=10?1:t<=30?5:10}renderTrack(t,e){const i=t.startTime/e*100,a=t.duration/e*100,r=t.colorIndex+1;let n="";t.hasStagger&&t.staggerChildren&&t.staggerChildren.length>0&&(n='<span class="gtv-track-stagger"><svg class="gtv-expand-icon" viewBox="0 0 24 24" width="10" height="10"><path fill="currentColor" d="M7 10l5 5 5-5z"/></svg> Stagger</span>');let p="";if(t.staggerChildren&&t.staggerChildren.length>0){const u=t.staggerChildren.map(g=>{const y=g.startTime/e*100,f=(g.endTime-g.startTime)/e*100;return`
76
+ <div class="gtv-stagger-child">
77
+ <div class="gtv-stagger-child-bar"
78
+ style="left: ${y}%; width: ${f}%; background: var(--gtv-track-${r});">
79
+ <span class="gtv-track-label">${g.targetLabel}</span>
80
+ </div>
81
+ </div>
82
+ `}).join("");p=`<div class="gtv-stagger-children" data-for="${t.id}">${u}</div>`}let m="";if(t.overlapWithPrev!==void 0){const u=t.overlapWithPrev>0,g=Math.abs(t.overlapWithPrev)/e*100,y=u?`-${x(t.overlapWithPrev)}s`:`+${x(Math.abs(t.overlapWithPrev))}s`;u?m=`
83
+ <div class="gtv-overlap-region" style="left: ${i}%; width: ${g}%;"></div>
84
+ <span class="gtv-offset-badge gtv-offset-overlap" style="left: ${i}%;">${y}</span>
85
+ `:m=`
86
+ <div class="gtv-gap-connector" style="left: ${i-g}%; width: ${g}%;"></div>
87
+ <span class="gtv-offset-badge gtv-offset-gap" style="left: ${i}%;">${y}</span>
88
+ `}return`
89
+ <div class="gtv-track" data-expandable="${t.hasStagger&&t.staggerChildren?"true":"false"}">
90
+ ${m}
66
91
  <div class="gtv-track-bar"
67
- style="left: ${a}%; width: ${r}%; background: ${c};"
68
- title="${t.label} (${g(t.startTime)}s - ${g(t.endTime)}s)">
69
- ${t.label}
92
+ data-color="${r}"
93
+ data-tween-id="${t.id}"
94
+ style="left: ${i}%; width: ${a}%; background: var(--gtv-track-${r});">
95
+ <span class="gtv-track-label">${t.label}</span>
96
+ ${n}
70
97
  </div>
98
+ ${p}
71
99
  </div>
72
- `}}customElements.define("gsap-timeline-viewer",m);class P{constructor(i){s(this,"element");this.element=document.createElement("gsap-timeline-viewer"),i.height&&this.element.style.setProperty("--viewer-height",`${i.height}px`),i.timeline&&setTimeout(()=>{this.element.setTimeline(i.timeline)},0)}attach(i=document.body){i.appendChild(this.element)}detach(){this.element.remove()}setTimeline(i){this.element.setTimeline(i)}get htmlElement(){return this.element}}l.TimelineViewer=P,l.TimelineViewerElement=m,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
100
+ `}}customElements.define("gsap-timeline-viewer",T);const v=new Map;let o=null,z=!0,q=0,P=null;function I(){const c=window.gsap;!c||P||(P=c.timeline.bind(c),c.timeline=function(s){const t=P(s);if(z){let e;s!=null&&s.id&&typeof s.id=="string"?e=s.id:e=`Timeline ${++q}`,v.has(e)||(v.set(e,t),o&&(o.htmlElement.updateTimelineSelector(),v.size===1&&o.select(e)))}return t})}class k{constructor(s={}){l(this,"element");l(this,"currentTimelineName",null);this.element=document.createElement("gsap-timeline-viewer"),s.height&&this.element.style.setProperty("--viewer-height",`${s.height}px`)}static create(s={}){return o||(z=s.autoDetect!==!1,z&&I(),o=new k(s),document.body.appendChild(o.element),setTimeout(()=>{if(o.element.updateTimelineSelector(),s.defaultTimeline&&v.has(s.defaultTimeline))o.select(s.defaultTimeline);else if(v.size>0){const t=v.keys().next().value;t&&o.select(t)}},0),o)}static register(s,t){v.set(s,t),o&&(o.element.updateTimelineSelector(),v.size===1&&o.select(s))}static unregister(s){v.delete(s),o&&o.element.updateTimelineSelector()}static getTimelines(){return v}static getInstance(){return o}select(s){const t=v.get(s);t&&(this.currentTimelineName=s,this.element.setTimeline(t),this.element.setSelectedTimeline(s))}getCurrentTimelineName(){return this.currentTimelineName}destroy(){this.element.remove(),o=null}get htmlElement(){return this.element}}const B=Object.freeze(Object.defineProperty({__proto__:null,TimelineViewer:k,TimelineViewerElement:T},Symbol.toStringTag,{value:"Module"}));h.TimelineViewer=k,h.TimelineViewerElement=T,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
package/dist/index.d.ts CHANGED
@@ -1,16 +1,48 @@
1
1
  export declare class TimelineViewer {
2
2
  private element;
3
- constructor(config: TimelineViewerConfig);
4
- attach(container?: HTMLElement): void;
5
- detach(): void;
6
- setTimeline(timeline: gsap.core.Timeline): void;
3
+ private currentTimelineName;
4
+ private constructor();
5
+ /**
6
+ * Create and attach the timeline viewer to the page.
7
+ * Call this once - subsequent calls return the existing instance.
8
+ */
9
+ static create(config?: TimelineViewerConfig): TimelineViewer;
10
+ /**
11
+ * Register a timeline with a name so it appears in the dropdown.
12
+ */
13
+ static register(name: string, timeline: gsap.core.Timeline): void;
14
+ /**
15
+ * Unregister a timeline.
16
+ */
17
+ static unregister(name: string): void;
18
+ /**
19
+ * Get all registered timelines.
20
+ */
21
+ static getTimelines(): Map<string, gsap.core.Timeline>;
22
+ /**
23
+ * Get the viewer instance (if created).
24
+ */
25
+ static getInstance(): TimelineViewer | null;
26
+ /**
27
+ * Select a timeline by name.
28
+ */
29
+ select(name: string): void;
30
+ /**
31
+ * Get current timeline name.
32
+ */
33
+ getCurrentTimelineName(): string | null;
34
+ /**
35
+ * Remove the viewer from the page.
36
+ */
37
+ destroy(): void;
7
38
  get htmlElement(): TimelineViewerElement;
8
39
  }
9
40
 
10
41
  export declare interface TimelineViewerConfig {
11
- timeline: gsap.core.Timeline;
12
42
  height?: number;
13
43
  collapsed?: boolean;
44
+ defaultTimeline?: string;
45
+ autoDetect?: boolean;
14
46
  }
15
47
 
16
48
  export declare class TimelineViewerElement extends HTMLElement {
@@ -23,6 +55,8 @@ export declare class TimelineViewerElement extends HTMLElement {
23
55
  private collapsed;
24
56
  private height;
25
57
  private isDragging;
58
+ private manageBodyPadding;
59
+ private isAutofit;
26
60
  private container;
27
61
  private playBtn;
28
62
  private loopBtn;
@@ -32,29 +66,45 @@ export declare class TimelineViewerElement extends HTMLElement {
32
66
  private tracksScroll;
33
67
  private playhead;
34
68
  private scrubArea;
69
+ private resizeHandle;
70
+ private timelineSelect;
71
+ private isResizing;
35
72
  constructor();
36
73
  connectedCallback(): void;
37
74
  disconnectedCallback(): void;
38
75
  setTimeline(timeline: gsap.core.Timeline): void;
76
+ updateTimelineSelector(): void;
77
+ setSelectedTimeline(name: string): void;
39
78
  private detachTimeline;
40
79
  private render;
41
80
  private setupEventListeners;
42
81
  private startScrub;
43
82
  private onScrub;
44
83
  private endScrub;
84
+ private startResize;
85
+ private onResize;
86
+ private endResize;
87
+ private updateBodyPadding;
88
+ private clearBodyPadding;
45
89
  private scrubToPosition;
46
90
  private togglePlay;
47
91
  private skipToStart;
48
92
  private skipToEnd;
93
+ private getTimePoints;
94
+ private jumpToPrevPoint;
95
+ private jumpToNextPoint;
49
96
  private toggleLoop;
50
97
  private cycleSpeed;
51
98
  private toggleCollapse;
99
+ private toggleAutofit;
100
+ private applyAutofit;
52
101
  private updatePlayState;
53
102
  private onTimelineUpdate;
54
103
  private updatePlayhead;
55
104
  private updateTimeDisplay;
56
105
  private updateActiveTracks;
57
106
  private renderTracks;
107
+ private renderGridLines;
58
108
  private renderRuler;
59
109
  private calculateInterval;
60
110
  private renderTrack;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gsap-timeline-viewer",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A lightweight, framework-agnostic timeline viewer for GSAP animations",
5
5
  "type": "module",
6
6
  "main": "./dist/gsap-timeline-viewer.umd.cjs",