@meonode/ui 0.4.7 → 0.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/components/html.node.d.ts +139 -139
- package/dist/components/html.node.js +139 -139
- package/dist/components/meonode-unmounter.client.d.ts +6 -3
- package/dist/components/meonode-unmounter.client.d.ts.map +1 -1
- package/dist/components/meonode-unmounter.client.js +4 -2
- package/dist/components/react.node.d.ts +3 -3
- package/dist/components/react.node.js +3 -3
- package/dist/components/registry.client.js +6 -6
- package/dist/components/styled-renderer.client.js +2 -2
- package/dist/components/theme-provider.client.js +2 -2
- package/dist/components/theme-provider.d.ts +1 -1
- package/dist/components/theme-provider.js +1 -1
- package/dist/constant/common.const.d.ts.map +1 -0
- package/dist/constant/common.const.js +1 -0
- package/dist/constant/css-properties.const.d.ts.map +1 -0
- package/dist/constant/css-properties.const.js +1 -0
- package/dist/core.node.d.ts +9 -9
- package/dist/core.node.d.ts.map +1 -1
- package/dist/core.node.js +44 -39
- package/dist/helper/common.helper.js +9 -9
- package/dist/helper/obj.helper.js +14 -14
- package/dist/helper/react-is.helper.js +21 -21
- package/dist/hoc/component.hoc.js +1 -1
- package/dist/hoc/portal.hoc.js +13 -13
- package/dist/hook/usePortal.js +2 -2
- package/dist/hook/useTheme.js +3 -3
- package/dist/main.d.ts +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -1
- package/dist/nextjs-registry/index.d.ts +1 -1
- package/dist/nextjs-registry/index.js +1 -1
- package/dist/types/node.type.d.ts +6 -1
- package/dist/types/node.type.d.ts.map +1 -1
- package/dist/util/mount-tracker.util.js +3 -3
- package/dist/util/navigation-cache-manager.util.d.ts +5 -0
- package/dist/util/navigation-cache-manager.util.d.ts.map +1 -1
- package/dist/util/navigation-cache-manager.util.js +7 -7
- package/dist/util/node.util.d.ts +15 -12
- package/dist/util/node.util.d.ts.map +1 -1
- package/dist/util/node.util.js +67 -75
- package/dist/util/theme.util.d.ts +6 -6
- package/dist/util/theme.util.d.ts.map +1 -1
- package/dist/util/theme.util.js +17 -16
- package/package.json +11 -8
- package/dist/constants/common.const.d.ts.map +0 -1
- package/dist/constants/common.const.js +0 -1
- package/dist/constants/css-properties.const.d.ts.map +0 -1
- package/dist/constants/css-properties.const.js +0 -1
- /package/dist/{constants → constant}/common.const.d.ts +0 -0
- /package/dist/{constants → constant}/css-properties.const.d.ts +0 -0
package/dist/util/node.util.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { type ReactNode } from 'react';
|
|
2
|
-
import type { FunctionRendererProps, NodeElement, NodeElementType, NodeFunction, NodeInstance, NodeProps, DependencyList,
|
|
2
|
+
import type { FunctionRendererProps, NodeElement, NodeElementType, NodeFunction, NodeInstance, NodeProps, DependencyList, FinalNodeProps, NodePortal } from '../types/node.type.js';
|
|
3
|
+
import { type Root } from 'react-dom/client';
|
|
3
4
|
/**
|
|
4
5
|
* NodeUtil provides a collection of static utility methods and properties
|
|
5
6
|
* used internally by BaseNode for various tasks such as hashing, shallow comparison,
|
|
@@ -12,7 +13,7 @@ export declare class NodeUtil {
|
|
|
12
13
|
private static _functionSignatureCache;
|
|
13
14
|
private static readonly CACHE_SIZE_LIMIT = 500;
|
|
14
15
|
private static readonly CACHE_CLEANUP_BATCH = 50;
|
|
15
|
-
private static
|
|
16
|
+
private static _cssCache;
|
|
16
17
|
private static readonly CRITICAL_PROPS;
|
|
17
18
|
static portalInfrastructure: WeakMap<NodeInstance, {
|
|
18
19
|
domElement: HTMLDivElement;
|
|
@@ -44,18 +45,14 @@ export declare class NodeUtil {
|
|
|
44
45
|
* @method hashString
|
|
45
46
|
*/
|
|
46
47
|
static hashString(str: string): string;
|
|
47
|
-
|
|
48
|
-
* Performs a shallow equality check between two objects.
|
|
49
|
-
* @method shallowEqual
|
|
50
|
-
*/
|
|
51
|
-
static shallowEqual(a: Record<string, any>, b: Record<string, any>): boolean;
|
|
48
|
+
private static hashCSS;
|
|
52
49
|
/**
|
|
53
50
|
* Creates a unique, stable signature from the element type and props.
|
|
54
51
|
* This signature includes the element's type to prevent collisions between different components
|
|
55
52
|
* and handles primitive values in arrays and objects for better caching.
|
|
56
53
|
* @method createPropSignature
|
|
57
54
|
*/
|
|
58
|
-
static createPropSignature(element: NodeElementType, props: Record<string,
|
|
55
|
+
static createPropSignature(element: NodeElementType, props: Record<string, unknown>): string | undefined;
|
|
59
56
|
/**
|
|
60
57
|
* Extracts "critical" props from a given set of props. Critical props are those
|
|
61
58
|
* that are frequently used for styling or event handling, such as `on*` handlers,
|
|
@@ -63,14 +60,14 @@ export declare class NodeUtil {
|
|
|
63
60
|
* This method is used to optimize prop processing by focusing on props that are
|
|
64
61
|
* most likely to influence rendering or behavior.
|
|
65
62
|
*/
|
|
66
|
-
static extractCriticalProps(props: Record<string,
|
|
63
|
+
static extractCriticalProps(props: Record<string, unknown>, keys: string[]): Record<string, unknown>;
|
|
67
64
|
/**
|
|
68
65
|
* Retrieves computed CSS props from the cache with LRU tracking.
|
|
69
66
|
* Access time and hit count are tracked for smarter eviction.
|
|
70
67
|
* @method getCachedCssProps
|
|
71
68
|
*/
|
|
72
|
-
static getCachedCssProps(cacheableProps: Record<string,
|
|
73
|
-
cssProps: Record<string,
|
|
69
|
+
static getCachedCssProps(cacheableProps: Record<string, unknown>, signature?: string): {
|
|
70
|
+
cssProps: Record<string, unknown>;
|
|
74
71
|
};
|
|
75
72
|
/**
|
|
76
73
|
* Implements an LRU eviction strategy that removes multiple entries at once.
|
|
@@ -78,6 +75,12 @@ export declare class NodeUtil {
|
|
|
78
75
|
* @method _evictLRUEntries
|
|
79
76
|
*/
|
|
80
77
|
private static _evictLRUEntries;
|
|
78
|
+
/**
|
|
79
|
+
* Calculates an eviction score based on age and frequency of access.
|
|
80
|
+
* Higher scores mean more likelihood to be evicted.
|
|
81
|
+
* @method _calculateEvictionScore
|
|
82
|
+
*/
|
|
83
|
+
private static _calculateEvictionScore;
|
|
81
84
|
/**
|
|
82
85
|
* The main prop processing pipeline. It separates cacheable and non-cacheable props,
|
|
83
86
|
* generates a signature for caching, and assembles the final props object.
|
|
@@ -149,7 +152,7 @@ export declare class NodeUtil {
|
|
|
149
152
|
static ensurePortalInfrastructure(node: NodeInstance): boolean;
|
|
150
153
|
static cleanupPortalInfra(infra: {
|
|
151
154
|
domElement: HTMLDivElement;
|
|
152
|
-
reactRoot:
|
|
155
|
+
reactRoot: Root;
|
|
153
156
|
}): void;
|
|
154
157
|
}
|
|
155
158
|
//# sourceMappingURL=node.util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.util.d.ts","sourceRoot":"","sources":["../../src/util/node.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAyC,KAAK,SAAS,EAAiC,MAAM,OAAO,CAAA;AACnH,OAAO,KAAK,EACV,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"node.util.d.ts","sourceRoot":"","sources":["../../src/util/node.util.ts"],"names":[],"mappings":"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"}
|
package/dist/util/node.util.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
const _excluded=["ref","key","children","css","props","disableEmotion"],_excluded2=["style"];var _NodeUtil;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 _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 _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,isValidElement}from"react";import{isForwardRef,isMemo,isReactClassComponent}from"../helper/react-is.helper.js";import{getCSSProps,getDOMProps,getElementTypeName,omitUndefined}from"../helper/common.helper.js";import{__DEBUG__}from"../constant/common.const.js";import{BaseNode}from"../core.node.js";import{createRoot}from"react-dom/client";/**
|
|
2
2
|
* NodeUtil provides a collection of static utility methods and properties
|
|
3
3
|
* used internally by BaseNode for various tasks such as hashing, shallow comparison,
|
|
4
4
|
* and stable element ID generation. This centralizes common helper functions,
|
|
@@ -7,64 +7,72 @@ var _NodeUtil,_excluded=["ref","key","children","css","props","disableEmotion"],
|
|
|
7
7
|
/**
|
|
8
8
|
* Combines FNV-1a and djb2 hash functions for a more robust signature.
|
|
9
9
|
* @method hashString
|
|
10
|
-
*/static hashString(a){
|
|
10
|
+
*/static hashString(a){let b=2166136261,c=5381;// FNV offset basis
|
|
11
11
|
// djb2 init
|
|
12
|
-
for(
|
|
12
|
+
for(let d=0;d<a.length;d++){const e=a.charCodeAt(d);// FNV-1a
|
|
13
13
|
// djb2
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/static shallowEqual(c,a){if(c===a)return!0;var b=0,d=0;for(var e in c){if(!(e in a)||c[e]!==a[e])return!1;b++}for(var f in a)d++;return b===d}/**
|
|
14
|
+
b^=e,b=Math.imul(b,16777619),c=33*c^e}return`${(b>>>0).toString(36)}_${(c>>>0).toString(36)}`}static hashCSS(a){var b=Math.min;const c=this._cssCache.get(a);if(c)return c;// Fast structural hash without full serialization
|
|
15
|
+
const d=Object.keys(a);let e=d.length;for(let c=0;c<b(d.length,10);c++){// Sample first 10
|
|
16
|
+
const b=d[c],f=a[b],g=b.charCodeAt(0);e=(e<<5)-e+g,e&=e,"string"==typeof f&&(e=(e<<5)-e+f.length)}const f=e.toString(36);return this._cssCache.set(a,f),f}/**
|
|
18
17
|
* Creates a unique, stable signature from the element type and props.
|
|
19
18
|
* This signature includes the element's type to prevent collisions between different components
|
|
20
19
|
* and handles primitive values in arrays and objects for better caching.
|
|
21
20
|
* @method createPropSignature
|
|
22
|
-
*/static createPropSignature(a,b){if(
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
*/static createPropSignature(a,b){if(NodeUtil.isServer)return;const c=getElementTypeName(a),d=Object.keys(b).sort(),e=[`${c}:`];if("function"==typeof a){let b=NodeUtil._functionSignatureCache.get(a);b||(b=NodeUtil.hashString(a.toString()),NodeUtil._functionSignatureCache.set(a,b)),e.push(b)}for(const c of d){const a=b[c];let d;const f=typeof a;if("string"==f||"number"===f||"boolean"===f)d=`${c}:${a};`;else if(null===a)d=`${c}:null;`;else if(a===void 0)d=`${c}:undefined;`;else if("css"===c&&"object"==typeof a)d=`css:${this.hashCSS(a)};`;else if(Array.isArray(a)){// Hash primitive values in arrays for better cache hits
|
|
22
|
+
const b=a.filter(a=>{const b=typeof a;return"string"==b||"number"===b||"boolean"===b||null===a});d=b.length===a.length?`${c}:[${b.join(",")}];`:`${c}:[${a.length}];`}else if(a&&a.isBaseNode)d=`${c}:${a.stableKey};`;else{// Include sorted keys for object structure signature
|
|
23
|
+
const b=Object.keys(a).sort();d=`${c}:{${b.join(",")}};`}e.push(d)}return NodeUtil.hashString(e.join(","))}/**
|
|
25
24
|
* Extracts "critical" props from a given set of props. Critical props are those
|
|
26
25
|
* that are frequently used for styling or event handling, such as `on*` handlers,
|
|
27
26
|
* `aria-*` attributes, `data-*` attributes, `css`, `className`, and `style`.
|
|
28
27
|
* This method is used to optimize prop processing by focusing on props that are
|
|
29
28
|
* most likely to influence rendering or behavior.
|
|
30
|
-
*/static extractCriticalProps(a,b){
|
|
29
|
+
*/static extractCriticalProps(a,b){const c={_keyCount:b.length};let d=0;for(const e of b){if(50<=d)break;// Fast path: direct Set check first (O(1))
|
|
30
|
+
if(NodeUtil.CRITICAL_PROPS.has(e)){c[e]=a[e],d++;continue}// Inline prefix checks using charCode (faster than startsWith for short prefixes)
|
|
31
|
+
const f=e.charCodeAt(0);// Check 'on' prefix (111 = 'o', 110 = 'n')
|
|
32
|
+
if(111===f&&110===e.charCodeAt(1)){c[e]=a[e],d++;continue}// Check 'aria' prefix (97 = 'a', 114 = 'r', 105 = 'i')
|
|
33
|
+
if(97===f&&114===e.charCodeAt(1)&&105===e.charCodeAt(2)&&97===e.charCodeAt(3)){c[e]=a[e],d++;continue}// Check 'data' prefix (100 = 'd', 97 = 'a', 116 = 't')
|
|
34
|
+
if(100===f&&97===e.charCodeAt(1)&&116===e.charCodeAt(2)&&97===e.charCodeAt(3)){c[e]=a[e],d++;continue}// Style prop check last (most expensive), only for smaller objects
|
|
35
|
+
100>=b.length&&NodeUtil.isStyleProp(e)&&(c[e]=a[e],d++)}return c}/**
|
|
31
36
|
* Retrieves computed CSS props from the cache with LRU tracking.
|
|
32
37
|
* Access time and hit count are tracked for smarter eviction.
|
|
33
38
|
* @method getCachedCssProps
|
|
34
|
-
*/static getCachedCssProps(a,b){if(NodeUtil.isServer||!b)return{cssProps:getCSSProps(a)};
|
|
39
|
+
*/static getCachedCssProps(a,b){if(NodeUtil.isServer||!b)return{cssProps:getCSSProps(a)};const c=BaseNode.propProcessingCache.get(b);if(c)return c.lastAccess=Date.now(),c.hitCount++,{cssProps:c.cssProps};const d=getCSSProps(a);return BaseNode.propProcessingCache.set(b,{cssProps:d,signature:b,lastAccess:Date.now(),hitCount:1}),BaseNode.propProcessingCache.size>NodeUtil.CACHE_SIZE_LIMIT&&!BaseNode.scheduledCleanup&&(BaseNode.scheduledCleanup=!0,"undefined"==typeof requestIdleCallback?setTimeout(()=>{NodeUtil._evictLRUEntries(),BaseNode.scheduledCleanup=!1},100):requestIdleCallback(()=>{NodeUtil._evictLRUEntries(),BaseNode.scheduledCleanup=!1},{timeout:2e3})),{cssProps:d}}/**
|
|
35
40
|
* Implements an LRU eviction strategy that removes multiple entries at once.
|
|
36
41
|
* It uses a scoring system where older and less frequently used entries have a higher eviction priority.
|
|
37
42
|
* @method _evictLRUEntries
|
|
38
|
-
*/static _evictLRUEntries(){
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
*/static _evictLRUEntries(){const a=Date.now(),b=new MinHeap((c,a)=>a.score-c.score);// Create max-heap (using min-heap with inverted comparison) to get highest scores first
|
|
44
|
+
for(const[c,d]of BaseNode.propProcessingCache.entries()){const e=this._calculateEvictionScore(d,a);b.push({key:c,score:e})}// O(log n) eviction of top N entries
|
|
45
|
+
for(let a=0;a<NodeUtil.CACHE_CLEANUP_BATCH;a++){const a=b.pop();if(a)BaseNode.propProcessingCache.delete(a.key);else// No more items to evict
|
|
46
|
+
break}}/**
|
|
47
|
+
* Calculates an eviction score based on age and frequency of access.
|
|
48
|
+
* Higher scores mean more likelihood to be evicted.
|
|
49
|
+
* @method _calculateEvictionScore
|
|
50
|
+
*/static _calculateEvictionScore(a,b){const c=b-a.lastAccess,d=a.hitCount;// Weighted scoring: recency 30%, frequency 70% - favors frequently accessed items
|
|
51
|
+
return .3*(c/1e3)+.7*(1e3/(d+1))}/**
|
|
44
52
|
* The main prop processing pipeline. It separates cacheable and non-cacheable props,
|
|
45
53
|
* generates a signature for caching, and assembles the final props object.
|
|
46
54
|
* @method processProps
|
|
47
|
-
*/static processProps(a
|
|
48
|
-
if(0===Object.keys(
|
|
49
|
-
|
|
50
|
-
for(
|
|
51
|
-
|
|
55
|
+
*/static processProps(a,b={},c){const{ref:d,key:e,children:f,css:g,props:i={},disableEmotion:h}=b,j=_objectWithoutProperties(b,_excluded);// --- Fast Path Optimization ---
|
|
56
|
+
if(0===Object.keys(j).length&&!g)return omitUndefined({ref:d,key:e,disableEmotion:h,nativeProps:omitUndefined(i),children:NodeUtil._processChildren(f,h)});// --- Hybrid Caching Strategy ---
|
|
57
|
+
const k={},l={};// 1. Categorize props into cacheable (primitives) and non-cacheable (objects/functions).
|
|
58
|
+
for(const d in j)if(Object.prototype.hasOwnProperty.call(j,d)){const a=j[d],b=typeof a;"string"===b||"number"===b||"boolean"===b?k[d]=a:l[d]=a}// 2. Pass element type to signature generation
|
|
59
|
+
const m=NodeUtil.createPropSignature(a,k),{cssProps:n}=NodeUtil.getCachedCssProps(k,m),o=getCSSProps(l),p=getDOMProps(j),q=_objectSpread(_objectSpread(_objectSpread({},n),o),g),r=NodeUtil._processChildren(f,h,c);// 3. Process non-cacheable props on every render to ensure correctness for functions and objects.
|
|
52
60
|
// DOM props are always processed fresh.
|
|
53
61
|
// 4. Assemble the final CSS object.
|
|
54
62
|
// --- Child Normalization ---
|
|
55
63
|
// --- Final Assembly ---
|
|
56
|
-
return omitUndefined(_objectSpread(_objectSpread({ref:d,key:e,css:
|
|
64
|
+
return omitUndefined(_objectSpread(_objectSpread({ref:d,key:e,css:q},p),{},{disableEmotion:h,nativeProps:omitUndefined(i),children:r}))}/**
|
|
57
65
|
* Processes and normalizes children of the node.
|
|
58
66
|
* Converts raw children (React elements, primitives, or other BaseNodes) into a consistent format.
|
|
59
67
|
* @param children The raw children to process.
|
|
60
68
|
* @param disableEmotion If true, emotion styling will be disabled for these children.
|
|
61
69
|
* @param parentStableKey The stable key of the parent node, used for generating unique keys for children.
|
|
62
|
-
*/static _processChildren(a,b,c){return a?"function"==typeof a?a:Array.isArray(a)?a.map(
|
|
70
|
+
*/static _processChildren(a,b,c){return a?"function"==typeof a?a:Array.isArray(a)?a.map((a,d)=>NodeUtil.processRawNode(a,b,`${c}_${d}`)):NodeUtil.processRawNode(a,b,c):void 0}/**
|
|
63
71
|
* Determines if a node should update based on its dependency array.
|
|
64
72
|
* Uses a shallow comparison, similar to React's `useMemo` and `useCallback`.
|
|
65
73
|
* @method shouldNodeUpdate
|
|
66
74
|
*/static shouldNodeUpdate(a,b,c){// SSR has no concept of re-renders, so deps system doesn't apply
|
|
67
|
-
return!!NodeUtil.isServer||!c&&(!(void 0!==b)||!(void 0!==a)||b.length!==a.length||!!b.some(
|
|
75
|
+
return!!NodeUtil.isServer||!c&&(!(void 0!==b)||!(void 0!==a)||b.length!==a.length||!!b.some((b,c)=>!Object.is(b,a[c])));// No deps array means always update.
|
|
68
76
|
// First render for this keyed component, or no previous deps.
|
|
69
77
|
// Length change means update.
|
|
70
78
|
// Shallow compare deps. If any have changed, update.
|
|
@@ -76,12 +84,12 @@ return!!NodeUtil.isServer||!c&&(!(void 0!==b)||!(void 0!==a)||b.length!==a.lengt
|
|
|
76
84
|
* @method processRawNode
|
|
77
85
|
*/static processRawNode(a,b,c){// Primitives and null/undefined are returned as-is.
|
|
78
86
|
if(null===a||a===void 0||"string"==typeof a||"number"==typeof a||"boolean"==typeof a)return a;// If it's already a BaseNode, clone it with a positional key if available.
|
|
79
|
-
if(NodeUtil.isNodeInstance(a)){
|
|
80
|
-
|
|
87
|
+
if(NodeUtil.isNodeInstance(a)){const d=c||b&&!a.rawProps.disableEmotion;if(d){// Create a new BaseNode instance.
|
|
88
|
+
const d=new BaseNode(a.element,a.rawProps,a.dependencies);// Augment the internal stableKey with positional information.
|
|
81
89
|
// This is purely for BaseNode's internal caching, not for React's 'key' prop.
|
|
82
|
-
return
|
|
90
|
+
return d.stableKey=`${c}:${d.stableKey}`,b&&!d.rawProps.disableEmotion&&(d.rawProps.disableEmotion=!0),d}return a}// Handle function-as-a-child (render props).
|
|
83
91
|
if(NodeUtil.isFunctionChild(a))return new BaseNode(NodeUtil.functionRenderer,{props:{render:a,disableEmotion:b}},void 0);// Handle standard React elements.
|
|
84
|
-
if(isValidElement(a)){
|
|
92
|
+
if(isValidElement(a)){const c=a.props,{style:d}=c,e=_objectWithoutProperties(c,_excluded2),f=_objectSpread(_objectSpread({},e),d||{});return new BaseNode(a.type,_objectSpread(_objectSpread(_objectSpread({},f),null!==a.key&&void 0!==a.key?{key:a.key}:{}),{},{disableEmotion:b}),void 0)}// Handle component classes and memos.
|
|
85
93
|
return isReactClassComponent(a)||isMemo(a)||isForwardRef(a)?new BaseNode(a,{disableEmotion:b},void 0):a instanceof React.Component?NodeUtil.processRawNode(a.render(),b,c):a;// Handle component instances.
|
|
86
94
|
}/**
|
|
87
95
|
* A helper to reliably identify if a given function is a "function-as-a-child" (render prop)
|
|
@@ -100,22 +108,23 @@ return isReactClassComponent(a)||isMemo(a)||isForwardRef(a)?new BaseNode(a,{disa
|
|
|
100
108
|
* @param {Function} props.render The function-as-a-child to execute.
|
|
101
109
|
* @param {boolean} [props.disableEmotion] Inherited flag to disable Emotion styling for children.
|
|
102
110
|
* @returns {ReactNode | null | undefined} The processed and rendered output of the render function.
|
|
103
|
-
*/static functionRenderer(a){
|
|
104
|
-
|
|
105
|
-
__DEBUG__&&console.error("MeoNode: Error executing function-as-a-child.",a),
|
|
106
|
-
if(null===
|
|
107
|
-
if(NodeUtil.isNodeInstance(
|
|
111
|
+
*/static functionRenderer({render:a,disableEmotion:b}){let c;try{// Execute the render prop function to get its output.
|
|
112
|
+
c=a()}catch(a){// If the render function throws, treat its output as null to prevent crashes.
|
|
113
|
+
__DEBUG__&&console.error("MeoNode: Error executing function-as-a-child.",a),c=null}// Handle null or undefined results directly, as they are valid React render outputs.
|
|
114
|
+
if(null===c||c===void 0)return c;// If the result is already a BaseNode instance, process it.
|
|
115
|
+
if(NodeUtil.isNodeInstance(c))// If emotion is disabled for the parent and not explicitly re-enabled on the child,
|
|
108
116
|
// create a new BaseNode with emotion disabled and render it.
|
|
109
|
-
return
|
|
117
|
+
return b&&!c.rawProps.disableEmotion?new BaseNode(c.element,_objectSpread(_objectSpread({},c.rawProps),{},{disableEmotion:!0})).render():c.render();// Otherwise, render the existing BaseNode directly.
|
|
110
118
|
// If the result is an array, it likely contains multiple children.
|
|
111
|
-
if(Array.isArray(
|
|
112
|
-
|
|
113
|
-
return
|
|
114
|
-
return __DEBUG__&&console.error("MeoNode: Could not determine element type name for key in function-as-a-child.",a)
|
|
115
|
-
return
|
|
116
|
-
if(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
if(Array.isArray(c)){// Helper to generate a stable key for array items, crucial for React's reconciliation.
|
|
120
|
+
const a=(a,b)=>{try{// Attempt to get a meaningful name for the element type.
|
|
121
|
+
return`${getElementTypeName(a)}-${b}`}catch(a){// Fallback to a generic key if type name cannot be determined.
|
|
122
|
+
return __DEBUG__&&console.error("MeoNode: Could not determine element type name for key in function-as-a-child.",a),`item-${b}`}};// Map over the array, processing each item and assigning a key.
|
|
123
|
+
return c.map((c,d)=>NodeUtil.renderProcessedNode({processedElement:NodeUtil.processRawNode(c,b),passedKey:a(c,d),disableEmotion:b}))}// If the result is a React component instance (e.g., `new MyClassComponent()`).
|
|
124
|
+
if(c instanceof React.Component)return NodeUtil.renderProcessedNode({processedElement:NodeUtil.processRawNode(c.render(),b),disableEmotion:b});// Handle primitive types directly, as they are valid React children.
|
|
125
|
+
if("string"==typeof c||"number"==typeof c||"boolean"==typeof c)return c;// For any other non-primitive, non-array result, process it as a single NodeElement.
|
|
126
|
+
const d=NodeUtil.processRawNode(c,b);// If processing yields a valid element, render it.
|
|
127
|
+
return d?NodeUtil.renderProcessedNode({processedElement:d,disableEmotion:b}):c;// Fallback: return the original result if it couldn't be processed into a renderable node.
|
|
119
128
|
}/**
|
|
120
129
|
* Renders a processed `NodeElement` into a ReactNode.
|
|
121
130
|
* This helper is primarily used by `functionRenderer` to handle the output of render props,
|
|
@@ -125,18 +134,18 @@ return f?NodeUtil.renderProcessedNode({processedElement:f,disableEmotion:d}):b;/
|
|
|
125
134
|
* This method is part of the child processing pipeline, converting internal `NodeElement` representations
|
|
126
135
|
* into actual React elements that can be rendered by React.
|
|
127
136
|
* @method renderProcessedNode
|
|
128
|
-
*/static renderProcessedNode(
|
|
129
|
-
|
|
137
|
+
*/static renderProcessedNode({processedElement:a,passedKey:b,disableEmotion:c}){// Initialize an object to hold common props that might be applied to the new BaseNode.
|
|
138
|
+
const d={};// If a `passedKey` is provided, add it to `commonBaseNodeProps`.
|
|
130
139
|
// This key is typically used for React's reconciliation process.
|
|
131
140
|
// If the processed element is already a BaseNode instance.
|
|
132
|
-
if(void 0!==
|
|
133
|
-
|
|
141
|
+
if(void 0!==b&&(d.key=b),NodeUtil.isNodeInstance(a)){// Get the existing key from the raw props of the BaseNode.
|
|
142
|
+
const e=a.rawProps?.key;// Apply the `disableEmotion` flag to the raw props of the BaseNode.
|
|
134
143
|
// If the existing key is the same as the passed key, render the existing BaseNode directly.
|
|
135
144
|
// This avoids unnecessary re-creation of the BaseNode instance.
|
|
136
|
-
return
|
|
145
|
+
return a.rawProps.disableEmotion=c,e===b?a.render():new BaseNode(a.element,_objectSpread(_objectSpread({},a.rawProps),d)).render();// Otherwise, create a new BaseNode instance, merging existing raw props with common props, then render it.
|
|
137
146
|
}// If the processed element is a React class component (e.g., `class MyComponent extends React.Component`).
|
|
138
147
|
// Create a new BaseNode for it, applying common props and `disableEmotion`, then render.
|
|
139
|
-
return isReactClassComponent(
|
|
148
|
+
return isReactClassComponent(a)?new BaseNode(a,_objectSpread(_objectSpread({},d),{},{disableEmotion:c})).render():a instanceof React.Component?a.render():"function"==typeof a?createElement(a,{key:b}):a;// If the processed element is an instance of a React component (e.g., `new MyComponent()`).
|
|
140
149
|
// Directly call its `render` method.
|
|
141
150
|
// If the processed element is a function (likely a functional component or a render prop that returned a component type).
|
|
142
151
|
// Create a React element directly using `createElement`, passing the `passedKey`.
|
|
@@ -145,28 +154,11 @@ return isReactClassComponent(b)?new BaseNode(b,_objectSpread(_objectSpread({},e)
|
|
|
145
154
|
* Ensures that the necessary DOM element and React root are available for portal rendering.
|
|
146
155
|
* This is only executed on the client-side.
|
|
147
156
|
* @method ensurePortalInfrastructure
|
|
148
|
-
*/static ensurePortalInfrastructure(a){
|
|
149
|
-
if(
|
|
150
|
-
if(
|
|
151
|
-
|
|
152
|
-
};return
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
// Portal infrastructure using WeakMap for memory-safe management
|
|
157
|
-
/**
|
|
158
|
-
* Type guard to check if an object is a NodeInstance.
|
|
159
|
-
*
|
|
160
|
-
* A NodeInstance is expected to be a non-null object with:
|
|
161
|
-
* - an 'element' property,
|
|
162
|
-
* - a 'render' method,
|
|
163
|
-
* - a 'toPortal' method,
|
|
164
|
-
* - and an 'isBaseNode' property.
|
|
165
|
-
* @param obj The object to check.
|
|
166
|
-
* @returns True if the object is a NodeInstance, false otherwise.
|
|
167
|
-
*//**
|
|
168
|
-
* Determines if a given string `k` is a valid CSS style property.
|
|
169
|
-
* This check is performed only on the client-side by checking if the property exists in `document.body.style`.
|
|
170
|
-
* On the server-side, it always returns `false`.
|
|
171
|
-
* @param k The string to check.
|
|
172
|
-
*/_NodeUtil=NodeUtil,_defineProperty(NodeUtil,"isServer","undefined"==typeof window),_defineProperty(NodeUtil,"_functionSignatureCache",new WeakMap),_defineProperty(NodeUtil,"CACHE_SIZE_LIMIT",500),_defineProperty(NodeUtil,"CACHE_CLEANUP_BATCH",50),_defineProperty(NodeUtil,"CRITICAL_PROP_PREFIXES",new Set(["on","aria","data"])),_defineProperty(NodeUtil,"CRITICAL_PROPS",new Set(["css","className","disableEmotion","props"])),_defineProperty(NodeUtil,"portalInfrastructure",new WeakMap),_defineProperty(NodeUtil,"isNodeInstance",function(a){return"object"===_typeof(a)&&null!==a&&"element"in a&&"function"==typeof a.render&&"function"==typeof a.toPortal&&"isBaseNode"in a}),_defineProperty(NodeUtil,"isStyleProp",_NodeUtil.isServer||"undefined"==typeof document?function(){return!1}:function(a){return a in document.body.style});
|
|
157
|
+
*/static ensurePortalInfrastructure(a){if(NodeUtil.isServer)return!1;let b=NodeUtil.portalInfrastructure.get(a);// Check if infrastructure exists and is still connected
|
|
158
|
+
if(b?.domElement?.isConnected&&b?.reactRoot)return!0;// Clean up stale or disconnected infrastructure
|
|
159
|
+
if(b&&(!b.domElement?.isConnected||!b.reactRoot)){try{b.reactRoot?.unmount?.()}catch(a){__DEBUG__&&console.error("MeoNode: Error unmounting stale portal root.",a)}NodeUtil.cleanupPortalInfra(b),NodeUtil.portalInfrastructure.delete(a),b=void 0}// Create new infrastructure
|
|
160
|
+
const c=document.createElement("div");document.body.appendChild(c);const d=createRoot(c),e={render:d.render.bind(d),unmount:d.unmount.bind(d),update:()=>{}// Placeholder, will be overridden
|
|
161
|
+
};return b={domElement:c,reactRoot:e},NodeUtil.portalInfrastructure.set(a,b),BaseNode.portalCleanupRegistry.register(a,{domElement:c,reactRoot:e},a),!0}static cleanupPortalInfra(a){try{a.reactRoot?.unmount&&a.reactRoot.unmount()}catch(a){__DEBUG__&&console.error("Portal cleanup error:",a)}try{a.domElement?.isConnected&&a.domElement.remove()}catch(a){__DEBUG__&&console.error("DOM removal error:",a)}}}/**
|
|
162
|
+
* A min-heap implementation for efficient priority queue operations.
|
|
163
|
+
* Used for O(log n) eviction in the LRU cache system.
|
|
164
|
+
*/_NodeUtil=NodeUtil,_defineProperty(NodeUtil,"isServer","undefined"==typeof window),_defineProperty(NodeUtil,"_functionSignatureCache",new WeakMap),_defineProperty(NodeUtil,"CACHE_SIZE_LIMIT",500),_defineProperty(NodeUtil,"CACHE_CLEANUP_BATCH",50),_defineProperty(NodeUtil,"_cssCache",new WeakMap),_defineProperty(NodeUtil,"CRITICAL_PROPS",new Set(["css","className","disableEmotion","props"])),_defineProperty(NodeUtil,"portalInfrastructure",new WeakMap),_defineProperty(NodeUtil,"isNodeInstance",a=>"object"==typeof a&&null!==a&&"element"in a&&"function"==typeof a.render&&"function"==typeof a.toPortal&&"isBaseNode"in a),_defineProperty(NodeUtil,"isStyleProp",_NodeUtil.isServer||"undefined"==typeof document?()=>!1:a=>a in document.body.style);class MinHeap{constructor(a){_defineProperty(this,"heap",[]),this.comparator=a}size(){return this.heap.length}isEmpty(){return 0===this.size()}push(a){this.heap.push(a),this.bubbleUp()}pop(){if(!this.isEmpty()){this.swap(0,this.size()-1);const a=this.heap.pop();return this.bubbleDown(),a}}peek(){return this.isEmpty()?void 0:this.heap[0]}bubbleUp(a=this.size()-1){for(;0<a;){const b=Math.floor((a-1)/2);if(0>=this.comparator(this.heap[b],this.heap[a]))break;this.swap(b,a),a=b}}bubbleDown(a=0){for(const b=this.size()-1;;){const c=2*a+1,d=2*a+2;let e=a;if(c<=b&&0>this.comparator(this.heap[c],this.heap[e])&&(e=c),d<=b&&0>this.comparator(this.heap[d],this.heap[e])&&(e=d),e===a)break;this.swap(a,e),a=e}}swap(a,b){[this.heap[a],this.heap[b]]=[this.heap[b],this.heap[a]]}}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Theme } from '../types/node.type.js';
|
|
1
|
+
import type { CSSProperties } from '@emotion/serialize';
|
|
2
|
+
import type { CssProp, Theme } from '../types/node.type.js';
|
|
3
3
|
/**
|
|
4
4
|
* Parsed flex shorthand components for CSS flex property
|
|
5
5
|
* @interface FlexComponents
|
|
@@ -34,7 +34,7 @@ export declare class ThemeUtil {
|
|
|
34
34
|
* parseFlexShorthand('1 0 auto') // → {grow: 1, shrink: 0, basis: 'auto'}
|
|
35
35
|
*/
|
|
36
36
|
static parseFlexShorthand(flex: CSSProperties['flex']): FlexComponents | null;
|
|
37
|
-
static isPlainObject: (value:
|
|
37
|
+
static isPlainObject: (value: unknown) => value is Record<string, unknown>;
|
|
38
38
|
/**
|
|
39
39
|
* Resolves theme variable references in an object's values iteratively.
|
|
40
40
|
* This function uses a manual work stack to traverse the object, which prevents
|
|
@@ -44,9 +44,9 @@ export declare class ThemeUtil {
|
|
|
44
44
|
* object references for unchanged parts of the tree, which is critical for
|
|
45
45
|
* React's reconciliation and memoization.
|
|
46
46
|
*/
|
|
47
|
-
static resolveObjWithTheme:
|
|
47
|
+
static resolveObjWithTheme: <O extends Record<string, unknown>>(obj: O, theme?: Theme | undefined, options?: {
|
|
48
48
|
processFunctions?: boolean | undefined;
|
|
49
|
-
}) =>
|
|
49
|
+
}) => O;
|
|
50
50
|
static clearThemeCache: () => void;
|
|
51
51
|
/**
|
|
52
52
|
* Resolves default CSS styles to fix common flexbox layout issues.
|
|
@@ -102,7 +102,7 @@ export declare class ThemeUtil {
|
|
|
102
102
|
* })
|
|
103
103
|
* // → { display: 'flex', flexWrap: 'wrap', minHeight: 0, minWidth: 0 }
|
|
104
104
|
*/
|
|
105
|
-
static resolveDefaultStyle: (style:
|
|
105
|
+
static resolveDefaultStyle: (style: CssProp) => {};
|
|
106
106
|
}
|
|
107
107
|
export {};
|
|
108
108
|
//# sourceMappingURL=theme.util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.util.d.ts","sourceRoot":"","sources":["../../src/util/theme.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"theme.util.d.ts","sourceRoot":"","sources":["../../src/util/theme.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAe,MAAM,yBAAyB,CAAA;AAiG1E;;;;;;GAMG;AACH,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CACvB;AACD,qBAAa,SAAS;IACpB,OAAO,eAAiB;IAExB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAmC;IAE5D;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAc,kBAAkB,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,cAAc,GAAG,IAAI,CA2BnF;IAED,OAAc,aAAa,uDAM1B;IAED;;;;;;;;OAQG;IACH,OAAc,mBAAmB,GAAI,CAAC;;YA0HrC;IAED,OAAc,eAAe,aAE5B;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqDG;IACH,OAAc,mBAAmB,yBAmEhC;CACF"}
|
package/dist/util/theme.util.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
const _excluded=["flex"];var _ThemeUtil;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 _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{ObjHelper}from"../helper/obj.helper.js";import{getValueByPath}from"../helper/common.helper.js";/**
|
|
2
2
|
* Cache manager for theme resolution operations.
|
|
3
3
|
*/class ThemeResolverCache{constructor(){_defineProperty(this,"CACHE_SIZE_LIMIT",500),_defineProperty(this,"CACHE_EVICTION_BATCH_SIZE",50),_defineProperty(this,"_resolutionCache",new Map),_defineProperty(this,"_pathLookupCache",new Map),_defineProperty(this,"_themeRegex",/theme\.([a-zA-Z0-9_.-]+)/g)}static getInstance(){return ThemeResolverCache._instance||(ThemeResolverCache._instance=new ThemeResolverCache),ThemeResolverCache._instance}/**
|
|
4
4
|
* Generate a stable cache key from object and theme, including the theme mode.
|
|
5
5
|
*/_generateCacheKey(a,b){// Including theme.mode is critical for cache correctness.
|
|
6
|
-
return
|
|
6
|
+
return`${ObjHelper.stringify(a)}_${b.mode}_${ObjHelper.stringify(b.system)}`}getResolution(a,b){const c=this._generateCacheKey(a,b),d=this._resolutionCache.get(c);return d&&(this._resolutionCache.delete(c),this._resolutionCache.set(c,d)),d||null}setResolution(a,b,c){const d=this._generateCacheKey(a,b);this._resolutionCache.set(d,c),this._resolutionCache.size>this.CACHE_SIZE_LIMIT&&this._evict(this._resolutionCache)}getPathLookup(a,b){const c=`${ObjHelper.stringify(a)}_${b}`,d=this._pathLookupCache.get(c);return d&&(this._pathLookupCache.delete(c),this._pathLookupCache.set(c,d)),d??null}setPathLookup(a,b,c){const d=`${ObjHelper.stringify(a)}_${b}`;this._pathLookupCache.set(d,c),this._pathLookupCache.size>this.CACHE_SIZE_LIMIT&&this._evict(this._pathLookupCache)}_evict(a){const b=a.keys();for(let c=0;c<this.CACHE_EVICTION_BATCH_SIZE;c++){const c=b.next().value;if(c)a.delete(c);else break}}getThemeRegex(){return this._themeRegex.lastIndex=0,this._themeRegex}shouldCache(){return"undefined"==typeof window}clear(){this._resolutionCache.clear(),this._pathLookupCache.clear()}}/**
|
|
7
7
|
* Parsed flex shorthand components for CSS flex property
|
|
8
8
|
* @interface FlexComponents
|
|
9
9
|
* @property grow - The flex-grow value (how much the item should grow)
|
|
@@ -28,7 +28,7 @@ return"".concat(ObjHelper.stringify(a),"_").concat(b.mode,"_").concat(ObjHelper.
|
|
|
28
28
|
* parseFlexShorthand('1 0 auto') // → {grow: 1, shrink: 0, basis: 'auto'}
|
|
29
29
|
*/static parseFlexShorthand(a){// Early returns for invalid inputs
|
|
30
30
|
if(null===a||a===void 0)return null;// Handle numeric flex values (e.g., flex: 1)
|
|
31
|
-
if("number"==typeof a)return{grow:a,shrink:1,basis:"0%"};if("string"!=typeof a)return null;
|
|
31
|
+
if("number"==typeof a)return{grow:a,shrink:1,basis:"0%"};if("string"!=typeof a)return null;const b=a.trim().toLowerCase();if(!b)return null;// Handle CSS keyword values
|
|
32
32
|
return"none"===b?{grow:0,shrink:0,basis:"auto"}:"auto"===b?{grow:1,shrink:1,basis:"auto"}:"initial"===b?{grow:0,shrink:1,basis:"auto"}:null}}/**
|
|
33
33
|
* Resolves theme variable references in an object's values iteratively.
|
|
34
34
|
* This function uses a manual work stack to traverse the object, which prevents
|
|
@@ -90,11 +90,12 @@ return"none"===b?{grow:0,shrink:0,basis:"auto"}:"auto"===b?{grow:1,shrink:1,basi
|
|
|
90
90
|
* flexWrap: 'wrap'
|
|
91
91
|
* })
|
|
92
92
|
* // → { display: 'flex', flexWrap: 'wrap', minHeight: 0, minWidth: 0 }
|
|
93
|
-
*/_ThemeUtil=ThemeUtil,_defineProperty(ThemeUtil,"themeCache",ThemeResolverCache.getInstance()),_defineProperty(ThemeUtil,"isPlainObject",
|
|
94
|
-
for(
|
|
95
|
-
|
|
93
|
+
*/_ThemeUtil=ThemeUtil,_defineProperty(ThemeUtil,"themeCache",ThemeResolverCache.getInstance()),_defineProperty(ThemeUtil,"isPlainObject",a=>{if("object"!=typeof a||null===a)return!1;const b=Object.getPrototypeOf(a);return null===b||b===Object.prototype}),_defineProperty(ThemeUtil,"resolveObjWithTheme",(a,b,c={})=>{const{processFunctions:d=!1}=c;if(!b||!b.system||"object"!=typeof b.system||0===Object.keys(b.system).length||!a||0===Object.keys(a).length)return a;const e=b.system;if(_ThemeUtil.themeCache.shouldCache()){const c=_ThemeUtil.themeCache.getResolution(a,b);if(null!==c)return c}const f=[{value:a,isProcessed:!1}],g=new Map,h=new Set,i=a=>{const b=_ThemeUtil.themeCache.getThemeRegex();let c=!1;const d=a.replace(b,(a,b)=>{let d=_ThemeUtil.themeCache.getPathLookup(e,b);if(null===d&&(d=getValueByPath(e,b),_ThemeUtil.themeCache.setPathLookup(e,b,d)),void 0!==d&&null!==d){if(c=!0,"object"==typeof d){if(!Array.isArray(d)&&"default"in d)return d.default;throw new Error("The provided theme path is invalid!")}return d}return a});return c?d:a};// Used for cycle detection within the current traversal path.
|
|
94
|
+
for(;0<f.length;){const a=f[f.length-1],c=a.value;if(!_ThemeUtil.isPlainObject(c)&&!Array.isArray(c)){f.pop();continue}if(g.has(c)){f.pop();continue}if(!a.isProcessed){a.isProcessed=!0,h.add(c);const b=Array.isArray(c)?c:Object.values(c);for(let a=b.length-1;0<=a;a--){const c=b[a];// Only push containers that are not already in the current path (cycle detection).
|
|
95
|
+
(_ThemeUtil.isPlainObject(c)||Array.isArray(c))&&!h.has(c)&&f.push({value:c,isProcessed:!1})}}else{f.pop(),h.delete(c);// Unwind the path
|
|
96
|
+
let a=c;if(Array.isArray(c)){let b=null;for(let a=0;a<c.length;a++){const d=c[a],e=g.get(d)??d;e!==d&&(null===b&&(b=[...c]),b[a]=e)}null!==b&&(a=b)}else{let e=null;for(const a in c)if(Object.prototype.hasOwnProperty.call(c,a)){const f=c[a];let h=g.get(f)??f;if("function"==typeof h&&d){const a=h(b);h="string"==typeof a&&a.includes("theme.")?i(a):a}else"string"==typeof h&&h.includes("theme.")&&(h=i(h));h!==f&&(null===e&&(e=_objectSpread({},c)),e[a]=h)}null!==e&&(a=e)}g.set(c,a)}}const j=g.get(a)??a;return _ThemeUtil.themeCache.shouldCache()&&_ThemeUtil.themeCache.setResolution(a,b,j),j}),_defineProperty(ThemeUtil,"clearThemeCache",()=>{_ThemeUtil.themeCache.clear()}),_defineProperty(ThemeUtil,"resolveDefaultStyle",a=>{if(null===a||a===void 0||"string"==typeof a||"number"==typeof a||"boolean"==typeof a)return{};// === STEP 1: EXTRACT FLEX PROPERTY ===
|
|
96
97
|
// Extract flex shorthand to handle it separately from individual flex properties
|
|
97
|
-
|
|
98
|
+
const b=a,{flex:c}=b,d=_objectWithoutProperties(b,_excluded),e="flex"===d.display||"inline-flex"===d.display,f=!!(d.overflow||d.overflowY||d.overflowX),g=d.flexFlow?.includes("wrap")||"wrap"===d.flexWrap||"wrap-reverse"===d.flexWrap,h="flexShrink"in a&&a.flexShrink!==void 0,i=c?_ThemeUtil.parseFlexShorthand(c):null;// === STEP 2: ANALYZE LAYOUT CONTEXT ===
|
|
98
99
|
// Determine what kind of element we're dealing with
|
|
99
100
|
// Check if overflow is set (any overflow value indicates potential scrolling)
|
|
100
101
|
// Check if flex wrapping is enabled (allows items to wrap to new lines)
|
|
@@ -102,16 +103,16 @@ var c=a,d=c.flex,e=_objectWithoutProperties(c,_excluded),f="flex"===e.display||"
|
|
|
102
103
|
// Respect user's explicit flexShrink setting
|
|
103
104
|
// Extract shrink value from flex shorthand if provided
|
|
104
105
|
// === STEP 4: DETERMINE FLEX SHRINK BEHAVIOR ===
|
|
105
|
-
|
|
106
|
-
if(!
|
|
107
|
-
if(j
|
|
108
|
-
if(!
|
|
106
|
+
let j;// Only set flexShrink if user hasn't explicitly provided it
|
|
107
|
+
if(!h)// If flex shorthand contains a shrink value, use that
|
|
108
|
+
if(i)j=i.shrink;else// Apply context-based defaults
|
|
109
|
+
if(!e)// NON-FLEX CONTAINER LOGIC:
|
|
109
110
|
// Default flex-shrink to 0 to prevent unwanted shrinking of flex items
|
|
110
|
-
|
|
111
|
+
j=0;else// FLEX CONTAINER LOGIC:
|
|
111
112
|
// Only prevent shrinking when container is constrained (no overflow handling, no wrapping)
|
|
112
|
-
if(!
|
|
113
|
+
if(!f){const a="column"===d.flexDirection||"column-reverse"===d.flexDirection,b="row"===d.flexDirection||"row-reverse"===d.flexDirection||!d.flexDirection;a&&!g?j=0:b&&!g&&(j=0)}// === STEP 5: RETURN RESOLVED STYLES ===
|
|
113
114
|
// Combine all processed styles with essential defaults
|
|
114
|
-
return _objectSpread({flex:
|
|
115
|
-
flexShrink:
|
|
115
|
+
return _objectSpread({flex:c,// Preserve original flex shorthand
|
|
116
|
+
flexShrink:j,// Apply computed or explicit flexShrink
|
|
116
117
|
minHeight:0,// Fix flex item scrolling issues
|
|
117
|
-
minWidth:0},
|
|
118
|
+
minWidth:0},d)});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meonode/ui",
|
|
3
3
|
"description": "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.",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.9",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/main.js",
|
|
7
7
|
"types": "./dist/main.d.ts",
|
|
@@ -31,8 +31,10 @@
|
|
|
31
31
|
"scripts": {
|
|
32
32
|
"watch:build": "yarn dlx nodemon --watch src --ext ts,tsx,js,json --exec \"yarn build\"",
|
|
33
33
|
"lint": "eslint --fix",
|
|
34
|
-
"test": "NODE_OPTIONS='--expose-gc' node --stack-size=10000 --experimental-vm-modules node_modules/jest/bin/jest.js --ci --verbose",
|
|
35
|
-
"
|
|
34
|
+
"test": "NODE_OPTIONS='--expose-gc' node --stack-size=10000 --experimental-vm-modules node_modules/jest/bin/jest.js --ci --verbose --testPathIgnorePatterns=\"tests/performance.test.ts\"",
|
|
35
|
+
"test:perf": "NODE_OPTIONS='--expose-gc' node --stack-size=10000 --experimental-vm-modules node_modules/jest/bin/jest.js --ci --verbose tests/performance.test.ts",
|
|
36
|
+
"test:all": "NODE_OPTIONS='--expose-gc' node --stack-size=10000 --experimental-vm-modules node_modules/jest/bin/jest.js --ci --verbose",
|
|
37
|
+
"prebuild": "yarn lint && yarn test:all",
|
|
36
38
|
"build": "yarn prebuild && rm -rf ./dist && babel src --out-dir dist --extensions \".ts,.tsx,.js\" && tsgo -p tsconfig.build.json --diagnostics && tsc-alias -p tsconfig.build.json",
|
|
37
39
|
"publish:pre": "./prepublish.sh && yarn build && yarn version -i prerelease && yarn npm publish --tag next",
|
|
38
40
|
"publish:patch": "./prepublish.sh && yarn build && yarn version -i patch && yarn npm publish --tag latest",
|
|
@@ -55,13 +57,14 @@
|
|
|
55
57
|
"@testing-library/jest-dom": "^6.9.1",
|
|
56
58
|
"@testing-library/react": "^16.3.0",
|
|
57
59
|
"@types/jest": "^30.0.0",
|
|
58
|
-
"@types/react": "^19.2.
|
|
60
|
+
"@types/react": "^19.2.6",
|
|
59
61
|
"@types/react-dom": "^19.2.3",
|
|
60
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
61
|
-
"@typescript-eslint/parser": "^8.
|
|
62
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
62
|
+
"@typescript-eslint/eslint-plugin": "^8.47.0",
|
|
63
|
+
"@typescript-eslint/parser": "^8.47.0",
|
|
64
|
+
"@typescript/native-preview": "^7.0.0-dev.20251118.1",
|
|
63
65
|
"babel-plugin-module-resolver": "^5.0.2",
|
|
64
66
|
"babel-preset-minify": "0.5.2",
|
|
67
|
+
"cli-table3": "^0.6.5",
|
|
65
68
|
"eslint": "^9.39.1",
|
|
66
69
|
"eslint-plugin-jsdoc": "^61.2.1",
|
|
67
70
|
"eslint-plugin-prettier": "^5.5.4",
|
|
@@ -76,7 +79,7 @@
|
|
|
76
79
|
"ts-jest": "^29.4.5",
|
|
77
80
|
"tsc-alias": "^1.8.16",
|
|
78
81
|
"typescript": "^5.9.3",
|
|
79
|
-
"typescript-eslint": "^8.
|
|
82
|
+
"typescript-eslint": "^8.47.0"
|
|
80
83
|
},
|
|
81
84
|
"packageManager": "yarn@4.10.2",
|
|
82
85
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.const.d.ts","sourceRoot":"","sources":["../../src/constants/common.const.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,uOAwBhB,CAAA;AAEV,eAAO,MAAM,cAAc,uPAAyB,CAAA;AACpD,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA;AAEhD,eAAO,IAAI,SAAS,SAAQ,CAAA;AAE5B,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,QAK5C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export var NO_STYLE_TAGS=["html","head","meta","link","script","style","noscript","template","slot","base","param","source","track","wbr","embed","object","iframe","frame","frameset","applet","bgsound","noembed","noframes"];export var noStyleTagsSet=new Set(NO_STYLE_TAGS);export var __DEBUG__=!1;export function setDebugMode(a){__DEBUG__=a,__DEBUG__&&console.log("[MeoNode] Debug mode enabled.")}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"css-properties.const.d.ts","sourceRoot":"","sources":["../../src/constants/css-properties.const.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,aAAa,k0ZAirBT,CAAA;AAEV,eAAe,aAAa,CAAA"}
|