@ark-ui/vue
Version:
A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.
45 lines (40 loc) • 1.23 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const vue = require('vue');
const dynamic = require('../utils/dynamic.cjs');
const SELF_CLOSING_TAGS = "br, hr, img, input, area, textarea".split(", ");
const isSelfClosingTag = (tag) => typeof tag === "string" && SELF_CLOSING_TAGS.includes(tag);
const withAsChild = (component) => {
return vue.defineComponent({
name: "Polymorphic",
inheritAttrs: false,
props: {
asChild: {
type: Boolean,
default: false
}
},
setup(props, { attrs, slots }) {
if (!props.asChild) return () => vue.h(component, attrs, isSelfClosingTag(component) ? void 0 : slots.default?.());
return () => vue.h(dynamic.Dynamic, attrs, slots);
}
});
};
function jsxFactory() {
const cache = /* @__PURE__ */ new Map();
const factory = new Proxy(withAsChild, {
apply(_target, _thisArg, argArray) {
return withAsChild(argArray[0]);
},
get(_, element) {
if (!cache.has(element)) {
cache.set(element, withAsChild(element));
}
return cache.get(element);
}
});
return factory;
}
const ark = jsxFactory();
exports.ark = ark;
exports.jsxFactory = jsxFactory;
;