@meonode/ui 0.1.51 → 0.1.52
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hook/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./useClasses";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function getServerStyles(): string;
|
|
2
|
+
type CSSValue = string | number;
|
|
3
|
+
interface NestedStyle {
|
|
4
|
+
[key: string]: CSSValue | NestedStyle;
|
|
5
|
+
}
|
|
6
|
+
interface StyleObject extends NestedStyle {
|
|
7
|
+
[key: string]: CSSValue | StyleObject;
|
|
8
|
+
}
|
|
9
|
+
export declare function useClasses(sxObject: StyleObject, deps?: any[]): string;
|
|
10
|
+
export declare function purgeStyles(): void;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=useClasses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useClasses.d.ts","sourceRoot":"","sources":["../../src/hook/useClasses.ts"],"names":[],"mappings":"AAMA,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAuBD,KAAK,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAA;AAC/B,UAAU,WAAW;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAA;CACtC;AACD,UAAU,WAAY,SAAQ,WAAW;IACvC,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,GAAG,WAAW,CAAA;CACtC;AA+CD,wBAAgB,UAAU,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,GAAE,GAAG,EAAO,GAAG,MAAM,CA2F1E;AA4GD,wBAAgB,WAAW,SAa1B"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
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 _createForOfIteratorHelper(b,c){var d="undefined"!=typeof Symbol&&b[Symbol.iterator]||b["@@iterator"];if(!d){if(Array.isArray(b)||(d=_unsupportedIterableToArray(b))||c&&b&&"number"==typeof b.length){d&&(b=d);var e=0,f=function F(){};return{s:f,n:function n(){return e>=b.length?{done:!0}:{done:!1,value:b[e++]}},e:function e(a){throw a},f:f}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var g,h=!0,i=!1;return{s:function s(){d=d.call(b)},n:function n(){var a=d.next();return h=a.done,a},e:function e(a){i=!0,g=a},f:function f(){try{h||null==d["return"]||d["return"]()}finally{if(i)throw g}}}}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(b,c){if(b){if("string"==typeof b)return _arrayLikeToArray(b,c);var a={}.toString.call(b).slice(8,-1);return"Object"===a&&b.constructor&&(a=b.constructor.name),"Map"===a||"Set"===a?Array.from(b):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?_arrayLikeToArray(b,c):void 0}}function _arrayLikeToArray(b,c){(null==c||c>b.length)&&(c=b.length);for(var d=0,f=Array(c);d<c;d++)f[d]=b[d];return f}function _iterableToArrayLimit(b,c){var d=null==b?null:"undefined"!=typeof Symbol&&b[Symbol.iterator]||b["@@iterator"];if(null!=d){var g,h,j,k,l=[],a=!0,m=!1;try{if(j=(d=d.call(b)).next,0===c){if(Object(d)!==d)return;a=!1}else for(;!(a=(g=j.call(d)).done)&&(l.push(g.value),l.length!==c);a=!0);}catch(a){m=!0,h=a}finally{try{if(!a&&null!=d["return"]&&(k=d["return"](),Object(k)!==k))return}finally{if(m)throw h}}return l}}function _arrayWithHoles(a){if(Array.isArray(a))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{useEffect,useMemo}from"react";// Server-side rendering support
|
|
2
|
+
var serverStyles=[],serverRuleIndex=0;export function getServerStyles(){return serverStyles.join("\n")}// Client-side style management
|
|
3
|
+
var styleSheet;if("undefined"!=typeof document){var styleTag=document.head.querySelector("#__sx")||function(){var a=document.createElement("style");return a.id="__sx",document.head.appendChild(a),a}();styleSheet=styleTag.sheet}var ruleIndex=0,sxCache=new Map,refCountMap=new Map,ruleMap=new Map,unitlessProperties=new Set(["animationIterationCount","borderImageOutset","borderImageSlice","borderImageWidth","boxFlex","boxFlexGroup","boxOrdinalGroup","columnCount","columns","flex","flexGrow","flexPositive","flexShrink","flexNegative","flexOrder","gridRow","gridRowEnd","gridRowSpan","gridRowStart","gridColumn","gridColumnEnd","gridColumnSpan","gridColumnStart","fontWeight","lineClamp","lineHeight","opacity","order","orphans","tabSize","widows","zIndex","zoom","fillOpacity","floodOpacity","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth"]);// Improved type definitions
|
|
4
|
+
// Unitless CSS properties
|
|
5
|
+
export function useClasses(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],c=useMemo(function(){return"".concat(stableStringify(a),"::").concat(stableStringify(b))},[a,b]);// Stable cache key generation
|
|
6
|
+
// Manage reference counting
|
|
7
|
+
// Return cached className if available
|
|
8
|
+
if(useEffect(function(){return refCountMap.set(c,(refCountMap.get(c)||0)+1),function(){var a=refCountMap.get(c)||1;1===a?(removeStyleRules(c),sxCache["delete"](c),refCountMap["delete"](c)):refCountMap.set(c,a-1)}},[c]),sxCache.has(c))return sxCache.get(c);// Generate new className
|
|
9
|
+
var d="sx-".concat(ruleIndex++),e=[],f={},g={},h={},i={};// Process style object
|
|
10
|
+
for(var j in a){var k=a[j];// Handle nested selectors
|
|
11
|
+
if(j.startsWith("&")){var l=j.replace(/&/g,".".concat(d)),m=toCssString(k);m&&e.push("".concat(l," { ").concat(m," }"))}// Handle media queries
|
|
12
|
+
else j.startsWith("@media")?processAtRuleBlock(j,k,d,g):j.startsWith("@container")?processAtRuleBlock(j,k,d,h):j.startsWith("@supports")?processAtRuleBlock(j,k,d,i):f[j]=k}// Add base styles
|
|
13
|
+
var n=toCssString(f);// Inject styles
|
|
14
|
+
if(n&&e.unshift(".".concat(d," { ").concat(n," }")),processAtRuleBlocks(g,e),processAtRuleBlocks(h,e),processAtRuleBlocks(i,e),"undefined"==typeof document){// Server-side rendering
|
|
15
|
+
var o="sx-".concat(serverRuleIndex++),p=e.map(function(a){return a.replace(new RegExp(d,"g"),o)}).join("\n");return serverStyles.push(p),sxCache.set(c,o),o}// Cache and return
|
|
16
|
+
return styleSheet&&// Client-side injection
|
|
17
|
+
injectStyles(e),ruleMap.set(c,e),sxCache.set(c,d),d}// Helper function to process at-rule blocks
|
|
18
|
+
function processAtRuleBlock(a,b,c,d){for(var e in d[a]||(d[a]=[]),b){var f=b[e],g=".".concat(c);if(e.startsWith("&")){var h=e.replace(/&/g,g),i=toCssString(f);i&&d[a].push("".concat(h," { ").concat(i," }"))}else{var j=toCssString(_defineProperty({},e,f));j&&d[a].push("".concat(g," { ").concat(j," }"))}}}// Helper to finalize at-rule blocks
|
|
19
|
+
function processAtRuleBlocks(a,b){for(var c=0,d=Object.entries(a);c<d.length;c++){var e=_slicedToArray(d[c],2),f=e[0],g=e[1];g.length&&b.push("".concat(f," { ").concat(g.join(" ")," }"))}}// Inject styles using CSSStyleSheet API
|
|
20
|
+
function injectStyles(a){if(styleSheet){var b,c=_createForOfIteratorHelper(a);try{for(c.s();!(b=c.n()).done;){var d=b.value;try{styleSheet.insertRule(d,styleSheet.cssRules.length)}catch(a){console.error("Failed to insert CSS rule: ".concat(d),a)}}}catch(a){c.e(a)}finally{c.f()}}}// Remove unused style rules
|
|
21
|
+
function removeStyleRules(a){var b=ruleMap.get(a);if(b&&styleSheet){// Find and remove rules in reverse order
|
|
22
|
+
for(var c,d=styleSheet.cssRules.length-1;0<=d;d--)c=styleSheet.cssRules[d],b.includes(c.cssText)&&styleSheet.deleteRule(d);ruleMap["delete"](a)}}// Convert style objects to CSS strings with nesting support
|
|
23
|
+
function toCssString(a){return Object.entries(a).map(function(a){var b=_slicedToArray(a,2),c=b[0],d=b[1];// Handle nested objects recursively
|
|
24
|
+
return"object"===_typeof(d)&&null!==d?toCssString(d):"number"!=typeof d||isUnitlessProperty(c)?"".concat(camelToKebab(c),": ").concat(d,";"):"".concat(camelToKebab(c),": ").concat(d,"px;");// Handle numeric values
|
|
25
|
+
}).join(" ")}// Check if property is unitless
|
|
26
|
+
function isUnitlessProperty(a){return unitlessProperties.has(a)}// Stable JSON stringification
|
|
27
|
+
function stableStringify(a){if(null===a||"object"!==_typeof(a))return JSON.stringify(a);if(Array.isArray(a))return"[".concat(a.map(stableStringify).join(","),"]");var b=Object.keys(a).sort(),c=b.map(function(b){return"\"".concat(b,"\":").concat(stableStringify(a[b]))});return"{".concat(c.join(","),"}")}// Convert camelCase to kebab-case
|
|
28
|
+
function camelToKebab(a){return a.replace(/([A-Z])([A-Z])/g,"$1-$2").replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}// Global style cleanup function
|
|
29
|
+
export function purgeStyles(){if(styleSheet)for(;0<styleSheet.cssRules.length;)styleSheet.deleteRule(0);serverStyles=[],sxCache.clear(),ruleMap.clear(),refCountMap.clear(),ruleIndex=0,serverRuleIndex=0}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meonode/ui",
|
|
3
3
|
"description": "A structured approach to component composition with built-in theming, prop separation, and dynamic children handling.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.52",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/main.js",
|
|
7
7
|
"types": "./dist/main.d.ts",
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/main.js",
|
|
11
11
|
"types": "./dist/main.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./hook": {
|
|
14
|
+
"import": "./dist/hook/index.js",
|
|
15
|
+
"types": "./dist/hook/index.d.ts"
|
|
12
16
|
}
|
|
13
17
|
},
|
|
14
18
|
"files": [
|