UNPKG

@acdh-oeaw/universalviewer

Version:

The Universal Viewer is a community-developed open source project on a mission to help you share your 📚📜📰📽️📻🗿 with the 🌎

2 lines (1 loc) 14 kB
import{a as v,b as k}from"./chunk-JUZN4GG2.js";import{a as R,b as B,c as b,d as G,e as g,g as j}from"./chunk-XRXKGH36.js";import{a as q}from"./chunk-TVVVZZ43.js";import{f as c}from"./chunk-4DAZ7WDM.js";import{a as x,e as O,i as S,l as D,n as T,o as A}from"./chunk-JFPB5N6O.js";import"./chunk-L67DAW3A.js";var y=function(s,e,t,n){return new(t||(t=Promise))(function(r,i){function u(o){try{a(n.next(o))}catch(h){i(h)}}function f(o){try{a(n.throw(o))}catch(h){i(h)}}function a(o){o.done?r(o.value):new t(function(h){h(o.value)}).then(u,f)}a((n=n.apply(s,e||[])).next())})},w=function(s,e){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},n,r,i,u;return u={next:f(0),throw:f(1),return:f(2)},typeof Symbol=="function"&&(u[Symbol.iterator]=function(){return this}),u;function f(o){return function(h){return a([o,h])}}function a(o){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,r&&(i=o[0]&2?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[o[0]&2,i.value]),o[0]){case 0:case 1:i=o;break;case 4:return t.label++,{value:o[1],done:!1};case 5:t.label++,r=o[1],o=[0];continue;case 7:o=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(o[0]===6||o[0]===2)){t=0;continue}if(o[0]===3&&(!i||o[1]>i[0]&&o[1]<i[3])){t.label=o[1];break}if(o[0]===6&&t.label<i[1]){t.label=i[1],i=o;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(o);break}i[2]&&t.ops.pop(),t.trys.pop();continue}o=e.call(s,t)}catch(h){o=[6,h],r=0}finally{n=i=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}},F=1,Y=2,E=3,I=function(){function s(e,t){this.component=e,this.params=t,this.state=F}return s.prototype.init=function(e){return y(this,void 0,void 0,function(){var t,n;return w(this,function(r){switch(r.label){case 0:return this.state=Y,this.element?[3,2]:(t=this.component,n=this,[4,q(this.delegate,e,t,["ion-page","ion-page-invisible"],this.params)]);case 1:n.element=r.sent(),r.label=2;case 2:return[2]}})})},s.prototype._destroy=function(){c(this.state!==E,"view state must be ATTACHED");var e=this.element;e&&(this.delegate?this.delegate.removeViewFromDom(e.parentElement,e):e.remove()),this.nav=void 0,this.state=E},s}(),N=function(s,e,t){if(!s||s.component!==e)return!1;var n=s.params;if(n===t||!n&&!t)return!0;if(!n||!t)return!1;var r=Object.keys(n),i=Object.keys(t);if(r.length!==i.length)return!1;for(var u=0,f=r;u<f.length;u++){var a=f[u];if(n[a]!==t[a])return!1}return!0},W=function(s,e){return s?s instanceof I?s:new I(s,e):null},_=function(s){return s.map(function(e){return e instanceof I?e:"page"in e?W(e.page,e.params):W(e,void 0)}).filter(function(e){return e!==null})},K=function(){function s(e){x(this,e),this.transInstr=[],this.animationEnabled=!0,this.useRouter=!1,this.isTransitioning=!1,this.destroyed=!1,this.views=[],this.animated=!0,this.ionNavWillLoad=S(this,"ionNavWillLoad",7),this.ionNavWillChange=S(this,"ionNavWillChange",3),this.ionNavDidChange=S(this,"ionNavDidChange",3)}return s.prototype.swipeGestureChanged=function(){this.gesture&&this.gesture.setDisabled(this.swipeGesture!==!0)},s.prototype.rootChanged=function(){this.root!==void 0&&(this.useRouter||this.setRoot(this.root,this.rootParams))},s.prototype.componentWillLoad=function(){if(this.useRouter=!!document.querySelector("ion-router")&&!this.el.closest("[no-router]"),this.swipeGesture===void 0){var e=A(this);this.swipeGesture=T.getBoolean("swipeBackEnabled",e==="ios")}this.ionNavWillLoad.emit()},s.prototype.componentDidLoad=function(){return y(this,void 0,void 0,function(){var e;return w(this,function(t){switch(t.label){case 0:return this.rootChanged(),e=this,[4,import("./swipe-back-5ccee2ef-VZEIAALR.js")];case 1:return e.gesture=t.sent().createSwipeBackGesture(this.el,this.canStart.bind(this),this.onStart.bind(this),this.onMove.bind(this),this.onEnd.bind(this)),this.swipeGestureChanged(),[2]}})})},s.prototype.componentDidUnload=function(){for(var e=0,t=this.views;e<t.length;e++){var n=t[e];g(n.element,b),n._destroy()}this.gesture&&(this.gesture.destroy(),this.gesture=void 0),this.transInstr.length=this.views.length=0,this.destroyed=!0},s.prototype.push=function(e,t,n,r){return this.queueTrns({insertStart:-1,insertViews:[{page:e,params:t}],opts:n},r)},s.prototype.insert=function(e,t,n,r,i){return this.queueTrns({insertStart:e,insertViews:[{page:t,params:n}],opts:r},i)},s.prototype.insertPages=function(e,t,n,r){return this.queueTrns({insertStart:e,insertViews:t,opts:n},r)},s.prototype.pop=function(e,t){return this.queueTrns({removeStart:-1,removeCount:1,opts:e},t)},s.prototype.popTo=function(e,t,n){var r={removeStart:-1,removeCount:-1,opts:t};return typeof e=="object"&&e.component?(r.removeView=e,r.removeStart=1):typeof e=="number"&&(r.removeStart=e+1),this.queueTrns(r,n)},s.prototype.popToRoot=function(e,t){return this.queueTrns({removeStart:1,removeCount:-1,opts:e},t)},s.prototype.removeIndex=function(e,t,n,r){return t===void 0&&(t=1),this.queueTrns({removeStart:e,removeCount:t,opts:n},r)},s.prototype.setRoot=function(e,t,n,r){return this.setPages([{page:e,params:t}],n,r)},s.prototype.setPages=function(e,t,n){return t==null&&(t={}),t.animated!==!0&&(t.animated=!1),this.queueTrns({insertStart:0,insertViews:e,removeStart:0,removeCount:-1,opts:t},n)},s.prototype.setRouteId=function(e,t,n){var r=this,i=this.getActiveSync();if(N(i,e,t))return Promise.resolve({changed:!1,element:i.element});var u,f=new Promise(function(l){return u=l}),a,o={updateURL:!1,viewIsReady:function(l){var d,p=new Promise(function(m){return d=m});return u({changed:!0,element:l,markVisible:function(){return y(r,void 0,void 0,function(){return w(this,function(m){switch(m.label){case 0:return d(),[4,a];case 1:return m.sent(),[2]}})})}}),p}};if(n==="root")a=this.setRoot(e,t,o);else{var h=this.views.find(function(l){return N(l,e,t)});h?a=this.popTo(h,Object.assign(Object.assign({},o),{direction:"back"})):n==="forward"?a=this.push(e,t,o):n==="back"&&(a=this.setRoot(e,t,Object.assign(Object.assign({},o),{direction:"back",animated:!0})))}return f},s.prototype.getRouteId=function(){return y(this,void 0,void 0,function(){var e;return w(this,function(t){return e=this.getActiveSync(),[2,e?{id:e.element.tagName,params:e.params,element:e.element}:void 0]})})},s.prototype.getActive=function(){return Promise.resolve(this.getActiveSync())},s.prototype.getByIndex=function(e){return Promise.resolve(this.views[e])},s.prototype.canGoBack=function(e){return Promise.resolve(this.canGoBackSync(e))},s.prototype.getPrevious=function(e){return Promise.resolve(this.getPreviousSync(e))},s.prototype.getLength=function(){return this.views.length},s.prototype.getActiveSync=function(){return this.views[this.views.length-1]},s.prototype.canGoBackSync=function(e){return e===void 0&&(e=this.getActiveSync()),!!(e&&this.getPreviousSync(e))},s.prototype.getPreviousSync=function(e){if(e===void 0&&(e=this.getActiveSync()),!!e){var t=this.views,n=t.indexOf(e);return n>0?t[n-1]:void 0}},s.prototype.queueTrns=function(e,t){if(this.isTransitioning&&e.opts!=null&&e.opts.skipIfBusy)return Promise.resolve(!1);var n=new Promise(function(r,i){e.resolve=r,e.reject=i});return e.done=t,e.insertViews&&e.insertViews.length===0&&(e.insertViews=void 0),this.transInstr.push(e),this.nextTrns(),n},s.prototype.success=function(e,t){if(this.destroyed){this.fireError("nav controller was destroyed",t);return}if(t.done&&t.done(e.hasCompleted,e.requiresTransition,e.enteringView,e.leavingView,e.direction),t.resolve(e.hasCompleted),t.opts.updateURL!==!1&&this.useRouter){var n=document.querySelector("ion-router");if(n){var r=e.direction==="back"?"back":"forward";n.navChanged(r)}}},s.prototype.failed=function(e,t){if(this.destroyed){this.fireError("nav controller was destroyed",t);return}this.transInstr.length=0,this.fireError(e,t)},s.prototype.fireError=function(e,t){t.done&&t.done(!1,!1,e),t.reject&&!this.destroyed?t.reject(e):t.resolve(!1)},s.prototype.nextTrns=function(){if(this.isTransitioning)return!1;var e=this.transInstr.shift();return e?(this.runTransition(e),!0):!1},s.prototype.runTransition=function(e){return y(this,void 0,void 0,function(){var t,n,r,i,u,f;return w(this,function(a){switch(a.label){case 0:if(a.trys.push([0,6,,7]),this.ionNavWillChange.emit(),this.isTransitioning=!0,this.prepareTI(e),t=this.getActiveSync(),n=this.getEnteringView(e,t),!t&&!n)throw new Error("no views in the stack to be removed");return n&&n.state===F?[4,n.init(this.el)]:[3,2];case 1:a.sent(),a.label=2;case 2:return this.postViewInit(n,t,e),r=(e.enteringRequiresTransition||e.leavingRequiresTransition)&&n!==t,r?[4,this.transition(n,t,e)]:[3,4];case 3:return u=a.sent(),[3,5];case 4:u={hasCompleted:!0,requiresTransition:!1},a.label=5;case 5:return i=u,this.success(i,e),this.ionNavDidChange.emit(),[3,7];case 6:return f=a.sent(),this.failed(f,e),[3,7];case 7:return this.isTransitioning=!1,this.nextTrns(),[2]}})})},s.prototype.prepareTI=function(e){var t=this.views.length;if(e.opts=e.opts||{},e.opts.delegate===void 0&&(e.opts.delegate=this.delegate),e.removeView!==void 0){c(e.removeStart!==void 0,"removeView needs removeStart"),c(e.removeCount!==void 0,"removeView needs removeCount");var n=this.views.indexOf(e.removeView);if(n<0)throw new Error("removeView was not found");e.removeStart+=n}e.removeStart!==void 0&&(e.removeStart<0&&(e.removeStart=t-1),e.removeCount<0&&(e.removeCount=t-e.removeStart),e.leavingRequiresTransition=e.removeCount>0&&e.removeStart+e.removeCount===t),e.insertViews&&((e.insertStart<0||e.insertStart>t)&&(e.insertStart=t),e.enteringRequiresTransition=e.insertStart===t);var r=e.insertViews;if(r){c(r.length>0,"length can not be zero");var i=_(r);if(i.length===0)throw new Error("invalid views to insert");for(var u=0,f=i;u<f.length;u++){var a=f[u];a.delegate=e.opts.delegate;var o=a.nav;if(o&&o!==this)throw new Error("inserted view was already inserted");if(a.state===E)throw new Error("inserted view was already destroyed")}e.insertViews=i}},s.prototype.getEnteringView=function(e,t){var n=e.insertViews;if(n!==void 0)return n[n.length-1];var r=e.removeStart;if(r!==void 0)for(var i=this.views,u=r+e.removeCount,f=i.length-1;f>=0;f--){var a=i[f];if((f<r||f>=u)&&a!==t)return a}},s.prototype.postViewInit=function(e,t,n){c(t||e,"Both leavingView and enteringView are null"),c(n.resolve,"resolve must be valid"),c(n.reject,"reject must be valid");var r=n.opts,i=n.insertViews,u=n.removeStart,f=n.removeCount,a;if(u!==void 0&&f!==void 0){c(u>=0,"removeStart can not be negative"),c(f>=0,"removeCount can not be negative"),a=[];for(var o=0;o<f;o++){var h=this.views[o+u];h&&h!==e&&h!==t&&a.push(h)}r.direction=r.direction||"back"}var l=this.views.length+(i!==void 0?i.length:0)-(f!==void 0?f:0);if(c(l>=0,"final balance can not be negative"),l===0)throw console.warn("You can't remove all the pages in the navigation stack. nav.pop() is probably called too many times.",this,this.el),new Error("navigation stack needs at least one root page");if(i){for(var d=n.insertStart,p=0,m=i;p<m.length;p++){var h=m[p];this.insertViewAt(h,d),d++}n.enteringRequiresTransition&&(r.direction=r.direction||"forward")}if(a&&a.length>0){for(var C=0,P=a;C<P.length;C++){var h=P[C];g(h.element,R),g(h.element,B),g(h.element,b)}for(var V=0,L=a;V<L.length;V++){var h=L[V];this.destroyView(h)}}},s.prototype.transition=function(e,t,n){return y(this,void 0,void 0,function(){var r,i,u,f,a,o,h,l=this;return w(this,function(d){switch(d.label){case 0:return r=n.opts,i=r.progressAnimation?function(p){return l.sbAni=p}:void 0,u=A(this),f=e.element,a=t&&t.element,o=Object.assign({mode:u,showGoBack:this.canGoBackSync(e),baseEl:this.el,animationBuilder:this.animation||r.animationBuilder||T.get("navAnimation"),progressCallback:i,animated:this.animated&&T.getBoolean("animated",!0),enteringEl:f,leavingEl:a},r),[4,G(o)];case 1:return h=d.sent().hasCompleted,[2,this.transitionFinish(h,e,t,r)]}})})},s.prototype.transitionFinish=function(e,t,n,r){var i=e?t:n;return i&&this.cleanup(i),{hasCompleted:e,requiresTransition:!0,enteringView:t,leavingView:n,direction:r.direction}},s.prototype.insertViewAt=function(e,t){var n=this.views,r=n.indexOf(e);r>-1?(c(e.nav===this,"view is not part of the nav"),n.splice(t,0,n.splice(r,1)[0])):(c(!e.nav,"nav is used"),e.nav=this,n.splice(t,0,e))},s.prototype.removeView=function(e){c(e.state===Y||e.state===E,"view state should be loaded or destroyed");var t=this.views,n=t.indexOf(e);c(n>-1,"view must be part of the stack"),n>=0&&t.splice(n,1)},s.prototype.destroyView=function(e){e._destroy(),this.removeView(e)},s.prototype.cleanup=function(e){if(!this.destroyed)for(var t=this.views,n=t.indexOf(e),r=t.length-1;r>=0;r--){var i=t[r],u=i.element;r>n?(g(u,b),this.destroyView(i)):r<n&&j(u,!0)}},s.prototype.canStart=function(){return!!this.swipeGesture&&!this.isTransitioning&&this.transInstr.length===0&&this.animationEnabled&&this.canGoBackSync()},s.prototype.onStart=function(){this.queueTrns({removeStart:-1,removeCount:1,opts:{direction:"back",progressAnimation:!0}},void 0)},s.prototype.onMove=function(e){this.sbAni&&this.sbAni.progressStep(e)},s.prototype.onEnd=function(e,t,n){var r=this;if(this.sbAni){this.animationEnabled=!1,this.sbAni.onFinish(function(){r.animationEnabled=!0},{oneTimeCallback:!0});var i=e?-.001:.001;e?i+=k(new v(0,0),new v(.32,.72),new v(0,1),new v(1,1),t):(this.sbAni.easing("cubic-bezier(1, 0, 0.68, 0.28)"),i+=k(new v(0,0),new v(1,0),new v(.68,.28),new v(1,1),t)),this.sbAni.progressEnd(e?1:0,i,n)}},s.prototype.render=function(){return O("slot",null)},Object.defineProperty(s.prototype,"el",{get:function(){return D(this)},enumerable:!0,configurable:!0}),Object.defineProperty(s,"watchers",{get:function(){return{swipeGesture:["swipeGestureChanged"],root:["rootChanged"]}},enumerable:!0,configurable:!0}),Object.defineProperty(s,"style",{get:function(){return":host{left:0;right:0;top:0;bottom:0;position:absolute;contain:layout size style;overflow:hidden;z-index:0}"},enumerable:!0,configurable:!0}),s}();export{K as ion_nav};