UNPKG

various-ui

Version:

This is a test version of the Vue 3 component library

94 lines (90 loc) 3.36 kB
'use strict'; require('../dispose/boundary/index.js'); require('../dispose/size/index.js'); var relativeContainerBody = require('../dispose/boundary/src/relativeContainerBody.js'); var scrollbar = require('../dispose/size/src/scrollbar.js'); const use = (selector) => { if (typeof selector == "string") { return document.querySelector(`#${selector}`); } else { return selector; } }; const append = (selector, el) => { var _a; let container = use(selector); if (!container) { container = document.createElement("div"); container.id = selector; document.body.appendChild(container); } else { for (let i = 0, l = ((_a = container == null ? void 0 : container.children) == null ? void 0 : _a.length) || 0; i < l; i++) { if (el && (container == null ? void 0 : container.children[i]) == el) return; } } container.appendChild(el); }; const remove = (selector, el) => { var _a; const container = use(selector); for (let i = 0, l = ((_a = container == null ? void 0 : container.children) == null ? void 0 : _a.length) || 0; i < l; i++) { if (el && (container == null ? void 0 : container.children[i]) == el) { container.removeChild(el); break; } } }; const includes = (current, container) => { if (!current) return false; else if (current == container) { return true; } else { return includes(current.parentElement, container); } }; const menus = { open: (options) => { append(document.body, options.content); const observer = new ResizeObserver(() => { var _a, _b; const data = { container: options.container, view: options.content }; const config = options.option; const width = ((_a = options.container) == null ? void 0 : _a.offsetWidth) || 0; const widthExtra = Number(options.widthExtra); if (options.widthExtra == "auto" || widthExtra < width) config.width = { min: width, max: 0 }; else if (options.widthExtra == "content") config.width = width; else if (options.widthExtra && options.widthExtra > 0) { config.width = { min: width, max: widthExtra }; } relativeContainerBody.relativeContainerBody(data, config); (_b = options.handler) == null ? void 0 : _b.call(options); }); observer.observe(document.body); observer.observe(options.container); return observer; } }; const scrollbarHidden = (option) => { const config = { scrollbar: scrollbar.scrollbar(), overflow: document.body.style.overflow, spacing: { x: document.body.style.paddingRight, y: document.body.style.paddingBottom }, unit: (option == null ? void 0 : option.unit) || "px" }; if (config.scrollbar.x) { document.body.style.overflow = "hidden"; document.body.style.paddingRight = config.spacing.x ? `calc(${config.spacing.x}+${config.scrollbar.x}${config.unit})` : `${config.scrollbar.x}${config.unit}`; } if (config.scrollbar.y) { document.body.style.overflow = "hidden"; document.body.style.paddingBottom = config.spacing.y ? `calc(${config.spacing.y}+${config.scrollbar.y}${config.unit})` : `${config.scrollbar.y}${config.unit}`; } return config; }; exports.append = append; exports.includes = includes; exports.menus = menus; exports.remove = remove; exports.scrollbarHidden = scrollbarHidden; exports.use = use; //# sourceMappingURL=index.js.map