gsap-timeline-viewer 0.1.1 → 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.
- package/dist/gsap-timeline-viewer.iife.js +32 -10
- package/dist/gsap-timeline-viewer.js +286 -96
- package/dist/gsap-timeline-viewer.umd.cjs +34 -12
- package/dist/index.d.ts +47 -5
- package/package.json +1 -1
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
var GSAPTimelineViewer=function(
|
|
2
|
-
<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>
|
|
7
10
|
<button class="gtv-btn" data-action="loop" title="Loop (L)">
|
|
8
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>
|
|
9
12
|
</button>
|
|
@@ -28,6 +31,9 @@ var GSAPTimelineViewer=function(o){"use strict";var P=Object.defineProperty;var
|
|
|
28
31
|
</div>
|
|
29
32
|
|
|
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>
|
|
@@ -61,18 +67,34 @@ var GSAPTimelineViewer=function(o){"use strict";var P=Object.defineProperty;var
|
|
|
61
67
|
</div>
|
|
62
68
|
</div>
|
|
63
69
|
</div>
|
|
64
|
-
`,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")}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}}),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),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
|
|
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(`
|
|
65
71
|
<div class="gtv-ruler-marker" style="left: ${r}%;">
|
|
66
72
|
<div class="gtv-ruler-marker-line"></div>
|
|
67
|
-
<span class="gtv-ruler-marker-label">${
|
|
73
|
+
<span class="gtv-ruler-marker-label">${x(a,!1)}s</span>
|
|
68
74
|
</div>
|
|
69
|
-
`)}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;return`
|
|
70
|
-
|
|
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}
|
|
71
91
|
<div class="gtv-track-bar"
|
|
72
92
|
data-color="${r}"
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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}
|
|
76
97
|
</div>
|
|
98
|
+
${g}
|
|
77
99
|
</div>
|
|
78
|
-
`}}customElements.define("gsap-timeline-viewer",
|
|
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,13 +1,13 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
let
|
|
5
|
-
function
|
|
6
|
-
if (!
|
|
7
|
-
const i =
|
|
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
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
|
|
10
|
+
function E(o) {
|
|
11
11
|
const i = [
|
|
12
12
|
"ease",
|
|
13
13
|
"duration",
|
|
@@ -31,90 +31,131 @@ function x(r) {
|
|
|
31
31
|
"reversed",
|
|
32
32
|
"startAt"
|
|
33
33
|
];
|
|
34
|
-
return Object.keys(
|
|
34
|
+
return Object.keys(o).filter((t) => !i.includes(t));
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function H(o) {
|
|
37
37
|
const i = [];
|
|
38
|
-
|
|
38
|
+
o.getChildren(!0, !0, !1).forEach((e, s) => {
|
|
39
39
|
if (!("targets" in e)) return;
|
|
40
|
-
const a = e,
|
|
41
|
-
let
|
|
42
|
-
if (
|
|
43
|
-
|
|
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
|
|
46
|
-
|
|
45
|
+
const b = x(r), y = g.slice(0, 2).join(", ");
|
|
46
|
+
v = y ? `${b} (${y})` : b;
|
|
47
|
+
}
|
|
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
|
+
});
|
|
47
62
|
}
|
|
48
|
-
const p = e.startTime(), g = e.duration();
|
|
49
63
|
i.push({
|
|
50
|
-
id: `tween-${++
|
|
51
|
-
label:
|
|
52
|
-
startTime:
|
|
53
|
-
endTime:
|
|
54
|
-
duration:
|
|
55
|
-
targets:
|
|
56
|
-
properties:
|
|
57
|
-
colorIndex: s % 6
|
|
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
|
-
|
|
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(),
|
|
61
84
|
tweens: i
|
|
62
85
|
};
|
|
63
86
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
87
|
+
function q() {
|
|
88
|
+
B = 0;
|
|
66
89
|
}
|
|
67
|
-
function
|
|
68
|
-
const t = Math.abs(
|
|
90
|
+
function f(o, i = !0) {
|
|
91
|
+
const t = Math.abs(o);
|
|
69
92
|
return i ? t.toFixed(2) : t.toFixed(0);
|
|
70
93
|
}
|
|
71
|
-
const
|
|
72
|
-
class
|
|
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 {
|
|
73
96
|
constructor() {
|
|
74
97
|
super();
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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);
|
|
81
104
|
// 1x
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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);
|
|
85
110
|
// DOM references
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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);
|
|
97
123
|
this.shadow = this.attachShadow({ mode: "open" });
|
|
98
124
|
}
|
|
99
125
|
connectedCallback() {
|
|
100
|
-
this.render(), this.setupEventListeners();
|
|
126
|
+
this.render(), this.setupEventListeners(), this.updateBodyPadding();
|
|
101
127
|
}
|
|
102
128
|
disconnectedCallback() {
|
|
103
|
-
this.detachTimeline();
|
|
129
|
+
this.detachTimeline(), this.clearBodyPadding();
|
|
104
130
|
}
|
|
105
131
|
setTimeline(t) {
|
|
106
|
-
this.detachTimeline(), this.timeline = t,
|
|
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;
|
|
107
145
|
}
|
|
108
146
|
detachTimeline() {
|
|
109
147
|
this.timeline && (this.timeline.eventCallback("onUpdate", null), this.timeline = null, this.timelineData = null);
|
|
110
148
|
}
|
|
111
149
|
render() {
|
|
112
150
|
this.shadow.innerHTML = `
|
|
113
|
-
<style>${
|
|
151
|
+
<style>${I}</style>
|
|
114
152
|
<div class="gtv-container ${this.collapsed ? "collapsed" : ""}" style="height: ${this.height}px;">
|
|
115
153
|
<!-- Controls Bar -->
|
|
116
154
|
<div class="gtv-controls">
|
|
117
155
|
<div class="gtv-controls-left">
|
|
156
|
+
<select class="gtv-timeline-select" title="Select timeline">
|
|
157
|
+
<option value="">No timeline</option>
|
|
158
|
+
</select>
|
|
118
159
|
<button class="gtv-btn" data-action="loop" title="Loop (L)">
|
|
119
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>
|
|
120
161
|
</button>
|
|
@@ -139,6 +180,9 @@ class z extends HTMLElement {
|
|
|
139
180
|
</div>
|
|
140
181
|
|
|
141
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>
|
|
142
186
|
<button class="gtv-btn gtv-collapse-btn" data-action="collapse" title="Collapse/Expand">
|
|
143
187
|
<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>
|
|
144
188
|
</button>
|
|
@@ -172,7 +216,7 @@ class z extends HTMLElement {
|
|
|
172
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-playhead"), this.scrubArea = this.shadow.querySelector(".gtv-scrub-area"), this.resizeHandle = this.shadow.querySelector(".gtv-resize-handle");
|
|
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) => {
|
|
@@ -197,8 +241,25 @@ class z extends HTMLElement {
|
|
|
197
241
|
case "collapse":
|
|
198
242
|
this.toggleCollapse();
|
|
199
243
|
break;
|
|
244
|
+
case "autofit":
|
|
245
|
+
this.toggleAutofit();
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
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()));
|
|
200
259
|
}
|
|
201
|
-
}), this.scrubArea.addEventListener("mousedown", (t) => this.startScrub(t)), this.shadow.querySelector(".gtv-ruler").addEventListener("mousedown", (t) => this.startScrub(t)),
|
|
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) => {
|
|
202
263
|
this.onScrub(t), this.onResize(t);
|
|
203
264
|
}), document.addEventListener("mouseup", () => {
|
|
204
265
|
this.endScrub(), this.endResize();
|
|
@@ -235,11 +296,19 @@ class z extends HTMLElement {
|
|
|
235
296
|
onResize(t) {
|
|
236
297
|
if (!this.isResizing) return;
|
|
237
298
|
const e = window.innerHeight, s = e - t.clientY;
|
|
238
|
-
this.height = Math.max(100, Math.min(s, e - 100)), this.container.style.height = `${this.height}px
|
|
299
|
+
this.height = Math.max(100, Math.min(s, e - 100)), this.container.style.height = `${this.height}px`, this.updateBodyPadding();
|
|
239
300
|
}
|
|
240
301
|
endResize() {
|
|
241
302
|
this.isResizing && (this.isResizing = !1, document.body.style.cursor = "", document.body.style.userSelect = "");
|
|
242
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 = "");
|
|
311
|
+
}
|
|
243
312
|
scrubToPosition(t) {
|
|
244
313
|
if (!this.timeline || !this.timelineData) return;
|
|
245
314
|
const e = this.rulerInner.getBoundingClientRect(), a = Math.max(0, Math.min(t.clientX - e.left, e.width)) / e.width;
|
|
@@ -288,14 +357,31 @@ class z extends HTMLElement {
|
|
|
288
357
|
}
|
|
289
358
|
cycleSpeed() {
|
|
290
359
|
if (!this.timeline) return;
|
|
291
|
-
this.speedIndex = (this.speedIndex + 1) %
|
|
292
|
-
const t =
|
|
360
|
+
this.speedIndex = (this.speedIndex + 1) % P.length;
|
|
361
|
+
const t = P[this.speedIndex];
|
|
293
362
|
this.timeline.timeScale(t), this.speedBtn.textContent = `${t}x`;
|
|
294
363
|
}
|
|
295
364
|
toggleCollapse() {
|
|
296
365
|
this.collapsed = !this.collapsed, this.container.classList.toggle("collapsed", this.collapsed);
|
|
297
366
|
const t = this.shadow.querySelector('[data-action="collapse"]');
|
|
298
|
-
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();
|
|
299
385
|
}
|
|
300
386
|
updatePlayState() {
|
|
301
387
|
if (!this.timeline) return;
|
|
@@ -314,31 +400,39 @@ class z extends HTMLElement {
|
|
|
314
400
|
updateTimeDisplay() {
|
|
315
401
|
if (!this.timeline || !this.timelineData) return;
|
|
316
402
|
const t = this.timeline.time(), e = this.timelineData.duration, s = this.timeDisplay.querySelector(".gtv-time-current"), a = this.timeDisplay.querySelector(".gtv-time-total");
|
|
317
|
-
s.textContent =
|
|
403
|
+
s.textContent = f(t), a.textContent = ` / ${f(e)}`;
|
|
318
404
|
}
|
|
319
405
|
updateActiveTracks() {
|
|
320
406
|
if (!this.timeline || !this.timelineData) return;
|
|
321
407
|
const t = this.timeline.time();
|
|
322
408
|
this.tracksScroll.querySelectorAll(".gtv-track-bar").forEach((s, a) => {
|
|
323
|
-
const
|
|
324
|
-
|
|
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})`;
|
|
325
411
|
});
|
|
326
412
|
}
|
|
327
413
|
renderTracks() {
|
|
328
414
|
if (!this.timelineData) return;
|
|
329
415
|
const { duration: t, tweens: e } = this.timelineData, s = this.shadow.querySelector(".gtv-empty");
|
|
330
416
|
s.style.display = e.length > 0 ? "none" : "flex", this.renderRuler(t);
|
|
331
|
-
const a = e.map((
|
|
332
|
-
this.tracksScroll.innerHTML = a, this.tracksScroll.prepend(
|
|
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("");
|
|
333
427
|
}
|
|
334
428
|
renderRuler(t) {
|
|
335
429
|
const e = [], s = this.calculateInterval(t);
|
|
336
430
|
for (let a = 0; a <= t; a += s) {
|
|
337
|
-
const
|
|
431
|
+
const r = a / t * 100;
|
|
338
432
|
e.push(`
|
|
339
|
-
<div class="gtv-ruler-marker" style="left: ${
|
|
433
|
+
<div class="gtv-ruler-marker" style="left: ${r}%;">
|
|
340
434
|
<div class="gtv-ruler-marker-line"></div>
|
|
341
|
-
<span class="gtv-ruler-marker-label">${
|
|
435
|
+
<span class="gtv-ruler-marker-label">${f(a, !1)}s</span>
|
|
342
436
|
</div>
|
|
343
437
|
`);
|
|
344
438
|
}
|
|
@@ -348,41 +442,137 @@ class z extends HTMLElement {
|
|
|
348
442
|
return t <= 1 ? 0.25 : t <= 3 ? 0.5 : t <= 10 ? 1 : t <= 30 ? 5 : 10;
|
|
349
443
|
}
|
|
350
444
|
renderTrack(t, e) {
|
|
351
|
-
const s = t.startTime / e * 100, a = t.duration / e * 100,
|
|
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
|
+
}
|
|
352
474
|
return `
|
|
353
|
-
<div class="gtv-track">
|
|
475
|
+
<div class="gtv-track" data-expandable="${t.hasStagger && t.staggerChildren ? "true" : "false"}">
|
|
476
|
+
${v}
|
|
354
477
|
<div class="gtv-track-bar"
|
|
355
|
-
data-color="${
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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}
|
|
359
483
|
</div>
|
|
484
|
+
${g}
|
|
360
485
|
</div>
|
|
361
486
|
`;
|
|
362
487
|
}
|
|
363
488
|
}
|
|
364
|
-
customElements.define("gsap-timeline-viewer",
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
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;
|
|
546
|
+
}
|
|
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));
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Get current timeline name.
|
|
556
|
+
*/
|
|
557
|
+
getCurrentTimelineName() {
|
|
558
|
+
return this.currentTimelineName;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Remove the viewer from the page.
|
|
562
|
+
*/
|
|
563
|
+
destroy() {
|
|
564
|
+
this.element.remove(), c = null;
|
|
380
565
|
}
|
|
381
566
|
get htmlElement() {
|
|
382
567
|
return this.element;
|
|
383
568
|
}
|
|
384
569
|
}
|
|
570
|
+
const $ = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
571
|
+
__proto__: null,
|
|
572
|
+
TimelineViewer: S,
|
|
573
|
+
TimelineViewerElement: C
|
|
574
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
385
575
|
export {
|
|
386
|
-
|
|
387
|
-
|
|
576
|
+
S as TimelineViewer,
|
|
577
|
+
C as TimelineViewerElement
|
|
388
578
|
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
<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>
|
|
7
10
|
<button class="gtv-btn" data-action="loop" title="Loop (L)">
|
|
8
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>
|
|
9
12
|
</button>
|
|
@@ -28,6 +31,9 @@
|
|
|
28
31
|
</div>
|
|
29
32
|
|
|
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>
|
|
@@ -61,18 +67,34 @@
|
|
|
61
67
|
</div>
|
|
62
68
|
</div>
|
|
63
69
|
</div>
|
|
64
|
-
`,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")}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}}),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),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
|
|
65
|
-
<div class="gtv-ruler-marker" style="left: ${
|
|
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}%;">
|
|
66
72
|
<div class="gtv-ruler-marker-line"></div>
|
|
67
|
-
<span class="gtv-ruler-marker-label">${
|
|
73
|
+
<span class="gtv-ruler-marker-label">${x(a,!1)}s</span>
|
|
68
74
|
</div>
|
|
69
|
-
`)}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,
|
|
70
|
-
|
|
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}
|
|
71
91
|
<div class="gtv-track-bar"
|
|
72
|
-
data-color="${
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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}
|
|
76
97
|
</div>
|
|
98
|
+
${p}
|
|
77
99
|
</div>
|
|
78
|
-
`}}customElements.define("gsap-timeline-viewer",
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
@@ -33,11 +67,14 @@ export declare class TimelineViewerElement extends HTMLElement {
|
|
|
33
67
|
private playhead;
|
|
34
68
|
private scrubArea;
|
|
35
69
|
private resizeHandle;
|
|
70
|
+
private timelineSelect;
|
|
36
71
|
private isResizing;
|
|
37
72
|
constructor();
|
|
38
73
|
connectedCallback(): void;
|
|
39
74
|
disconnectedCallback(): void;
|
|
40
75
|
setTimeline(timeline: gsap.core.Timeline): void;
|
|
76
|
+
updateTimelineSelector(): void;
|
|
77
|
+
setSelectedTimeline(name: string): void;
|
|
41
78
|
private detachTimeline;
|
|
42
79
|
private render;
|
|
43
80
|
private setupEventListeners;
|
|
@@ -47,6 +84,8 @@ export declare class TimelineViewerElement extends HTMLElement {
|
|
|
47
84
|
private startResize;
|
|
48
85
|
private onResize;
|
|
49
86
|
private endResize;
|
|
87
|
+
private updateBodyPadding;
|
|
88
|
+
private clearBodyPadding;
|
|
50
89
|
private scrubToPosition;
|
|
51
90
|
private togglePlay;
|
|
52
91
|
private skipToStart;
|
|
@@ -57,12 +96,15 @@ export declare class TimelineViewerElement extends HTMLElement {
|
|
|
57
96
|
private toggleLoop;
|
|
58
97
|
private cycleSpeed;
|
|
59
98
|
private toggleCollapse;
|
|
99
|
+
private toggleAutofit;
|
|
100
|
+
private applyAutofit;
|
|
60
101
|
private updatePlayState;
|
|
61
102
|
private onTimelineUpdate;
|
|
62
103
|
private updatePlayhead;
|
|
63
104
|
private updateTimeDisplay;
|
|
64
105
|
private updateActiveTracks;
|
|
65
106
|
private renderTracks;
|
|
107
|
+
private renderGridLines;
|
|
66
108
|
private renderRuler;
|
|
67
109
|
private calculateInterval;
|
|
68
110
|
private renderTrack;
|