@ark-ui/vue
Version:
A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.
35 lines (34 loc) • 1.04 kB
JavaScript
import { Dynamic } from "../utils/dynamic.js";
import { defineComponent, h } from "vue";
//#region src/components/factory.ts
var SELF_CLOSING_TAGS = "br, hr, img, input, area, textarea".split(", ");
var isSelfClosingTag = (tag) => typeof tag === "string" && SELF_CLOSING_TAGS.includes(tag);
var withAsChild = (component) => {
return defineComponent({
name: "Polymorphic",
inheritAttrs: false,
props: { asChild: {
type: Boolean,
default: false
} },
setup(props, { attrs, slots }) {
if (!props.asChild) return () => h(component, attrs, isSelfClosingTag(component) ? void 0 : slots.default?.());
return () => h(Dynamic, attrs, slots);
}
});
};
function jsxFactory() {
const cache = /* @__PURE__ */ new Map();
return 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);
}
});
}
var ark = jsxFactory();
//#endregion
export { ark, jsxFactory };