UNPKG

@shopware-ag/meteor-component-library

Version:

The meteor component library is a Vue component library developed by Shopware. It is based on the [Meteor Design System](https://shopware.design/).

167 lines (166 loc) 5.14 kB
"use strict"; const floatingUi_dom = require("./floating-ui.dom-fe395b67.js"); const vue = require("vue"); function isComponentPublicInstance(target) { return target != null && typeof target === "object" && "$el" in target; } function unwrapElement(target) { if (isComponentPublicInstance(target)) { const element = target.$el; return floatingUi_dom.isNode(element) && floatingUi_dom.getNodeName(element) === "#comment" ? null : element; } return target; } function toValue(source) { return typeof source === "function" ? source() : vue.unref(source); } function arrow(options) { return { name: "arrow", options, fn(args) { const element = unwrapElement(toValue(options.element)); if (element == null) { return {}; } return floatingUi_dom.arrow({ element, padding: options.padding }).fn(args); } }; } function getDPR(element) { if (typeof window === "undefined") { return 1; } const win = element.ownerDocument.defaultView || window; return win.devicePixelRatio || 1; } function roundByDPR(element, value) { const dpr = getDPR(element); return Math.round(value * dpr) / dpr; } function useFloating(reference, floating, options) { if (options === void 0) { options = {}; } const whileElementsMountedOption = options.whileElementsMounted; const openOption = vue.computed(() => { var _toValue; return (_toValue = toValue(options.open)) != null ? _toValue : true; }); const middlewareOption = vue.computed(() => toValue(options.middleware)); const placementOption = vue.computed(() => { var _toValue2; return (_toValue2 = toValue(options.placement)) != null ? _toValue2 : "bottom"; }); const strategyOption = vue.computed(() => { var _toValue3; return (_toValue3 = toValue(options.strategy)) != null ? _toValue3 : "absolute"; }); const transformOption = vue.computed(() => { var _toValue4; return (_toValue4 = toValue(options.transform)) != null ? _toValue4 : true; }); const referenceElement = vue.computed(() => unwrapElement(reference.value)); const floatingElement = vue.computed(() => unwrapElement(floating.value)); const x = vue.ref(0); const y = vue.ref(0); const strategy = vue.ref(strategyOption.value); const placement = vue.ref(placementOption.value); const middlewareData = vue.shallowRef({}); const isPositioned = vue.ref(false); const floatingStyles = vue.computed(() => { const initialStyles = { position: strategy.value, left: "0", top: "0" }; if (!floatingElement.value) { return initialStyles; } const xVal = roundByDPR(floatingElement.value, x.value); const yVal = roundByDPR(floatingElement.value, y.value); if (transformOption.value) { return { ...initialStyles, transform: "translate(" + xVal + "px, " + yVal + "px)", ...getDPR(floatingElement.value) >= 1.5 && { willChange: "transform" } }; } return { position: strategy.value, left: xVal + "px", top: yVal + "px" }; }); let whileElementsMountedCleanup; function update() { if (referenceElement.value == null || floatingElement.value == null) { return; } const open = openOption.value; floatingUi_dom.computePosition(referenceElement.value, floatingElement.value, { middleware: middlewareOption.value, placement: placementOption.value, strategy: strategyOption.value }).then((position) => { x.value = position.x; y.value = position.y; strategy.value = position.strategy; placement.value = position.placement; middlewareData.value = position.middlewareData; isPositioned.value = open !== false; }); } function cleanup() { if (typeof whileElementsMountedCleanup === "function") { whileElementsMountedCleanup(); whileElementsMountedCleanup = void 0; } } function attach() { cleanup(); if (whileElementsMountedOption === void 0) { update(); return; } if (referenceElement.value != null && floatingElement.value != null) { whileElementsMountedCleanup = whileElementsMountedOption(referenceElement.value, floatingElement.value, update); return; } } function reset() { if (!openOption.value) { isPositioned.value = false; } } vue.watch([middlewareOption, placementOption, strategyOption, openOption], update, { flush: "sync" }); vue.watch([referenceElement, floatingElement], attach, { flush: "sync" }); vue.watch(openOption, reset, { flush: "sync" }); if (vue.getCurrentScope()) { vue.onScopeDispose(cleanup); } return { x: vue.shallowReadonly(x), y: vue.shallowReadonly(y), strategy: vue.shallowReadonly(strategy), placement: vue.shallowReadonly(placement), middlewareData: vue.shallowReadonly(middlewareData), isPositioned: vue.shallowReadonly(isPositioned), floatingStyles, update }; } exports.arrow = arrow; exports.useFloating = useFloating; //# sourceMappingURL=floating-ui.vue-48d5c774.js.map