UNPKG

@ark-ui/vue

Version:

A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.

40 lines (39 loc) 1.33 kB
let vue = require("vue"); let _zag_js_utils = require("@zag-js/utils"); //#region src/utils/use-scope-id.ts function hasVnodeScopeId(vnode) { if (vnode === null || typeof vnode !== "object") return false; const vnodeObj = vnode; return (0, _zag_js_utils.hasProp)(vnodeObj, "scopeId") && (0, _zag_js_utils.isString)(vnodeObj.scopeId); } function hasTypeScopeId(type) { if (type === null || typeof type !== "object") return false; const typeObj = type; return (0, _zag_js_utils.hasProp)(typeObj, "__scopeId") && (0, _zag_js_utils.isString)(typeObj.__scopeId); } /** * Get scope ID from a component instance. */ function getScopeIdFromInstance(instance) { if (hasVnodeScopeId(instance.vnode)) return instance.vnode.scopeId; if (hasTypeScopeId(instance.type)) return instance.type.__scopeId; } /** * Access scope ID for scoped styles from parent component. * We need to traverse up the component tree to find a parent with scoped styles. */ function useScopeId() { const instance = (0, vue.getCurrentInstance)(); if (!instance) return; let scopeId = getScopeIdFromInstance(instance); if (!scopeId && instance.parent) { let parent = instance.parent; while (parent && !scopeId) { scopeId = getScopeIdFromInstance(parent); parent = parent.parent; } } return scopeId; } //#endregion exports.useScopeId = useScopeId;