ENH: model info display UI

Change-Id: I066c0e7f8ce87ec00b1141a1b44430444a819b42
(cherry picked from commit 05907a1a42da82737090d55046974d401f8af057)
This commit is contained in:
zorro.zhang 2023-02-17 19:51:28 +08:00 committed by Lane.Wei
parent 0cc953ad41
commit b4ffa91cb4
343 changed files with 54828 additions and 2 deletions

View file

@ -0,0 +1,75 @@
import { getWindow } from 'ssr-window';
export default function Observer({
swiper,
extendParams,
on,
emit
}) {
const observers = [];
const window = getWindow();
const attach = (target, options = {}) => {
const ObserverFunc = window.MutationObserver || window.WebkitMutationObserver;
const observer = new ObserverFunc(mutations => {
// The observerUpdate event should only be triggered
// once despite the number of mutations. Additional
// triggers are redundant and are very costly
if (mutations.length === 1) {
emit('observerUpdate', mutations[0]);
return;
}
const observerUpdate = function observerUpdate() {
emit('observerUpdate', mutations[0]);
};
if (window.requestAnimationFrame) {
window.requestAnimationFrame(observerUpdate);
} else {
window.setTimeout(observerUpdate, 0);
}
});
observer.observe(target, {
attributes: typeof options.attributes === 'undefined' ? true : options.attributes,
childList: typeof options.childList === 'undefined' ? true : options.childList,
characterData: typeof options.characterData === 'undefined' ? true : options.characterData
});
observers.push(observer);
};
const init = () => {
if (!swiper.params.observer) return;
if (swiper.params.observeParents) {
const containerParents = swiper.$el.parents();
for (let i = 0; i < containerParents.length; i += 1) {
attach(containerParents[i]);
}
} // Observe container
attach(swiper.$el[0], {
childList: swiper.params.observeSlideChildren
}); // Observe wrapper
attach(swiper.$wrapperEl[0], {
attributes: false
});
};
const destroy = () => {
observers.forEach(observer => {
observer.disconnect();
});
observers.splice(0, observers.length);
};
extendParams({
observer: false,
observeParents: false,
observeSlideChildren: false
});
on('init', init);
on('destroy', destroy);
}

View file

@ -0,0 +1,68 @@
import { getWindow } from 'ssr-window';
export default function Resize({
swiper,
on,
emit
}) {
const window = getWindow();
let observer = null;
const resizeHandler = () => {
if (!swiper || swiper.destroyed || !swiper.initialized) return;
emit('beforeResize');
emit('resize');
};
const createObserver = () => {
if (!swiper || swiper.destroyed || !swiper.initialized) return;
observer = new ResizeObserver(entries => {
const {
width,
height
} = swiper;
let newWidth = width;
let newHeight = height;
entries.forEach(({
contentBoxSize,
contentRect,
target
}) => {
if (target && target !== swiper.el) return;
newWidth = contentRect ? contentRect.width : (contentBoxSize[0] || contentBoxSize).inlineSize;
newHeight = contentRect ? contentRect.height : (contentBoxSize[0] || contentBoxSize).blockSize;
});
if (newWidth !== width || newHeight !== height) {
resizeHandler();
}
});
observer.observe(swiper.el);
};
const removeObserver = () => {
if (observer && observer.unobserve && swiper.el) {
observer.unobserve(swiper.el);
observer = null;
}
};
const orientationChangeHandler = () => {
if (!swiper || swiper.destroyed || !swiper.initialized) return;
emit('orientationchange');
};
on('init', () => {
if (swiper.params.resizeObserver && typeof window.ResizeObserver !== 'undefined') {
createObserver();
return;
}
window.addEventListener('resize', resizeHandler);
window.addEventListener('orientationchange', orientationChangeHandler);
});
on('destroy', () => {
removeObserver();
window.removeEventListener('resize', resizeHandler);
window.removeEventListener('orientationchange', orientationChangeHandler);
});
}