"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { clsx: () => clsx, createSlottableComponent: () => slottable, mergeProps: () => mergeProps, slottable: () => slottable, useSlot: () => useSlot }); module.exports = __toCommonJS(src_exports); // src/clsx.ts var concat = (a, b) => { return [a, b].filter(Boolean).join(" "); }; var castValue = (input) => { if (typeof input === "string" || typeof input === "number") { return `${input}`; } if (Array.isArray(input)) { return clsx(...input); } if (typeof input === "object") { let res = ""; for (let className in input) { if (input[className]) { res = concat(res, clsx(className)); } } return res; } return ""; }; var clsx = (...inputs) => { return inputs.reduce((acc, input) => { if (input) { const value = castValue(input); return concat(acc, value); } return acc; }, ""); }; // src/merge-props.ts var isPlainObject = (value) => { if (typeof value !== "object" || value === null) { return false; } const prototype = Object.getPrototypeOf(value); return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value); }; var mergeProps = (...inputs) => { if (inputs.length === 0) { return {}; } const initial = {}; return inputs.reduce((acc, input) => { if (typeof input !== "object" || Array.isArray(input)) { return acc; } for (const prop in input) { if (isPlainObject(input[prop]) && !Array.isArray(input[prop])) { acc[prop] = mergeProps( acc[prop], input[prop] ); } else if (typeof input[prop] === "function") { acc[prop] = input[prop]; } else { acc[prop] = structuredClone( input[prop] ); } } return acc; }, initial); }; // src/use-slot.ts var merger = (v) => { return v; }; function useSlot(name, params) { const { className, // base className for the slot component: defaultComponent, // default Component type ref, props: inProps, extraProps, classNameMergeFn = merger } = params; const { component: rootComponent, slots = { [name]: void 0 }, slotProps: inSlotProps = { [name]: void 0 }, ...other } = inProps; const slotProps = { [name]: void 0, ...inSlotProps }; const resolveComponentElement = () => { if (name === "root" && rootComponent) { return rootComponent; } if (slots[name]) { return slots[name]; } return defaultComponent; }; const componentElement = resolveComponentElement(); const slotClassName = classNameMergeFn( clsx( className ?? "", { [inProps.className]: name === "root" && !!inProps.className }, extraProps?.className ?? false, // TODO: weird warning here slotProps[name]?.className ) ); const props = Object.assign( // merge function recursively merges Array and Object values, // that means ref is being cloned rather then passed by reference mergeProps( name === "root" ? other : {}, extraProps, slotProps[name], slotClassName ? { className: slotClassName } : {} ), { ref } ); return [componentElement, props]; } // src/slottable.ts var import_react = require("react"); function slottable(render, displayName) { const Component = (0, import_react.forwardRef)( render ); Component.displayName = displayName ?? `@zemd/react-slottable/${render.name || "UnknownComponent"}`; return Component; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { clsx, createSlottableComponent, mergeProps, slottable, useSlot });