@zoff-tech/zt-bottom-drawer
Version:
Bottom Drawer / Web Component
75 lines (72 loc) • 2.44 kB
JavaScript
import { c as componentOnReady } from './helpers.js';
/*!
* (C) Ionic http://ionicframework.com - MIT License
*/
const ION_CONTENT_TAG_NAME = 'ION-CONTENT';
const ION_CONTENT_ELEMENT_SELECTOR = 'ion-content';
const ION_CONTENT_CLASS_SELECTOR = '.ion-content-scroll-host';
/**
* Selector used for implementations reliant on `<ion-content>` for scroll event changes.
*
* Developers should use the `.ion-content-scroll-host` selector to target the element emitting
* scroll events. With virtual scroll implementations this will be the host element for
* the scroll viewport.
*/
const ION_CONTENT_SELECTOR = `${ION_CONTENT_ELEMENT_SELECTOR}, ${ION_CONTENT_CLASS_SELECTOR}`;
const isIonContent = (el) => el.tagName === ION_CONTENT_TAG_NAME;
/**
* Waits for the element host fully initialize before
* returning the inner scroll element.
*
* For `ion-content` the scroll target will be the result
* of the `getScrollElement` function.
*
* For custom implementations it will be the element host
* or a selector within the host, if supplied through `scrollTarget`.
*/
const getScrollElement = async (el) => {
if (isIonContent(el)) {
await new Promise((resolve) => componentOnReady(el, resolve));
return el.getScrollElement();
}
return el;
};
/**
* Queries the closest element matching the selector for IonContent.
*/
const findClosestIonContent = (el) => {
return el.closest(ION_CONTENT_SELECTOR);
};
/**
* Scrolls to the top of the element. If an `ion-content` is found, it will scroll
* using the public API `scrollToTop` with a duration.
*/
// TODO(FW-2832): type
const scrollToTop = (el, durationMs) => {
if (isIonContent(el)) {
const content = el;
return content.scrollToTop(durationMs);
}
return Promise.resolve(el.scrollTo({
top: 0,
left: 0,
behavior: durationMs > 0 ? 'smooth' : 'auto',
}));
};
/**
* Scrolls by a specified X/Y distance in the component. If an `ion-content` is found, it will scroll
* using the public API `scrollByPoint` with a duration.
*/
const scrollByPoint = (el, x, y, durationMs) => {
if (isIonContent(el)) {
const content = el;
return content.scrollByPoint(x, y, durationMs);
}
return Promise.resolve(el.scrollBy({
top: y,
left: x,
behavior: durationMs > 0 ? 'smooth' : 'auto',
}));
};
export { scrollByPoint as a, findClosestIonContent as f, getScrollElement as g, scrollToTop as s };
//# sourceMappingURL=index6.js.map