@ionic/core
Version:
Base components for Ionic
4 lines • 2.83 kB
JavaScript
/*!
* (C) Ionic http://ionicframework.com - MIT License
*/
import{w as t}from"./p-ZjP4CjeZ.js";import{r as o}from"./p-B4IBdPVJ.js";import{i as n}from"./p-Dojwmvde.js";const e=(n,e,i)=>{let r;const s=()=>void 0!==e()&&void 0===n.label&&null!==i(),d=()=>{const o=e();if(void 0===o)return;if(!s())return void o.style.removeProperty("width");const a=i().scrollWidth;if(0===a&&null===o.offsetParent&&void 0!==t&&"IntersectionObserver"in t){if(void 0!==r)return;const t=r=new IntersectionObserver((o=>{1===o[0].intersectionRatio&&(d(),t.disconnect(),r=void 0)}),{threshold:.01,root:n});t.observe(o)}else o.style.setProperty("width",.75*a+"px")};return{calculateNotchWidth:()=>{s()&&o((()=>{d()}))},destroy:()=>{r&&(r.disconnect(),r=void 0)}}},i="skip-label-transition",r=(t,e,r,s)=>{let d,a,c,v,l,u,f;const m=t=>Math.round(10*t)/10,h=()=>{void 0===v&&(v=o((()=>{v=void 0;const{adjustment:d,startEndWidth:a}=(()=>{const o=e();if(!o||!s())return{adjustment:"",startEndWidth:""};const i=m(o.getBoundingClientRect().width),d=m(r()?.getBoundingClientRect().width??0),a=n(t)?"":"-";return{adjustment:i?`${a}${i}px`:"0px",startEndWidth:`${m(i+d)}px`}})();a!==f&&(t.style.setProperty("--internal-start-end-container-width",a),f=a),d!==u&&(void 0!==l&&cancelAnimationFrame(l),t.classList.add(i),t.style.setProperty("--internal-start-container-adjustment",d),u=d,l=o((()=>{l=void 0,t.classList.remove(i)}))),b()})))},p=()=>{d&&(d.disconnect(),d=void 0,a=void 0,c=void 0)},b=()=>{const t=e(),o=r();t&&s()?"function"!=typeof ResizeObserver||d&&a===t&&c===o||(p(),d=new ResizeObserver((()=>{h()})),a=t,d.observe(t),o&&(c=o,d.observe(o))):p()};return{calculateContainerWidths:()=>{h()},destroy:()=>{p(),void 0!==v&&(cancelAnimationFrame(v),v=void 0),void 0!==l&&(cancelAnimationFrame(l),l=void 0,t.classList.remove(i)),u=void 0,f=void 0}}},s=(t,o)=>{const n=t.target.closest('[slot="start"], [slot="end"]');return null!==n&&n!==o&&o.contains(n)?n:null},d=(t,n)=>{let e=!1;return{handleClickCapture:i=>{if(((t,o)=>null!==s(t,o))(i,t))return e=!0,void o((()=>e=!1));if(void 0===n)return void(e&&(i.stopPropagation(),e=!1));const r=n();void 0!==r&&i.target===r&&(i.stopPropagation(),e||t.click(),e=!1)}}},a=(n,e,i)=>{let r,s;if(void 0!==t&&"MutationObserver"in t){const t=Array.isArray(e)?e:[e];r=new MutationObserver((n=>{for(const e of n)for(const n of e.addedNodes)if(n.nodeType===Node.ELEMENT_NODE&&t.includes(n.slot))return i(),void o((()=>d(n)))})),r.observe(n,{childList:!0,subtree:!0})}const d=t=>{s&&(s.disconnect(),s=void 0),s=new MutationObserver((t=>{i();for(const o of t)for(const t of o.removedNodes)t.nodeType===Node.ELEMENT_NODE&&t.slot===e&&a()})),s.observe(t.parentElement??t,{subtree:!0,childList:!0})},a=()=>{s&&(s.disconnect(),s=void 0)};return{destroy:()=>{r&&(r.disconnect(),r=void 0),a()}}};export{e as a,r as b,a as c,d,s as g}