UNPKG

lath

Version:

Seamless connection of pages.

140 lines 11.6 kB
import{_ as __awaiter,l as loadWebAnimations}from"./launcher-f761b2d6.js";import{s as setTimeout,S as SmoothScroller,c as clearAllAnimations,r as requestIdleCallback,w as waitAllAnimations}from"./index-553c4cec.js";const switcherCSSText=` box-sizing: border-box; position: fixed; top: 0px; right: 0px; bottom: 0px; left: 0px; z-index: 102; width: 100%; height: 100%; background: rgb(70 70 70 / 50%); opacity: 0; transform: translate3d(0, 0, 0); backface-visibility: hidden; transition: opacity .4s ease; backdrop-filter: blur(20px) saturate(180%); `,snapWrapperCSSText=` display: grid; box-sizing: border-box; position: fixed; top: 0px; right: 0px; bottom: 0px; left: 0px; z-index: 2; width: 100%; height: 100%; padding: 20px 10px; padding-top: calc(20px + constant(safe-area-inset-top)); padding-top: calc(20px + env(safe-area-inset-top)); scroll-padding-top: calc(20px + constant(safe-area-inset-top)); scroll-padding-top: calc(20px + env(safe-area-inset-top)); overflow-y: hidden; scroll-behavior: smooth; transform: translate3d(0, 0, 0); backface-visibility: hidden; `,snapWrapper2CSSText=` ${snapWrapperCSSText} grid-template-columns: 50% 50%; grid-template-rows: repeat(30, 40%); row-gap: 15px; `,snapWrapper3CSSText=` ${snapWrapperCSSText} grid-template-columns: repeat(3, 33.33%); grid-template-rows: repeat(30, 50%); row-gap: 15px; `,itemImgWrapperCSSText=` display: block; position: relative; width: 100%; height: 100%; border-radius: 16px; overflow: hidden; box-shadow: 0 3px 10px rgb(0 0 0 / 30%); `,itemViewCSSText=` display: flex; flex-direction: column; box-sizing: border-box; scroll-snap-align: start; cursor: pointer; margin: 0 10px; transition: transform .4s ease; `,itemImgCSSText=` display: block; width: 100%; height: 100%; border-radius: 16px; transform-origin: top left; transform: translate3d(0, 0, 0); backface-visibility: hidden; overflow: hidden; `,itemImgCoverCSSText=` position: fixed; top: 0; left: 0; ${itemImgCSSText} `,itemInfoCSSText=` display: flex; margin: 0 auto; width: 100%; justify-content: center; align-items: center; `,itemTitleCSSText=` margin-top: 4px; font-size: 16px; color: #fff; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-family: "SF Pro Text","Myriad Set Pro","SF Pro Icons","Apple Legacy Chevron","Helvetica","Arial",sans-serif; `,itemCloseBtnCSSText=` display: grid; place-items: center; position: absolute; right: 4px; top: 4px; width: 22px; height: 22px; border-radius: 11px; background-color: #666; opacity: .7 `,itemCloseBtnXShapeCSSText=` position: absolute; height: 2px; width: 60%; background: #fff; border-radius: 1px; `,itemCloseBtnX1ShapeCSSText=` ${itemCloseBtnXShapeCSSText} transform: rotate(-45deg); `,itemCloseBtnX2ShapeCSSText=` ${itemCloseBtnXShapeCSSText} transform: rotate(45deg); `,EASE={smoothAcceleration:"cubic-bezier(0.52, 0.16, 0.24, 1)",quickDeceleration:"cubic-bezier(0.32, 0.08, 0.24, 1)"},supportedBackdropFilter=CSS.supports("backdrop-filter","blur(1px)");class AppSwitcher{constructor(e){this.progressName="",this.deleteMap={},this.options={readonly:!1};var{relativeViewport:t,absoluteViewport:i,fixedViewport:s}=e.segue;this.relativeViewport=t,this.absoluteViewport=i,this.fixedViewport=s,this.application=e,this.delayDynamicImport()}bindResize(){const e=()=>{this.close(),window.removeEventListener("resize",e),window.removeEventListener("orientationchange",e)};window.addEventListener("resize",e),window.addEventListener("orientationchange",e)}open(e){return __awaiter(this,void 0,void 0,function*(){"open"!==this.progressName&&(this.progressName="open",e&&(this.options=e),yield loadWebAnimations(),yield this.createAppSwitcher(),supportedBackdropFilter||(yield this.blurBackgroundImage()),this.switcher.style.opacity="1",this.bindResize(),setTimeout(()=>{"close"!==this.progressName&&(this.progressName="")},400))})}close(){return __awaiter(this,void 0,void 0,function*(){"close"!==this.progressName&&(this.progressName="close",supportedBackdropFilter||(yield this.focusBackgroundImage()),this.switcher.style.opacity="0",setTimeout(()=>{"open"!==this.progressName&&(this.progressName="",this.switcher.parentElement===this.fixedViewport)&&this.fixedViewport.removeChild(this.switcher)},400))})}createAppSwitcher(){var x;return __awaiter(this,void 0,void 0,function*(){this.switcher=document.createElement("applet-switcher"),this.switcher.style.cssText=switcherCSSText,this.snapWrapper=document.createElement("applet-switcher-snap"),this.snapWrapper.style.cssText=800<this.switcher.offsetWidth?snapWrapper3CSSText:snapWrapper2CSSText,this.scroll=new SmoothScroller(this.snapWrapper);var e=this.application.applets,t=this.getActiveApplet(),i=null==(x=null==t?void 0:t.parentApplet)?void 0:x.allSubAppletIds;for(const p in e){const d=e[p];var s=d.color,r=null==i?void 0:i.includes(p);if(this.deleteMap[d.id]!==d.createTime&&("applet"===d.rel&&!d.isModality&&!d.slide&&d.view)){const c=document.createElement("applet-switcher-item"),h=document.createElement("div"),m=document.createElement("div");var a=document.createElement("div"),o=document.createElement("div"),n=document.createElement("div"),l=(c.style.cssText=itemViewCSSText,d.config.poster?` background-image: url(${d.config.poster}); background-size: cover; `:"");if(h.style.cssText=` ${itemImgWrapperCSSText} background: ${s}; ${l} `,m.style.cssText=` ${itemImgCSSText} background: ${s}; `,o.style.cssText=itemInfoCSSText,a.style.cssText=d.config.icon?` width: 16px; height: 16px; background-image: url(${d.config.icon}); `:"display: none;",n.style.cssText=itemTitleCSSText,n.innerText=d.config.title||d.id,o.appendChild(a),o.appendChild(n),h.appendChild(m),c.appendChild(h),c.appendChild(o),this.snapWrapper.appendChild(c),this.switcher.appendChild(this.snapWrapper),this.fixedViewport.appendChild(this.switcher),d.id===(null==t?void 0:t.id))yield this.setActivityItem(d,h,m);else{this.options.readonly||r||!0===d.config.background||d.isPresetAppletsView||(l=document.createElement("div"),s=document.createElement("div"),a=document.createElement("div"),l.style.cssText=itemCloseBtnCSSText,s.style.cssText=itemCloseBtnX1ShapeCSSText,a.style.cssText=itemCloseBtnX2ShapeCSSText,l.appendChild(s),l.appendChild(a),h.appendChild(l),l.addEventListener("click",()=>{var e;if(d.parentApplet){for(const t of d.parentApplet.allSubAppletIds)null!=(e=this.application.applets[t])&&e.destroy();d.parentApplet.destroy()}else d.destroy();this.deleteItem(c),this.deleteMap[d.id]=d.createTime},!1));const f=()=>{requestIdleCallback(()=>{this.setNormalItem(d,m)})},u=new IntersectionObserver(function(e){e[0].intersectionRatio<0||(u.unobserve(h),f())});u.observe(h)}this.bindItemClick(d,h,m)}}})}deleteItem(e){var t=[],i=Array.from(this.snapWrapper.children),s=i.indexOf(e),r=i.slice(s).filter(e=>!e.getAttribute("applet-to-delete"));for(let e=1;e<=r.length-1;e++){var a=r[e-1],o=r[e],a=a.getBoundingClientRect();t.push({x:a.x-o.offsetLeft,y:a.y-o.offsetTop})}e.setAttribute("applet-to-delete","true"),e.style.transform="translate3d(-100vw, 0, 0)";for(let e=1;e<=r.length-1;e++){var n=r[e],l=t[e-1];n.style.transform=`translate3d(${l.x}px, ${l.y}px, 0)`}}bindItemClick(e,t,i){i.addEventListener("click",()=>{"close"!==this.progressName&&(this.progressName="close",this.restoreToItem(e,t,i))})}setNormalItem(e,t){return __awaiter(this,void 0,void 0,function*(){e.captureShot(12e4<=Date.now()-e.visitTime).then(e=>__awaiter(this,void 0,void 0,function*(){e&&(t.appendChild(e),yield e.animate([{opacity:0},{opacity:.1}],{duration:0,easing:EASE.smoothAcceleration,fill:"forwards"}).finished,e.animate([{opacity:.1},{opacity:1}],{duration:300,easing:EASE.smoothAcceleration,fill:"forwards"}).play())})).catch(e=>{console.warn(e)})})}setActivityItem(o,n,l){return __awaiter(this,void 0,void 0,function*(){var e=o.color;const t=n.offsetWidth/this.switcher.offsetWidth,i=l.style.cssText,s=n.offsetHeight,r=n.offsetTop,a=n.offsetLeft;l.style.cssText=` ${itemImgCoverCSSText} z-index: 3; background: ${e}; border-radius: ${16/t}px; `,this.switcher.appendChild(l);e=yield o.captureShot();e&&l.appendChild(e),"close"!==this.progressName&&(yield l.animate([{opacity:0},{opacity:1}],{duration:100,easing:EASE.smoothAcceleration,fill:"forwards"}).finished,this.snapWrapper.animate({transform:"translate3d(0, 0, 0) scale(.9)",opacity:.5},{duration:0,fill:"forwards"}).finished.then(()=>__awaiter(this,void 0,void 0,function*(){yield Promise.all([l.animate({height:s/t+"px"},{duration:460,easing:EASE.smoothAcceleration,fill:"forwards"}).finished,l.animate({transform:`translate3d(${a}px, ${r}px, 0) scale(${t})`},{duration:360,easing:EASE.quickDeceleration,fill:"forwards"}).finished,this.snapWrapper.animate({transform:"translate3d(0, 0, 0) scale(1)"},{duration:440,easing:EASE.smoothAcceleration,fill:"forwards"}).finished,this.snapWrapper.animate({opacity:1},{duration:360,easing:EASE.smoothAcceleration,fill:"forwards"}).finished]),"close"!==this.progressName&&(l.style.cssText=i,clearAllAnimations(l),clearAllAnimations(n),n.appendChild(l),this.snapWrapper.style.overflowY="scroll",this.snapWrapper.style.scrollSnapType="y mandatory",this.snapWrapper.offsetHeight<=r)&&requestIdleCallback(()=>{this.scroll.snapTo(0,r)})})))})}restoreToItem(a,o,n){return __awaiter(this,void 0,void 0,function*(){var e=o.offsetTop,t=o.offsetLeft,i=o.offsetWidth,s=o.offsetHeight,i=i/this.switcher.offsetWidth,r=a.color;this.switcher.appendChild(n),n.style.cssText=` ${itemImgCoverCSSText} z-index: 5; height: ${s/i}px; background: ${r}; border-radius: ${16/i}px; transform: translate3d(${t}px, ${e}px, 0px) scale(${i}); `,"open"!==this.progressName&&(supportedBackdropFilter||this.application.segue.resetBaseStyle("filter: blur(20px);"),yield Promise.all([this.application.to(a.id,a.param,void 0,void 0,!0),n.animate({transform:"translate3d(0, 0, 0) scale(1)"},{duration:400,easing:EASE.quickDeceleration,fill:"forwards"}).finished,n.animate({height:this.switcher.offsetHeight+"px"},{duration:100,easing:EASE.smoothAcceleration,fill:"forwards"}).finished,n.animate({borderRadius:"0px"},{duration:800,easing:EASE.smoothAcceleration,fill:"forwards"}).finished,this.snapWrapper.animate({transform:"translate3d(0, 0, 0) scale(.9)"},{duration:440,easing:EASE.smoothAcceleration,fill:"forwards"}).finished,this.snapWrapper.animate({opacity:.5},{duration:200,easing:EASE.smoothAcceleration,fill:"forwards"}).finished]),supportedBackdropFilter||(this.application.segue.resetBaseStyle("filter: none;"),this.application.segue.appletGroup.forEach(e=>{e.viewport&&(e.viewport.style.filter="none",clearAllAnimations(e.viewport))})),this.progressName="",this.close())})}getActiveApplet(){var e=this.application.activityApplet;return null!=e&&e.slide?e.subApplet:e}blurBackgroundImage(e=!0){return __awaiter(this,void 0,void 0,function*(){yield waitAllAnimations(this.relativeViewport),yield waitAllAnimations(this.absoluteViewport),this.relativeViewport.style.filter=this.absoluteViewport.style.filter=e?"blur(20px)":"none",clearAllAnimations(this.relativeViewport),clearAllAnimations(this.absoluteViewport)})}focusBackgroundImage(){return __awaiter(this,void 0,void 0,function*(){yield this.blurBackgroundImage(!1)})}delayDynamicImport(){import("./index-1a219611.js").catch(e=>{console.warn(e)})}}export{AppSwitcher};