@algorisys/tinyfly 0.70.1 → 0.70.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -205,7 +205,7 @@ GSAP-shaped functions at the top level. Teaching embeds are included: add
|
|
|
205
205
|
itself.
|
|
206
206
|
|
|
207
207
|
```html
|
|
208
|
-
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.70.
|
|
208
|
+
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.70.2/cdn/tinyfly.iife.js"></script>
|
|
209
209
|
<script>
|
|
210
210
|
tinyfly.to('.box', { x: 200, rotate: 90, duration: 1, ease: 'power2.out' })
|
|
211
211
|
|
|
@@ -227,7 +227,7 @@ itself.
|
|
|
227
227
|
| `cdn/tinyfly-player.iife.js` | Player only (~17 KB gzipped), for playing editor exports |
|
|
228
228
|
| `cdn/tinyfly-embed.iife.js` | Only teaching figures (~19 KB gzipped): player, step controls, auto-mount |
|
|
229
229
|
|
|
230
|
-
Replace `@v0.70.
|
|
230
|
+
Replace `@v0.70.2` with the version you want. **Pin a version in production**:
|
|
231
231
|
a tag's files never change, and each release's `cdn/README.md` lists an SRI hash
|
|
232
232
|
for `integrity=`. `@main` follows the latest release, which jsDelivr caches for up
|
|
233
233
|
to a day. Loading more than one bundle is safe: they add to the same `tinyfly`
|
|
@@ -241,7 +241,7 @@ A teaching figure needs no code at all:
|
|
|
241
241
|
<script type="application/json" data-tinyfly-timeline>{ …timeline JSON with markers… }</script>
|
|
242
242
|
<figcaption>Appending to a full slice</figcaption>
|
|
243
243
|
</figure>
|
|
244
|
-
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.70.
|
|
244
|
+
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.70.2/cdn/tinyfly.iife.js" data-tinyfly-auto></script>
|
|
245
245
|
```
|
|
246
246
|
|
|
247
247
|
See [Teaching Animations](docs/teaching.md).
|
|
@@ -340,7 +340,7 @@ Without a build step, the player bundle puts the same functions on a `tinyfly` g
|
|
|
340
340
|
<div data-tinyfly="box" style="width: 60px; height: 60px; background: #4a9eff;"></div>
|
|
341
341
|
</div>
|
|
342
342
|
|
|
343
|
-
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.70.
|
|
343
|
+
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.70.2/cdn/tinyfly-player.iife.js"></script>
|
|
344
344
|
<script>
|
|
345
345
|
tinyfly.play('#animation', './animation.json', { loop: -1 })
|
|
346
346
|
</script>
|
|
@@ -449,7 +449,7 @@ Or skip the code entirely with declarative embeds (see [Teaching Animations](doc
|
|
|
449
449
|
<svg viewBox="0 0 720 200">…</svg>
|
|
450
450
|
<script type="application/json" data-tinyfly-timeline>{ …timeline JSON… }</script>
|
|
451
451
|
</figure>
|
|
452
|
-
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.70.
|
|
452
|
+
<script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.70.2/cdn/tinyfly-embed.iife.js" data-tinyfly-auto></script>
|
|
453
453
|
```
|
|
454
454
|
|
|
455
455
|
### Audio / Video Sync
|
|
@@ -692,6 +692,18 @@ npm run e2e
|
|
|
692
692
|
npm run build
|
|
693
693
|
```
|
|
694
694
|
|
|
695
|
+
### Publishing to npm
|
|
696
|
+
|
|
697
|
+
```bash
|
|
698
|
+
npm login # once
|
|
699
|
+
npm run release:npm # npm publish
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
`release:npm` runs `npm publish`. npm then runs the `prepublishOnly` script,
|
|
703
|
+
which runs the unit tests and `npm run build:libs`, so a failing test stops the
|
|
704
|
+
publish. npm will not publish the same version twice, so bump `version` in
|
|
705
|
+
`package.json` (and add a note under `release-notes/`) before you publish.
|
|
706
|
+
|
|
695
707
|
### Cross-browser checks
|
|
696
708
|
|
|
697
709
|
`npm run e2e` runs tinyfly in real Chromium, Firefox and WebKit and measures the
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
.tf-fullscreen > svg, .tf-fullscreen > canvas { grid-column: 1; grid-row: 1 / span 12; height: calc(100vh - 24px) !important; height: calc(100dvh - 24px) !important; }
|
|
48
48
|
.tf-fullscreen > :not(svg):not(canvas) { grid-column: 2; }
|
|
49
49
|
}
|
|
50
|
-
`;let _o=0;function Io(i){if(i.getElementById(zn))return;const t=i.createElement("style");t.id=zn,t.textContent=Co,i.head.appendChild(t)}function Hn(i,t,e={}){const n=t.ownerDocument;Io(n);const s={...jn,...e.labels},r=e.speeds??[.5,1,2],o=()=>i.markers.length>0,a=()=>i.markers.some(x=>x.label!==void 0||i.caption(x.id)!==void 0),c=n.createElement("div");c.className="tf-ctl";const l=n.createElement("div");l.className="tf-ctl-bar",l.setAttribute("role","group");const h=(x,R,$,B="")=>{const N=n.createElement("button");return N.type="button",N.className=`tf-ctl-btn ${B}`.trim(),N.setAttribute("aria-label",x),N.title=x,N.textContent=R,N.addEventListener("click",$),N},f=h(s.restart,"⟲",()=>{i.pause(),i.seek(0)}),u=h(s.prev,"
|
|
50
|
+
`;let _o=0;function Io(i){if(i.getElementById(zn))return;const t=i.createElement("style");t.id=zn,t.textContent=Co,i.head.appendChild(t)}function Hn(i,t,e={}){const n=t.ownerDocument;Io(n);const s={...jn,...e.labels},r=e.speeds??[.5,1,2],o=()=>i.markers.length>0,a=()=>i.markers.some(x=>x.label!==void 0||i.caption(x.id)!==void 0),c=n.createElement("div");c.className="tf-ctl";const l=n.createElement("div");l.className="tf-ctl-bar",l.setAttribute("role","group");const h=(x,R,$,B="")=>{const N=n.createElement("button");return N.type="button",N.className=`tf-ctl-btn ${B}`.trim(),N.setAttribute("aria-label",x),N.title=x,N.textContent=R,N.addEventListener("click",$),N},f=h(s.restart,"⟲",()=>{i.pause(),i.seek(0)}),u=h(s.prev,"|◀",()=>i.prev()),d=h(s.play,"▶",()=>i.isPlaying?i.pause():p(),"tf-ctl-primary"),m=h(s.next,"▶|",()=>i.next()),p=()=>{i.currentTime>=i.duration-.5&&i.seek(0),i.play()},y=n.createElement("input");y.type="range",y.className="tf-ctl-scrub",y.min="0",y.max="1000",y.step="1",y.setAttribute("aria-label",s.scrub),y.addEventListener("input",()=>{i.pause(),i.seek(Number(y.value)/1e3*i.duration)});const b=n.createElement("span");b.className="tf-ctl-step";const w=n.createElement("select");w.className="tf-ctl-speed",w.setAttribute("aria-label",s.speed);for(const x of r){const R=n.createElement("option");R.value=String(x),R.textContent=`${x}×`,x===1&&(R.selected=!0),w.appendChild(R)}w.addEventListener("change",()=>i.setSpeed(Number(w.value))),l.append(f,u,d,m,y,b),r.length>0&&l.append(w),c.append(l);const v=e.fullscreen?$o(t,n,s):void 0;v&&l.append(v.button);const k=n.createElement("p");k.className="tf-ctl-caption",k.setAttribute("aria-live","polite"),e.captions!==!1&&c.append(k);const T=n.createElement("div");T.className="tf-ctl-question",T.hidden=!0;const S=n.createElement("span"),A=h(s.reveal,s.reveal,()=>i.play(),"tf-ctl-primary");T.append(S,A),c.append(T);const I=Ro(i,n,s.scenario,e.scenarioControl??"buttons");I&&c.append(I.element);const O=e.mount;O?O.appendChild(c):t.insertAdjacentElement("afterend",c);const E=()=>{const x=i.isPlaying;d.textContent=x?"❚❚":"▶",d.setAttribute("aria-label",x?s.pause:s.play),d.title=x?s.pause:s.play;const R=i.duration;n.activeElement!==y&&(y.value=String(R>0?Math.round(i.currentTime/R*1e3):0));const $=i.markers;if(u.hidden=m.hidden=b.hidden=$.length===0,$.length>0){const B=i.currentMarker,N=B?$.indexOf(B)+1:0;b.textContent=s.stepFormat.replace("{index}",String(N)).replace("{total}",String($.length)),b.setAttribute("aria-label",`${s.step} ${N} ${s.of} ${$.length}`),u.disabled=i.currentTime<=.5,m.disabled=i.currentTime>=R-.5;const L=i.caption()??"";k.textContent!==L&&(k.textContent=L),k.hidden=!a();const D=!x&&B?.question!==void 0&&Math.abs(i.currentTime-B.time)<1;T.hidden=!D,D&&S.textContent!==B.question&&(S.textContent=B.question)}else T.hidden=!0,k.hidden=!0;I?.update()},M=i.subscribe(E);E();const C=e.keyboardScope??t;!C.hasAttribute("tabindex")&&C.tabIndex<0&&(C.tabIndex=0);const P=new WeakSet,_=x=>{if(P.has(x)||(P.add(x),x.defaultPrevented||x.altKey||x.ctrlKey||x.metaKey))return;const R=x.target;if(!(R.tagName==="INPUT"||R.tagName==="SELECT")&&!(x.key===" "&&R.tagName==="BUTTON"))switch(x.key){case" ":x.preventDefault(),i.isPlaying?i.pause():p();break;case"ArrowRight":if(!o())return;x.preventDefault(),i.next();break;case"ArrowLeft":if(!o())return;x.preventDefault(),i.prev();break;case"Home":x.preventDefault(),i.pause(),i.seek(0);break;case"f":case"F":if(!v)return;x.preventDefault(),v.active?v.exit():v.enter();break}};return C.addEventListener("keydown",_),c.addEventListener("keydown",_),{element:c,fullscreen:v&&{get active(){return v.active},enter:v.enter,exit:v.exit},destroy(){v?.destroy(),M(),C.removeEventListener("keydown",_),c.removeEventListener("keydown",_),c.remove()}}}function Ro(i,t,e,n){const s=i.scenarios;if(s.length<2)return;if(n==="slider"){const h=t.createElement("div");h.className="tf-ctl-choice-slider";const f=t.createElement("span");f.textContent=e,f.setAttribute("aria-hidden","true");const u=t.createElement("input");u.type="range",u.min="0",u.max=String(s.length-1),u.step="1",u.setAttribute("aria-label",e);const d=t.createElement("output");return d.setAttribute("aria-hidden","true"),u.addEventListener("input",()=>{const p=s[Number(u.value)];p&&i.setScenario(p.id)}),h.append(f,u,d),{element:h,update:()=>{const p=Math.max(0,s.findIndex(b=>b.id===i.scenario));t.activeElement!==u&&(u.value=String(p));const y=s[p].label;d.textContent!==y&&(d.textContent=y),u.setAttribute("aria-valuetext",y)}}}const r=t.createElement("fieldset");r.className="tf-ctl-choices";const o=t.createElement("legend");o.textContent=e,r.append(o);const a=`tf-ctl-scenario-${++_o}`,c=s.map(h=>{const f=t.createElement("label");f.className="tf-ctl-choice";const u=t.createElement("input");u.type="radio",u.name=a,u.value=h.id,u.addEventListener("change",()=>{u.checked&&i.setScenario(h.id)});const d=t.createElement("span");return d.textContent=h.label,f.append(u,d),r.append(f),u});return{element:r,update:()=>{for(const h of c){const f=h.value===i.scenario;h.checked!==f&&(h.checked=f)}}}}const Lo='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',Fo='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function $o(i,t,e){const n=t,s=i,r=t.createElement("button");r.type="button",r.className="tf-ctl-btn tf-ctl-fullscreen";let o,a="";const c=()=>{const p=o!==void 0;r.innerHTML=p?Fo:Lo;const y=p?e.exitFullscreen:e.fullscreen;r.setAttribute("aria-label",y),r.title=y,r.setAttribute("aria-pressed",String(p)),i.classList.toggle("tf-fullscreen",p),i.classList.toggle("tf-fullscreen-overlay",o==="overlay")},l=()=>n.fullscreenElement??n.webkitFullscreenElement??null,h=()=>{l()===i?o="native":o==="native"&&(o=void 0),c()},f=p=>{p.key==="Escape"&&m()},u=()=>{o="overlay",a=t.documentElement.style.overflow,t.documentElement.style.overflow="hidden",t.addEventListener("keydown",f),c()};async function d(){if(o)return;const p=s.requestFullscreen?.bind(s)??s.webkitRequestFullscreen?.bind(s),y=n.fullscreenEnabled??n.webkitFullscreenEnabled??!1;if(p&&y)try{if(await p(),l()===i){o="native",c();return}}catch{}u()}async function m(){if(o==="overlay")t.removeEventListener("keydown",f),t.documentElement.style.overflow=a,o=void 0,c();else if(o==="native"){o=void 0,c();const p=n.exitFullscreen?.bind(n)??n.webkitExitFullscreen?.bind(n);l()===i&&p&&await p()}}return r.addEventListener("click",()=>{o?m():d()}),t.addEventListener("fullscreenchange",h),t.addEventListener("webkitfullscreenchange",h),c(),{button:r,get active(){return o!==void 0},enter:d,exit:m,destroy(){m(),t.removeEventListener("fullscreenchange",h),t.removeEventListener("webkitfullscreenchange",h),r.remove()}}}const Gn="tinyfly-choices-style",Do=`
|
|
51
51
|
[data-tinyfly-choose] { cursor: pointer; }
|
|
52
52
|
[data-tinyfly-choose]:focus-visible { outline: 2px solid var(--tf-ctl-accent, #c2410c); outline-offset: 2px; }
|
|
53
53
|
`;function Oo(i){if(i.getElementById(Gn))return;const t=i.createElement("style");t.id=Gn,t.textContent=Do,i.head.appendChild(t)}function Kn(i,t){const e=Array.from(t.querySelectorAll("[data-tinyfly-choose]"));if(e.length===0)return()=>{};Oo(t.ownerDocument);const n=[],s=[];for(const a of e){const c=a.getAttribute("data-tinyfly-choose")??"",l=[],h=(m,p)=>{a.hasAttribute(m)||(a.setAttribute(m,p),l.push(m))};h("role","button"),h("tabindex","0");const f=i.scenarios.find(m=>m.id===c)?.label;f!==void 0&&h("aria-label",f),a.setAttribute("aria-pressed","false"),l.push("aria-pressed"),n.push({element:a,attributes:l});const u=()=>i.setScenario(c),d=m=>{const p=m.key;p!=="Enter"&&p!==" "||(m.preventDefault(),u())};a.addEventListener("click",u),a.addEventListener("keydown",d),s.push(()=>{a.removeEventListener("click",u),a.removeEventListener("keydown",d)})}const r=()=>{for(const{element:a}of n)a.setAttribute("aria-pressed",String(a.getAttribute("data-tinyfly-choose")===i.scenario))},o=i.subscribe(r);return r(),()=>{o();for(const a of s)a();for(const{element:a,attributes:c}of n)for(const l of c)a.removeAttribute(l)}}const Kt=new WeakMap,Ue=new WeakMap;let No=0;function Ct(i,t,e){if(i)try{return JSON.parse(i)}catch(n){console.warn(`tinyfly: invalid ${t} JSON on`,e,n);return}}async function Qn(i,t={}){const e=Kt.get(i);if(e)return e;const n=Array.from(i.querySelectorAll("script[data-tinyfly-timeline]")),s=n[0],r=i.getAttribute("data-src"),o=qo(i.getAttribute("data-markers")),a=n.length>1||s?.hasAttribute("data-scenario")?Bo(n,o,i):void 0;if(a&&a.length===0)return;let c=s&&!a?Ct(s.textContent,"timeline",i):void 0;if(!c&&r&&o){const d=await fetch(r);d.ok&&(c=await d.json())}if(c&&o&&(c=Zn(c,o)),!c&&!r&&!a){console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)',i);return}const l=Ct(i.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",i),h={playWhenVisible:!0,...t.player,...l&&{captions:l},...Ct(i.getAttribute("data-options"),"data-options",i)};Yo(i);const f=new Gt(i,h),u={element:i,player:f};if(Kt.set(i,u),i.setAttribute("data-tinyfly-mounted",""),a){const d=i.getAttribute("data-scenario")??void 0;await f.loadScenarios(a,{initial:a.some(m=>m.id===d)?d:void 0}),Ue.set(i,Kn(f,i))}else await f.load(c??r);if(i.getAttribute("data-controls")!=="false"){const d=Ct(i.getAttribute("data-labels"),"data-labels",i),m=i.querySelector("figcaption"),p=i.getAttribute("data-scenario-legend"),y=i.getAttribute("data-scenario-control");u.controls=Hn(f,i,{...t.controls,...i.getAttribute("data-fullscreen")==="true"?{fullscreen:!0}:{},...y==="slider"||y==="buttons"?{scenarioControl:y}:{},labels:{...t.controls?.labels,...d,...p?{scenario:p}:{}},mount:void 0}),m?i.insertBefore(u.controls.element,m):i.appendChild(u.controls.element)}return u}function Bo(i,t,e){const n=[];return i.forEach((s,r)=>{const o=Ct(s.textContent,"timeline",e);if(!o)return;const a=s.getAttribute("data-scenario")||`scenario-${r+1}`;if(n.some(l=>l.id===a)){console.warn(`tinyfly: scenario id "${a}" is used more than once; the later one is skipped`,e);return}const c=s.getAttribute("data-scenario-label")??void 0;n.push({id:a,label:c,timeline:t?Zn(o,t):o})}),n}function Zn(i,t){return i.config.markers?.length?i:{...i,config:{...i.config,markers:t.map((e,n)=>({id:`step-${n+1}`,time:e}))}}}function qo(i){if(!i)return;const t=i.split(/[\s,]+/).filter(Boolean).map(Number).filter(e=>Number.isFinite(e)&&e>=0).sort((e,n)=>e-n);return t.length>0?t:void 0}async function Jn(i=document,t={}){const e=Array.from(i.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(e.map(s=>Qn(s,t)))).filter(s=>s!==void 0)}function Xo(i){const t=Kt.get(i);t&&(Ue.get(i)?.(),Ue.delete(i),t.controls?.destroy(),t.player.destroy(),Kt.delete(i),i.removeAttribute("data-tinyfly-mounted"))}function Yo(i){const t=i.querySelector("svg");if(!t||t.hasAttribute("role")||t.hasAttribute("aria-hidden"))return;const e=i.getAttribute("data-alt"),n=i.querySelector("figcaption");t.setAttribute("role","img"),e?t.setAttribute("aria-label",e):n&&(n.id||=`tinyfly-caption-${++No}`,t.setAttribute("aria-labelledby",n.id))}function Vo(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const t=()=>{Jn()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}class ts{container;containerA;containerB;adapterA;adapterB;timelineA=null;timelineB=null;symbolDefs=new Map;nestedByAdapter=new Map;sequence=null;options;_currentSceneIndex=0;_state="idle";_isPlaying=!1;_isDestroyed=!1;loopIteration=0;animationFrameId;lastTime;transitionTimer;constructor(t,e={}){if(typeof t=="string"){const n=document.querySelector(t);if(!n)throw new Error(`Container not found: ${t}`);this.container=n}else this.container=t;this.options=e,this.container.style.position="relative",this.container.style.overflow="hidden",this.containerA=this.createSceneContainer(),this.containerB=this.createSceneContainer(),this.container.appendChild(this.containerA),this.container.appendChild(this.containerB),this.containerB.style.visibility="hidden",this.adapterA=new et,this.adapterB=new et}async load(t){let e;if(typeof t=="string"){const n=await fetch(t);if(!n.ok)throw new Error(`Failed to load sequence: ${n.statusText}`);e=await n.json()}else e=t;this.sequence=e,this.symbolDefs.clear();for(const n of e.symbols??[])n.timeline?.tracks?.length&&this.symbolDefs.set(n.id,n.timeline);this.container.style.width=`${e.canvas.width}px`,this.container.style.height=`${e.canvas.height}px`,e.scenes.length>0&&(this.renderScene(e.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(e.scenes[0])),this.options.autoplay&&this.play()}play(){if(!(!this.sequence||this._isDestroyed)&&this.sequence.scenes.length!==0){if(this._isPlaying=!0,this._state==="idle"){if(this._state="playing-scene",this._currentSceneIndex=0,this.timelineA)this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play();else{this.onSceneComplete();return}this.options.onSceneChange?.(0)}else this._state==="playing-scene"&&this.timelineA&&this.timelineA.play();this.startAnimationLoop()}}pause(){this._isPlaying&&(this._isPlaying=!1,this.timelineA&&this.timelineA.pause(),this.timelineB&&this.timelineB.pause(),this.stopAnimationLoop())}stop(){if(this._isPlaying=!1,this._state="idle",this._currentSceneIndex=0,this.loopIteration=0,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.stopAnimationLoop(),this.sequence&&this.sequence.scenes.length>0&&(this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this.renderScene(this.sequence.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(this.sequence.scenes[0]),this.timelineA)){const t=this.timelineA.getStateAtTime(0);this.adapterA.applyState(t),this.applyNested(this.adapterA,0)}}goToScene(t){if(!this.sequence||t<0||t>=this.sequence.scenes.length)return;const e=this._isPlaying;this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this._currentSceneIndex=t,this._state=e?"playing-scene":"idle",this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB);const n=this.sequence.scenes[t];if(this.renderScene(n,this.containerA,this.adapterA),this.timelineA=this.createTimeline(n),this.options.onSceneChange?.(t),e)this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play(),this.startAnimationLoop()):this.onSceneComplete();else if(this.timelineA){const s=this.timelineA.getStateAtTime(0);this.adapterA.applyState(s),this.applyNested(this.adapterA,0)}}destroy(){this._isDestroyed=!0,this._isPlaying=!1,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.adapterA.clearTargets(),this.adapterB.clearTargets();for(const t of this.nestedByAdapter.values())for(const e of t)e.adapter.clearTargets();this.nestedByAdapter.clear(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.timelineA=null,this.timelineB=null,this.containerA.parentNode&&this.containerA.remove(),this.containerB.parentNode&&this.containerB.remove(),this.sequence=null}get currentSceneIndex(){return this._currentSceneIndex}get sceneCount(){return this.sequence?.scenes.length??0}get isPlaying(){return this._isPlaying}get state(){return this._state}createSceneContainer(){const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="100%",t.style.height="100%",t}renderScene(t,e,n){e.innerHTML="",n.clearTargets();const s=document.createElement("div");s.style.cssText="position:absolute;inset:0;transform-origin:center center",s.setAttribute("data-tinyfly","Camera"),e.appendChild(s),n.registerTarget("Camera",s);for(const r of t.elements){if(!r.html)continue;const o=document.createElement("div");o.innerHTML=r.html.trim();const a=o.firstElementChild;if(a){s.appendChild(a);const c=a.getAttribute("data-tinyfly");c&&n.registerTarget(c,a)}}this.setupNested(s,n)}setupNested(t,e){const n=[];t.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const r=s.getAttribute("data-tinyfly-symbol");if(!r)return;const o=this.symbolDefs.get(r);if(!o)return;const a=new et;s.querySelectorAll("[data-tinyfly]").forEach(c=>{const l=c.getAttribute("data-tinyfly");l&&a.registerTarget(l,c)}),n.push({adapter:a,timeline:ct(o)})}),n.length?this.nestedByAdapter.set(e,n):this.nestedByAdapter.delete(e)}applyNested(t,e){const n=this.nestedByAdapter.get(t);if(n)for(const s of n){const r=s.timeline.duration;s.adapter.applyState(s.timeline.getStateAtTime(r>0?e%r:e))}}clearContainer(t){t.innerHTML=""}createTimeline(t){return t.timeline?ct(t.timeline):null}onSceneComplete(){if(this._isDestroyed||!this.sequence)return;const t=this._currentSceneIndex+1;if(t>=this.sequence.scenes.length){const e=this.options.loop??this.sequence.loop??0;e===-1||e>0&&this.loopIteration<e-1?(this.loopIteration++,this.beginTransitionTo(0)):(this._isPlaying=!1,this._state="idle",this.stopAnimationLoop(),this.options.onComplete?.())}else this.beginTransitionTo(t)}beginTransitionTo(t){if(!this.sequence||this._isDestroyed)return;const e=this.sequence.scenes[t],n=e.transition;if(n.type==="none"||n.duration<=0){this.switchToScene(t);return}this._state="transitioning",this.containerB.style.visibility="visible",this.renderScene(e,this.containerB,this.adapterB),this.timelineB=this.createTimeline(e),this.timelineB&&this.timelineB.play(),this.applyTransition(n.type,n.duration),this.transitionTimer=window.setTimeout(()=>{this.finishTransition(t)},n.duration)}applyTransition(t,e){const n=`${e}ms`,s="ease-in-out";switch(this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),t){case"fade":this.containerB.style.opacity="0";break;case"slide-left":this.containerB.style.transform="translateX(100%)";break;case"slide-right":this.containerB.style.transform="translateX(-100%)";break;case"slide-up":this.containerB.style.transform="translateY(100%)";break;case"slide-down":this.containerB.style.transform="translateY(-100%)";break}switch(this.containerB.offsetHeight,this.containerA.style.transition=`opacity ${n} ${s}, transform ${n} ${s}`,this.containerB.style.transition=`opacity ${n} ${s}, transform ${n} ${s}`,t){case"fade":this.containerA.style.opacity="0",this.containerB.style.opacity="1";break;case"slide-left":this.containerA.style.transform="translateX(-100%)",this.containerB.style.transform="translateX(0)";break;case"slide-right":this.containerA.style.transform="translateX(100%)",this.containerB.style.transform="translateX(0)";break;case"slide-up":this.containerA.style.transform="translateY(-100%)",this.containerB.style.transform="translateY(0)";break;case"slide-down":this.containerA.style.transform="translateY(100%)",this.containerB.style.transform="translateY(0)";break}}resetTransitionStyles(t){t.style.transition="",t.style.opacity="1",t.style.transform=""}finishTransition(t){this.transitionTimer=void 0,this.timelineA&&(this.timelineA.stop(),this.timelineA=null),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.containerA;this.containerA=this.containerB,this.containerB=e;const n=this.adapterA;this.adapterA=this.adapterB,this.adapterB=n,this.timelineA=this.timelineB,this.timelineB=null,this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.playbackState!=="playing"&&this.timelineA.play()):this.onSceneComplete()}switchToScene(t){if(!this.sequence||this._isDestroyed)return;this.timelineA&&this.timelineA.stop(),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.sequence.scenes[t];this.renderScene(e,this.containerA,this.adapterA),this.timelineA=this.createTimeline(e),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play()):this.onSceneComplete()}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this._isDestroyed||!this._isPlaying)return;const n=e-(this.lastTime??e);if(this.lastTime=e,this.timelineA&&this.timelineA.playbackState==="playing"){this.timelineA.tick(n);const s=this.timelineA.getStateAtTime(this.timelineA.currentTime);this.adapterA.applyState(s),this.applyNested(this.adapterA,this.timelineA.currentTime)}if(this._state==="transitioning"&&this.timelineB&&this.timelineB.playbackState==="playing"){this.timelineB.tick(n);const s=this.timelineB.getStateAtTime(this.timelineB.currentTime);this.adapterB.applyState(s),this.applyNested(this.adapterB,this.timelineB.currentTime)}this._isPlaying?this.animationFrameId=requestAnimationFrame(t):this.animationFrameId=void 0};this.animationFrameId=requestAnimationFrame(t)}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}}async function Wo(i,t,e={}){const n=new ts(i,{...e,autoplay:!0});return await n.load(t),n}const Uo={type:"none",duration:0};function jo(i){const{timeline:t}=i,e=new et;for(const[l,h]of Object.entries(i.targets)){const f=typeof h=="string"?document.querySelector(h):h;if(!f)throw new Error(`quickPlay: no element found for target "${l}" (${String(h)})`);e.registerTarget(l,f)}t.onUpdate=l=>{e.applyState(l),i.onUpdate?.(l)},i.onComplete&&(t.onComplete=i.onComplete);let n=null,s=null,r=!1;const o=l=>{if(r)return;const h=s===null?0:l-s;s=l,h>0&&t.tick(h),n=requestAnimationFrame(o)},a=()=>{n!==null||r||(s=null,n=requestAnimationFrame(o))},c=()=>{n!==null&&cancelAnimationFrame(n),n=null,s=null};return e.applyState(t.getStateAtTime(t.currentTime)),i.autoplay!==!1&&(t.play(),a()),{timeline:t,adapter:e,play(){t.play(),a()},pause(){t.pause(),c()},restart(){t.stop(),t.play(),a()},seek(l){t.seek(l*1e3),e.applyState(t.getStateAtTime(t.currentTime))},destroy(){r=!0,c(),t.stop(),e.clearTargets()}}}const zo={timeline:vr,to(i,t,e){const n=new tt(e);return n.to(i,t),n},from(i,t,e){const n=new tt(e);return n.from(i,t),n},fromTo(i,t,e,n){const s=new tt(n);return s.fromTo(i,t,e),s},set(i,t,e){const n=new tt(e);return n.set(i,t),n}},Ho=q.to,Go=q.from,Ko=q.fromTo,Qo=q.set,Zo=q.timeline,Jo=q.ticker,ta=q.splitText,ea=q.context,ia=q.matchMedia,na=q.quickTo,sa=q.imageSequence,ra=q.pageTransition;Vo(),g.Clock=ns,g.CompatTimeline=tt,g.CustomBounce=Dn,g.CustomEase=$n,g.CustomWiggle=On,g.DEFAULT_BAKE_INTERVAL_MS=fe,g.DEFAULT_INERTIA_FRICTION=ie,g.DEFAULT_LABELS=jn,g.DEFAULT_SPRING=Y,g.DEFAULT_TRANSITION=Uo,g.Draggable=_e,g.FORMAT_VERSION=mt,g.INERTIA_MAX_DURATION_MS=Ke,g.InertiaTrackPlayer=Ri,g.LiveTimeline=z,g.MORPH_SAMPLES=As,g.ManualClock=is,g.MediaSync=We,g.Observer=fn,g.SPRING_MAX_DURATION_MS=ee,g.SPRING_PRESETS=$t,g.SPRING_STEP_MS=it,g.ScrollAnimator=Pn,g.ScrollDriver=Et,g.ScrollMarkers=Cn,g.ScrollPin=Mn,g.SmoothScroll=Xe,g.SpringSampler=yt,g.SpringTrackPlayer=Ii,g.Stage=on,g.Timeline=be,g.TinyflyPlayer=Gt,g.TinyflySequencer=ts,g.TrackPlayer=Yt,g.ValueResolver=Hs,g.VisibilityDriver=Sn,g.backOut=oi,g.bakeEasing=me,g.bakeInertiaTrack=pe,g.bakeSpringTrack=de,g.bindChoiceHotspots=Kn,g.bounceOut=ri,g.charactersFor=Li,g.clamp01=Oe,g.clearMorphCache=Fs,g.clearPathCache=ws,g.containerProgressAt=Ne,g.context=ea,g.create=Po,g.createControls=Hn,g.createCubicBezier=ni,g.createLive=qn,g.createRandom=Bi,g.createTrack=Xt,g.criticalDamping=os,g.customBounce=Ui,g.customEase=Wi,g.customWiggle=ji,g.deserializeTimeline=ct,g.deserializeTrack=Oi,g.draggable=qr,g.easeIn=ti,g.easeInCubic=ne,g.easeInOut=ii,g.easeInOutCubic=vt,g.easeInOutQuad=Je,g.easeInQuad=Qe,g.easeOut=ei,g.easeOutCubic=se,g.easeOutQuad=Ze,g.elasticOut=si,g.expandParametricEasings=Ci,g.from=Go,g.fromJSON=Ws,g.fromTo=Ko,g.getEasingFunction=V,g.getInterpolator=St,g.getMotionPathPoint=ge,g.getPathLength=Ts,g.getPointAtProgress=ui,g.gridLinesFor=mn,g.hasKeyframes=He,g.hashSeed=Us,g.imageSequence=sa,g.inertiaDuration=st,g.inertiaRest=nt,g.inertiaValueAt=Ot,g.inertiaVelocityAt=hs,g.interpolateArray=xi,g.interpolateColor=Ai,g.interpolateMotionPath=Bs,g.interpolateNumber=W,g.interpolatePathString=Ei,g.interpolateString=ue,g.isCubicBezierEasing=ze,g.isInertiaTrack=H,g.isMotionPathPoint=es,g.isMotionPathTrack=Zt,g.isParametricEasing=pt,g.isPathData=ot,g.isSpringTrack=G,g.isTextTrack=It,g.isUnderdamped=rs,g.isUnresolved=zs,g.linear=Nt,g.live=q,g.mapEase=Mt,g.matchMedia=ia,g.maxStaggerDistance=te,g.morphPath=bi,g.mount=Qn,g.mountAll=Jn,g.naturalRest=bt,g.pageTransition=ra,g.parametricEasing=ci,g.parseEdge=$e,g.parsePath=J,g.parseTrigger=De,g.play=Eo,g.playSequence=Wo,g.playWhenVisible=Jr,g.playheadCrossings=ve,g.pointAtDistance=oe,g.pointsToPath=Hi,g.quickPlay=jo,g.quickTo=na,g.randomBetween=Te,g.randomChoice=js,g.randomSnapped=qi,g.resolveSequence=Vi,g.resolveValue=ke,g.scrollProgress=Zr,g.scrubOnScroll=no,g.serializeTimeline=Ni,g.serializeTrack=$i,g.set=Qo,g.shapeToPathData=Vt,g.simplifyKeyframes=_i,g.smoothToward=kn,g.snapAxis=pn,g.snapConfig=An,g.snapDuration=En,g.snapProgress=xn,g.splitText=ta,g.springDuration=Ge,g.springValueAt=ss,g.staggerDistance=Jt,g.staggerOffset=Rt,g.staggerOffsets=Lt,g.staggerSpan=gt,g.stepsEasing=ai,g.syncMediaElement=Un,g.textAt=Fi,g.tf=zo,g.ticker=Jo,g.timeline=Zo,g.to=Ho,g.toJSON=Vs,g.toKeyframedTrack=Os,g.toKeyframedTracks=Ns,g.trackTargets=Z,g.triggerDistance=lt,g.unmount=Xo,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});
|
package/lib/browser/tinyfly.js
CHANGED
|
@@ -6049,7 +6049,7 @@ function no(i, t, e = {}) {
|
|
|
6049
6049
|
return O.type = "button", O.className = `tf-ctl-btn ${N}`.trim(), O.setAttribute("aria-label", M), O.title = M, O.textContent = I, O.addEventListener("click", L), O;
|
|
6050
6050
|
}, f = h(s.restart, "⟲", () => {
|
|
6051
6051
|
i.pause(), i.seek(0);
|
|
6052
|
-
}), u = h(s.prev, "
|
|
6052
|
+
}), u = h(s.prev, "|◀", () => i.prev()), d = h(s.play, "▶", () => i.isPlaying ? i.pause() : p(), "tf-ctl-primary"), m = h(s.next, "▶|", () => i.next()), p = () => {
|
|
6053
6053
|
i.currentTime >= i.duration - 0.5 && i.seek(0), i.play();
|
|
6054
6054
|
}, g = n.createElement("input");
|
|
6055
6055
|
g.type = "range", g.className = "tf-ctl-scrub", g.min = "0", g.max = "1000", g.step = "1", g.setAttribute("aria-label", s.scrub), g.addEventListener("input", () => {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
.tf-fullscreen > svg, .tf-fullscreen > canvas { grid-column: 1; grid-row: 1 / span 12; height: calc(100vh - 24px) !important; height: calc(100dvh - 24px) !important; }
|
|
48
48
|
.tf-fullscreen > :not(svg):not(canvas) { grid-column: 2; }
|
|
49
49
|
}
|
|
50
|
-
`;let _o=0;function Io(i){if(i.getElementById(zn))return;const t=i.createElement("style");t.id=zn,t.textContent=Co,i.head.appendChild(t)}function Hn(i,t,e={}){const n=t.ownerDocument;Io(n);const s={...jn,...e.labels},r=e.speeds??[.5,1,2],o=()=>i.markers.length>0,a=()=>i.markers.some(x=>x.label!==void 0||i.caption(x.id)!==void 0),c=n.createElement("div");c.className="tf-ctl";const l=n.createElement("div");l.className="tf-ctl-bar",l.setAttribute("role","group");const h=(x,R,$,B="")=>{const N=n.createElement("button");return N.type="button",N.className=`tf-ctl-btn ${B}`.trim(),N.setAttribute("aria-label",x),N.title=x,N.textContent=R,N.addEventListener("click",$),N},f=h(s.restart,"⟲",()=>{i.pause(),i.seek(0)}),u=h(s.prev,"
|
|
50
|
+
`;let _o=0;function Io(i){if(i.getElementById(zn))return;const t=i.createElement("style");t.id=zn,t.textContent=Co,i.head.appendChild(t)}function Hn(i,t,e={}){const n=t.ownerDocument;Io(n);const s={...jn,...e.labels},r=e.speeds??[.5,1,2],o=()=>i.markers.length>0,a=()=>i.markers.some(x=>x.label!==void 0||i.caption(x.id)!==void 0),c=n.createElement("div");c.className="tf-ctl";const l=n.createElement("div");l.className="tf-ctl-bar",l.setAttribute("role","group");const h=(x,R,$,B="")=>{const N=n.createElement("button");return N.type="button",N.className=`tf-ctl-btn ${B}`.trim(),N.setAttribute("aria-label",x),N.title=x,N.textContent=R,N.addEventListener("click",$),N},f=h(s.restart,"⟲",()=>{i.pause(),i.seek(0)}),u=h(s.prev,"|◀",()=>i.prev()),d=h(s.play,"▶",()=>i.isPlaying?i.pause():p(),"tf-ctl-primary"),g=h(s.next,"▶|",()=>i.next()),p=()=>{i.currentTime>=i.duration-.5&&i.seek(0),i.play()},y=n.createElement("input");y.type="range",y.className="tf-ctl-scrub",y.min="0",y.max="1000",y.step="1",y.setAttribute("aria-label",s.scrub),y.addEventListener("input",()=>{i.pause(),i.seek(Number(y.value)/1e3*i.duration)});const b=n.createElement("span");b.className="tf-ctl-step";const w=n.createElement("select");w.className="tf-ctl-speed",w.setAttribute("aria-label",s.speed);for(const x of r){const R=n.createElement("option");R.value=String(x),R.textContent=`${x}×`,x===1&&(R.selected=!0),w.appendChild(R)}w.addEventListener("change",()=>i.setSpeed(Number(w.value))),l.append(f,u,d,g,y,b),r.length>0&&l.append(w),c.append(l);const v=e.fullscreen?$o(t,n,s):void 0;v&&l.append(v.button);const k=n.createElement("p");k.className="tf-ctl-caption",k.setAttribute("aria-live","polite"),e.captions!==!1&&c.append(k);const T=n.createElement("div");T.className="tf-ctl-question",T.hidden=!0;const S=n.createElement("span"),A=h(s.reveal,s.reveal,()=>i.play(),"tf-ctl-primary");T.append(S,A),c.append(T);const I=Ro(i,n,s.scenario,e.scenarioControl??"buttons");I&&c.append(I.element);const O=e.mount;O?O.appendChild(c):t.insertAdjacentElement("afterend",c);const E=()=>{const x=i.isPlaying;d.textContent=x?"❚❚":"▶",d.setAttribute("aria-label",x?s.pause:s.play),d.title=x?s.pause:s.play;const R=i.duration;n.activeElement!==y&&(y.value=String(R>0?Math.round(i.currentTime/R*1e3):0));const $=i.markers;if(u.hidden=g.hidden=b.hidden=$.length===0,$.length>0){const B=i.currentMarker,N=B?$.indexOf(B)+1:0;b.textContent=s.stepFormat.replace("{index}",String(N)).replace("{total}",String($.length)),b.setAttribute("aria-label",`${s.step} ${N} ${s.of} ${$.length}`),u.disabled=i.currentTime<=.5,g.disabled=i.currentTime>=R-.5;const L=i.caption()??"";k.textContent!==L&&(k.textContent=L),k.hidden=!a();const D=!x&&B?.question!==void 0&&Math.abs(i.currentTime-B.time)<1;T.hidden=!D,D&&S.textContent!==B.question&&(S.textContent=B.question)}else T.hidden=!0,k.hidden=!0;I?.update()},M=i.subscribe(E);E();const C=e.keyboardScope??t;!C.hasAttribute("tabindex")&&C.tabIndex<0&&(C.tabIndex=0);const P=new WeakSet,_=x=>{if(P.has(x)||(P.add(x),x.defaultPrevented||x.altKey||x.ctrlKey||x.metaKey))return;const R=x.target;if(!(R.tagName==="INPUT"||R.tagName==="SELECT")&&!(x.key===" "&&R.tagName==="BUTTON"))switch(x.key){case" ":x.preventDefault(),i.isPlaying?i.pause():p();break;case"ArrowRight":if(!o())return;x.preventDefault(),i.next();break;case"ArrowLeft":if(!o())return;x.preventDefault(),i.prev();break;case"Home":x.preventDefault(),i.pause(),i.seek(0);break;case"f":case"F":if(!v)return;x.preventDefault(),v.active?v.exit():v.enter();break}};return C.addEventListener("keydown",_),c.addEventListener("keydown",_),{element:c,fullscreen:v&&{get active(){return v.active},enter:v.enter,exit:v.exit},destroy(){v?.destroy(),M(),C.removeEventListener("keydown",_),c.removeEventListener("keydown",_),c.remove()}}}function Ro(i,t,e,n){const s=i.scenarios;if(s.length<2)return;if(n==="slider"){const h=t.createElement("div");h.className="tf-ctl-choice-slider";const f=t.createElement("span");f.textContent=e,f.setAttribute("aria-hidden","true");const u=t.createElement("input");u.type="range",u.min="0",u.max=String(s.length-1),u.step="1",u.setAttribute("aria-label",e);const d=t.createElement("output");return d.setAttribute("aria-hidden","true"),u.addEventListener("input",()=>{const p=s[Number(u.value)];p&&i.setScenario(p.id)}),h.append(f,u,d),{element:h,update:()=>{const p=Math.max(0,s.findIndex(b=>b.id===i.scenario));t.activeElement!==u&&(u.value=String(p));const y=s[p].label;d.textContent!==y&&(d.textContent=y),u.setAttribute("aria-valuetext",y)}}}const r=t.createElement("fieldset");r.className="tf-ctl-choices";const o=t.createElement("legend");o.textContent=e,r.append(o);const a=`tf-ctl-scenario-${++_o}`,c=s.map(h=>{const f=t.createElement("label");f.className="tf-ctl-choice";const u=t.createElement("input");u.type="radio",u.name=a,u.value=h.id,u.addEventListener("change",()=>{u.checked&&i.setScenario(h.id)});const d=t.createElement("span");return d.textContent=h.label,f.append(u,d),r.append(f),u});return{element:r,update:()=>{for(const h of c){const f=h.value===i.scenario;h.checked!==f&&(h.checked=f)}}}}const Lo='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',Fo='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function $o(i,t,e){const n=t,s=i,r=t.createElement("button");r.type="button",r.className="tf-ctl-btn tf-ctl-fullscreen";let o,a="";const c=()=>{const p=o!==void 0;r.innerHTML=p?Fo:Lo;const y=p?e.exitFullscreen:e.fullscreen;r.setAttribute("aria-label",y),r.title=y,r.setAttribute("aria-pressed",String(p)),i.classList.toggle("tf-fullscreen",p),i.classList.toggle("tf-fullscreen-overlay",o==="overlay")},l=()=>n.fullscreenElement??n.webkitFullscreenElement??null,h=()=>{l()===i?o="native":o==="native"&&(o=void 0),c()},f=p=>{p.key==="Escape"&&g()},u=()=>{o="overlay",a=t.documentElement.style.overflow,t.documentElement.style.overflow="hidden",t.addEventListener("keydown",f),c()};async function d(){if(o)return;const p=s.requestFullscreen?.bind(s)??s.webkitRequestFullscreen?.bind(s),y=n.fullscreenEnabled??n.webkitFullscreenEnabled??!1;if(p&&y)try{if(await p(),l()===i){o="native",c();return}}catch{}u()}async function g(){if(o==="overlay")t.removeEventListener("keydown",f),t.documentElement.style.overflow=a,o=void 0,c();else if(o==="native"){o=void 0,c();const p=n.exitFullscreen?.bind(n)??n.webkitExitFullscreen?.bind(n);l()===i&&p&&await p()}}return r.addEventListener("click",()=>{o?g():d()}),t.addEventListener("fullscreenchange",h),t.addEventListener("webkitfullscreenchange",h),c(),{button:r,get active(){return o!==void 0},enter:d,exit:g,destroy(){g(),t.removeEventListener("fullscreenchange",h),t.removeEventListener("webkitfullscreenchange",h),r.remove()}}}const Gn="tinyfly-choices-style",Do=`
|
|
51
51
|
[data-tinyfly-choose] { cursor: pointer; }
|
|
52
52
|
[data-tinyfly-choose]:focus-visible { outline: 2px solid var(--tf-ctl-accent, #c2410c); outline-offset: 2px; }
|
|
53
53
|
`;function Oo(i){if(i.getElementById(Gn))return;const t=i.createElement("style");t.id=Gn,t.textContent=Do,i.head.appendChild(t)}function Kn(i,t){const e=Array.from(t.querySelectorAll("[data-tinyfly-choose]"));if(e.length===0)return()=>{};Oo(t.ownerDocument);const n=[],s=[];for(const a of e){const c=a.getAttribute("data-tinyfly-choose")??"",l=[],h=(g,p)=>{a.hasAttribute(g)||(a.setAttribute(g,p),l.push(g))};h("role","button"),h("tabindex","0");const f=i.scenarios.find(g=>g.id===c)?.label;f!==void 0&&h("aria-label",f),a.setAttribute("aria-pressed","false"),l.push("aria-pressed"),n.push({element:a,attributes:l});const u=()=>i.setScenario(c),d=g=>{const p=g.key;p!=="Enter"&&p!==" "||(g.preventDefault(),u())};a.addEventListener("click",u),a.addEventListener("keydown",d),s.push(()=>{a.removeEventListener("click",u),a.removeEventListener("keydown",d)})}const r=()=>{for(const{element:a}of n)a.setAttribute("aria-pressed",String(a.getAttribute("data-tinyfly-choose")===i.scenario))},o=i.subscribe(r);return r(),()=>{o();for(const a of s)a();for(const{element:a,attributes:c}of n)for(const l of c)a.removeAttribute(l)}}const Qt=new WeakMap,je=new WeakMap;let No=0;function _t(i,t,e){if(i)try{return JSON.parse(i)}catch(n){console.warn(`tinyfly: invalid ${t} JSON on`,e,n);return}}async function Qn(i,t={}){const e=Qt.get(i);if(e)return e;const n=Array.from(i.querySelectorAll("script[data-tinyfly-timeline]")),s=n[0],r=i.getAttribute("data-src"),o=qo(i.getAttribute("data-markers")),a=n.length>1||s?.hasAttribute("data-scenario")?Bo(n,o,i):void 0;if(a&&a.length===0)return;let c=s&&!a?_t(s.textContent,"timeline",i):void 0;if(!c&&r&&o){const d=await fetch(r);d.ok&&(c=await d.json())}if(c&&o&&(c=Zn(c,o)),!c&&!r&&!a){console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)',i);return}const l=_t(i.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",i),h={playWhenVisible:!0,...t.player,...l&&{captions:l},..._t(i.getAttribute("data-options"),"data-options",i)};Yo(i);const f=new Kt(i,h),u={element:i,player:f};if(Qt.set(i,u),i.setAttribute("data-tinyfly-mounted",""),a){const d=i.getAttribute("data-scenario")??void 0;await f.loadScenarios(a,{initial:a.some(g=>g.id===d)?d:void 0}),je.set(i,Kn(f,i))}else await f.load(c??r);if(i.getAttribute("data-controls")!=="false"){const d=_t(i.getAttribute("data-labels"),"data-labels",i),g=i.querySelector("figcaption"),p=i.getAttribute("data-scenario-legend"),y=i.getAttribute("data-scenario-control");u.controls=Hn(f,i,{...t.controls,...i.getAttribute("data-fullscreen")==="true"?{fullscreen:!0}:{},...y==="slider"||y==="buttons"?{scenarioControl:y}:{},labels:{...t.controls?.labels,...d,...p?{scenario:p}:{}},mount:void 0}),g?i.insertBefore(u.controls.element,g):i.appendChild(u.controls.element)}return u}function Bo(i,t,e){const n=[];return i.forEach((s,r)=>{const o=_t(s.textContent,"timeline",e);if(!o)return;const a=s.getAttribute("data-scenario")||`scenario-${r+1}`;if(n.some(l=>l.id===a)){console.warn(`tinyfly: scenario id "${a}" is used more than once; the later one is skipped`,e);return}const c=s.getAttribute("data-scenario-label")??void 0;n.push({id:a,label:c,timeline:t?Zn(o,t):o})}),n}function Zn(i,t){return i.config.markers?.length?i:{...i,config:{...i.config,markers:t.map((e,n)=>({id:`step-${n+1}`,time:e}))}}}function qo(i){if(!i)return;const t=i.split(/[\s,]+/).filter(Boolean).map(Number).filter(e=>Number.isFinite(e)&&e>=0).sort((e,n)=>e-n);return t.length>0?t:void 0}async function Jn(i=document,t={}){const e=Array.from(i.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(e.map(s=>Qn(s,t)))).filter(s=>s!==void 0)}function Xo(i){const t=Qt.get(i);t&&(je.get(i)?.(),je.delete(i),t.controls?.destroy(),t.player.destroy(),Qt.delete(i),i.removeAttribute("data-tinyfly-mounted"))}function Yo(i){const t=i.querySelector("svg");if(!t||t.hasAttribute("role")||t.hasAttribute("aria-hidden"))return;const e=i.getAttribute("data-alt"),n=i.querySelector("figcaption");t.setAttribute("role","img"),e?t.setAttribute("aria-label",e):n&&(n.id||=`tinyfly-caption-${++No}`,t.setAttribute("aria-labelledby",n.id))}function Vo(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const t=()=>{Jn()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}class ts{container;containerA;containerB;adapterA;adapterB;timelineA=null;timelineB=null;symbolDefs=new Map;nestedByAdapter=new Map;sequence=null;options;_currentSceneIndex=0;_state="idle";_isPlaying=!1;_isDestroyed=!1;loopIteration=0;animationFrameId;lastTime;transitionTimer;constructor(t,e={}){if(typeof t=="string"){const n=document.querySelector(t);if(!n)throw new Error(`Container not found: ${t}`);this.container=n}else this.container=t;this.options=e,this.container.style.position="relative",this.container.style.overflow="hidden",this.containerA=this.createSceneContainer(),this.containerB=this.createSceneContainer(),this.container.appendChild(this.containerA),this.container.appendChild(this.containerB),this.containerB.style.visibility="hidden",this.adapterA=new et,this.adapterB=new et}async load(t){let e;if(typeof t=="string"){const n=await fetch(t);if(!n.ok)throw new Error(`Failed to load sequence: ${n.statusText}`);e=await n.json()}else e=t;this.sequence=e,this.symbolDefs.clear();for(const n of e.symbols??[])n.timeline?.tracks?.length&&this.symbolDefs.set(n.id,n.timeline);this.container.style.width=`${e.canvas.width}px`,this.container.style.height=`${e.canvas.height}px`,e.scenes.length>0&&(this.renderScene(e.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(e.scenes[0])),this.options.autoplay&&this.play()}play(){if(!(!this.sequence||this._isDestroyed)&&this.sequence.scenes.length!==0){if(this._isPlaying=!0,this._state==="idle"){if(this._state="playing-scene",this._currentSceneIndex=0,this.timelineA)this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play();else{this.onSceneComplete();return}this.options.onSceneChange?.(0)}else this._state==="playing-scene"&&this.timelineA&&this.timelineA.play();this.startAnimationLoop()}}pause(){this._isPlaying&&(this._isPlaying=!1,this.timelineA&&this.timelineA.pause(),this.timelineB&&this.timelineB.pause(),this.stopAnimationLoop())}stop(){if(this._isPlaying=!1,this._state="idle",this._currentSceneIndex=0,this.loopIteration=0,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.stopAnimationLoop(),this.sequence&&this.sequence.scenes.length>0&&(this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this.renderScene(this.sequence.scenes[0],this.containerA,this.adapterA),this.timelineA=this.createTimeline(this.sequence.scenes[0]),this.timelineA)){const t=this.timelineA.getStateAtTime(0);this.adapterA.applyState(t),this.applyNested(this.adapterA,0)}}goToScene(t){if(!this.sequence||t<0||t>=this.sequence.scenes.length)return;const e=this._isPlaying;this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this._currentSceneIndex=t,this._state=e?"playing-scene":"idle",this.clearContainer(this.containerA),this.clearContainer(this.containerB),this.adapterA.clearTargets(),this.adapterB.clearTargets(),this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB);const n=this.sequence.scenes[t];if(this.renderScene(n,this.containerA,this.adapterA),this.timelineA=this.createTimeline(n),this.options.onSceneChange?.(t),e)this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play(),this.startAnimationLoop()):this.onSceneComplete();else if(this.timelineA){const s=this.timelineA.getStateAtTime(0);this.adapterA.applyState(s),this.applyNested(this.adapterA,0)}}destroy(){this._isDestroyed=!0,this._isPlaying=!1,this.transitionTimer!==void 0&&(clearTimeout(this.transitionTimer),this.transitionTimer=void 0),this.stopAnimationLoop(),this.adapterA.clearTargets(),this.adapterB.clearTargets();for(const t of this.nestedByAdapter.values())for(const e of t)e.adapter.clearTargets();this.nestedByAdapter.clear(),this.timelineA&&this.timelineA.stop(),this.timelineB&&this.timelineB.stop(),this.timelineA=null,this.timelineB=null,this.containerA.parentNode&&this.containerA.remove(),this.containerB.parentNode&&this.containerB.remove(),this.sequence=null}get currentSceneIndex(){return this._currentSceneIndex}get sceneCount(){return this.sequence?.scenes.length??0}get isPlaying(){return this._isPlaying}get state(){return this._state}createSceneContainer(){const t=document.createElement("div");return t.style.position="absolute",t.style.top="0",t.style.left="0",t.style.width="100%",t.style.height="100%",t}renderScene(t,e,n){e.innerHTML="",n.clearTargets();const s=document.createElement("div");s.style.cssText="position:absolute;inset:0;transform-origin:center center",s.setAttribute("data-tinyfly","Camera"),e.appendChild(s),n.registerTarget("Camera",s);for(const r of t.elements){if(!r.html)continue;const o=document.createElement("div");o.innerHTML=r.html.trim();const a=o.firstElementChild;if(a){s.appendChild(a);const c=a.getAttribute("data-tinyfly");c&&n.registerTarget(c,a)}}this.setupNested(s,n)}setupNested(t,e){const n=[];t.querySelectorAll("[data-tinyfly-symbol]").forEach(s=>{const r=s.getAttribute("data-tinyfly-symbol");if(!r)return;const o=this.symbolDefs.get(r);if(!o)return;const a=new et;s.querySelectorAll("[data-tinyfly]").forEach(c=>{const l=c.getAttribute("data-tinyfly");l&&a.registerTarget(l,c)}),n.push({adapter:a,timeline:lt(o)})}),n.length?this.nestedByAdapter.set(e,n):this.nestedByAdapter.delete(e)}applyNested(t,e){const n=this.nestedByAdapter.get(t);if(n)for(const s of n){const r=s.timeline.duration;s.adapter.applyState(s.timeline.getStateAtTime(r>0?e%r:e))}}clearContainer(t){t.innerHTML=""}createTimeline(t){return t.timeline?lt(t.timeline):null}onSceneComplete(){if(this._isDestroyed||!this.sequence)return;const t=this._currentSceneIndex+1;if(t>=this.sequence.scenes.length){const e=this.options.loop??this.sequence.loop??0;e===-1||e>0&&this.loopIteration<e-1?(this.loopIteration++,this.beginTransitionTo(0)):(this._isPlaying=!1,this._state="idle",this.stopAnimationLoop(),this.options.onComplete?.())}else this.beginTransitionTo(t)}beginTransitionTo(t){if(!this.sequence||this._isDestroyed)return;const e=this.sequence.scenes[t],n=e.transition;if(n.type==="none"||n.duration<=0){this.switchToScene(t);return}this._state="transitioning",this.containerB.style.visibility="visible",this.renderScene(e,this.containerB,this.adapterB),this.timelineB=this.createTimeline(e),this.timelineB&&this.timelineB.play(),this.applyTransition(n.type,n.duration),this.transitionTimer=window.setTimeout(()=>{this.finishTransition(t)},n.duration)}applyTransition(t,e){const n=`${e}ms`,s="ease-in-out";switch(this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),t){case"fade":this.containerB.style.opacity="0";break;case"slide-left":this.containerB.style.transform="translateX(100%)";break;case"slide-right":this.containerB.style.transform="translateX(-100%)";break;case"slide-up":this.containerB.style.transform="translateY(100%)";break;case"slide-down":this.containerB.style.transform="translateY(-100%)";break}switch(this.containerB.offsetHeight,this.containerA.style.transition=`opacity ${n} ${s}, transform ${n} ${s}`,this.containerB.style.transition=`opacity ${n} ${s}, transform ${n} ${s}`,t){case"fade":this.containerA.style.opacity="0",this.containerB.style.opacity="1";break;case"slide-left":this.containerA.style.transform="translateX(-100%)",this.containerB.style.transform="translateX(0)";break;case"slide-right":this.containerA.style.transform="translateX(100%)",this.containerB.style.transform="translateX(0)";break;case"slide-up":this.containerA.style.transform="translateY(-100%)",this.containerB.style.transform="translateY(0)";break;case"slide-down":this.containerA.style.transform="translateY(100%)",this.containerB.style.transform="translateY(0)";break}}resetTransitionStyles(t){t.style.transition="",t.style.opacity="1",t.style.transform=""}finishTransition(t){this.transitionTimer=void 0,this.timelineA&&(this.timelineA.stop(),this.timelineA=null),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.containerA;this.containerA=this.containerB,this.containerB=e;const n=this.adapterA;this.adapterA=this.adapterB,this.adapterB=n,this.timelineA=this.timelineB,this.timelineB=null,this.containerB.style.visibility="hidden",this.resetTransitionStyles(this.containerA),this.resetTransitionStyles(this.containerB),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.playbackState!=="playing"&&this.timelineA.play()):this.onSceneComplete()}switchToScene(t){if(!this.sequence||this._isDestroyed)return;this.timelineA&&this.timelineA.stop(),this.adapterA.clearTargets(),this.clearContainer(this.containerA);const e=this.sequence.scenes[t];this.renderScene(e,this.containerA,this.adapterA),this.timelineA=this.createTimeline(e),this._currentSceneIndex=t,this._state="playing-scene",this.options.onSceneChange?.(t),this.timelineA?(this.timelineA.onComplete=()=>this.onSceneComplete(),this.timelineA.play()):this.onSceneComplete()}startAnimationLoop(){if(this.animationFrameId!==void 0)return;this.lastTime=performance.now();const t=e=>{if(this._isDestroyed||!this._isPlaying)return;const n=e-(this.lastTime??e);if(this.lastTime=e,this.timelineA&&this.timelineA.playbackState==="playing"){this.timelineA.tick(n);const s=this.timelineA.getStateAtTime(this.timelineA.currentTime);this.adapterA.applyState(s),this.applyNested(this.adapterA,this.timelineA.currentTime)}if(this._state==="transitioning"&&this.timelineB&&this.timelineB.playbackState==="playing"){this.timelineB.tick(n);const s=this.timelineB.getStateAtTime(this.timelineB.currentTime);this.adapterB.applyState(s),this.applyNested(this.adapterB,this.timelineB.currentTime)}this._isPlaying?this.animationFrameId=requestAnimationFrame(t):this.animationFrameId=void 0};this.animationFrameId=requestAnimationFrame(t)}stopAnimationLoop(){this.animationFrameId!==void 0&&(cancelAnimationFrame(this.animationFrameId),this.animationFrameId=void 0)}}async function Wo(i,t,e={}){const n=new ts(i,{...e,autoplay:!0});return await n.load(t),n}const Uo={type:"none",duration:0};function jo(i){const{timeline:t}=i,e=new et;for(const[l,h]of Object.entries(i.targets)){const f=typeof h=="string"?document.querySelector(h):h;if(!f)throw new Error(`quickPlay: no element found for target "${l}" (${String(h)})`);e.registerTarget(l,f)}t.onUpdate=l=>{e.applyState(l),i.onUpdate?.(l)},i.onComplete&&(t.onComplete=i.onComplete);let n=null,s=null,r=!1;const o=l=>{if(r)return;const h=s===null?0:l-s;s=l,h>0&&t.tick(h),n=requestAnimationFrame(o)},a=()=>{n!==null||r||(s=null,n=requestAnimationFrame(o))},c=()=>{n!==null&&cancelAnimationFrame(n),n=null,s=null};return e.applyState(t.getStateAtTime(t.currentTime)),i.autoplay!==!1&&(t.play(),a()),{timeline:t,adapter:e,play(){t.play(),a()},pause(){t.pause(),c()},restart(){t.stop(),t.play(),a()},seek(l){t.seek(l*1e3),e.applyState(t.getStateAtTime(t.currentTime))},destroy(){r=!0,c(),t.stop(),e.clearTargets()}}}const zo={timeline:vr,to(i,t,e){const n=new tt(e);return n.to(i,t),n},from(i,t,e){const n=new tt(e);return n.from(i,t),n},fromTo(i,t,e,n){const s=new tt(n);return s.fromTo(i,t,e),s},set(i,t,e){const n=new tt(e);return n.set(i,t),n}},Ho=q.to,Go=q.from,Ko=q.fromTo,Qo=q.set,Zo=q.timeline,Jo=q.ticker,ta=q.splitText,ea=q.context,ia=q.matchMedia,na=q.quickTo,sa=q.imageSequence,ra=q.pageTransition;Vo(),m.Clock=ns,m.CompatTimeline=tt,m.CustomBounce=Dn,m.CustomEase=$n,m.CustomWiggle=On,m.DEFAULT_BAKE_INTERVAL_MS=de,m.DEFAULT_INERTIA_FRICTION=ne,m.DEFAULT_LABELS=jn,m.DEFAULT_SPRING=Y,m.DEFAULT_TRANSITION=Uo,m.Draggable=Ie,m.FORMAT_VERSION=gt,m.INERTIA_MAX_DURATION_MS=Ke,m.InertiaTrackPlayer=Ri,m.LiveTimeline=z,m.MORPH_SAMPLES=As,m.ManualClock=is,m.MediaSync=Ue,m.Observer=fn,m.SPRING_MAX_DURATION_MS=ie,m.SPRING_PRESETS=Dt,m.SPRING_STEP_MS=nt,m.ScrollAnimator=Pn,m.ScrollDriver=Pt,m.ScrollMarkers=Cn,m.ScrollPin=Mn,m.SmoothScroll=Ye,m.SpringSampler=bt,m.SpringTrackPlayer=Ii,m.Stage=on,m.Timeline=ve,m.TinyflyPlayer=Kt,m.TinyflySequencer=ts,m.TrackPlayer=Vt,m.ValueResolver=Hs,m.VisibilityDriver=Sn,m.backOut=oi,m.bakeEasing=ge,m.bakeInertiaTrack=me,m.bakeSpringTrack=pe,m.bindChoiceHotspots=Kn,m.bounceOut=ri,m.charactersFor=Li,m.clamp01=Ne,m.clearMorphCache=Fs,m.clearPathCache=ws,m.containerProgressAt=Be,m.context=ea,m.create=Po,m.createControls=Hn,m.createCubicBezier=ni,m.createLive=qn,m.createRandom=Bi,m.createTrack=Yt,m.criticalDamping=os,m.customBounce=Ui,m.customEase=Wi,m.customWiggle=ji,m.deserializeTimeline=lt,m.deserializeTrack=Oi,m.draggable=qr,m.easeIn=ti,m.easeInCubic=se,m.easeInOut=ii,m.easeInOutCubic=wt,m.easeInOutQuad=Je,m.easeInQuad=Qe,m.easeOut=ei,m.easeOutCubic=re,m.easeOutQuad=Ze,m.elasticOut=si,m.expandParametricEasings=Ci,m.from=Go,m.fromJSON=Ws,m.fromTo=Ko,m.getEasingFunction=V,m.getInterpolator=Mt,m.getMotionPathPoint=ye,m.getPathLength=Ts,m.getPointAtProgress=ui,m.gridLinesFor=mn,m.hasKeyframes=He,m.hashSeed=Us,m.imageSequence=sa,m.inertiaDuration=rt,m.inertiaRest=st,m.inertiaValueAt=Nt,m.inertiaVelocityAt=hs,m.interpolateArray=xi,m.interpolateColor=Ai,m.interpolateMotionPath=Bs,m.interpolateNumber=W,m.interpolatePathString=Ei,m.interpolateString=fe,m.isCubicBezierEasing=it,m.isInertiaTrack=H,m.isMotionPathPoint=es,m.isMotionPathTrack=Jt,m.isParametricEasing=mt,m.isPathData=at,m.isSpringTrack=G,m.isTextTrack=Rt,m.isUnderdamped=rs,m.isUnresolved=zs,m.linear=Bt,m.live=q,m.mapEase=At,m.matchMedia=ia,m.maxStaggerDistance=ee,m.morphPath=bi,m.mount=Qn,m.mountAll=Jn,m.naturalRest=vt,m.pageTransition=ra,m.parametricEasing=ci,m.parseEdge=De,m.parsePath=J,m.parseTrigger=Oe,m.play=Eo,m.playSequence=Wo,m.playWhenVisible=Jr,m.playheadCrossings=we,m.pointAtDistance=ae,m.pointsToPath=Hi,m.quickPlay=jo,m.quickTo=na,m.randomBetween=ke,m.randomChoice=js,m.randomSnapped=qi,m.resolveSequence=Vi,m.resolveValue=Se,m.scrollProgress=Zr,m.scrubOnScroll=no,m.serializeTimeline=Ni,m.serializeTrack=$i,m.set=Qo,m.shapeToPathData=Wt,m.simplifyKeyframes=_i,m.smoothToward=kn,m.snapAxis=pn,m.snapConfig=An,m.snapDuration=En,m.snapProgress=xn,m.splitText=ta,m.springDuration=Ge,m.springValueAt=ss,m.staggerDistance=te,m.staggerOffset=Lt,m.staggerOffsets=Ft,m.staggerSpan=yt,m.stepsEasing=ai,m.syncMediaElement=Un,m.textAt=Fi,m.tf=zo,m.ticker=Jo,m.timeline=Zo,m.to=Ho,m.toJSON=Vs,m.toKeyframedTrack=Os,m.toKeyframedTracks=Ns,m.trackTargets=Z,m.triggerDistance=ht,m.unmount=Xo,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
.tf-fullscreen > svg, .tf-fullscreen > canvas { grid-column: 1; grid-row: 1 / span 12; height: calc(100vh - 24px) !important; height: calc(100dvh - 24px) !important; }
|
|
48
48
|
.tf-fullscreen > :not(svg):not(canvas) { grid-column: 2; }
|
|
49
49
|
}
|
|
50
|
-
`;let Fn=0;function Xn(e){if(e.getElementById(se))return;const t=e.createElement("style");t.id=se,t.textContent=Nn,e.head.appendChild(t)}function ie(e,t,n={}){const s=t.ownerDocument;Xn(s);const i={...ne,...n.labels},r=n.speeds??[.5,1,2],a=()=>e.markers.length>0,o=()=>e.markers.some(w=>w.label!==void 0||e.caption(w.id)!==void 0),c=s.createElement("div");c.className="tf-ctl";const l=s.createElement("div");l.className="tf-ctl-bar",l.setAttribute("role","group");const u=(w,E,F,N="")=>{const D=s.createElement("button");return D.type="button",D.className=`tf-ctl-btn ${N}`.trim(),D.setAttribute("aria-label",w),D.title=w,D.textContent=E,D.addEventListener("click",F),D},h=u(i.restart,"⟲",()=>{e.pause(),e.seek(0)}),d=u(i.prev,"
|
|
50
|
+
`;let Fn=0;function Xn(e){if(e.getElementById(se))return;const t=e.createElement("style");t.id=se,t.textContent=Nn,e.head.appendChild(t)}function ie(e,t,n={}){const s=t.ownerDocument;Xn(s);const i={...ne,...n.labels},r=n.speeds??[.5,1,2],a=()=>e.markers.length>0,o=()=>e.markers.some(w=>w.label!==void 0||e.caption(w.id)!==void 0),c=s.createElement("div");c.className="tf-ctl";const l=s.createElement("div");l.className="tf-ctl-bar",l.setAttribute("role","group");const u=(w,E,F,N="")=>{const D=s.createElement("button");return D.type="button",D.className=`tf-ctl-btn ${N}`.trim(),D.setAttribute("aria-label",w),D.title=w,D.textContent=E,D.addEventListener("click",F),D},h=u(i.restart,"⟲",()=>{e.pause(),e.seek(0)}),d=u(i.prev,"|◀",()=>e.prev()),f=u(i.play,"▶",()=>e.isPlaying?e.pause():p(),"tf-ctl-primary"),g=u(i.next,"▶|",()=>e.next()),p=()=>{e.currentTime>=e.duration-.5&&e.seek(0),e.play()},m=s.createElement("input");m.type="range",m.className="tf-ctl-scrub",m.min="0",m.max="1000",m.step="1",m.setAttribute("aria-label",i.scrub),m.addEventListener("input",()=>{e.pause(),e.seek(Number(m.value)/1e3*e.duration)});const b=s.createElement("span");b.className="tf-ctl-step";const v=s.createElement("select");v.className="tf-ctl-speed",v.setAttribute("aria-label",i.speed);for(const w of r){const E=s.createElement("option");E.value=String(w),E.textContent=`${w}×`,w===1&&(E.selected=!0),v.appendChild(E)}v.addEventListener("change",()=>e.setSpeed(Number(v.value))),l.append(h,d,f,g,m,b),r.length>0&&l.append(v),c.append(l);const k=n.fullscreen?Wn(t,s,i):void 0;k&&l.append(k.button);const M=s.createElement("p");M.className="tf-ctl-caption",M.setAttribute("aria-live","polite"),n.captions!==!1&&c.append(M);const y=s.createElement("div");y.className="tf-ctl-question",y.hidden=!0;const S=s.createElement("span"),x=u(i.reveal,i.reveal,()=>e.play(),"tf-ctl-primary");y.append(S,x),c.append(y);const P=Yn(e,s,i.scenario,n.scenarioControl??"buttons");P&&c.append(P.element);const W=n.mount;W?W.appendChild(c):t.insertAdjacentElement("afterend",c);const T=()=>{const w=e.isPlaying;f.textContent=w?"❚❚":"▶",f.setAttribute("aria-label",w?i.pause:i.play),f.title=w?i.pause:i.play;const E=e.duration;s.activeElement!==m&&(m.value=String(E>0?Math.round(e.currentTime/E*1e3):0));const F=e.markers;if(d.hidden=g.hidden=b.hidden=F.length===0,F.length>0){const N=e.currentMarker,D=N?F.indexOf(N)+1:0;b.textContent=i.stepFormat.replace("{index}",String(D)).replace("{total}",String(F.length)),b.setAttribute("aria-label",`${i.step} ${D} ${i.of} ${F.length}`),d.disabled=e.currentTime<=.5,g.disabled=e.currentTime>=E-.5;const A=e.caption()??"";M.textContent!==A&&(M.textContent=A),M.hidden=!o();const I=!w&&N?.question!==void 0&&Math.abs(e.currentTime-N.time)<1;y.hidden=!I,I&&S.textContent!==N.question&&(S.textContent=N.question)}else y.hidden=!0,M.hidden=!0;P?.update()},R=e.subscribe(T);T();const _=n.keyboardScope??t;!_.hasAttribute("tabindex")&&_.tabIndex<0&&(_.tabIndex=0);const C=new WeakSet,O=w=>{if(C.has(w)||(C.add(w),w.defaultPrevented||w.altKey||w.ctrlKey||w.metaKey))return;const E=w.target;if(!(E.tagName==="INPUT"||E.tagName==="SELECT")&&!(w.key===" "&&E.tagName==="BUTTON"))switch(w.key){case" ":w.preventDefault(),e.isPlaying?e.pause():p();break;case"ArrowRight":if(!a())return;w.preventDefault(),e.next();break;case"ArrowLeft":if(!a())return;w.preventDefault(),e.prev();break;case"Home":w.preventDefault(),e.pause(),e.seek(0);break;case"f":case"F":if(!k)return;w.preventDefault(),k.active?k.exit():k.enter();break}};return _.addEventListener("keydown",O),c.addEventListener("keydown",O),{element:c,fullscreen:k&&{get active(){return k.active},enter:k.enter,exit:k.exit},destroy(){k?.destroy(),R(),_.removeEventListener("keydown",O),c.removeEventListener("keydown",O),c.remove()}}}function Yn(e,t,n,s){const i=e.scenarios;if(i.length<2)return;if(s==="slider"){const u=t.createElement("div");u.className="tf-ctl-choice-slider";const h=t.createElement("span");h.textContent=n,h.setAttribute("aria-hidden","true");const d=t.createElement("input");d.type="range",d.min="0",d.max=String(i.length-1),d.step="1",d.setAttribute("aria-label",n);const f=t.createElement("output");return f.setAttribute("aria-hidden","true"),d.addEventListener("input",()=>{const p=i[Number(d.value)];p&&e.setScenario(p.id)}),u.append(h,d,f),{element:u,update:()=>{const p=Math.max(0,i.findIndex(b=>b.id===e.scenario));t.activeElement!==d&&(d.value=String(p));const m=i[p].label;f.textContent!==m&&(f.textContent=m),d.setAttribute("aria-valuetext",m)}}}const r=t.createElement("fieldset");r.className="tf-ctl-choices";const a=t.createElement("legend");a.textContent=n,r.append(a);const o=`tf-ctl-scenario-${++Fn}`,c=i.map(u=>{const h=t.createElement("label");h.className="tf-ctl-choice";const d=t.createElement("input");d.type="radio",d.name=o,d.value=u.id,d.addEventListener("change",()=>{d.checked&&e.setScenario(u.id)});const f=t.createElement("span");return f.textContent=u.label,h.append(d,f),r.append(h),d});return{element:r,update:()=>{for(const u of c){const h=u.value===e.scenario;u.checked!==h&&(u.checked=h)}}}}const qn='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/></svg>',Vn='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M9 4v5H4M15 4v5h5M9 20v-5H4M15 20v-5h5"/></svg>';function Wn(e,t,n){const s=t,i=e,r=t.createElement("button");r.type="button",r.className="tf-ctl-btn tf-ctl-fullscreen";let a,o="";const c=()=>{const p=a!==void 0;r.innerHTML=p?Vn:qn;const m=p?n.exitFullscreen:n.fullscreen;r.setAttribute("aria-label",m),r.title=m,r.setAttribute("aria-pressed",String(p)),e.classList.toggle("tf-fullscreen",p),e.classList.toggle("tf-fullscreen-overlay",a==="overlay")},l=()=>s.fullscreenElement??s.webkitFullscreenElement??null,u=()=>{l()===e?a="native":a==="native"&&(a=void 0),c()},h=p=>{p.key==="Escape"&&g()},d=()=>{a="overlay",o=t.documentElement.style.overflow,t.documentElement.style.overflow="hidden",t.addEventListener("keydown",h),c()};async function f(){if(a)return;const p=i.requestFullscreen?.bind(i)??i.webkitRequestFullscreen?.bind(i),m=s.fullscreenEnabled??s.webkitFullscreenEnabled??!1;if(p&&m)try{if(await p(),l()===e){a="native",c();return}}catch{}d()}async function g(){if(a==="overlay")t.removeEventListener("keydown",h),t.documentElement.style.overflow=o,a=void 0,c();else if(a==="native"){a=void 0,c();const p=s.exitFullscreen?.bind(s)??s.webkitExitFullscreen?.bind(s);l()===e&&p&&await p()}}return r.addEventListener("click",()=>{a?g():f()}),t.addEventListener("fullscreenchange",u),t.addEventListener("webkitfullscreenchange",u),c(),{button:r,get active(){return a!==void 0},enter:f,exit:g,destroy(){g(),t.removeEventListener("fullscreenchange",u),t.removeEventListener("webkitfullscreenchange",u),r.remove()}}}const re="tinyfly-choices-style",Bn=`
|
|
51
51
|
[data-tinyfly-choose] { cursor: pointer; }
|
|
52
52
|
[data-tinyfly-choose]:focus-visible { outline: 2px solid var(--tf-ctl-accent, #c2410c); outline-offset: 2px; }
|
|
53
53
|
`;function Un(e){if(e.getElementById(re))return;const t=e.createElement("style");t.id=re,t.textContent=Bn,e.head.appendChild(t)}function ae(e,t){const n=Array.from(t.querySelectorAll("[data-tinyfly-choose]"));if(n.length===0)return()=>{};Un(t.ownerDocument);const s=[],i=[];for(const o of n){const c=o.getAttribute("data-tinyfly-choose")??"",l=[],u=(g,p)=>{o.hasAttribute(g)||(o.setAttribute(g,p),l.push(g))};u("role","button"),u("tabindex","0");const h=e.scenarios.find(g=>g.id===c)?.label;h!==void 0&&u("aria-label",h),o.setAttribute("aria-pressed","false"),l.push("aria-pressed"),s.push({element:o,attributes:l});const d=()=>e.setScenario(c),f=g=>{const p=g.key;p!=="Enter"&&p!==" "||(g.preventDefault(),d())};o.addEventListener("click",d),o.addEventListener("keydown",f),i.push(()=>{o.removeEventListener("click",d),o.removeEventListener("keydown",f)})}const r=()=>{for(const{element:o}of s)o.setAttribute("aria-pressed",String(o.getAttribute("data-tinyfly-choose")===e.scenario))},a=e.subscribe(r);return r(),()=>{a();for(const o of i)o();for(const{element:o,attributes:c}of s)for(const l of c)o.removeAttribute(l)}}const ot=new WeakMap,Mt=new WeakMap;let jn=0;function J(e,t,n){if(e)try{return JSON.parse(e)}catch(s){console.warn(`tinyfly: invalid ${t} JSON on`,n,s);return}}async function oe(e,t={}){const n=ot.get(e);if(n)return n;const s=Array.from(e.querySelectorAll("script[data-tinyfly-timeline]")),i=s[0],r=e.getAttribute("data-src"),a=zn(e.getAttribute("data-markers")),o=s.length>1||i?.hasAttribute("data-scenario")?Hn(s,a,e):void 0;if(o&&o.length===0)return;let c=i&&!o?J(i.textContent,"timeline",e):void 0;if(!c&&r&&a){const f=await fetch(r);f.ok&&(c=await f.json())}if(c&&a&&(c=ce(c,a)),!c&&!r&&!o){console.warn('tinyfly: embed has no timeline (a <script type="application/json" data-tinyfly-timeline> or data-src)',e);return}const l=J(e.querySelector("script[data-tinyfly-captions]")?.textContent,"captions",e),u={playWhenVisible:!0,...t.player,...l&&{captions:l},...J(e.getAttribute("data-options"),"data-options",e)};Qn(e);const h=new at(e,u),d={element:e,player:h};if(ot.set(e,d),e.setAttribute("data-tinyfly-mounted",""),o){const f=e.getAttribute("data-scenario")??void 0;await h.loadScenarios(o,{initial:o.some(g=>g.id===f)?f:void 0}),Mt.set(e,ae(h,e))}else await h.load(c??r);if(e.getAttribute("data-controls")!=="false"){const f=J(e.getAttribute("data-labels"),"data-labels",e),g=e.querySelector("figcaption"),p=e.getAttribute("data-scenario-legend"),m=e.getAttribute("data-scenario-control");d.controls=ie(h,e,{...t.controls,...e.getAttribute("data-fullscreen")==="true"?{fullscreen:!0}:{},...m==="slider"||m==="buttons"?{scenarioControl:m}:{},labels:{...t.controls?.labels,...f,...p?{scenario:p}:{}},mount:void 0}),g?e.insertBefore(d.controls.element,g):e.appendChild(d.controls.element)}return d}function Hn(e,t,n){const s=[];return e.forEach((i,r)=>{const a=J(i.textContent,"timeline",n);if(!a)return;const o=i.getAttribute("data-scenario")||`scenario-${r+1}`;if(s.some(l=>l.id===o)){console.warn(`tinyfly: scenario id "${o}" is used more than once; the later one is skipped`,n);return}const c=i.getAttribute("data-scenario-label")??void 0;s.push({id:o,label:c,timeline:t?ce(a,t):a})}),s}function ce(e,t){return e.config.markers?.length?e:{...e,config:{...e.config,markers:t.map((n,s)=>({id:`step-${s+1}`,time:n}))}}}function zn(e){if(!e)return;const t=e.split(/[\s,]+/).filter(Boolean).map(Number).filter(n=>Number.isFinite(n)&&n>=0).sort((n,s)=>n-s);return t.length>0?t:void 0}async function le(e=document,t={}){const n=Array.from(e.querySelectorAll("[data-tinyfly-embed]"));return(await Promise.all(n.map(i=>oe(i,t)))).filter(i=>i!==void 0)}function Gn(e){const t=ot.get(e);t&&(Mt.get(e)?.(),Mt.delete(e),t.controls?.destroy(),t.player.destroy(),ot.delete(e),e.removeAttribute("data-tinyfly-mounted"))}function Qn(e){const t=e.querySelector("svg");if(!t||t.hasAttribute("role")||t.hasAttribute("aria-hidden"))return;const n=e.getAttribute("data-alt"),s=e.querySelector("figcaption");t.setAttribute("role","img"),n?t.setAttribute("aria-label",n):s&&(s.id||=`tinyfly-caption-${++jn}`,t.setAttribute("aria-labelledby",s.id))}function Zn(){if(!(typeof document<"u"?document.currentScript:null)?.hasAttribute("data-tinyfly-auto"))return;const t=()=>{le()};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}function St(e){const t=new Set;for(const n of e.matchAll(/data-tinyfly\s*=\s*("([^"]*)"|'([^']*)')/g))t.add(n[2]??n[3]);return[...t]}function he(e,t={}){const n=[],s=l=>n.push({level:"error",message:l}),i=l=>n.push({level:"warning",message:l});if((e.formatVersion??1)>H)return s(`format version ${e.formatVersion} is newer than this tinyfly reads (${H})`),n;let r=0;try{r=rt(e).duration}catch(l){return s(`the timeline does not load: ${l instanceof Error?l.message:String(l)}`),n}const a=e.config?.duration;if(a!==void 0)for(const l of e.tracks){if(!("keyframes"in l))continue;const u=l.keyframes.filter(h=>h.time>a);u.length>0&&s(`track "${l.id}" has a keyframe at ${u[0].time}ms, after the ${a}ms duration`)}const o=e.config?.markers??[],c=new Set;o.forEach((l,u)=>{c.has(l.id)&&s(`marker id "${l.id}" is used more than once`),c.add(l.id),(l.time<0||l.time>r)&&s(`marker "${l.id}" at ${l.time}ms is outside the animation (0–${r}ms)`),u>0&&l.time<o[u-1].time&&s(`marker "${l.id}" comes before "${o[u-1].id}" in time; list markers in order`)});for(const[l,u]of Object.entries(e.captions??{})){for(const h of Object.keys(u))c.has(h)||s(`caption "${h}" (${l}) has no marker with that id`);for(const h of c)h in u||i(`marker "${h}" has no ${l} caption; its label is shown instead`)}if(t.markup!==void 0){const l=new Set(St(t.markup)),u=new Set;for(const h of e.tracks)for(const d of[h.target,...h.targets??[]])u.add(d),l.has(d)||s(`track "${h.id}" targets "${d}", but no element has data-tinyfly="${d}"`);for(const h of l)u.has(h)||i(`data-tinyfly="${h}" is never animated`)}return n}function Kn(e){const t=new Set;for(const n of e.matchAll(/data-tinyfly-choose\s*=\s*("([^"]*)"|'([^']*)')/g))t.add(n[2]??n[3]);return[...t]}function Jn(e,t={}){const n=[];e.length===1&&n.push({level:"warning",message:"only one scenario, so the reader has nothing to choose"});const s=new Set,i=new Set;for(const r of e){if(s.has(r.id)){n.push({level:"error",message:`scenario id "${r.id}" is used more than once`});continue}s.add(r.id);for(const a of he(r.timeline,t))/is never animated$/.test(a.message)||n.push({level:a.level,message:`scenario "${r.id}": ${a.message}`});for(const a of r.timeline.tracks)for(const o of[a.target,...a.targets??[]])i.add(o)}if(t.markup!==void 0){for(const r of Kn(t.markup))s.has(r)||n.push({level:"error",message:`data-tinyfly-choose="${r}" names no scenario`});for(const r of St(t.markup))i.has(r)||n.push({level:"warning",message:`data-tinyfly="${r}" is never animated in any scenario`})}return n}function ts(e,t,n="end"){const s=rt(t),i=t.config?.markers??[],r=n==="start"?0:n==="end"?s.duration:typeof n=="number"?n:i.find(d=>d.id===n)?.time??s.duration,a=s.getStateAtTime(Math.max(0,Math.min(s.duration,r))),o=new wt,c=new Map,l=ns(e);for(const d of e.matchAll(ue)){const f=/data-tinyfly\s*=\s*("([^"]*)"|'([^']*)')/.exec(d[2]??"");if(!f)continue;const g=f[2]??f[3];if(c.has(g))continue;const p=es(l(d.index??0));c.set(g,p),o.registerTarget(g,p)}o.applyState(a);let u="",h=0;for(const d of e.matchAll(ue)){const[f,g,p="",m]=d,b=d.index??0,v=/data-tinyfly\s*=\s*("([^"]*)"|'([^']*)')/.exec(p),k=v?c.get(v[2]??v[3]):void 0;if(!k||Object.keys(k.style).length===0&&k.text===void 0)continue;u+=e.slice(h,b);const M=Object.entries(k.style).map(([x,P])=>`${ss(x)}: ${P}`).join("; "),y=/\sstyle\s*=\s*("([^"]*)"|'([^']*)')/.exec(p);let S=p;if(M)if(y){const x=`${(y[2]??y[3]).trim().replace(/;?$/,";")} ${M}`.trim();S=p.replace(y[0],` style="${de(x)}"`)}else S=`${p} style="${de(M)}"`;if(u+=`<${g}${S}${m?" /":""}>`,h=b+f.length,k.text!==void 0&&!m){const x=e.indexOf(`</${g}`,h),P=x===-1?"":e.slice(h,x);x!==-1&&!P.includes("<")&&(u+=is(k.text),h=x)}}return u+e.slice(h)}const ue=/<([a-zA-Z][\w:-]*)((?:\s+[^\s=>/]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+))?)*)\s*(\/?)>/g;function es(e){const t={style:{},dataset:{},namespaceURI:e?"http://www.w3.org/2000/svg":"http://www.w3.org/1999/xhtml",childNodes:[],get textContent(){return t.text??""},set textContent(n){t.text=n}};return e&&(t.ownerSVGElement=null),t}function ns(e){const t=[],n=/<svg[\s>]/gi;let s;for(;s=n.exec(e);){const i=e.toLowerCase().indexOf("</svg>",s.index);t.push([s.index+1,i===-1?e.length:i])}return i=>t.some(([r,a])=>i>r&&i<a)}function ss(e){const t=e.replace(/[A-Z]/g,n=>`-${n.toLowerCase()}`);return/^(webkit|moz|ms)-/.test(t)?`-${t}`:t}function de(e){return e.replace(/&/g,"&").replace(/"/g,""")}function is(e){return e.replace(/&/g,"&").replace(/</g,"<")}Zn(),$.DEFAULT_LABELS=ne,$.TinyflyPlayer=at,$.bindChoiceHotspots=ae,$.create=On,$.createControls=ie,$.mount=oe,$.mountAll=le,$.play=Ln,$.renderFrame=ts,$.targetNamesIn=St,$.unmount=Gn,$.validateEmbed=he,$.validateScenarios=Jn,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})})(this.tinyfly=this.tinyfly||{});
|
|
@@ -2188,7 +2188,7 @@ function Xn(e, t, n = {}) {
|
|
|
2188
2188
|
return $.type = "button", $.className = `tf-ctl-btn ${O}`.trim(), $.setAttribute("aria-label", w), $.title = w, $.textContent = E, $.addEventListener("click", N), $;
|
|
2189
2189
|
}, h = u(i.restart, "⟲", () => {
|
|
2190
2190
|
e.pause(), e.seek(0);
|
|
2191
|
-
}), d = u(i.prev, "
|
|
2191
|
+
}), d = u(i.prev, "|◀", () => e.prev()), f = u(i.play, "▶", () => e.isPlaying ? e.pause() : p(), "tf-ctl-primary"), g = u(i.next, "▶|", () => e.next()), p = () => {
|
|
2192
2192
|
e.currentTime >= e.duration - 0.5 && e.seek(0), e.play();
|
|
2193
2193
|
}, m = s.createElement("input");
|
|
2194
2194
|
m.type = "range", m.className = "tf-ctl-scrub", m.min = "0", m.max = "1000", m.step = "1", m.setAttribute("aria-label", i.scrub), m.addEventListener("input", () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algorisys/tinyfly",
|
|
3
|
-
"version": "0.70.
|
|
3
|
+
"version": "0.70.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Lightweight, API-driven animation engine and editor. The engine is framework-agnostic and runs in browsers, Web Workers, and Node.",
|
|
6
6
|
"license": "MIT",
|