text: import{m as e,C as t,c as r,e as n,d as o,o as a,u as l,_ as c,b as s,h as i}from"./useTheme-342e9351.js";import u,{useMemo as f}from"react";import{hasDomAccess as m,hashString as d,isArr as p,isStr as v,noPropArr as y,isObj as S,splitByKeys as h,exists as _,eitherArr as b,hyphenator as g,deepMerge as j,flatArr as E,isEmptyColl as x,noOpObj as C}from"@keg-hub/jsutils";import N from"react-native-web/dist/modules/prefixStyles";import w from"react-native-web/dist/exports/StyleSheet/createReactDOMStyle";import T from"react-native-web/dist/exports/StyleSheet/createCompileableStyle";var k,loopArrStyle=function(e,t){for(var r=0,n=e.length;r<n;++r){var o=flattenStyle(e[r]);if(o)for(var a in o){var l=o[a];t[a]=l}}return t},flattenStyle=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e&&!0!==e?Array.isArray(e)?loopArrStyle(e,t):e:void 0},O={important:[],filter:["aspectRatio","elevation","overlayColor","resizeMode","tintColor","backgroundSize","animationKeyframes","placeholderTextColor","pointerEvents","scrollbarWidth"],allowedStyleObject:["transform","shadowOffset","textShadowOffset","animationKeyframes"]},K=m(),R=new Set,selectorExists=function(e){return R.has(e)},getKegSheet=function(){return k=k||document.head.querySelector("#".concat(t.KEG_STYLES_TAG_ID))},formatSelectors=function(e,t,r,o){var a=_(o)?o:1,l=t.filter((function(e){return e&&r?e.startsWith(r):e})).reverse().slice(0,a).sort().reduce((function(e,t){return t&&e.push.apply(e,n(t.split(" "))),e}),[]);return{selector:".".concat(l.concat([e]).join(".")).trim(),classNames:t.concat([e]).join(" ").trim()}},getSelector=function(e,t,r,n){var o="".concat(r,"-").concat(d(t)),a=p(e)?formatSelectors(o,e,r,n):v(e)?formatSelectors(o,e.split(" "),r,n):formatSelectors(o,y,r,n),l=a.selector;return{hashClass:o,classNames:a.classNames,selector:!selectorExists(l)&&l}},addStylesToDom=function(e,t){if(K&&t&&t.all&&!selectorExists(e))try{R.add(e),getKegSheet().sheet.insertRule(t.all)}catch(e){console.error(e)}};e(t.BUILD_EVENT,(function(){R.clear(),getKegSheet().textContent=""})),function(){if(K){if(k=document.head.querySelector("#".concat(t.KEG_STYLES_TAG_ID)))return k;(k=document.createElement("style")).id=t.KEG_STYLES_TAG_ID,document.head.append(k)}}();var createBlock=function(e,t){var r=O.important.concat(null==t?void 0:t.important),n=N(w(e)),o=Object.keys(n).map((function(e){var t=function(e,t,r){return r.includes(e)?"".concat(t," !important"):t}(e,n[e],r),o=g(e);return p(t)?t.map((function(e){return"".concat(o,":").concat(e)})).join(";"):"".concat(o,":").concat(t)})).sort().join(";");return o.length?"{".concat(o,";}"):"{}"},convertToCss=function(e,t){var o=j.apply(void 0,n(E(b(e,[e])))),a={blocks:[],filtered:{}};if(!S(o))return a;var l=function(e,t){var n=p(t)?O.filter.concat(t):O.filter,o={},a=!1,l=Object.entries(e).reduce((function(e,t){var n=r(t,2),l=n[0],c=n[1];return!S(c)&&!p(c)||O.allowedStyleObject.includes(l)?o[l]=c:(a=!0,e[l]=c),e}),{});if(a)return{style:o,filtered:l};var c=h(e,n),s=r(c,2),i=s[0];return{style:s[1],filtered:i}}(o,null==t?void 0:t.filter),c=l.style,s=l.filtered;if(a.filtered=s,!c||x(c))return a;var i=flattenStyle(c),u=T(i);return a.blocks.push(createBlock(u,t)),a},useStyleTag=function(e){var t,r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",a=arguments.length>2?arguments[2]:void 0;a=S(a)?a:C;var l=o(),c=null==l||null===(t=l.RTMeta)||void 0===t?void 0:t.size,s=null==l||null===(r=l.RTMeta)||void 0===r?void 0:r.key;return f((function(){var t={all:"",rules:[]},r=convertToCss(e,a),o=r.blocks,l=r.filtered;if(!o.length)return{css:t,filteredStyle:l,classNames:b(n,[n]).join(" ")};var c=getSelector(n,o.join(""),a.prefix||"keg",a.maxSelectors),s=c.selector,i=c.classNames;return s&&o.map((function(e){var r="".concat(s).concat(e);t.all+=r,t.rules.push(r)})),t.all&&addStylesToDom(s,t),{css:t,classNames:i,filteredStyle:l}}),[e,n,c,s,a])},G=["config","children","Component","className","styleProp","splitStyles"],I=C,buildConfig=function(e){var t=e.kegComponent?e.maxSelectors:I.maxSelectors;return i(i(i({},e),I),{},{maxSelectors:t||0})},A=u.forwardRef((function(e,t){var r=e.config,n=e.children,o=e.Component,i=e.className,f=e.styleProp,m=e.splitStyles,d=a(e,G),p=r.className,v=l(m),y=useStyleTag(v,i||p,r),S=y.classNames,h=y.filteredStyle;return u.createElement(o,c({},d,s({},f,h),{ref:t,className:S}),n)})),StyleInjector=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:C;return t=buildConfig(t),u.forwardRef((function(n,o){var a=n.__reStyleStylePropKey__||"style",l=h(n,[a,"__reStyleStylePropKey__"]),i=r(l,2),f=i[0],m=i[1],d=f[a];return d&&d!==C?u.createElement(A,c({},m,{ref:o,config:t,Component:e,splitStyles:d,styleProp:a})):u.createElement(e,c({},m,s({},a,d),{ref:o}))}))};StyleInjector.setConfig=function(e){S(e)||console.warn('Injector config must be an "Object". Instead got',e),I=e};export{StyleInjector as S,convertToCss as a,createBlock as c,useStyleTag as u};
  //# sourceMappingURL=styleInjector-a4cde898.js.map
  