UNPKG

@loke/ui

Version:
2 lines (1 loc) 5.66 kB
var __create=Object.create;var{getPrototypeOf:__getProtoOf,defineProperty:__defProp,getOwnPropertyNames:__getOwnPropNames,getOwnPropertyDescriptor:__getOwnPropDesc}=Object,__hasOwnProp=Object.prototype.hasOwnProperty;function __accessProp(key){return this[key]}var __toESMCache_node,__toESMCache_esm,__toESM=(mod,isNodeMode,target)=>{var canCache=mod!=null&&typeof mod==="object";if(canCache){var cache=isNodeMode?__toESMCache_node??=new WeakMap:__toESMCache_esm??=new WeakMap,cached=cache.get(mod);if(cached)return cached}target=mod!=null?__create(__getProtoOf(mod)):{};let to=isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target;for(let key of __getOwnPropNames(mod))if(!__hasOwnProp.call(to,key))__defProp(to,key,{get:__accessProp.bind(mod,key),enumerable:!0});if(canCache)cache.set(mod,to);return to},__toCommonJS=(from)=>{var entry=(__moduleCache??=new WeakMap).get(from),desc;if(entry)return entry;if(entry=__defProp({},"__esModule",{value:!0}),from&&typeof from==="object"||typeof from==="function"){for(var key of __getOwnPropNames(from))if(!__hasOwnProp.call(entry,key))__defProp(entry,key,{get:__accessProp.bind(from,key),enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable})}return __moduleCache.set(from,entry),entry},__moduleCache;var __returnValue=(v)=>v;function __exportSetter(name,newValue){this[name]=__returnValue.bind(null,newValue)}var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0,configurable:!0,set:__exportSetter.bind(all,name)})};var exports_slot={};__export(exports_slot,{createSlottable:()=>createSlottable,createSlot:()=>createSlot,Slottable:()=>Slottable,Slot:()=>Slot,Root:()=>Slot});module.exports=__toCommonJS(exports_slot);var import_compose_refs=require("@loke/ui/compose-refs"),import_react=__toESM(require("react")),jsx_runtime=require("react/jsx-runtime"),REACT_LAZY_TYPE=Symbol.for("react.lazy"),use=import_react.default[" use ".trim().toString()];function isPromiseLike(value){return typeof value==="object"&&value!==null&&"then"in value}function isLazyComponent(element){return element!=null&&typeof element==="object"&&"$$typeof"in element&&element.$$typeof===REACT_LAZY_TYPE&&"_payload"in element&&isPromiseLike(element._payload)}function createSlot(ownerName){let SlotClone=createSlotClone(ownerName),Slot=import_react.default.forwardRef((props,forwardedRef)=>{let{children,...slotProps}=props;if(isLazyComponent(children)&&typeof use==="function")children=use(children._payload);let childrenArray=import_react.default.Children.toArray(children),slottable=childrenArray.find(isSlottable);if(slottable){let newElement=slottable.props.children,newChildren=childrenArray.map((child)=>{if(child===slottable){if(import_react.default.Children.count(newElement)>1)return import_react.default.Children.only(null);return import_react.default.isValidElement(newElement)?newElement.props.children:null}return child});return jsx_runtime.jsx(SlotClone,{...slotProps,ref:forwardedRef,children:import_react.default.isValidElement(newElement)?import_react.default.cloneElement(newElement,void 0,newChildren):null})}return jsx_runtime.jsx(SlotClone,{...slotProps,ref:forwardedRef,children})});return Slot.displayName=`${ownerName}.Slot`,Slot}var Slot=createSlot("Slot");function createSlotClone(ownerName){let SlotClone=import_react.default.forwardRef((props,forwardedRef)=>{let{children,...slotProps}=props;if(isLazyComponent(children)&&typeof use==="function")children=use(children._payload);if(import_react.default.isValidElement(children)){let childrenRef=getElementRef(children),mergedProps=mergeProps(slotProps,children.props);if(children.type!==import_react.default.Fragment)mergedProps.ref=forwardedRef?import_compose_refs.composeRefs(forwardedRef,childrenRef):childrenRef;return import_react.default.cloneElement(children,mergedProps)}return import_react.default.Children.count(children)>1?import_react.default.Children.only(null):null});return SlotClone.displayName=`${ownerName}.SlotClone`,SlotClone}var SLOTTABLE_IDENTIFIER=Symbol("loke.slottable");function createSlottable(ownerName){let Slottable=({children})=>{return jsx_runtime.jsx(jsx_runtime.Fragment,{children})};return Slottable.displayName=`${ownerName}.Slottable`,Slottable.__lokeId=SLOTTABLE_IDENTIFIER,Slottable}var Slottable=createSlottable("Slottable"),HANDLER_REGEX=/^on[A-Z]/;function isSlottable(child){return import_react.default.isValidElement(child)&&typeof child.type==="function"&&"__lokeId"in child.type&&child.type.__lokeId===SLOTTABLE_IDENTIFIER}function mergeProps(slotProps,childProps){let overrideProps={...childProps};for(let propName in childProps){if(!Object.hasOwn(childProps,propName))continue;let slotPropValue=slotProps[propName],childPropValue=childProps[propName];if(HANDLER_REGEX.test(propName)){if(slotPropValue&&childPropValue)overrideProps[propName]=(...args)=>{let result=childPropValue(...args);return slotPropValue(...args),result};else if(slotPropValue)overrideProps[propName]=slotPropValue}else if(propName==="style")overrideProps[propName]={...slotPropValue,...childPropValue};else if(propName==="className")overrideProps[propName]=[slotPropValue,childPropValue].filter(Boolean).join(" ")}return{...slotProps,...overrideProps}}function getElementRef(element){let getter=Object.getOwnPropertyDescriptor(element.props,"ref")?.get,mayWarn=getter&&"isReactWarning"in getter&&getter.isReactWarning;if(mayWarn)return element.ref;if(getter=Object.getOwnPropertyDescriptor(element,"ref")?.get,mayWarn=getter&&"isReactWarning"in getter&&getter.isReactWarning,mayWarn)return element.props.ref;return element.props.ref||element.ref}