@meonode/ui
Version:
A structured approach to component composition, direct CSS-first prop styling, built-in theming, smart prop handling (including raw property pass-through), and dynamic children.
296 lines • 28.7 kB
JavaScript
"use strict";var _excluded=["ref","key","children","nodetheme","theme","props"],_excluded2=["style"],_excluded3=["style","css"],_excluded4=["style"],_excluded5=["children","key","nativeProps"];function _objectWithoutProperties(a,b){if(null==a)return{};var c,d,e=_objectWithoutPropertiesLoose(a,b);if(Object.getOwnPropertySymbols){var f=Object.getOwnPropertySymbols(a);for(d=0;d<f.length;d++)c=f[d],-1===b.indexOf(c)&&{}.propertyIsEnumerable.call(a,c)&&(e[c]=a[c])}return e}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c={};for(var d in a)if({}.hasOwnProperty.call(a,d)){if(-1!==b.indexOf(d))continue;c[d]=a[d]}return c}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _defineProperty(a,b,c){return(b=_toPropertyKey(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==_typeof(b)?b:b+""}function _toPrimitive(a,b){if("object"!=_typeof(a)||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=_typeof(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}import React,{createElement,Fragment,isValidElement}from"react";import{createStableHash,isNodeInstance,resolveDefaultStyle}from"./helper/node.helper.js";import{isForwardRef,isFragment,isMemo,isReactClassComponent,isValidElementType}from"./helper/react-is.helper.js";import{createRoot}from"react-dom/client";import{getComponentType,getCSSProps,getDOMProps,getElementTypeName,hasNoStyleTag}from"./helper/common.helper.js";import StyledRenderer from"./components/styled-renderer.client.js";import{resolveObjWithTheme}from"./helper/theme.helper.js";/**
* Represents a node in a React component tree with theme and styling capabilities.
* This class wraps React elements and handles:
* - Props processing and normalization
* - Theme inheritance and resolution
* - Child node processing and management
* - Style processing with theme variables
* @template E The type of React element or component this node represents
*/export class BaseNode{/**
* Constructs a new BaseNode instance.
*
* This constructor initializes a node with a given React element or component type
* and the raw props passed to it. The props are not processed until they are
* accessed via the `props` getter, allowing for lazy evaluation.
* @param element The React element or component type this node will represent.
* @param rawProps The initial, unprocessed props for the element.
*/constructor(a){var b=this,c=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{};/** The underlying React element or component type that this node represents *//** Original props passed during construction, preserved for cloning/recreation *//** Flag to identify BaseNode instances *//** DOM element used for portal rendering *//** React root instance for portal rendering *//**
* Generates a stable key for a node, especially for elements within an array.
*
* If an `existingKey` is provided, it is returned. Otherwise, a key is generated
* based on the element's type name and its index within a list of siblings.
* This helps prevent re-rendering issues in React when dealing with dynamic lists.
* @param options The options for key generation.
* @param options.nodeIndex The index of the node in an array of children.
* @param options.element The element for which to generate a key.
* @param options.existingKey An existing key, if one was already provided.
* @param options.children The children of the node, used to add complexity to the key.
* @returns A React key, or `undefined` if no key could be generated.
* @private
*//**
* Normalizes a processed child node into a final, renderable `ReactNode`.
*
* This method is called during the `render` phase. It takes a child that has already
* been processed by `_processChildren` and prepares it for `React.createElement`.
*
* - For `BaseNode` instances, it calls their `render()` method, ensuring the theme is consistent.
* - It validates that other children are valid React element types.
* - Primitives and other valid nodes are returned as-is.
* @param child The processed child node to normalize.
* @returns A renderable `ReactNode`.
* @throws {Error} If the child is not a valid React element type.
* @private
*/_defineProperty(this,"rawProps",{}),_defineProperty(this,"isBaseNode",!0),_defineProperty(this,"_portalDOMElement",null),_defineProperty(this,"_portalReactRoot",null),_defineProperty(this,"_generateKey",function(a){var b=a.nodeIndex,c=a.element,d=a.existingKey,e=a.children;if(d)return d;var f,g=getElementTypeName(c);return f=Array.isArray(e)&&0<e.length?void 0===b?"".concat(g,"-").concat(e.length):"".concat(g,"-").concat(b,"-").concat(e.length):void 0===b?g:"".concat(g,"-").concat(b),f}),_defineProperty(this,"_normalizeChild",function(a){var c,d;// Handle null/undefined quickly
if(null===a||a===void 0)return a;// Primitives should be returned as-is (text nodes, numbers, booleans)
var e=_typeof(a);if("string"===e||"number"===e||"boolean"===e)return a;var f=(null===(c=b.rawProps)||void 0===c?void 0:c.nodetheme)||(null===(d=b.rawProps)||void 0===d?void 0:d.theme)||b.props.nodetheme||b.props.theme;// For BaseNode instances, apply current theme if child has no theme
if(a instanceof BaseNode){var g;return null!==(g=a.rawProps)&&void 0!==g&&g.nodetheme||void 0===f?a.render():new BaseNode(a.element,_objectSpread(_objectSpread({},a.rawProps),{},{nodetheme:f})).render()}// Validate element type before returning
if(!isValidElementType(a)){var h=getComponentType(a);throw new Error("Invalid element type: ".concat(h," provided!"))}// Return valid React elements as-is
return a}),this.element=a,this.rawProps=c}/**
* Lazily processes and retrieves the final, normalized props for the node.
*
* The first time this getter is accessed, it triggers `_processProps` to resolve
* themes, styles, and children. Subsequent accesses return the cached result
* until the node is cloned or recreated.
* @returns The fully processed and normalized `FinalNodeProps`.
*/get props(){return this._props||(this._props=this._processProps()),this._props}/**
* Performs the core logic of processing raw props into their final, normalized form.
*
* This method is called by the `props` getter on its first access. It handles:
* 1. **Theme Resolution**: Selects the active theme from `theme` or `nodetheme` props.
* 2. **Prop Resolution**: Resolves theme-aware values (functions) in `rawProps` and `nativeProps.style`.
* 3. **Style Extraction**: Separates style-related props (`css`, `style`) from other DOM/component props.
* 4. **Default Style Merging**: Combines default styles with resolved style props.
* 5. **Child Processing**: Normalizes the `children` prop, propagating the theme.
* @returns The processed `FinalNodeProps` object.
* @private
*/_processProps(){// Destructure raw props into relevant parts
var a=this.rawProps,b=a.ref,c=a.key,d=a.children,e=a.nodetheme,f=a.theme,g=a.props,h=void 0===g?{}:g,i=_objectWithoutProperties(a,_excluded),j=f||e,k=h,l=k.style,m=_objectWithoutProperties(k,_excluded2),n=resolveObjWithTheme(i,j),o=resolveObjWithTheme(l,j),p=n.style,q=n.css,r=_objectWithoutProperties(n,_excluded3),s=getCSSProps(r),t=getDOMProps(r),u=resolveDefaultStyle(_objectSpread(_objectSpread({},s),p)),v=this._processChildren(d,j);// Process children while maintaining theme inheritance
// Combine processed props into final normalized form
return _objectSpread(_objectSpread({ref:b,key:c,nodetheme:j,theme:f,css:_objectSpread(_objectSpread({},u),q),style:o},t),{},{nativeProps:m,children:v})}/**
* Deeply clones processed children before returning them from cache so that each parent receives
* independent `BaseNode` instances (prevents sharing cycles and mutation bugs).
*
* - If the input is an array, each child is cloned recursively.
* - If the input is a `BaseNode`, a new instance is created with the same element and copied rawProps.
* - For other objects/primitives, the value is returned as-is (they are immutable or safe to reuse).
*
* This ensures that cached children are never shared between different parents in the React tree.
* @param processed The processed child or array of children to clone.
* @returns A deep clone of the processed children, safe for use in multiple parents.
* @private
*/static _cloneProcessedChildren(a){var b=function cloneOne(a){return a instanceof BaseNode?new BaseNode(a.element,_objectSpread({},a.rawProps)):a;// NodeInstance returns its own instances when render() is called - we avoid calling render here.
// For other objects/primitives, return as-is (they are immutable or safe to reuse).
};return Array.isArray(a)?a.map(function(a){return b(a)}):b(a)}/**
* Retrieves cached processed children for a given set of `children` and an optional `theme`.
*
* - Skips caching entirely when executed on the server (returns `null`).
* - Uses a **WeakMap** for identity-based caching when `children` is an object or array,
* ensuring garbage collection safety.
* - Falls back to a **Map** keyed by a stable hash of `children` and `theme`
* for value-based caching.
* - Only returns cached entries that are **not server-side**.
* @param children The child node(s) to resolve cached results for.
* @param theme The theme context that may influence child processing.
* @returns A cloned version of the cached processed children if available, otherwise `null`.
* @private
*/_getCachedChildren(a,b){if(BaseNode._isServer)return null;// No server caching
// Compute hash once
var c=createStableHash(a,b);// If children is an object (array or object), try identity-keyed WeakMap first
if(a&&"object"===_typeof(a)){var d=BaseNode._processedChildrenWeakCache.get(a);if(d&&d.hash===c&&!d.isServerSide)return BaseNode._cloneProcessedChildren(d.children)}// Fallback to string-hash Map cache
var e=BaseNode._processedChildrenMapCache.get(c);return e&&!e.isServerSide?BaseNode._cloneProcessedChildren(e.children):null}/**
* Caches processed children for a given set of children and theme.
* This method stores the processed NodeElement(s) in a Map keyed by a stable hash.
* The cache is bounded to avoid unbounded memory growth.
* No caching is performed on the server to avoid RSC issues.
* @param children The original children to cache.
* @param theme The theme associated with the children.
* @param processed The processed NodeElement(s) to cache.
* @private
*/_setCachedChildren(a,b,c){if(!BaseNode._isServer){var d=createStableHash(a,b);if(a&&"object"===_typeof(a))return void BaseNode._processedChildrenWeakCache.set(a,{hash:d,children:c,isServerSide:!1});// Manage bounded Map cache (FIFO eviction)
if(BaseNode._processedChildrenMapCache.has(d))return void BaseNode._processedChildrenMapCache.set(d,{children:c,isServerSide:!1});if(BaseNode._processedChildrenMapCache.size>=BaseNode._MAX_PROCESSED_CHILDREN_CACHE){var e=BaseNode._processedChildrenMapCache.keys().next().value;void 0!==e&&BaseNode._processedChildrenMapCache["delete"](e)}BaseNode._processedChildrenMapCache.set(d,{children:c,isServerSide:!1})}}/**
* Recursively processes raw children, converting them into `BaseNode` instances as needed
* and propagating the provided theme.
*
* This method ensures consistent theme handling for all children and optimizes performance
* using caching strategies: a Map for client-side and no caching for server-side.
*
* - If `children` is an array, each child is processed individually.
* - If `children` is a single node, it is processed directly.
* - The processed result is cached on the client to avoid redundant work.
* @param children The raw child or array of children to process.
* @param theme The theme to propagate to the children.
* @returns The processed children, ready for normalization and rendering.
* @private
*/_processChildren(a,b){var c=this;if(a){// Use RSC-safe caching strategy
var d=this._getCachedChildren(a,b);if(d)return d;var e=Array.isArray(a)?a.map(function(a,d){return c._processRawNode(a,b,d)}):this._processRawNode(a,b);// Only cache on client-side
return BaseNode._isServer||this._setCachedChildren(a,b,e),e}}/**
* Renders a processed `NodeElement` into a `ReactNode`, applying a theme and key if necessary.
*
* This static method centralizes the logic for converting various types of processed elements
* into renderable React nodes. It handles:
* - `BaseNode` instances: Re-wraps them to apply a new key or theme.
* - React class components: Wraps them in a new `BaseNode`.
* - `NodeInstance` objects: Invokes their `render()` method.
* - React component instances: Invokes their `render()` method.
* - Functional components: Creates a React element from them.
* - Other valid `ReactNode` types (strings, numbers, etc.): Returns them as-is.
* @param processedElement The node element to render.
* @param passedTheme The theme to propagate.
* @param passedKey The React key to assign.
* @returns A renderable `ReactNode`.
* @private
* @static
*/static _renderProcessedNode(a,b,c){var d={};// 1. BaseNode instance: re-wrap to apply key/theme if needed
if(void 0!==c&&(d.key=c),a instanceof BaseNode){var e,f,g,h,i,j=(null===(e=a.rawProps)||void 0===e?void 0:e.theme)||(null===(f=a.rawProps)||void 0===f?void 0:f.nodetheme)||b,k=null===(g=a.rawProps)||void 0===g?void 0:g.key;return k===c&&j===((null===(h=a.rawProps)||void 0===h?void 0:h.nodetheme)||(null===(i=a.rawProps)||void 0===i?void 0:i.theme))?a.render():new BaseNode(a.element,_objectSpread(_objectSpread(_objectSpread({},a.rawProps),d),{},{nodetheme:j})).render()}// 2. React class component type: wrap in BaseNode
return isReactClassComponent(a)?new BaseNode(a,d).render():isNodeInstance(a)?a.render():a instanceof React.Component?a.render():"function"==typeof a?createElement(a,{key:c}):a;// 3. NodeInstance object: call its render
// 4. React.Component instance: call its render
// 5. Functional component: create element with key
// 6. Other valid ReactNode types
}/**
* Renders the output of a function-as-a-child, ensuring theme propagation.
*
* This method is designed to handle "render prop" style children (`() => ReactNode`).
* It invokes the function, processes its result, and ensures the parent's theme is
* correctly passed down to any `BaseNode` instances returned by the function.
* @param props The properties for the function renderer.
* @param props.render The function to execute to get the child content.
* @param props.passedTheme The theme to propagate to the rendered child.
* @param props.processRawNode A reference to the `_processRawNode` method for recursive processing.
* @returns The rendered `ReactNode`.
* @private
*/_functionRenderer(a){var b,c=a.render,d=a.passedTheme,e=a.processRawNode;// Invoke the render function to get the child node.
try{b=c()}catch(a){b=null}// Handle React.Component instance
if(b instanceof React.Component){var f=b.render(),g=e(f,d);return BaseNode._renderProcessedNode(g,d)}// Handle BaseNode instance
if(b instanceof BaseNode||isNodeInstance(b)){var h,i=b;return void 0===(null===(h=i.rawProps)||void 0===h?void 0:h.nodetheme)&&void 0!==d?new BaseNode(i.element,_objectSpread(_objectSpread({},i.rawProps),{},{nodetheme:d})).render():i.render()}// Process other result types
var j=e(b,d);return j?BaseNode._renderProcessedNode(j,d):b}/**
* Processes a single raw node, recursively converting it into a `BaseNode` or other renderable type.
*
* This is a central method for normalizing children. It handles various types of input:
* - **`BaseNode` instances**: Re-creates them to ensure the correct theme and key are applied.
* - **Primitives**: Returns strings, numbers, booleans, null, and undefined as-is.
* - **Functions (Render Props)**: Wraps them in a `BaseNode` that uses `_functionRenderer` to delay execution.
* - **Valid React Elements**: Converts them into `BaseNode` instances, extracting props and propagating the theme.
* - **React Component Types**: Wraps them in a `BaseNode` with the parent theme.
* - **React Component Instances**: Renders them and processes the output recursively.
*
* It also generates a stable key for elements within an array if one is not provided.
* @param rawNode The raw child node to process.
* @param parentTheme The theme inherited from the parent.
* @param nodeIndex The index of the child if it is in an array, used for key generation.
* @returns A processed `NodeElement` (typically a `BaseNode` instance or a primitive).
* @private
*/_processRawNode(a,b,c// Index for generating stable keys for array children
){var d=getComponentType(a);// Determine the type of the raw node
// Case 1: Child is already a BaseNode instance
if(a instanceof BaseNode){var e=a,f=e.rawProps||{},g=f.theme||f.nodetheme||b;// Get initial raw props of the child
// Prefer child's own theme
// Check if we can reuse the existing node
if(f.nodetheme===g&&f.key!==void 0)return e;var h=this._generateKey({nodeIndex:c,element:e.element,existingKey:f.key,children:f.children});// Generate key if needed
return new BaseNode(e.element,_objectSpread(_objectSpread({},f),{},{nodetheme:g,// Use the determined theme for the new node
key:h}));// Create a new BaseNode with merged props and theme
}// Case 2: Child is a primitive (string, number, boolean, null, undefined)
if("string"===d||"number"===d||"boolean"===d||null===a||void 0===a)return a;// Case 3: Child is a function that needs to be called during render (FunctionRenderer).
if("function"===d&&!isReactClassComponent(a)&&!isMemo(a)&&!isForwardRef(a)){// The key is for the BaseNode that wraps the _functionRenderer component.
// Functions themselves don't have a .key prop that we can access here.
var i=this._generateKey({nodeIndex:c,element:this._functionRenderer});// Generate key for function renderer
return new BaseNode(this._functionRenderer,{processRawNode:this._processRawNode.bind(this),render:a,passedTheme:b,key:i})}// Case 4: Child is a React Element (JSX element like <div> or <MyComponent>)
if(isValidElement(a)){var j=a.props,k=j.style,l=_objectWithoutProperties(j,_excluded4),m=_objectSpread(_objectSpread({},l),k||{}),n=m.theme||m.nodetheme||b,o=this._generateKey({nodeIndex:c,element:a.type,existingKey:a.key,children:m.children});// Combine top-level props from the element with its flattened style object properties
return new BaseNode(a.type,_objectSpread(_objectSpread({},m),{},{// Pass the combined props
nodetheme:n,key:o}))}// Case 5: Child is an ElementType (string tag, class component, Memo/ForwardRef)
if(isReactClassComponent(a)||"object"===d&&(isMemo(a)||isForwardRef(a))){var p,q=this._generateKey({nodeIndex:c,element:a,children:"object"===_typeof(a)&&"props"in a?null===(p=a.props)||void 0===p?void 0:p.children:void 0});// ElementTypes don't have an intrinsic key from the rawNode itself.
return new BaseNode(a,{nodetheme:b,// Apply parent theme
key:q})}// Case 6: Handle instances of React.Component
if(a instanceof React.Component){var r=a.render();// Recursively process the rendered element with a parent theme and index if available
return this._processRawNode(r,b,c)}// Case 7: Fallback for other ReactNode types (e.g., Fragments, Portals if not caught by isValidElement)
// These are returned as-is. If they are elements within an array, React expects them to have keys.
// This logic primarily adds keys to BaseNode instances we create, other ReactNodes are returned as-is.
return a}/**
* Renders the `BaseNode` into a `ReactElement`.
*
* This method is the final step in the rendering pipeline. It constructs a React element
* by:
* 1. Validating that the node's `element` type is renderable.
* 2. Normalizing processed children into `ReactNode`s using `_normalizeChild`.
* 3. Caching normalized children to avoid re-processing on subsequent renders.
* 4. Assembling the final props, including `key`, `style`, and other attributes.
* 5. If the element has a `css` prop, it may be wrapped in a `StyledRenderer` to handle
* CSS-in-JS styling.
* 6. Finally, calling `React.createElement` with the element, props, and children.
* @returns The rendered `ReactElement`.
* @throws {Error} If the node's `element` is not a valid React element type.
*/render(){var a=this;if(!isValidElementType(this.element)){var b=getComponentType(this.element);throw new Error("Invalid element type: ".concat(b," provided!"))}// Extract children and key
var c=this.props,d=c.children,e=c.key,f=c.nativeProps,g=_objectWithoutProperties(c,_excluded5),h=void 0;if(void 0!==d&&null!==d){if(!this._normalizedChildren||this._childrenHash!==createStableHash(d,this.props.nodetheme||this.props.theme))if(!Array.isArray(d))this._normalizedChildren=this._normalizeChild(d);else if(0<d.length){var i=d.map(function(b){return a._normalizeChild(b)});this._normalizedChildren=i.every(function(a){return null===a||void 0===a})?void 0:i}else this._normalizedChildren=void 0;h=this._normalizedChildren}// Prepare props for React.createElement
var j;// If the element has a `css` prop and has style tag, render using the `StyledRenderer` component
// This enables emotion-based style handling for the element
if(j=this.element===Fragment||isFragment(this.element)?{key:e}:_objectSpread(_objectSpread(_objectSpread({},g),{},{key:e},f),{},{suppressHydrationWarning:!0}),this.element&&!hasNoStyleTag(this.element)&&j.css){var k=_objectSpread({element:this.element},j);try{var l=getElementTypeName(k.element);StyledRenderer.displayName="Styled(".concat(l,")")}catch(a){// swallow: displayName is not critical
}return createElement(StyledRenderer,k,h)}try{this.element.displayName=getElementTypeName(this.element)}catch(a){// swallow: displayName is not critical
}return createElement(this.element,j,h)}/**
* Ensures the necessary DOM elements for portal rendering are created and attached.
*
* On the client-side, this method checks for or creates a `div` element appended
* to the `document.body` and initializes a React root on it. This setup is
* required for the `toPortal` method to function. It is idempotent and safe
* to call multiple times.
* @returns `true` if the portal infrastructure is ready, `false` if on the server.
* @private
*/_ensurePortalInfrastructure(){if(BaseNode._isServer)return!1;// If both exist and DOM is connected, we're ready
if(this._portalDOMElement&&this._portalReactRoot&&this._portalDOMElement.isConnected)return!0;// If DOM element exists but isn't connected, clear both DOM element and root
if(this._portalDOMElement&&!this._portalDOMElement.isConnected){// attempt to unmount root if present
if(this._portalReactRoot){try{this._portalReactRoot.unmount()}catch(a){// swallow: unmount might fail if already removed; avoid breaking the app
}this._portalReactRoot=null}this._portalDOMElement=null}// Create DOM element if needed
// Create react root if needed
if(this._portalDOMElement||(this._portalDOMElement=document.createElement("div"),document.body.appendChild(this._portalDOMElement)),!this._portalReactRoot){if(!this._portalDOMElement)return!1;this._portalReactRoot=createRoot(this._portalDOMElement)}return!0}/**
* Renders the node into a React Portal.
*
* This method mounts the node's rendered content into a separate DOM tree
* attached to the `document.body`. It's useful for rendering components like
* modals, tooltips, or notifications that need to appear above other UI elements.
*
* The returned object includes an `unmount` function to clean up the portal.
* @returns A `ReactDOMRoot` instance for managing the portal, or `null` if
* called in a server-side environment. The returned instance is enhanced
* with a custom `unmount` method that also cleans up the associated DOM element.
*/toPortal(){var a=this;if(!this._ensurePortalInfrastructure()||!this._portalReactRoot)return null;var b=this.render();this._portalReactRoot.render(b);// Augment the actual root's unmount to also clean up the DOM element and internal refs.
try{var c=this._portalReactRoot.unmount.bind(this._portalReactRoot);this._portalReactRoot.unmount=function(){try{c()}catch(a){// swallow: original unmount might throw in edge cases
}// Clear references and remove DOM element
a._portalDOMElement&&(a._portalDOMElement.parentNode&&a._portalDOMElement.parentNode.removeChild(a._portalDOMElement),a._portalDOMElement=null),a._portalReactRoot=null}}catch(a){// swallow: if anything goes wrong while patching, still return the root
}return this._portalReactRoot}}/**
* Factory function to create a `BaseNode` instance.
* @template AdditionalProps Additional props to merge with node props.
* @template E The React element or component type.
* @param element The React element or component type to wrap.
* @param props The props for the node (optional).
* @param additionalProps Additional props to merge into the node (optional).
* @returns A new `BaseNode` instance as a `NodeInstance<E>`.
*/_defineProperty(BaseNode,"_isServer","undefined"==typeof window),_defineProperty(BaseNode,"_processedChildrenWeakCache",new WeakMap),_defineProperty(BaseNode,"_processedChildrenMapCache",new Map),_defineProperty(BaseNode,"_MAX_PROCESSED_CHILDREN_CACHE",1e3);export function Node(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},d=_objectSpread(_objectSpread({},b),c);return d.theme&&!d.nodetheme&&(d.nodetheme=d.theme),new BaseNode(a,d)}/**
* Creates a curried node factory for a given React element or component type.
*
* Returns a function that, when called with props, produces a `NodeInstance<E>`.
* Useful for creating reusable node factories for specific components or element types.
* @template AdditionalInitialProps Additional initial props to merge with node props.
* @template E The React element or component type.
* @param element The React element or component type to wrap.
* @param initialProps Initial props to apply to every node instance.
* @returns A function that takes node props and returns a `NodeInstance<E>`.
* @example
* const ButtonNode = createNode('button', { type: 'button' });
* const myButton = ButtonNode({ children: 'Click me', style: { color: 'red' } });
*/export function createNode(a,b){var c=function Instance(c){return Node(a,_objectSpread(_objectSpread({},b),c))};return c.element=a,c}/**
* Creates a node factory function where the first argument is `children` and the second is `props`.
*
* Useful for ergonomic creation of nodes where children are the primary concern,
* such as layout or container components.
*
* The returned function takes `children` as the first argument and `props` (excluding `children`) as the second.
* It merges any `initialProps` provided at factory creation, then creates a `BaseNode` instance.
*
* Type parameters:
* - `AdditionalInitialProps`: Extra props to merge with node props.
* - `E`: The React element or component type.
* @param element The React element or component type to wrap.
* @param initialProps Initial props to apply to every node instance (excluding `children`).
* @returns A function that takes `children` and `props`, returning a `NodeInstance<E>`.
* @example
* const Text = createChildrenFirstNode('p');
* const myDiv = Text('Hello', { className: 'text-lg' });
*/export function createChildrenFirstNode(a,b){var c=function Instance(c,d){return Node(a,_objectSpread(_objectSpread(_objectSpread({},b),d),{},{children:c}))};return c.element=a,c}