text: import { w as writeTask } from './chunk-d0403a2f.js';
  import { b as LIFECYCLE_WILL_LEAVE, L as LIFECYCLE_WILL_ENTER, a as LIFECYCLE_DID_ENTER, c as LIFECYCLE_DID_LEAVE } from './chunk-94c4865f.js';
  
  const iosTransitionAnimation = () => import('./ios.transition-3107e07c.js');
  const mdTransitionAnimation = () => import('./md.transition-90b00ffe.js');
  const transition = (opts) => {
      return new Promise((resolve, reject) => {
          writeTask(() => {
              beforeTransition(opts);
              runTransition(opts).then(result => {
                  if (result.animation) {
                      result.animation.destroy();
                  }
                  afterTransition(opts);
                  resolve(result);
              }, error => {
                  afterTransition(opts);
                  reject(error);
              });
          });
      });
  };
  const beforeTransition = (opts) => {
      const enteringEl = opts.enteringEl;
      const leavingEl = opts.leavingEl;
      setZIndex(enteringEl, leavingEl, opts.direction);
      if (opts.showGoBack) {
          enteringEl.classList.add('can-go-back');
      }
      else {
          enteringEl.classList.remove('can-go-back');
      }
      setPageHidden(enteringEl, false);
      if (leavingEl) {
          setPageHidden(leavingEl, false);
      }
  };
  const runTransition = async (opts) => {
      const animationBuilder = await getAnimationBuilder(opts);
      const ani = (animationBuilder)
          ? animation(animationBuilder, opts)
          : noAnimation(opts); // fast path for no animation
      return ani;
  };
  const afterTransition = (opts) => {
      const enteringEl = opts.enteringEl;
      const leavingEl = opts.leavingEl;
      enteringEl.classList.remove('ion-page-invisible');
      if (leavingEl !== undefined) {
          leavingEl.classList.remove('ion-page-invisible');
      }
  };
  const getAnimationBuilder = async (opts) => {
      if (!opts.leavingEl || !opts.animated || opts.duration === 0) {
          return undefined;
      }
      if (opts.animationBuilder) {
          return opts.animationBuilder;
      }
      const builder = (opts.mode === 'ios')
          ? (await iosTransitionAnimation()).iosTransitionAnimation
          : (await mdTransitionAnimation()).mdTransitionAnimation;
      return builder;
  };
  const animation = async (animationBuilder, opts) => {
      await waitForReady(opts, true);
      const trans = await import('./index-d9adb105.js').then(mod => mod.create(animationBuilder, opts.baseEl, opts));
      fireWillEvents(opts.enteringEl, opts.leavingEl);
      await playTransition(trans, opts);
      if (opts.progressCallback) {
          opts.progressCallback(undefined);
      }
      if (trans.hasCompleted) {
          fireDidEvents(opts.enteringEl, opts.leavingEl);
      }
      return {
          hasCompleted: trans.hasCompleted,
          animation: trans
      };
  };
  const noAnimation = async (opts) => {
      const enteringEl = opts.enteringEl;
      const leavingEl = opts.leavingEl;
      await waitForReady(opts, false);
      fireWillEvents(enteringEl, leavingEl);
      fireDidEvents(enteringEl, leavingEl);
      return {
          hasCompleted: true
      };
  };
  const waitForReady = async (opts, defaultDeep) => {
      const deep = opts.deepWait !== undefined ? opts.deepWait : defaultDeep;
      const promises = deep ? [
          deepReady(opts.enteringEl),
          deepReady(opts.leavingEl),
      ] : [
          shallowReady(opts.enteringEl),
          shallowReady(opts.leavingEl),
      ];
      await Promise.all(promises);
      await notifyViewReady(opts.viewIsReady, opts.enteringEl);
  };
  const notifyViewReady = async (viewIsReady, enteringEl) => {
      if (viewIsReady) {
          await viewIsReady(enteringEl);
      }
  };
  const playTransition = (trans, opts) => {
      const progressCallback = opts.progressCallback;
      const promise = new Promise(resolve => trans.onFinish(resolve));
      // cool, let's do this, start the transition
      if (progressCallback) {
          // this is a swipe to go back, just get the transition progress ready
          // kick off the swipe animation start
          trans.progressStart();
          progressCallback(trans);
      }
      else {
          // only the top level transition should actually start "play"
          // kick it off and let it play through
          // ******** DOM WRITE ****************
          trans.play();
      }
      // create a callback for when the animation is done
      return promise;
  };
  const fireWillEvents = (enteringEl, leavingEl) => {
      lifecycle(leavingEl, LIFECYCLE_WILL_LEAVE);
      lifecycle(enteringEl, LIFECYCLE_WILL_ENTER);
  };
  const fireDidEvents = (enteringEl, leavingEl) => {
      lifecycle(enteringEl, LIFECYCLE_DID_ENTER);
      lifecycle(leavingEl, LIFECYCLE_DID_LEAVE);
  };
  const lifecycle = (el, eventName) => {
      if (el) {
          const ev = new CustomEvent(eventName, {
              bubbles: false,
              cancelable: false,
          });
          el.dispatchEvent(ev);
      }
  };
  const shallowReady = (el) => {
      if (el && el.componentOnReady) {
          return el.componentOnReady();
      }
      return Promise.resolve();
  };
  const deepReady = async (el) => {
      const element = el;
      if (element) {
          if (element.componentOnReady != null) {
              const stencilEl = await element.componentOnReady();
              if (stencilEl != null) {
                  return;
              }
          }
          await Promise.all(Array.from(element.children).map(deepReady));
      }
  };
  const setPageHidden = (el, hidden) => {
      if (hidden) {
          el.setAttribute('aria-hidden', 'true');
          el.classList.add('ion-page-hidden');
      }
      else {
          el.hidden = false;
          el.removeAttribute('aria-hidden');
          el.classList.remove('ion-page-hidden');
      }
  };
  const setZIndex = (enteringEl, leavingEl, direction) => {
      if (enteringEl !== undefined) {
          enteringEl.style.zIndex = (direction === 'back')
              ? '99'
              : '101';
      }
      if (leavingEl !== undefined) {
          leavingEl.style.zIndex = '100';
      }
  };
  
  export { deepReady as d, lifecycle as l, setPageHidden as s, transition as t };
  