gsap-timeline-viewer 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -49
- package/dist/gsap-timeline-viewer.iife.js +43 -12
- package/dist/gsap-timeline-viewer.js +324 -95
- package/dist/gsap-timeline-viewer.umd.cjs +43 -12
- package/dist/index.d.ts +51 -5
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
1
|
# GSAP Timeline Viewer
|
|
2
2
|
|
|
3
|
-
A lightweight, framework-agnostic development tool for visualizing GSAP timelines.
|
|
3
|
+
A lightweight, framework-agnostic development tool for visualizing and debugging GSAP timelines. Inspect your animations with a visual timeline panel.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
**~7 KB gzipped** | Works with React, Vue, Angular, Svelte, or vanilla JS
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Auto-detection** - Automatically captures all `gsap.timeline()` calls
|
|
12
|
+
- **Visual timeline** - Colored tracks for each tween with labels
|
|
13
|
+
- **Ease curve visualization** - Toggle to see ease curves as track shapes
|
|
14
|
+
- **Stagger expansion** - Expand staggered animations to see individual targets
|
|
15
|
+
- **Overlap/gap indicators** - Visual badges showing `-=` and `+=` timing offsets
|
|
16
|
+
- **Playback controls** - Play/pause, skip, speed control (0.25x to 4x), loop
|
|
17
|
+
- **Scrubbing** - Click or drag anywhere on the timeline
|
|
18
|
+
- **Auto-fit height** - Toggle to fit panel to content
|
|
19
|
+
- **Resizable** - Drag the top edge to resize
|
|
20
|
+
- **Keyboard shortcuts** - Space, J, K, L
|
|
21
|
+
- **Timeline selector** - Switch between multiple timelines
|
|
22
|
+
- **Collapsible panel** - Minimize when not in use
|
|
6
23
|
|
|
7
24
|
## Installation
|
|
8
25
|
|
|
@@ -10,7 +27,7 @@ A lightweight, framework-agnostic development tool for visualizing GSAP timeline
|
|
|
10
27
|
npm install gsap-timeline-viewer
|
|
11
28
|
```
|
|
12
29
|
|
|
13
|
-
Note: GSAP is a peer dependency
|
|
30
|
+
Note: GSAP is a peer dependency:
|
|
14
31
|
|
|
15
32
|
```bash
|
|
16
33
|
npm install gsap
|
|
@@ -22,71 +39,73 @@ npm install gsap
|
|
|
22
39
|
import { TimelineViewer } from 'gsap-timeline-viewer';
|
|
23
40
|
import gsap from 'gsap';
|
|
24
41
|
|
|
25
|
-
// Create
|
|
26
|
-
|
|
27
|
-
tl.to('.box', { x: 100, duration: 1 })
|
|
28
|
-
.to('.box', { y: 50, duration: 0.5 });
|
|
42
|
+
// Create the viewer - that's it!
|
|
43
|
+
TimelineViewer.create();
|
|
29
44
|
|
|
30
|
-
//
|
|
31
|
-
const
|
|
32
|
-
|
|
45
|
+
// All timelines are auto-detected
|
|
46
|
+
const tl = gsap.timeline({ id: 'My Animation' });
|
|
47
|
+
tl.to('.box', { x: 100, duration: 1, id: 'Move Right' })
|
|
48
|
+
.to('.box', { y: 50, duration: 0.5, id: 'Move Down' });
|
|
33
49
|
```
|
|
34
50
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
- Visual timeline with colored tracks for each tween
|
|
38
|
-
- Scrubber/playhead synced with your timeline
|
|
39
|
-
- Playback controls (play/pause, skip to start/end)
|
|
40
|
-
- Speed control (0.25x, 0.5x, 1x, 2x, 4x)
|
|
41
|
-
- Loop toggle
|
|
42
|
-
- Auto-scaling time ruler
|
|
43
|
-
- Keyboard shortcut: `Space` to play/pause
|
|
44
|
-
- Collapsible panel
|
|
45
|
-
- Dark theme
|
|
51
|
+
The `id` on timelines and tweens is optional but provides better labels in the viewer.
|
|
46
52
|
|
|
47
53
|
## API
|
|
48
54
|
|
|
49
|
-
### TimelineViewer
|
|
55
|
+
### TimelineViewer.create(config?)
|
|
50
56
|
|
|
51
|
-
|
|
52
|
-
import { TimelineViewer } from 'gsap-timeline-viewer';
|
|
57
|
+
Creates and attaches the viewer to the page. Call once - subsequent calls return the existing instance.
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
height: 200, // Optional:
|
|
59
|
+
```typescript
|
|
60
|
+
TimelineViewer.create({
|
|
61
|
+
height: 200, // Optional: Initial panel height (default: 200)
|
|
62
|
+
collapsed: false, // Optional: Start collapsed (default: false)
|
|
63
|
+
defaultTimeline: 'My Animation', // Optional: Auto-select this timeline
|
|
64
|
+
autoDetect: true, // Optional: Auto-detect timelines (default: true)
|
|
57
65
|
});
|
|
66
|
+
```
|
|
58
67
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
### TimelineViewer.register(name, timeline)
|
|
69
|
+
|
|
70
|
+
Manually register a timeline (useful if autoDetect is disabled):
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
const tl = gsap.timeline({ paused: true });
|
|
74
|
+
TimelineViewer.register('Hero Animation', tl);
|
|
63
75
|
```
|
|
64
76
|
|
|
65
|
-
###
|
|
77
|
+
### TimelineViewer.unregister(name)
|
|
78
|
+
|
|
79
|
+
Remove a timeline from the viewer.
|
|
80
|
+
|
|
81
|
+
### TimelineViewer.getInstance()
|
|
66
82
|
|
|
67
|
-
|
|
83
|
+
Get the current viewer instance:
|
|
68
84
|
|
|
69
85
|
```javascript
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
duration: 1,
|
|
73
|
-
id: 'Hero Fade In' // This label appears in the viewer
|
|
74
|
-
});
|
|
86
|
+
const viewer = TimelineViewer.getInstance();
|
|
87
|
+
viewer.select('Other Timeline');
|
|
75
88
|
```
|
|
76
89
|
|
|
77
|
-
##
|
|
90
|
+
## Keyboard Shortcuts
|
|
78
91
|
|
|
79
|
-
|
|
92
|
+
| Key | Action |
|
|
93
|
+
|-----|--------|
|
|
94
|
+
| `Space` | Play / Pause |
|
|
95
|
+
| `J` | Jump to previous point |
|
|
96
|
+
| `K` | Jump to next point |
|
|
97
|
+
| `L` | Toggle loop |
|
|
80
98
|
|
|
81
|
-
|
|
82
|
-
<gsap-timeline-viewer></gsap-timeline-viewer>
|
|
99
|
+
## Named Tweens
|
|
83
100
|
|
|
84
|
-
|
|
85
|
-
import 'gsap-timeline-viewer';
|
|
101
|
+
Add `id` to your tweens for better labels:
|
|
86
102
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
103
|
+
```javascript
|
|
104
|
+
tl.to('.hero', {
|
|
105
|
+
opacity: 1,
|
|
106
|
+
duration: 1,
|
|
107
|
+
id: 'Hero Fade In' // Shows in viewer instead of ".hero (opacity)"
|
|
108
|
+
});
|
|
90
109
|
```
|
|
91
110
|
|
|
92
111
|
## UMD / Script Tag
|
|
@@ -96,15 +115,40 @@ The viewer is also available as a custom element:
|
|
|
96
115
|
<script src="https://unpkg.com/gsap-timeline-viewer"></script>
|
|
97
116
|
|
|
98
117
|
<script>
|
|
99
|
-
|
|
100
|
-
|
|
118
|
+
GSAPTimelineViewer.TimelineViewer.create();
|
|
119
|
+
|
|
120
|
+
// Your animations are auto-detected
|
|
121
|
+
gsap.timeline({ id: 'Main' })
|
|
122
|
+
.to('.box', { x: 100, duration: 1 });
|
|
101
123
|
</script>
|
|
102
124
|
```
|
|
103
125
|
|
|
126
|
+
## IIFE (Self-executing)
|
|
127
|
+
|
|
128
|
+
```html
|
|
129
|
+
<script src="https://unpkg.com/gsap-timeline-viewer/dist/gsap-timeline-viewer.iife.js"></script>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Disabling Auto-Detection
|
|
133
|
+
|
|
134
|
+
If you prefer manual control:
|
|
135
|
+
|
|
136
|
+
```javascript
|
|
137
|
+
TimelineViewer.create({ autoDetect: false });
|
|
138
|
+
|
|
139
|
+
// Manually register timelines
|
|
140
|
+
const tl = gsap.timeline();
|
|
141
|
+
TimelineViewer.register('My Timeline', tl);
|
|
142
|
+
```
|
|
143
|
+
|
|
104
144
|
## Browser Support
|
|
105
145
|
|
|
106
146
|
Works in all modern browsers that support Web Components (Chrome, Firefox, Safari, Edge).
|
|
107
147
|
|
|
148
|
+
## Repository
|
|
149
|
+
|
|
150
|
+
[GitHub](https://github.com/reboiedo/gsap-timeline-viewer)
|
|
151
|
+
|
|
108
152
|
## License
|
|
109
153
|
|
|
110
154
|
MIT
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
var GSAPTimelineViewer=function(o){"use strict";var P=Object.defineProperty;var L=(o,c,h)=>c in o?P(o,c,{enumerable:!0,configurable:!0,writable:!0,value:h}):o[c]=h;var n=(o,c,h)=>L(o,typeof c!="symbol"?c+"":c,h);let c=0;function h(l){if(!l||l.length===0)return"Unknown";const s=l[0];return s.id?`#${s.id}`:s.classList&&s.classList.length>0?`.${s.classList[0]}`:s.tagName?s.tagName.toLowerCase():"element"}function x(l){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(l).filter(t=>!s.includes(t))}function w(l){const s=[];return l.getChildren(!0,!0,!1).forEach((e,i)=>{if(!("targets"in e))return;const a=e,r=a.targets(),d=a.vars||{},p=x(d);let v="";if(d.id&&typeof d.id=="string")v=d.id;else{const b=h(r),k=p.slice(0,2).join(", ");v=k?`${b} (${k})`:b}const y=e.startTime(),f=e.duration();s.push({id:`tween-${++c}`,label:v,startTime:y,endTime:y+f,duration:f,targets:h(r),properties:p,colorIndex:i%6})}),{duration:l.duration(),tweens:s}}function S(){c=0}function g(l,s=!0){const t=Math.abs(l);return s?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: 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-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;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;padding:0 var(--gtv-timeline-padding)}.gtv-tracks-scroll{position:relative;min-height:100%;width:100%}.gtv-track{position:relative;height: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;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-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-empty{display:flex;align-items:center;justify-content:center;padding:24px;color:var(--gtv-text-muted)}",u=[.25,.5,1,2,4];class m extends HTMLElement{constructor(){super();n(this,"shadow");n(this,"timeline",null);n(this,"timelineData",null);n(this,"isPlaying",!1);n(this,"isLooping",!1);n(this,"speedIndex",2);n(this,"collapsed",!1);n(this,"height",200);n(this,"isDragging",!1);n(this,"container");n(this,"playBtn");n(this,"loopBtn");n(this,"speedBtn");n(this,"timeDisplay");n(this,"rulerInner");n(this,"tracksScroll");n(this,"playhead");n(this,"scrubArea");n(this,"resizeHandle");n(this,"isResizing",!1);this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.setupEventListeners()}disconnectedCallback(){this.detachTimeline()}setTimeline(t){this.detachTimeline(),this.timeline=t,S(),this.timelineData=w(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>${
|
|
1
|
+
var GSAPTimelineViewer=function(p){"use strict";var V=Object.defineProperty;var N=(p,u,b)=>u in p?V(p,u,{enumerable:!0,configurable:!0,writable:!0,value:b}):p[u]=b;var o=(p,u,b)=>N(p,typeof u!="symbol"?u+"":u,b);let u=0;function b(c){if(!c||c.length===0)return"Unknown";const a=c[0];return a.id?`#${a.id}`:a.classList&&a.classList.length>0?`.${a.classList[0]}`:a.tagName?a.tagName.toLowerCase():"element"}function M(c){const a=["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=>!a.includes(t))}function D(c,a=20){const t=window.gsap;if(!(t!=null&&t.parseEase))return[];const e=t.parseEase(c);if(!e)return[];const i=[];for(let s=0;s<=a;s++)i.push(e(s/a));return i}function A(c){const a=[];c.getChildren(!0,!0,!1).forEach((e,i)=>{if(!("targets"in e))return;const s=e,n=s.targets(),r=s.vars||{},d=M(r);let y="";if(r.id&&typeof r.id=="string")y=r.id;else{const w=b(n),T=d.slice(0,2).join(", ");y=T?`${w} (${T})`:w}const m=e.startTime(),f=e.duration();let g="none";r.ease&&(g=typeof r.ease=="string"?r.ease:"custom");let v,x;if(r.stagger&&n.length>1&&(typeof r.stagger=="number"?v=r.stagger:typeof r.stagger=="object"&&(v=r.stagger.each||0),v)){const w=f-v*(n.length-1);x=n.map((T,j)=>{const B=m+j*v;return{targetLabel:b([T]),startTime:B,endTime:B+w}})}a.push({id:`tween-${++u}`,label:y,startTime:m,endTime:m+f,duration:f,targets:b(n),properties:d,colorIndex:i%6,hasStagger:!!r.stagger,ease:g,easeSamples:D(g),staggerValue:v,staggerChildren:x})});for(let e=1;e<a.length;e++){const i=a[e-1],s=a[e],n=i.endTime-s.startTime;Math.abs(n)>.001&&(s.overlapWithPrev=Math.round(n*1e3)/1e3)}return{duration:c.duration(),tweens:a}}function H(){u=0}function k(c,a=!0){const t=Math.abs(c);return a?t.toFixed(2):t.toFixed(0)}const q=":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: 36px;--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;position:relative;z-index:1}.gtv-track-stagger{font-size:10px;font-weight:400;flex-shrink:0;position:relative;z-index:1}.gtv-track-bar:hover{filter:brightness(1.1)}.gtv-ease-curve{position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%;pointer-events:none;opacity:0;transition:opacity .15s}.gtv-ease-curve path{fill:var(--track-color);stroke:none}.gtv-container.show-ease-curves .gtv-ease-curve{opacity:1}.gtv-container.show-ease-curves .gtv-track-bar,.gtv-container.show-ease-curves .gtv-stagger-child-bar{background:transparent!important}.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;overflow:hidden}.gtv-stagger-child-bar .gtv-track-label{overflow:hidden;position:relative;z-index:1;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-container.show-ease-curves .gtv-overlap-region{display:none}.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)}",$=[.25,.5,1,2,4],C=40;class P extends HTMLElement{constructor(){super();o(this,"shadow");o(this,"timeline",null);o(this,"timelineData",null);o(this,"isPlaying",!1);o(this,"isLooping",!1);o(this,"speedIndex",2);o(this,"collapsed",!1);o(this,"height",200);o(this,"isDragging",!1);o(this,"manageBodyPadding",!0);o(this,"isAutofit",!1);o(this,"showEaseCurves",!1);o(this,"container");o(this,"playBtn");o(this,"loopBtn");o(this,"speedBtn");o(this,"timeDisplay");o(this,"rulerInner");o(this,"tracksScroll");o(this,"playhead");o(this,"scrubArea");o(this,"resizeHandle");o(this,"timelineSelect");o(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,H(),this.timelineData=A(t),t.eventCallback("onUpdate",()=>this.onTimelineUpdate()),this.renderTracks(),this.updatePlayhead(),this.updateTimeDisplay(),this.updatePlayState(),requestAnimationFrame(()=>this.applyAutofit())}updateTimelineSelector(){Promise.resolve().then(()=>E).then(({TimelineViewer:t})=>{const e=t.getTimelines(),i=this.timelineSelect.value;this.timelineSelect.innerHTML="",e.forEach((s,n)=>{const r=document.createElement("option");r.value=n,r.textContent=n,this.timelineSelect.appendChild(r)}),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>${q}</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,12 @@ 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="ease-curves" title="Show ease curves">
|
|
35
|
+
<svg viewBox="0 0 24 24"><path d="M3 17c0 0 3-8 9-8s9 8 9 8" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
|
|
36
|
+
</button>
|
|
37
|
+
<button class="gtv-btn" data-action="autofit" title="Auto-fit height">
|
|
38
|
+
<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>
|
|
39
|
+
</button>
|
|
31
40
|
<button class="gtv-btn gtv-collapse-btn" data-action="collapse" title="Collapse/Expand">
|
|
32
41
|
<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>
|
|
33
42
|
</button>
|
|
@@ -61,18 +70,40 @@ var GSAPTimelineViewer=function(o){"use strict";var P=Object.defineProperty;var
|
|
|
61
70
|
</div>
|
|
62
71
|
</div>
|
|
63
72
|
</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: ${
|
|
73
|
+
`,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;case"ease-curves":this.toggleEaseCurves();break}}),this.timelineSelect.addEventListener("change",()=>{const t=this.timelineSelect.value;t&&Promise.resolve().then(()=>E).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 s=i.closest(".gtv-track");(s==null?void 0:s.dataset.expandable)==="true"&&(t.stopPropagation(),s.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?C: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(),s=Math.max(0,Math.min(t.clientX-e.left,e.width))/e.width;this.timeline.progress(s),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 s of e)if(s<t-.001)i=s;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 s of e)if(s>t+.001){i=s;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)%$.length;const t=$[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()}toggleEaseCurves(){this.showEaseCurves=!this.showEaseCurves,this.shadow.querySelector('[data-action="ease-curves"]').classList.toggle("active",this.showEaseCurves),this.container.classList.toggle("show-ease-curves",this.showEaseCurves)}applyAutofit(){if(!this.isAutofit||this.collapsed)return;const t=this.shadow.querySelectorAll(".gtv-track");let e=0;const i=36,s=30;t.forEach(m=>{if(e+=i,m.classList.contains("expanded")){const f=m.querySelectorAll(".gtv-stagger-child");e+=f.length*s}});const n=24,r=16,d=100,y=window.innerHeight-100;this.height=Math.max(d,Math.min(C+n+e+r,y)),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"),s=this.timeDisplay.querySelector(".gtv-time-total");i.textContent=k(t),s.textContent=` / ${k(e)}`}updateActiveTracks(){if(!this.timeline||!this.timelineData)return;const t=this.timeline.time();this.tracksScroll.querySelectorAll(".gtv-track-bar").forEach((i,s)=>{const n=this.timelineData.tweens[s],r=t>=n.startTime&&t<=n.endTime,d=i.dataset.color;r?i.style.background=`var(--gtv-track-${d}-active)`:i.style.background=`var(--gtv-track-${d})`})}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 s=this.renderGridLines(t),n=e.map(d=>this.renderTrack(d,t)).join(""),r=this.tracksScroll.querySelector(".gtv-scrub-area");this.tracksScroll.innerHTML=s+n,this.tracksScroll.prepend(r),this.scrubArea=r}renderGridLines(t){const e=[],i=this.calculateInterval(t);for(let s=0;s<=t;s+=i){const n=s/t*100;e.push(`<div class="gtv-grid-line" style="left: ${n}%;"></div>`)}return e.join("")}renderRuler(t){const e=[],i=this.calculateInterval(t);for(let s=0;s<=t;s+=i){const n=s/t*100;e.push(`
|
|
74
|
+
<div class="gtv-ruler-marker" style="left: ${n}%;">
|
|
66
75
|
<div class="gtv-ruler-marker-line"></div>
|
|
67
|
-
<span class="gtv-ruler-marker-label">${
|
|
76
|
+
<span class="gtv-ruler-marker-label">${k(s,!1)}s</span>
|
|
68
77
|
</div>
|
|
69
|
-
`)}this.rulerInner.innerHTML=e.join("")}calculateInterval(t){return t<=1?.25:t<=3?.5:t<=10?1:t<=30?5:10}
|
|
70
|
-
<
|
|
78
|
+
`)}this.rulerInner.innerHTML=e.join("")}calculateInterval(t){return t<=1?.25:t<=3?.5:t<=10?1:t<=30?5:10}renderEaseCurve(t){return t!=null&&t.length?`
|
|
79
|
+
<svg class="gtv-ease-curve" viewBox="0 0 100 100" preserveAspectRatio="none">
|
|
80
|
+
<path d="${`M0,100 L${t.map((s,n)=>{const r=n/(t.length-1)*100,d=100-s*100;return`${r},${d}`}).join(" L")} L100,100 Z`}" />
|
|
81
|
+
</svg>
|
|
82
|
+
`:""}getEaseClipPath(t){return t!=null&&t.length?`polygon(0% 100%, ${t.map((i,s)=>{const n=s/(t.length-1)*100,r=100-i*100;return`${n}% ${r}%`}).join(", ")}, 100% 100%)`:""}renderTrack(t,e){const i=t.startTime/e*100,s=t.duration/e*100,n=t.colorIndex+1,r=this.renderEaseCurve(t.easeSamples);let d="";t.hasStagger&&t.staggerChildren&&t.staggerChildren.length>0&&(d='<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 y="";if(t.staggerChildren&&t.staggerChildren.length>0){const f=t.staggerChildren.map(g=>{const v=g.startTime/e*100,x=(g.endTime-g.startTime)/e*100;return`
|
|
83
|
+
<div class="gtv-stagger-child">
|
|
84
|
+
<div class="gtv-stagger-child-bar"
|
|
85
|
+
style="left: ${v}%; width: ${x}%; background: var(--gtv-track-${n}); --track-color: var(--gtv-track-${n});">
|
|
86
|
+
${r}
|
|
87
|
+
<span class="gtv-track-label">${g.targetLabel}</span>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
`}).join("");y=`<div class="gtv-stagger-children" data-for="${t.id}">${f}</div>`}let m="";if(t.overlapWithPrev!==void 0){const f=t.overlapWithPrev>0,g=Math.abs(t.overlapWithPrev)/e*100,v=f?`-${k(t.overlapWithPrev)}s`:`+${k(Math.abs(t.overlapWithPrev))}s`,x=this.getEaseClipPath(t.easeSamples);f?m=`
|
|
91
|
+
<div class="gtv-overlap-region" style="left: ${i}%; width: ${g}%; --ease-clip: ${x};"></div>
|
|
92
|
+
<span class="gtv-offset-badge gtv-offset-overlap" style="left: ${i}%;">${v}</span>
|
|
93
|
+
`:m=`
|
|
94
|
+
<div class="gtv-gap-connector" style="left: ${i-g}%; width: ${g}%;"></div>
|
|
95
|
+
<span class="gtv-offset-badge gtv-offset-gap" style="left: ${i}%;">${v}</span>
|
|
96
|
+
`}return`
|
|
97
|
+
<div class="gtv-track" data-expandable="${t.hasStagger&&t.staggerChildren?"true":"false"}">
|
|
98
|
+
${m}
|
|
71
99
|
<div class="gtv-track-bar"
|
|
72
|
-
data-color="${
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
${
|
|
100
|
+
data-color="${n}"
|
|
101
|
+
data-tween-id="${t.id}"
|
|
102
|
+
style="left: ${i}%; width: ${s}%; background: var(--gtv-track-${n}); --track-color: var(--gtv-track-${n});">
|
|
103
|
+
${r}
|
|
104
|
+
<span class="gtv-track-label">${t.label}</span>
|
|
105
|
+
${d}
|
|
76
106
|
</div>
|
|
107
|
+
${y}
|
|
77
108
|
</div>
|
|
78
|
-
`}}customElements.define("gsap-timeline-viewer",
|
|
109
|
+
`}}customElements.define("gsap-timeline-viewer",P);const h=new Map;let l=null,z=!0,I=0,L=null;function R(){const c=window.gsap;!c||L||(L=c.timeline.bind(c),c.timeline=function(a){const t=L(a);if(z){let e;a!=null&&a.id&&typeof a.id=="string"?e=a.id:e=`Timeline ${++I}`,h.has(e)||(h.set(e,t),l&&(l.htmlElement.updateTimelineSelector(),h.size===1&&l.select(e)))}return t})}class S{constructor(a={}){o(this,"element");o(this,"currentTimelineName",null);this.element=document.createElement("gsap-timeline-viewer"),a.height&&this.element.style.setProperty("--viewer-height",`${a.height}px`)}static create(a={}){return l||(z=a.autoDetect!==!1,z&&R(),l=new S(a),document.body.appendChild(l.element),setTimeout(()=>{if(l.element.updateTimelineSelector(),a.defaultTimeline&&h.has(a.defaultTimeline))l.select(a.defaultTimeline);else if(h.size>0){const t=h.keys().next().value;t&&l.select(t)}},0),l)}static register(a,t){h.set(a,t),l&&(l.element.updateTimelineSelector(),h.size===1&&l.select(a))}static unregister(a){h.delete(a),l&&l.element.updateTimelineSelector()}static getTimelines(){return h}static getInstance(){return l}select(a){const t=h.get(a);t&&(this.currentTimelineName=a,this.element.setTimeline(t),this.element.setSelectedTimeline(a))}getCurrentTimelineName(){return this.currentTimelineName}destroy(){this.element.remove(),l=null}get htmlElement(){return this.element}}const E=Object.freeze(Object.defineProperty({__proto__:null,TimelineViewer:S,TimelineViewerElement:P},Symbol.toStringTag,{value:"Module"}));return p.TimelineViewer=S,p.TimelineViewerElement=P,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"}),p}({});
|
|
@@ -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 D = (l, i, t) => i in l ? M(l, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : l[i] = t;
|
|
3
|
+
var o = (l, i, t) => D(l, typeof i != "symbol" ? i + "" : i, t);
|
|
4
|
+
let C = 0;
|
|
5
|
+
function k(l) {
|
|
6
|
+
if (!l || l.length === 0) return "Unknown";
|
|
7
|
+
const i = l[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 A(l) {
|
|
11
11
|
const i = [
|
|
12
12
|
"ease",
|
|
13
13
|
"duration",
|
|
@@ -31,90 +31,143 @@ function x(r) {
|
|
|
31
31
|
"reversed",
|
|
32
32
|
"startAt"
|
|
33
33
|
];
|
|
34
|
-
return Object.keys(
|
|
34
|
+
return Object.keys(l).filter((t) => !i.includes(t));
|
|
35
35
|
}
|
|
36
|
-
function
|
|
36
|
+
function H(l, i = 20) {
|
|
37
|
+
const t = window.gsap;
|
|
38
|
+
if (!(t != null && t.parseEase)) return [];
|
|
39
|
+
const e = t.parseEase(l);
|
|
40
|
+
if (!e) return [];
|
|
41
|
+
const s = [];
|
|
42
|
+
for (let a = 0; a <= i; a++)
|
|
43
|
+
s.push(e(a / i));
|
|
44
|
+
return s;
|
|
45
|
+
}
|
|
46
|
+
function q(l) {
|
|
37
47
|
const i = [];
|
|
38
|
-
|
|
48
|
+
l.getChildren(!0, !0, !1).forEach((e, s) => {
|
|
39
49
|
if (!("targets" in e)) return;
|
|
40
|
-
const a = e,
|
|
41
|
-
let
|
|
42
|
-
if (
|
|
43
|
-
|
|
50
|
+
const a = e, n = a.targets(), r = a.vars || {}, d = A(r);
|
|
51
|
+
let m = "";
|
|
52
|
+
if (r.id && typeof r.id == "string")
|
|
53
|
+
m = r.id;
|
|
44
54
|
else {
|
|
45
|
-
const
|
|
46
|
-
|
|
55
|
+
const b = k(n), x = d.slice(0, 2).join(", ");
|
|
56
|
+
m = x ? `${b} (${x})` : b;
|
|
57
|
+
}
|
|
58
|
+
const p = e.startTime(), u = e.duration();
|
|
59
|
+
let g = "none";
|
|
60
|
+
r.ease && (g = typeof r.ease == "string" ? r.ease : "custom");
|
|
61
|
+
let h, f;
|
|
62
|
+
if (r.stagger && n.length > 1 && (typeof r.stagger == "number" ? h = r.stagger : typeof r.stagger == "object" && (h = r.stagger.each || 0), h)) {
|
|
63
|
+
const b = u - h * (n.length - 1);
|
|
64
|
+
f = n.map((x, B) => {
|
|
65
|
+
const P = p + B * h;
|
|
66
|
+
return {
|
|
67
|
+
targetLabel: k([x]),
|
|
68
|
+
startTime: P,
|
|
69
|
+
endTime: P + b
|
|
70
|
+
};
|
|
71
|
+
});
|
|
47
72
|
}
|
|
48
|
-
const p = e.startTime(), g = e.duration();
|
|
49
73
|
i.push({
|
|
50
|
-
id: `tween-${++
|
|
51
|
-
label:
|
|
74
|
+
id: `tween-${++C}`,
|
|
75
|
+
label: m,
|
|
52
76
|
startTime: p,
|
|
53
|
-
endTime: p +
|
|
54
|
-
duration:
|
|
55
|
-
targets:
|
|
56
|
-
properties:
|
|
57
|
-
colorIndex: s % 6
|
|
77
|
+
endTime: p + u,
|
|
78
|
+
duration: u,
|
|
79
|
+
targets: k(n),
|
|
80
|
+
properties: d,
|
|
81
|
+
colorIndex: s % 6,
|
|
82
|
+
hasStagger: !!r.stagger,
|
|
83
|
+
ease: g,
|
|
84
|
+
easeSamples: H(g),
|
|
85
|
+
staggerValue: h,
|
|
86
|
+
staggerChildren: f
|
|
58
87
|
});
|
|
59
|
-
})
|
|
60
|
-
|
|
88
|
+
});
|
|
89
|
+
for (let e = 1; e < i.length; e++) {
|
|
90
|
+
const s = i[e - 1], a = i[e], n = s.endTime - a.startTime;
|
|
91
|
+
Math.abs(n) > 1e-3 && (a.overlapWithPrev = Math.round(n * 1e3) / 1e3);
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
duration: l.duration(),
|
|
61
95
|
tweens: i
|
|
62
96
|
};
|
|
63
97
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
98
|
+
function I() {
|
|
99
|
+
C = 0;
|
|
66
100
|
}
|
|
67
|
-
function
|
|
68
|
-
const t = Math.abs(
|
|
101
|
+
function y(l, i = !0) {
|
|
102
|
+
const t = Math.abs(l);
|
|
69
103
|
return i ? t.toFixed(2) : t.toFixed(0);
|
|
70
104
|
}
|
|
71
|
-
const
|
|
72
|
-
class
|
|
105
|
+
const R = ":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: 36px;--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;position:relative;z-index:1}.gtv-track-stagger{font-size:10px;font-weight:400;flex-shrink:0;position:relative;z-index:1}.gtv-track-bar:hover{filter:brightness(1.1)}.gtv-ease-curve{position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%;pointer-events:none;opacity:0;transition:opacity .15s}.gtv-ease-curve path{fill:var(--track-color);stroke:none}.gtv-container.show-ease-curves .gtv-ease-curve{opacity:1}.gtv-container.show-ease-curves .gtv-track-bar,.gtv-container.show-ease-curves .gtv-stagger-child-bar{background:transparent!important}.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;overflow:hidden}.gtv-stagger-child-bar .gtv-track-label{overflow:hidden;position:relative;z-index:1;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-container.show-ease-curves .gtv-overlap-region{display:none}.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)}", z = [0.25, 0.5, 1, 2, 4], L = 40;
|
|
106
|
+
class E extends HTMLElement {
|
|
73
107
|
constructor() {
|
|
74
108
|
super();
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
109
|
+
o(this, "shadow");
|
|
110
|
+
o(this, "timeline", null);
|
|
111
|
+
o(this, "timelineData", null);
|
|
112
|
+
o(this, "isPlaying", !1);
|
|
113
|
+
o(this, "isLooping", !1);
|
|
114
|
+
o(this, "speedIndex", 2);
|
|
81
115
|
// 1x
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
116
|
+
o(this, "collapsed", !1);
|
|
117
|
+
o(this, "height", 200);
|
|
118
|
+
o(this, "isDragging", !1);
|
|
119
|
+
o(this, "manageBodyPadding", !0);
|
|
120
|
+
o(this, "isAutofit", !1);
|
|
121
|
+
o(this, "showEaseCurves", !1);
|
|
85
122
|
// DOM references
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
123
|
+
o(this, "container");
|
|
124
|
+
o(this, "playBtn");
|
|
125
|
+
o(this, "loopBtn");
|
|
126
|
+
o(this, "speedBtn");
|
|
127
|
+
o(this, "timeDisplay");
|
|
128
|
+
o(this, "rulerInner");
|
|
129
|
+
o(this, "tracksScroll");
|
|
130
|
+
o(this, "playhead");
|
|
131
|
+
o(this, "scrubArea");
|
|
132
|
+
o(this, "resizeHandle");
|
|
133
|
+
o(this, "timelineSelect");
|
|
134
|
+
o(this, "isResizing", !1);
|
|
97
135
|
this.shadow = this.attachShadow({ mode: "open" });
|
|
98
136
|
}
|
|
99
137
|
connectedCallback() {
|
|
100
|
-
this.render(), this.setupEventListeners();
|
|
138
|
+
this.render(), this.setupEventListeners(), this.updateBodyPadding();
|
|
101
139
|
}
|
|
102
140
|
disconnectedCallback() {
|
|
103
|
-
this.detachTimeline();
|
|
141
|
+
this.detachTimeline(), this.clearBodyPadding();
|
|
104
142
|
}
|
|
105
143
|
setTimeline(t) {
|
|
106
|
-
this.detachTimeline(), this.timeline = t,
|
|
144
|
+
this.detachTimeline(), this.timeline = t, I(), this.timelineData = q(t), t.eventCallback("onUpdate", () => this.onTimelineUpdate()), this.renderTracks(), this.updatePlayhead(), this.updateTimeDisplay(), this.updatePlayState(), requestAnimationFrame(() => this.applyAutofit());
|
|
145
|
+
}
|
|
146
|
+
updateTimelineSelector() {
|
|
147
|
+
Promise.resolve().then(() => $).then(({ TimelineViewer: t }) => {
|
|
148
|
+
const e = t.getTimelines(), s = this.timelineSelect.value;
|
|
149
|
+
this.timelineSelect.innerHTML = "", e.forEach((a, n) => {
|
|
150
|
+
const r = document.createElement("option");
|
|
151
|
+
r.value = n, r.textContent = n, this.timelineSelect.appendChild(r);
|
|
152
|
+
}), s && e.has(s) && (this.timelineSelect.value = s);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
setSelectedTimeline(t) {
|
|
156
|
+
this.timelineSelect.value = t;
|
|
107
157
|
}
|
|
108
158
|
detachTimeline() {
|
|
109
159
|
this.timeline && (this.timeline.eventCallback("onUpdate", null), this.timeline = null, this.timelineData = null);
|
|
110
160
|
}
|
|
111
161
|
render() {
|
|
112
162
|
this.shadow.innerHTML = `
|
|
113
|
-
<style>${
|
|
163
|
+
<style>${R}</style>
|
|
114
164
|
<div class="gtv-container ${this.collapsed ? "collapsed" : ""}" style="height: ${this.height}px;">
|
|
115
165
|
<!-- Controls Bar -->
|
|
116
166
|
<div class="gtv-controls">
|
|
117
167
|
<div class="gtv-controls-left">
|
|
168
|
+
<select class="gtv-timeline-select" title="Select timeline">
|
|
169
|
+
<option value="">No timeline</option>
|
|
170
|
+
</select>
|
|
118
171
|
<button class="gtv-btn" data-action="loop" title="Loop (L)">
|
|
119
172
|
<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
173
|
</button>
|
|
@@ -139,6 +192,12 @@ class z extends HTMLElement {
|
|
|
139
192
|
</div>
|
|
140
193
|
|
|
141
194
|
<div class="gtv-controls-right">
|
|
195
|
+
<button class="gtv-btn" data-action="ease-curves" title="Show ease curves">
|
|
196
|
+
<svg viewBox="0 0 24 24"><path d="M3 17c0 0 3-8 9-8s9 8 9 8" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
|
|
197
|
+
</button>
|
|
198
|
+
<button class="gtv-btn" data-action="autofit" title="Auto-fit height">
|
|
199
|
+
<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>
|
|
200
|
+
</button>
|
|
142
201
|
<button class="gtv-btn gtv-collapse-btn" data-action="collapse" title="Collapse/Expand">
|
|
143
202
|
<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>
|
|
144
203
|
</button>
|
|
@@ -172,7 +231,7 @@ class z extends HTMLElement {
|
|
|
172
231
|
</div>
|
|
173
232
|
</div>
|
|
174
233
|
</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");
|
|
234
|
+
`, 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
235
|
}
|
|
177
236
|
setupEventListeners() {
|
|
178
237
|
this.shadow.addEventListener("click", (t) => {
|
|
@@ -197,8 +256,28 @@ class z extends HTMLElement {
|
|
|
197
256
|
case "collapse":
|
|
198
257
|
this.toggleCollapse();
|
|
199
258
|
break;
|
|
259
|
+
case "autofit":
|
|
260
|
+
this.toggleAutofit();
|
|
261
|
+
break;
|
|
262
|
+
case "ease-curves":
|
|
263
|
+
this.toggleEaseCurves();
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
}), this.timelineSelect.addEventListener("change", () => {
|
|
267
|
+
const t = this.timelineSelect.value;
|
|
268
|
+
t && Promise.resolve().then(() => $).then(({ TimelineViewer: e }) => {
|
|
269
|
+
var s;
|
|
270
|
+
(s = e.getInstance()) == null || s.select(t);
|
|
271
|
+
});
|
|
272
|
+
}), this.shadow.addEventListener("click", (t) => {
|
|
273
|
+
const s = t.target.closest(".gtv-track-bar");
|
|
274
|
+
if (s) {
|
|
275
|
+
const a = s.closest(".gtv-track");
|
|
276
|
+
(a == null ? void 0 : a.dataset.expandable) === "true" && (t.stopPropagation(), a.classList.toggle("expanded"), requestAnimationFrame(() => this.applyAutofit()));
|
|
200
277
|
}
|
|
201
|
-
}), this.scrubArea.addEventListener("mousedown", (t) => this.startScrub(t)), this.shadow.querySelector(".gtv-ruler").addEventListener("mousedown", (t) => this.startScrub(t)),
|
|
278
|
+
}), 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) => {
|
|
279
|
+
t.target.closest(".gtv-track-bar") || this.startScrub(t);
|
|
280
|
+
}), document.addEventListener("mousemove", (t) => {
|
|
202
281
|
this.onScrub(t), this.onResize(t);
|
|
203
282
|
}), document.addEventListener("mouseup", () => {
|
|
204
283
|
this.endScrub(), this.endResize();
|
|
@@ -235,11 +314,19 @@ class z extends HTMLElement {
|
|
|
235
314
|
onResize(t) {
|
|
236
315
|
if (!this.isResizing) return;
|
|
237
316
|
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
|
|
317
|
+
this.height = Math.max(100, Math.min(s, e - 100)), this.container.style.height = `${this.height}px`, this.updateBodyPadding();
|
|
239
318
|
}
|
|
240
319
|
endResize() {
|
|
241
320
|
this.isResizing && (this.isResizing = !1, document.body.style.cursor = "", document.body.style.userSelect = "");
|
|
242
321
|
}
|
|
322
|
+
updateBodyPadding() {
|
|
323
|
+
if (!this.manageBodyPadding) return;
|
|
324
|
+
const t = this.collapsed ? L : this.height;
|
|
325
|
+
document.body.style.paddingBottom = `${t}px`;
|
|
326
|
+
}
|
|
327
|
+
clearBodyPadding() {
|
|
328
|
+
this.manageBodyPadding && (document.body.style.paddingBottom = "");
|
|
329
|
+
}
|
|
243
330
|
scrubToPosition(t) {
|
|
244
331
|
if (!this.timeline || !this.timelineData) return;
|
|
245
332
|
const e = this.rulerInner.getBoundingClientRect(), a = Math.max(0, Math.min(t.clientX - e.left, e.width)) / e.width;
|
|
@@ -288,14 +375,34 @@ class z extends HTMLElement {
|
|
|
288
375
|
}
|
|
289
376
|
cycleSpeed() {
|
|
290
377
|
if (!this.timeline) return;
|
|
291
|
-
this.speedIndex = (this.speedIndex + 1) %
|
|
292
|
-
const t =
|
|
378
|
+
this.speedIndex = (this.speedIndex + 1) % z.length;
|
|
379
|
+
const t = z[this.speedIndex];
|
|
293
380
|
this.timeline.timeScale(t), this.speedBtn.textContent = `${t}x`;
|
|
294
381
|
}
|
|
295
382
|
toggleCollapse() {
|
|
296
383
|
this.collapsed = !this.collapsed, this.container.classList.toggle("collapsed", this.collapsed);
|
|
297
384
|
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>';
|
|
385
|
+
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();
|
|
386
|
+
}
|
|
387
|
+
toggleAutofit() {
|
|
388
|
+
this.isAutofit = !this.isAutofit, this.shadow.querySelector('[data-action="autofit"]').classList.toggle("active", this.isAutofit), this.isAutofit && this.applyAutofit();
|
|
389
|
+
}
|
|
390
|
+
toggleEaseCurves() {
|
|
391
|
+
this.showEaseCurves = !this.showEaseCurves, this.shadow.querySelector('[data-action="ease-curves"]').classList.toggle("active", this.showEaseCurves), this.container.classList.toggle("show-ease-curves", this.showEaseCurves);
|
|
392
|
+
}
|
|
393
|
+
applyAutofit() {
|
|
394
|
+
if (!this.isAutofit || this.collapsed) return;
|
|
395
|
+
const t = this.shadow.querySelectorAll(".gtv-track");
|
|
396
|
+
let e = 0;
|
|
397
|
+
const s = 36, a = 30;
|
|
398
|
+
t.forEach((p) => {
|
|
399
|
+
if (e += s, p.classList.contains("expanded")) {
|
|
400
|
+
const u = p.querySelectorAll(".gtv-stagger-child");
|
|
401
|
+
e += u.length * a;
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
const n = 24, r = 16, d = 100, m = window.innerHeight - 100;
|
|
405
|
+
this.height = Math.max(d, Math.min(L + n + e + r, m)), this.container.style.height = `${this.height}px`, this.updateBodyPadding();
|
|
299
406
|
}
|
|
300
407
|
updatePlayState() {
|
|
301
408
|
if (!this.timeline) return;
|
|
@@ -314,31 +421,39 @@ class z extends HTMLElement {
|
|
|
314
421
|
updateTimeDisplay() {
|
|
315
422
|
if (!this.timeline || !this.timelineData) return;
|
|
316
423
|
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 =
|
|
424
|
+
s.textContent = y(t), a.textContent = ` / ${y(e)}`;
|
|
318
425
|
}
|
|
319
426
|
updateActiveTracks() {
|
|
320
427
|
if (!this.timeline || !this.timelineData) return;
|
|
321
428
|
const t = this.timeline.time();
|
|
322
429
|
this.tracksScroll.querySelectorAll(".gtv-track-bar").forEach((s, a) => {
|
|
323
|
-
const
|
|
324
|
-
|
|
430
|
+
const n = this.timelineData.tweens[a], r = t >= n.startTime && t <= n.endTime, d = s.dataset.color;
|
|
431
|
+
r ? s.style.background = `var(--gtv-track-${d}-active)` : s.style.background = `var(--gtv-track-${d})`;
|
|
325
432
|
});
|
|
326
433
|
}
|
|
327
434
|
renderTracks() {
|
|
328
435
|
if (!this.timelineData) return;
|
|
329
436
|
const { duration: t, tweens: e } = this.timelineData, s = this.shadow.querySelector(".gtv-empty");
|
|
330
437
|
s.style.display = e.length > 0 ? "none" : "flex", this.renderRuler(t);
|
|
331
|
-
const a = e.map((
|
|
332
|
-
this.tracksScroll.innerHTML = a, this.tracksScroll.prepend(
|
|
438
|
+
const a = this.renderGridLines(t), n = e.map((d) => this.renderTrack(d, t)).join(""), r = this.tracksScroll.querySelector(".gtv-scrub-area");
|
|
439
|
+
this.tracksScroll.innerHTML = a + n, this.tracksScroll.prepend(r), this.scrubArea = r;
|
|
440
|
+
}
|
|
441
|
+
renderGridLines(t) {
|
|
442
|
+
const e = [], s = this.calculateInterval(t);
|
|
443
|
+
for (let a = 0; a <= t; a += s) {
|
|
444
|
+
const n = a / t * 100;
|
|
445
|
+
e.push(`<div class="gtv-grid-line" style="left: ${n}%;"></div>`);
|
|
446
|
+
}
|
|
447
|
+
return e.join("");
|
|
333
448
|
}
|
|
334
449
|
renderRuler(t) {
|
|
335
450
|
const e = [], s = this.calculateInterval(t);
|
|
336
451
|
for (let a = 0; a <= t; a += s) {
|
|
337
|
-
const
|
|
452
|
+
const n = a / t * 100;
|
|
338
453
|
e.push(`
|
|
339
|
-
<div class="gtv-ruler-marker" style="left: ${
|
|
454
|
+
<div class="gtv-ruler-marker" style="left: ${n}%;">
|
|
340
455
|
<div class="gtv-ruler-marker-line"></div>
|
|
341
|
-
<span class="gtv-ruler-marker-label">${
|
|
456
|
+
<span class="gtv-ruler-marker-label">${y(a, !1)}s</span>
|
|
342
457
|
</div>
|
|
343
458
|
`);
|
|
344
459
|
}
|
|
@@ -347,42 +462,156 @@ class z extends HTMLElement {
|
|
|
347
462
|
calculateInterval(t) {
|
|
348
463
|
return t <= 1 ? 0.25 : t <= 3 ? 0.5 : t <= 10 ? 1 : t <= 30 ? 5 : 10;
|
|
349
464
|
}
|
|
465
|
+
renderEaseCurve(t) {
|
|
466
|
+
return t != null && t.length ? `
|
|
467
|
+
<svg class="gtv-ease-curve" viewBox="0 0 100 100" preserveAspectRatio="none">
|
|
468
|
+
<path d="${`M0,100 L${t.map((a, n) => {
|
|
469
|
+
const r = n / (t.length - 1) * 100, d = 100 - a * 100;
|
|
470
|
+
return `${r},${d}`;
|
|
471
|
+
}).join(" L")} L100,100 Z`}" />
|
|
472
|
+
</svg>
|
|
473
|
+
` : "";
|
|
474
|
+
}
|
|
475
|
+
getEaseClipPath(t) {
|
|
476
|
+
return t != null && t.length ? `polygon(0% 100%, ${t.map((s, a) => {
|
|
477
|
+
const n = a / (t.length - 1) * 100, r = 100 - s * 100;
|
|
478
|
+
return `${n}% ${r}%`;
|
|
479
|
+
}).join(", ")}, 100% 100%)` : "";
|
|
480
|
+
}
|
|
350
481
|
renderTrack(t, e) {
|
|
351
|
-
const s = t.startTime / e * 100, a = t.duration / e * 100,
|
|
482
|
+
const s = t.startTime / e * 100, a = t.duration / e * 100, n = t.colorIndex + 1, r = this.renderEaseCurve(t.easeSamples);
|
|
483
|
+
let d = "";
|
|
484
|
+
t.hasStagger && t.staggerChildren && t.staggerChildren.length > 0 && (d = '<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>');
|
|
485
|
+
let m = "";
|
|
486
|
+
if (t.staggerChildren && t.staggerChildren.length > 0) {
|
|
487
|
+
const u = t.staggerChildren.map((g) => {
|
|
488
|
+
const h = g.startTime / e * 100, f = (g.endTime - g.startTime) / e * 100;
|
|
489
|
+
return `
|
|
490
|
+
<div class="gtv-stagger-child">
|
|
491
|
+
<div class="gtv-stagger-child-bar"
|
|
492
|
+
style="left: ${h}%; width: ${f}%; background: var(--gtv-track-${n}); --track-color: var(--gtv-track-${n});">
|
|
493
|
+
${r}
|
|
494
|
+
<span class="gtv-track-label">${g.targetLabel}</span>
|
|
495
|
+
</div>
|
|
496
|
+
</div>
|
|
497
|
+
`;
|
|
498
|
+
}).join("");
|
|
499
|
+
m = `<div class="gtv-stagger-children" data-for="${t.id}">${u}</div>`;
|
|
500
|
+
}
|
|
501
|
+
let p = "";
|
|
502
|
+
if (t.overlapWithPrev !== void 0) {
|
|
503
|
+
const u = t.overlapWithPrev > 0, g = Math.abs(t.overlapWithPrev) / e * 100, h = u ? `-${y(t.overlapWithPrev)}s` : `+${y(Math.abs(t.overlapWithPrev))}s`, f = this.getEaseClipPath(t.easeSamples);
|
|
504
|
+
u ? p = `
|
|
505
|
+
<div class="gtv-overlap-region" style="left: ${s}%; width: ${g}%; --ease-clip: ${f};"></div>
|
|
506
|
+
<span class="gtv-offset-badge gtv-offset-overlap" style="left: ${s}%;">${h}</span>
|
|
507
|
+
` : p = `
|
|
508
|
+
<div class="gtv-gap-connector" style="left: ${s - g}%; width: ${g}%;"></div>
|
|
509
|
+
<span class="gtv-offset-badge gtv-offset-gap" style="left: ${s}%;">${h}</span>
|
|
510
|
+
`;
|
|
511
|
+
}
|
|
352
512
|
return `
|
|
353
|
-
<div class="gtv-track">
|
|
513
|
+
<div class="gtv-track" data-expandable="${t.hasStagger && t.staggerChildren ? "true" : "false"}">
|
|
514
|
+
${p}
|
|
354
515
|
<div class="gtv-track-bar"
|
|
355
|
-
data-color="${
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
${
|
|
516
|
+
data-color="${n}"
|
|
517
|
+
data-tween-id="${t.id}"
|
|
518
|
+
style="left: ${s}%; width: ${a}%; background: var(--gtv-track-${n}); --track-color: var(--gtv-track-${n});">
|
|
519
|
+
${r}
|
|
520
|
+
<span class="gtv-track-label">${t.label}</span>
|
|
521
|
+
${d}
|
|
359
522
|
</div>
|
|
523
|
+
${m}
|
|
360
524
|
</div>
|
|
361
525
|
`;
|
|
362
526
|
}
|
|
363
527
|
}
|
|
364
|
-
customElements.define("gsap-timeline-viewer",
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
528
|
+
customElements.define("gsap-timeline-viewer", E);
|
|
529
|
+
const v = /* @__PURE__ */ new Map();
|
|
530
|
+
let c = null, S = !0, j = 0, w = null;
|
|
531
|
+
function V() {
|
|
532
|
+
const l = window.gsap;
|
|
533
|
+
!l || w || (w = l.timeline.bind(l), l.timeline = function(i) {
|
|
534
|
+
const t = w(i);
|
|
535
|
+
if (S) {
|
|
536
|
+
let e;
|
|
537
|
+
i != null && i.id && typeof i.id == "string" ? e = i.id : e = `Timeline ${++j}`, v.has(e) || (v.set(e, t), c && (c.htmlElement.updateTimelineSelector(), v.size === 1 && c.select(e)));
|
|
538
|
+
}
|
|
539
|
+
return t;
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
class T {
|
|
543
|
+
constructor(i = {}) {
|
|
544
|
+
o(this, "element");
|
|
545
|
+
o(this, "currentTimelineName", null);
|
|
546
|
+
this.element = document.createElement("gsap-timeline-viewer"), i.height && this.element.style.setProperty("--viewer-height", `${i.height}px`);
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Create and attach the timeline viewer to the page.
|
|
550
|
+
* Call this once - subsequent calls return the existing instance.
|
|
551
|
+
*/
|
|
552
|
+
static create(i = {}) {
|
|
553
|
+
return c || (S = i.autoDetect !== !1, S && V(), c = new T(i), document.body.appendChild(c.element), setTimeout(() => {
|
|
554
|
+
if (c.element.updateTimelineSelector(), i.defaultTimeline && v.has(i.defaultTimeline))
|
|
555
|
+
c.select(i.defaultTimeline);
|
|
556
|
+
else if (v.size > 0) {
|
|
557
|
+
const t = v.keys().next().value;
|
|
558
|
+
t && c.select(t);
|
|
559
|
+
}
|
|
560
|
+
}, 0), c);
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Register a timeline with a name so it appears in the dropdown.
|
|
564
|
+
*/
|
|
565
|
+
static register(i, t) {
|
|
566
|
+
v.set(i, t), c && (c.element.updateTimelineSelector(), v.size === 1 && c.select(i));
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Unregister a timeline.
|
|
570
|
+
*/
|
|
571
|
+
static unregister(i) {
|
|
572
|
+
v.delete(i), c && c.element.updateTimelineSelector();
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* Get all registered timelines.
|
|
576
|
+
*/
|
|
577
|
+
static getTimelines() {
|
|
578
|
+
return v;
|
|
579
|
+
}
|
|
580
|
+
/**
|
|
581
|
+
* Get the viewer instance (if created).
|
|
582
|
+
*/
|
|
583
|
+
static getInstance() {
|
|
584
|
+
return c;
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* Select a timeline by name.
|
|
588
|
+
*/
|
|
589
|
+
select(i) {
|
|
590
|
+
const t = v.get(i);
|
|
591
|
+
t && (this.currentTimelineName = i, this.element.setTimeline(t), this.element.setSelectedTimeline(i));
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Get current timeline name.
|
|
595
|
+
*/
|
|
596
|
+
getCurrentTimelineName() {
|
|
597
|
+
return this.currentTimelineName;
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Remove the viewer from the page.
|
|
601
|
+
*/
|
|
602
|
+
destroy() {
|
|
603
|
+
this.element.remove(), c = null;
|
|
380
604
|
}
|
|
381
605
|
get htmlElement() {
|
|
382
606
|
return this.element;
|
|
383
607
|
}
|
|
384
608
|
}
|
|
609
|
+
const $ = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
610
|
+
__proto__: null,
|
|
611
|
+
TimelineViewer: T,
|
|
612
|
+
TimelineViewerElement: E
|
|
613
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
385
614
|
export {
|
|
386
|
-
|
|
387
|
-
|
|
615
|
+
T as TimelineViewer,
|
|
616
|
+
E as TimelineViewerElement
|
|
388
617
|
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
(function(l,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(l=typeof globalThis<"u"?globalThis:l||self,r(l.GSAPTimelineViewer={}))})(this,function(l){"use strict";var P=Object.defineProperty;var L=(l,r,h)=>r in l?P(l,r,{enumerable:!0,configurable:!0,writable:!0,value:h}):l[r]=h;var n=(l,r,h)=>L(l,typeof r!="symbol"?r+"":r,h);let r=0;function h(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 x(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 w(c){const s=[];return c.getChildren(!0,!0,!1).forEach((e,i)=>{if(!("targets"in e))return;const a=e,o=a.targets(),d=a.vars||{},g=x(d);let v="";if(d.id&&typeof d.id=="string")v=d.id;else{const b=h(o),k=g.slice(0,2).join(", ");v=k?`${b} (${k})`:b}const f=e.startTime(),y=e.duration();s.push({id:`tween-${++r}`,label:v,startTime:f,endTime:f+y,duration:y,targets:h(o),properties:g,colorIndex:i%6})}),{duration:c.duration(),tweens:s}}function S(){r=0}function p(c,s=!0){const t=Math.abs(c);return s?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: 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-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;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;padding:0 var(--gtv-timeline-padding)}.gtv-tracks-scroll{position:relative;min-height:100%;width:100%}.gtv-track{position:relative;height: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;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-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-empty{display:flex;align-items:center;justify-content:center;padding:24px;color:var(--gtv-text-muted)}",u=[.25,.5,1,2,4];class m extends HTMLElement{constructor(){super();n(this,"shadow");n(this,"timeline",null);n(this,"timelineData",null);n(this,"isPlaying",!1);n(this,"isLooping",!1);n(this,"speedIndex",2);n(this,"collapsed",!1);n(this,"height",200);n(this,"isDragging",!1);n(this,"container");n(this,"playBtn");n(this,"loopBtn");n(this,"speedBtn");n(this,"timeDisplay");n(this,"rulerInner");n(this,"tracksScroll");n(this,"playhead");n(this,"scrubArea");n(this,"resizeHandle");n(this,"isResizing",!1);this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.setupEventListeners()}disconnectedCallback(){this.detachTimeline()}setTimeline(t){this.detachTimeline(),this.timeline=t,S(),this.timelineData=w(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>${
|
|
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 V=Object.defineProperty;var N=(h,d,b)=>d in h?V(h,d,{enumerable:!0,configurable:!0,writable:!0,value:b}):h[d]=b;var o=(h,d,b)=>N(h,typeof d!="symbol"?d+"":d,b);let d=0;function b(c){if(!c||c.length===0)return"Unknown";const a=c[0];return a.id?`#${a.id}`:a.classList&&a.classList.length>0?`.${a.classList[0]}`:a.tagName?a.tagName.toLowerCase():"element"}function M(c){const a=["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=>!a.includes(t))}function D(c,a=20){const t=window.gsap;if(!(t!=null&&t.parseEase))return[];const e=t.parseEase(c);if(!e)return[];const i=[];for(let s=0;s<=a;s++)i.push(e(s/a));return i}function A(c){const a=[];c.getChildren(!0,!0,!1).forEach((e,i)=>{if(!("targets"in e))return;const s=e,n=s.targets(),r=s.vars||{},g=M(r);let y="";if(r.id&&typeof r.id=="string")y=r.id;else{const w=b(n),T=g.slice(0,2).join(", ");y=T?`${w} (${T})`:w}const m=e.startTime(),f=e.duration();let p="none";r.ease&&(p=typeof r.ease=="string"?r.ease:"custom");let u,x;if(r.stagger&&n.length>1&&(typeof r.stagger=="number"?u=r.stagger:typeof r.stagger=="object"&&(u=r.stagger.each||0),u)){const w=f-u*(n.length-1);x=n.map((T,R)=>{const B=m+R*u;return{targetLabel:b([T]),startTime:B,endTime:B+w}})}a.push({id:`tween-${++d}`,label:y,startTime:m,endTime:m+f,duration:f,targets:b(n),properties:g,colorIndex:i%6,hasStagger:!!r.stagger,ease:p,easeSamples:D(p),staggerValue:u,staggerChildren:x})});for(let e=1;e<a.length;e++){const i=a[e-1],s=a[e],n=i.endTime-s.startTime;Math.abs(n)>.001&&(s.overlapWithPrev=Math.round(n*1e3)/1e3)}return{duration:c.duration(),tweens:a}}function H(){d=0}function k(c,a=!0){const t=Math.abs(c);return a?t.toFixed(2):t.toFixed(0)}const q=":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: 36px;--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;position:relative;z-index:1}.gtv-track-stagger{font-size:10px;font-weight:400;flex-shrink:0;position:relative;z-index:1}.gtv-track-bar:hover{filter:brightness(1.1)}.gtv-ease-curve{position:absolute;top:0;right:0;bottom:0;left:0;width:100%;height:100%;pointer-events:none;opacity:0;transition:opacity .15s}.gtv-ease-curve path{fill:var(--track-color);stroke:none}.gtv-container.show-ease-curves .gtv-ease-curve{opacity:1}.gtv-container.show-ease-curves .gtv-track-bar,.gtv-container.show-ease-curves .gtv-stagger-child-bar{background:transparent!important}.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;overflow:hidden}.gtv-stagger-child-bar .gtv-track-label{overflow:hidden;position:relative;z-index:1;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-container.show-ease-curves .gtv-overlap-region{display:none}.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)}",$=[.25,.5,1,2,4],C=40;class P extends HTMLElement{constructor(){super();o(this,"shadow");o(this,"timeline",null);o(this,"timelineData",null);o(this,"isPlaying",!1);o(this,"isLooping",!1);o(this,"speedIndex",2);o(this,"collapsed",!1);o(this,"height",200);o(this,"isDragging",!1);o(this,"manageBodyPadding",!0);o(this,"isAutofit",!1);o(this,"showEaseCurves",!1);o(this,"container");o(this,"playBtn");o(this,"loopBtn");o(this,"speedBtn");o(this,"timeDisplay");o(this,"rulerInner");o(this,"tracksScroll");o(this,"playhead");o(this,"scrubArea");o(this,"resizeHandle");o(this,"timelineSelect");o(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,H(),this.timelineData=A(t),t.eventCallback("onUpdate",()=>this.onTimelineUpdate()),this.renderTracks(),this.updatePlayhead(),this.updateTimeDisplay(),this.updatePlayState(),requestAnimationFrame(()=>this.applyAutofit())}updateTimelineSelector(){Promise.resolve().then(()=>E).then(({TimelineViewer:t})=>{const e=t.getTimelines(),i=this.timelineSelect.value;this.timelineSelect.innerHTML="",e.forEach((s,n)=>{const r=document.createElement("option");r.value=n,r.textContent=n,this.timelineSelect.appendChild(r)}),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>${q}</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,12 @@
|
|
|
28
31
|
</div>
|
|
29
32
|
|
|
30
33
|
<div class="gtv-controls-right">
|
|
34
|
+
<button class="gtv-btn" data-action="ease-curves" title="Show ease curves">
|
|
35
|
+
<svg viewBox="0 0 24 24"><path d="M3 17c0 0 3-8 9-8s9 8 9 8" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>
|
|
36
|
+
</button>
|
|
37
|
+
<button class="gtv-btn" data-action="autofit" title="Auto-fit height">
|
|
38
|
+
<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>
|
|
39
|
+
</button>
|
|
31
40
|
<button class="gtv-btn gtv-collapse-btn" data-action="collapse" title="Collapse/Expand">
|
|
32
41
|
<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"/></svg>
|
|
33
42
|
</button>
|
|
@@ -61,18 +70,40 @@
|
|
|
61
70
|
</div>
|
|
62
71
|
</div>
|
|
63
72
|
</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: ${
|
|
73
|
+
`,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;case"ease-curves":this.toggleEaseCurves();break}}),this.timelineSelect.addEventListener("change",()=>{const t=this.timelineSelect.value;t&&Promise.resolve().then(()=>E).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 s=i.closest(".gtv-track");(s==null?void 0:s.dataset.expandable)==="true"&&(t.stopPropagation(),s.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?C: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(),s=Math.max(0,Math.min(t.clientX-e.left,e.width))/e.width;this.timeline.progress(s),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 s of e)if(s<t-.001)i=s;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 s of e)if(s>t+.001){i=s;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)%$.length;const t=$[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()}toggleEaseCurves(){this.showEaseCurves=!this.showEaseCurves,this.shadow.querySelector('[data-action="ease-curves"]').classList.toggle("active",this.showEaseCurves),this.container.classList.toggle("show-ease-curves",this.showEaseCurves)}applyAutofit(){if(!this.isAutofit||this.collapsed)return;const t=this.shadow.querySelectorAll(".gtv-track");let e=0;const i=36,s=30;t.forEach(m=>{if(e+=i,m.classList.contains("expanded")){const f=m.querySelectorAll(".gtv-stagger-child");e+=f.length*s}});const n=24,r=16,g=100,y=window.innerHeight-100;this.height=Math.max(g,Math.min(C+n+e+r,y)),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"),s=this.timeDisplay.querySelector(".gtv-time-total");i.textContent=k(t),s.textContent=` / ${k(e)}`}updateActiveTracks(){if(!this.timeline||!this.timelineData)return;const t=this.timeline.time();this.tracksScroll.querySelectorAll(".gtv-track-bar").forEach((i,s)=>{const n=this.timelineData.tweens[s],r=t>=n.startTime&&t<=n.endTime,g=i.dataset.color;r?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 s=this.renderGridLines(t),n=e.map(g=>this.renderTrack(g,t)).join(""),r=this.tracksScroll.querySelector(".gtv-scrub-area");this.tracksScroll.innerHTML=s+n,this.tracksScroll.prepend(r),this.scrubArea=r}renderGridLines(t){const e=[],i=this.calculateInterval(t);for(let s=0;s<=t;s+=i){const n=s/t*100;e.push(`<div class="gtv-grid-line" style="left: ${n}%;"></div>`)}return e.join("")}renderRuler(t){const e=[],i=this.calculateInterval(t);for(let s=0;s<=t;s+=i){const n=s/t*100;e.push(`
|
|
74
|
+
<div class="gtv-ruler-marker" style="left: ${n}%;">
|
|
66
75
|
<div class="gtv-ruler-marker-line"></div>
|
|
67
|
-
<span class="gtv-ruler-marker-label">${
|
|
76
|
+
<span class="gtv-ruler-marker-label">${k(s,!1)}s</span>
|
|
68
77
|
</div>
|
|
69
|
-
`)}this.rulerInner.innerHTML=e.join("")}calculateInterval(t){return t<=1?.25:t<=3?.5:t<=10?1:t<=30?5:10}
|
|
70
|
-
<
|
|
78
|
+
`)}this.rulerInner.innerHTML=e.join("")}calculateInterval(t){return t<=1?.25:t<=3?.5:t<=10?1:t<=30?5:10}renderEaseCurve(t){return t!=null&&t.length?`
|
|
79
|
+
<svg class="gtv-ease-curve" viewBox="0 0 100 100" preserveAspectRatio="none">
|
|
80
|
+
<path d="${`M0,100 L${t.map((s,n)=>{const r=n/(t.length-1)*100,g=100-s*100;return`${r},${g}`}).join(" L")} L100,100 Z`}" />
|
|
81
|
+
</svg>
|
|
82
|
+
`:""}getEaseClipPath(t){return t!=null&&t.length?`polygon(0% 100%, ${t.map((i,s)=>{const n=s/(t.length-1)*100,r=100-i*100;return`${n}% ${r}%`}).join(", ")}, 100% 100%)`:""}renderTrack(t,e){const i=t.startTime/e*100,s=t.duration/e*100,n=t.colorIndex+1,r=this.renderEaseCurve(t.easeSamples);let g="";t.hasStagger&&t.staggerChildren&&t.staggerChildren.length>0&&(g='<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 y="";if(t.staggerChildren&&t.staggerChildren.length>0){const f=t.staggerChildren.map(p=>{const u=p.startTime/e*100,x=(p.endTime-p.startTime)/e*100;return`
|
|
83
|
+
<div class="gtv-stagger-child">
|
|
84
|
+
<div class="gtv-stagger-child-bar"
|
|
85
|
+
style="left: ${u}%; width: ${x}%; background: var(--gtv-track-${n}); --track-color: var(--gtv-track-${n});">
|
|
86
|
+
${r}
|
|
87
|
+
<span class="gtv-track-label">${p.targetLabel}</span>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
`}).join("");y=`<div class="gtv-stagger-children" data-for="${t.id}">${f}</div>`}let m="";if(t.overlapWithPrev!==void 0){const f=t.overlapWithPrev>0,p=Math.abs(t.overlapWithPrev)/e*100,u=f?`-${k(t.overlapWithPrev)}s`:`+${k(Math.abs(t.overlapWithPrev))}s`,x=this.getEaseClipPath(t.easeSamples);f?m=`
|
|
91
|
+
<div class="gtv-overlap-region" style="left: ${i}%; width: ${p}%; --ease-clip: ${x};"></div>
|
|
92
|
+
<span class="gtv-offset-badge gtv-offset-overlap" style="left: ${i}%;">${u}</span>
|
|
93
|
+
`:m=`
|
|
94
|
+
<div class="gtv-gap-connector" style="left: ${i-p}%; width: ${p}%;"></div>
|
|
95
|
+
<span class="gtv-offset-badge gtv-offset-gap" style="left: ${i}%;">${u}</span>
|
|
96
|
+
`}return`
|
|
97
|
+
<div class="gtv-track" data-expandable="${t.hasStagger&&t.staggerChildren?"true":"false"}">
|
|
98
|
+
${m}
|
|
71
99
|
<div class="gtv-track-bar"
|
|
72
|
-
data-color="${
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
${
|
|
100
|
+
data-color="${n}"
|
|
101
|
+
data-tween-id="${t.id}"
|
|
102
|
+
style="left: ${i}%; width: ${s}%; background: var(--gtv-track-${n}); --track-color: var(--gtv-track-${n});">
|
|
103
|
+
${r}
|
|
104
|
+
<span class="gtv-track-label">${t.label}</span>
|
|
105
|
+
${g}
|
|
76
106
|
</div>
|
|
107
|
+
${y}
|
|
77
108
|
</div>
|
|
78
|
-
`}}customElements.define("gsap-timeline-viewer",
|
|
109
|
+
`}}customElements.define("gsap-timeline-viewer",P);const v=new Map;let l=null,z=!0,I=0,L=null;function j(){const c=window.gsap;!c||L||(L=c.timeline.bind(c),c.timeline=function(a){const t=L(a);if(z){let e;a!=null&&a.id&&typeof a.id=="string"?e=a.id:e=`Timeline ${++I}`,v.has(e)||(v.set(e,t),l&&(l.htmlElement.updateTimelineSelector(),v.size===1&&l.select(e)))}return t})}class S{constructor(a={}){o(this,"element");o(this,"currentTimelineName",null);this.element=document.createElement("gsap-timeline-viewer"),a.height&&this.element.style.setProperty("--viewer-height",`${a.height}px`)}static create(a={}){return l||(z=a.autoDetect!==!1,z&&j(),l=new S(a),document.body.appendChild(l.element),setTimeout(()=>{if(l.element.updateTimelineSelector(),a.defaultTimeline&&v.has(a.defaultTimeline))l.select(a.defaultTimeline);else if(v.size>0){const t=v.keys().next().value;t&&l.select(t)}},0),l)}static register(a,t){v.set(a,t),l&&(l.element.updateTimelineSelector(),v.size===1&&l.select(a))}static unregister(a){v.delete(a),l&&l.element.updateTimelineSelector()}static getTimelines(){return v}static getInstance(){return l}select(a){const t=v.get(a);t&&(this.currentTimelineName=a,this.element.setTimeline(t),this.element.setSelectedTimeline(a))}getCurrentTimelineName(){return this.currentTimelineName}destroy(){this.element.remove(),l=null}get htmlElement(){return this.element}}const E=Object.freeze(Object.defineProperty({__proto__:null,TimelineViewer:S,TimelineViewerElement:P},Symbol.toStringTag,{value:"Module"}));h.TimelineViewer=S,h.TimelineViewerElement=P,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,9 @@ export declare class TimelineViewerElement extends HTMLElement {
|
|
|
23
55
|
private collapsed;
|
|
24
56
|
private height;
|
|
25
57
|
private isDragging;
|
|
58
|
+
private manageBodyPadding;
|
|
59
|
+
private isAutofit;
|
|
60
|
+
private showEaseCurves;
|
|
26
61
|
private container;
|
|
27
62
|
private playBtn;
|
|
28
63
|
private loopBtn;
|
|
@@ -33,11 +68,14 @@ export declare class TimelineViewerElement extends HTMLElement {
|
|
|
33
68
|
private playhead;
|
|
34
69
|
private scrubArea;
|
|
35
70
|
private resizeHandle;
|
|
71
|
+
private timelineSelect;
|
|
36
72
|
private isResizing;
|
|
37
73
|
constructor();
|
|
38
74
|
connectedCallback(): void;
|
|
39
75
|
disconnectedCallback(): void;
|
|
40
76
|
setTimeline(timeline: gsap.core.Timeline): void;
|
|
77
|
+
updateTimelineSelector(): void;
|
|
78
|
+
setSelectedTimeline(name: string): void;
|
|
41
79
|
private detachTimeline;
|
|
42
80
|
private render;
|
|
43
81
|
private setupEventListeners;
|
|
@@ -47,6 +85,8 @@ export declare class TimelineViewerElement extends HTMLElement {
|
|
|
47
85
|
private startResize;
|
|
48
86
|
private onResize;
|
|
49
87
|
private endResize;
|
|
88
|
+
private updateBodyPadding;
|
|
89
|
+
private clearBodyPadding;
|
|
50
90
|
private scrubToPosition;
|
|
51
91
|
private togglePlay;
|
|
52
92
|
private skipToStart;
|
|
@@ -57,14 +97,20 @@ export declare class TimelineViewerElement extends HTMLElement {
|
|
|
57
97
|
private toggleLoop;
|
|
58
98
|
private cycleSpeed;
|
|
59
99
|
private toggleCollapse;
|
|
100
|
+
private toggleAutofit;
|
|
101
|
+
private toggleEaseCurves;
|
|
102
|
+
private applyAutofit;
|
|
60
103
|
private updatePlayState;
|
|
61
104
|
private onTimelineUpdate;
|
|
62
105
|
private updatePlayhead;
|
|
63
106
|
private updateTimeDisplay;
|
|
64
107
|
private updateActiveTracks;
|
|
65
108
|
private renderTracks;
|
|
109
|
+
private renderGridLines;
|
|
66
110
|
private renderRuler;
|
|
67
111
|
private calculateInterval;
|
|
112
|
+
private renderEaseCurve;
|
|
113
|
+
private getEaseClipPath;
|
|
68
114
|
private renderTrack;
|
|
69
115
|
}
|
|
70
116
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gsap-timeline-viewer",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
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",
|
|
@@ -27,7 +27,13 @@
|
|
|
27
27
|
"animation",
|
|
28
28
|
"devtools",
|
|
29
29
|
"viewer",
|
|
30
|
-
"debug"
|
|
30
|
+
"debug",
|
|
31
|
+
"greensock",
|
|
32
|
+
"inspector",
|
|
33
|
+
"visualization",
|
|
34
|
+
"easing",
|
|
35
|
+
"tween",
|
|
36
|
+
"scrubber"
|
|
31
37
|
],
|
|
32
38
|
"author": "reboiedo",
|
|
33
39
|
"license": "MIT",
|