Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gluestack-style/babel-plugin-styled-resolver

Package Overview
Dependencies
Maintainers
9
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gluestack-style/babel-plugin-styled-resolver - npm Package Compare versions

Comparing version 0.2.6 to 0.2.7-alpha.0

2

lib/index.js

@@ -1,1 +0,1 @@

var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var fs=require('fs');var path=require('path');var babel=require('@babel/parser');var generate=require('@babel/generator').default;var babelPresetTypeScript=require('@babel/preset-typescript');var traverse=require('@babel/traverse').default;var types=require('@babel/types');var _require=require('@gluestack-style/react/lib/commonjs/convertSxToSxVerbosed'),convertStyledToStyledVerbosed=_require.convertStyledToStyledVerbosed,convertSxToSxVerbosed=_require.convertSxToSxVerbosed;var _require2=require('@gluestack-style/react/lib/commonjs/propertyTokenMap'),propertyTokenMap=_require2.propertyTokenMap;var _require3=require('@gluestack-style/react/lib/commonjs/stableHash'),stableHash=_require3.stableHash;var _require4=require('@gluestack-style/react/lib/commonjs/core/styled-system'),CSSPropertiesMap=_require4.CSSPropertiesMap;var _require5=require('@gluestack-style/react/lib/commonjs/style-sheet/index'),StyleInjector=_require5.StyleInjector;var _require6=require('@gluestack-style/react/lib/commonjs/updateOrderUnResolvedMap'),updateOrderUnResolvedMap=_require6.updateOrderUnResolvedMap;var _require7=require('@gluestack-style/react/lib/commonjs/utils'),setObjectKeyValue=_require7.setObjectKeyValue;var IMPORT_NAME='@gluestack-style/react';var configThemePath=[];var BUILD_TIME_GLUESTACK_STYLESHEET=new StyleInjector();var convertExpressionContainerToStaticObject=function convertExpressionContainerToStaticObject(properties){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var keyPath=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var propsToBePersist=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{};properties==null?void 0:properties.forEach(function(property,index){var _property$key$name;var nodeName=(_property$key$name=property.key.name)!=null?_property$key$name:property.key.value;if(property.value.type==='ObjectExpression'){keyPath.push(nodeName);convertExpressionContainerToStaticObject(property.value.properties,result,keyPath,propsToBePersist);keyPath.pop();}else if(property.value.type==='Identifier'){if(property.key.value){setObjectKeyValue(propsToBePersist,[].concat((0,_toConsumableArray2.default)(keyPath),[nodeName]),property.value.name);}if(property.key.name){setObjectKeyValue(propsToBePersist,[].concat((0,_toConsumableArray2.default)(keyPath),[nodeName]),property.value.name);}}else{if(property.key.value){setObjectKeyValue(result,[].concat((0,_toConsumableArray2.default)(keyPath),[property.key.value]),property.value.value);}if(property.key.name){setObjectKeyValue(result,[].concat((0,_toConsumableArray2.default)(keyPath),[property.key.name]),property.value.value);}}});return{result:result,propsToBePersist:propsToBePersist};};function addQuotesToObjectKeys(code){var ast=babel.parse("var a = "+code,{presets:[babelPresetTypeScript],plugins:['typescript'],sourceType:'module'});traverse(ast,{ObjectProperty:function ObjectProperty(objectPropertyPath){if(types.isTemplateLiteral(objectPropertyPath.node.value)){objectPropertyPath.node.value=types.stringLiteral(objectPropertyPath.node.value.quasis[0].value.raw);}if(types.isIdentifier(objectPropertyPath.node.key)){objectPropertyPath.node.key=types.stringLiteral(objectPropertyPath.node.key.name);}if(types.isNumericLiteral(objectPropertyPath.node.key)){objectPropertyPath.node.key=types.stringLiteral(objectPropertyPath.node.key.extra.raw);}if(types.isStringLiteral(objectPropertyPath.node.value)){objectPropertyPath.node.value=types.stringLiteral(objectPropertyPath.node.value.value);}}});var initAst;traverse(ast,{ObjectProperty:function ObjectProperty(objectPropertyPath){var _objectPropertyPath$n,_objectPropertyPath$n2,_objectPropertyPath$n3,_objectPropertyPath$n4;if(types.isArrayExpression(objectPropertyPath==null?void 0:(_objectPropertyPath$n=objectPropertyPath.node)==null?void 0:_objectPropertyPath$n.value)){var arrayElements=objectPropertyPath.node.value.elements;var dynamicElementsIndex=[];arrayElements.forEach(function(element,index){if(types.isNewExpression(element)||types.isIdentifier(element)||types.isTemplateLiteral(element)){dynamicElementsIndex.push(index);}});arrayElements=arrayElements.filter(function(element,index){return!dynamicElementsIndex.includes(index);});objectPropertyPath.node.value.elements=arrayElements;}else if(types.isIdentifier(objectPropertyPath==null?void 0:(_objectPropertyPath$n2=objectPropertyPath.node)==null?void 0:_objectPropertyPath$n2.value)||types.isTemplateLiteral(objectPropertyPath==null?void 0:(_objectPropertyPath$n3=objectPropertyPath.node)==null?void 0:_objectPropertyPath$n3.value)||types.isConditionalExpression(objectPropertyPath==null?void 0:(_objectPropertyPath$n4=objectPropertyPath.node)==null?void 0:_objectPropertyPath$n4.value)){objectPropertyPath.remove();}}});traverse(ast,{VariableDeclarator:function VariableDeclarator(variableDeclaratorPath){initAst=variableDeclaratorPath.node.init;}});var _generate=generate(initAst,{sourceType:'module',presets:[babelPresetTypeScript],plugins:['typescript']}),output=_generate.code;return output;}var merge=require('lodash.merge');var _require8=require('process'),exit=_require8.exit;var checkIfPathIsAbsolute=function checkIfPathIsAbsolute(path){return path.startsWith('/');};function getConfig(configPath){if(configPath){return fs.readFileSync(path.join(!checkIfPathIsAbsolute(configPath)?process.cwd():'',configPath),'utf8');}var isConfigJSExist=fs.existsSync(path.join(process.cwd(),'./gluestack-style.config.js'));var isGlueStackUIConfigJSExist=fs.existsSync(path.join(process.cwd(),'./gluestack-ui.config.js'));var isConfigTSExist=fs.existsSync(path.join(process.cwd(),'./gluestack-style.config.ts'));var isGlueStackUIConfigTSExist=fs.existsSync(path.join(process.cwd(),'./gluestack-ui.config.ts'));if(isConfigTSExist){return fs.readFileSync(path.join(process.cwd(),'./gluestack-style.config.ts'),'utf8');}if(isConfigJSExist){return fs.readFileSync(path.join(process.cwd(),'./gluestack-style.config.js'),'utf8');}if(isGlueStackUIConfigJSExist){configThemePath=['theme'];return fs.readFileSync(path.join(process.cwd(),'./gluestack-ui.config.js'),'utf8');}if(isGlueStackUIConfigTSExist){configThemePath=['theme'];return fs.readFileSync(path.join(process.cwd(),'./gluestack-ui.config.ts'),'utf8');}}function getSurroundingCharacters(string,index){var start=Math.max(0,index-5);var end=Math.min(string.length,index+6);return string.slice(start,end);}function getExportedConfigFromFileString(fileData){var _fileData,_objectCode,_addQuotesToObjectKey;if(!fileData){return{};}fileData=(_fileData=fileData)==null?void 0:_fileData.replace(/as const/g,'');var ast=babel.parse(fileData,{presets:[babelPresetTypeScript],plugins:['typescript'],sourceType:'module',comments:false});var config={};traverse(ast,{CallExpression:function CallExpression(path){var _path$node=path.node,callee=_path$node.callee,args=_path$node.arguments;if(types.isIdentifier(callee,{name:'createConfig'})&&args.length===1&&types.isObjectExpression(args[0])){path.replaceWith(args[0]);}}});traverse(ast,{ExportNamedDeclaration:function ExportNamedDeclaration(path){path.traverse({VariableDeclarator:function VariableDeclarator(variableDeclaratorPath){config=variableDeclaratorPath.node.init;}});},Identifier:function Identifier(path){if(path.node.name==='undefined'){path.node.name='null';}}});var objectCode=generate(config).code;objectCode=(_objectCode=objectCode)==null?void 0:_objectCode.replace(/\/\/.*|\/\*[\s\S]*?\*\//g,'');objectCode=(_addQuotesToObjectKey=addQuotesToObjectKeys(objectCode))==null?void 0:_addQuotesToObjectKey.replace(/'/g,'"');return JSON.parse(objectCode);}function replaceSingleQuotes(str){var inDoubleQuotes=false;var newStr='';for(var i=0;i<str.length;i++){if(str[i]==='"'){inDoubleQuotes=!inDoubleQuotes;}if(str[i]==="'"&&!inDoubleQuotes){newStr+='"';}else{newStr+=str[i];}}return newStr;}function getObjectFromAstNode(node){var _objectCode2;var objectCode=generate(node).code;objectCode=(_objectCode2=objectCode)==null?void 0:_objectCode2.replace(/as const/g,'');objectCode=addQuotesToObjectKeys(objectCode.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,function(m,g){return g?'':m;}));objectCode=replaceSingleQuotes(objectCode);return JSON.parse(objectCode);}function removeLiteralPropertiesFromObjectProperties(code){var ast=babel.parse("var a = "+code,{presets:[babelPresetTypeScript],plugins:['typescript'],sourceType:'module'});traverse(ast,{ObjectExpression:function ObjectExpression(path){path.traverse({ObjectProperty:function ObjectProperty(path){var value=path.node.value;path.traverse({StringLiteral:function StringLiteral(stringPath){stringPath;}});if(value.type==='StringLiteral'||value.type==='NumericLiteral'){path.remove();}}});}});var initAst;traverse(ast,{VariableDeclarator:function VariableDeclarator(path){initAst=path.node.init;}});return initAst;}function getIdentifiersObjectFromAstNode(node){var objectCode=generate(node).code;return removeLiteralPropertiesFromObjectProperties(objectCode.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,function(m,g){return g?'':m;}));}function isImportedFromLibrary(libraries,importName){if(libraries.includes(importName)){return true;}return false;}function isImportFromAbsolutePath(absolutePaths,filePath,importedAbsolutePath){filePath.pop();var finalAbsolutePath=path.resolve(filePath.join('/'),importedAbsolutePath);if(absolutePaths.includes(finalAbsolutePath)){return true;}return false;}var CONFIG=getExportedConfigFromFileString(getConfig());var ConfigDefault=CONFIG;module.exports=function(b){var t=b.types;function generateObjectAst(obj){var properties=Object.entries(obj).map(function(_ref){var _ref2=(0,_slicedToArray2.default)(_ref,2),key=_ref2[0],value=_ref2[1];if(typeof value==='undefined'){return;}else if(typeof value==='object'&&!Array.isArray(value)){return t.objectProperty(t.stringLiteral(key),generateObjectAst(value));}else if(typeof value==='object'&&Array.isArray(value)){var elements=value.map(function(obj){if(typeof obj==='string'){return t.stringLiteral(obj);}else{return generateObjectAst(obj);}});return t.objectProperty(t.stringLiteral(key),t.arrayExpression(elements));}else if(typeof value==='boolean'){return t.objectProperty(t.stringLiteral(key),t.booleanLiteral(value));}else{return t.objectProperty(t.stringLiteral(key),typeof value==='number'?t.numericLiteral(value):t.stringLiteral(value));}});return t.objectExpression(properties.filter(function(property){return property;}));}function generateArrayAst(arr){return t.arrayExpression(arr.map(function(obj){return generateObjectAst(obj);}));}function checkWebFileExists(filePath){if(filePath.includes('node_modules')){return false;}var ext=path.extname(filePath);var dirname=path.dirname(filePath);var basename=path.basename(filePath,ext);var webFilePath=path.join(dirname,basename+".web"+ext);return fs.existsSync(webFilePath);}var styledImportName='';var styledAlias='';var styledAliasImportedName='';var tempPropertyResolverNode;var isValidConfig=true;var platform='all';var currentFileName='file not found!';var configPath;var outputLibrary;var componentSXProp;var componentUtilityProps;var guessingStyledComponents=[];var styled=['@gluestack-style/react','@gluestack-ui/themed'];var components=['@gluestack-ui/themed'];var isStyledPathConfigured=false;var isComponentsPathConfigured=false;var targetPlatform=process.env.GLUESTACK_STYLE_TARGET;return{name:'ast-transform',visitor:{ImportDeclaration:function ImportDeclaration(importPath,state){var _state$opts,_state$opts2,_state$opts3,_state$opts5,_state$opts7,_state$opts9,_state$opts10,_state$opts12,_state$opts13;currentFileName=state.file.opts.filename;styledAlias=state==null?void 0:(_state$opts=state.opts)==null?void 0:_state$opts.styledAlias;outputLibrary=(state==null?void 0:(_state$opts2=state.opts)==null?void 0:_state$opts2.outputLibrary)||outputLibrary;if(state!=null&&(_state$opts3=state.opts)!=null&&_state$opts3.configPath){var _state$opts4;configPath=state==null?void 0:(_state$opts4=state.opts)==null?void 0:_state$opts4.configPath;}if(state!=null&&(_state$opts5=state.opts)!=null&&_state$opts5.configThemePath){var _state$opts6;configThemePath=state==null?void 0:(_state$opts6=state.opts)==null?void 0:_state$opts6.configThemePath;}if(state!=null&&(_state$opts7=state.opts)!=null&&_state$opts7.platform){var _state$opts8;platform=state==null?void 0:(_state$opts8=state.opts)==null?void 0:_state$opts8.platform;}else{platform='all';}if(configPath){ConfigDefault=getExportedConfigFromFileString(getConfig(configPath));}configThemePath.forEach(function(path){var _ConfigDefault;ConfigDefault=(_ConfigDefault=ConfigDefault)==null?void 0:_ConfigDefault[path];});configThemePath=[];if(!currentFileName.includes('node_modules')){if(currentFileName.includes('.web.')){platform='web';}else if(checkWebFileExists(currentFileName)){platform='native';}}if(state!=null&&(_state$opts9=state.opts)!=null&&_state$opts9.styled&&Array.isArray(state==null?void 0:(_state$opts10=state.opts)==null?void 0:_state$opts10.styled)&&!isStyledPathConfigured){var _state$opts11;styled.push.apply(styled,(0,_toConsumableArray2.default)(state==null?void 0:(_state$opts11=state.opts)==null?void 0:_state$opts11.styled));isStyledPathConfigured=true;}if(state!=null&&(_state$opts12=state.opts)!=null&&_state$opts12.components&&Array.isArray(state==null?void 0:(_state$opts13=state.opts)==null?void 0:_state$opts13.components)&&!isComponentsPathConfigured){var _state$opts14;components.push.apply(components,(0,_toConsumableArray2.default)(state==null?void 0:(_state$opts14=state.opts)==null?void 0:_state$opts14.components));isComponentsPathConfigured=true;}var importName=importPath.node.source.value;var filePath=state.file.opts.filename.split('/');if(isImportFromAbsolutePath(components,filePath,importName)||isImportedFromLibrary(components,importName)){importPath.traverse({ImportSpecifier:function ImportSpecifier(importSpecifierPath){guessingStyledComponents.push(importSpecifierPath.node.local.name);}});}if(isImportFromAbsolutePath(styled,filePath,importName)||isImportedFromLibrary(styled,importName)){importPath.traverse({ImportSpecifier:function ImportSpecifier(importSpecifierPath){if(importSpecifierPath.node.imported.name==='styled'){styledImportName=importSpecifierPath.node.local.name;}if(importSpecifierPath.node.imported.name===styledAlias){styledAliasImportedName=importSpecifierPath.node.local.name;}}});}},AssignmentExpression:function AssignmentExpression(expressionPath,state){var _expressionPath$node,_expressionPath$node$,_expressionPath$node$2,_expressionPath$node2,_expressionPath$node3,_expressionPath$node4;if((expressionPath==null?void 0:(_expressionPath$node=expressionPath.node)==null?void 0:(_expressionPath$node$=_expressionPath$node.right)==null?void 0:(_expressionPath$node$2=_expressionPath$node$.callee)==null?void 0:_expressionPath$node$2.name)===styledAliasImportedName||(expressionPath==null?void 0:(_expressionPath$node2=expressionPath.node)==null?void 0:(_expressionPath$node3=_expressionPath$node2.right)==null?void 0:(_expressionPath$node4=_expressionPath$node3.callee)==null?void 0:_expressionPath$node4.name)===styledImportName){var _expressionPath$paren,_expressionPath$paren2;var componentName=expressionPath==null?void 0:(_expressionPath$paren=expressionPath.parent)==null?void 0:(_expressionPath$paren2=_expressionPath$paren.id)==null?void 0:_expressionPath$paren2.name;if(componentName){guessingStyledComponents.push(componentName);}}},CallExpression:function CallExpression(callExpressionPath){if(callExpressionPath.node.callee.name===styledAliasImportedName||callExpressionPath.node.callee.name===styledImportName){var _callExpressionPath$p,_callExpressionPath$p2;var componentName=callExpressionPath==null?void 0:(_callExpressionPath$p=callExpressionPath.parent)==null?void 0:(_callExpressionPath$p2=_callExpressionPath$p.id)==null?void 0:_callExpressionPath$p2.name;if(componentName){guessingStyledComponents.push(componentName);}callExpressionPath.traverse({ObjectProperty:function ObjectProperty(ObjectPath){if(t.isIdentifier(ObjectPath.node.value)){if(ObjectPath.node.value.name==='undefined'){ObjectPath.remove();}}}});if(isValidConfig){var _args$,_args$2;var args=callExpressionPath.node.arguments;var componentThemeNode=args[1];var componentConfigNode=(_args$=args[2])!=null?_args$:t.objectExpression([]);var extendedThemeNode=(_args$2=args[3])!=null?_args$2:t.objectExpression([]);if(!(t.isIdentifier(componentThemeNode)||t.isIdentifier(componentConfigNode)||t.isIdentifier(extendedThemeNode))){var _ConfigDefault2;var extendedThemeNodeProps=[];if(extendedThemeNode&&extendedThemeNode!=null&&extendedThemeNode.properties){extendedThemeNode==null?void 0:extendedThemeNode.properties.forEach(function(prop){if(prop.key.name==='propertyResolver'){tempPropertyResolverNode=prop;}else{extendedThemeNodeProps.push(prop);}});extendedThemeNode.properties=extendedThemeNodeProps;}var theme=getObjectFromAstNode(componentThemeNode);var ExtendedConfig=getObjectFromAstNode(extendedThemeNode);var componentConfig=getObjectFromAstNode(componentConfigNode);if(extendedThemeNode&&tempPropertyResolverNode){extendedThemeNode.properties.push(tempPropertyResolverNode);}var mergedPropertyConfig=Object.assign({},(_ConfigDefault2=ConfigDefault)==null?void 0:_ConfigDefault2.propertyTokenMap,propertyTokenMap);var componentExtendedConfig=merge({},Object.assign({},ConfigDefault,{propertyTokenMap:Object.assign({},mergedPropertyConfig)}),ExtendedConfig);if(theme&&Object.keys(theme).length>0){var verbosedTheme=convertStyledToStyledVerbosed(theme);var componentHash=stableHash(Object.assign({},theme,componentConfig,ExtendedConfig));if(outputLibrary){componentHash=outputLibrary+'-'+componentHash;}var _updateOrderUnResolve=updateOrderUnResolvedMap(verbosedTheme,componentHash,'boot',componentConfig,BUILD_TIME_GLUESTACK_STYLESHEET,platform),styledIds=_updateOrderUnResolve.styledIds,verbosedStyleIds=_updateOrderUnResolve.verbosedStyleIds;var toBeInjected=BUILD_TIME_GLUESTACK_STYLESHEET.resolve(styledIds,componentExtendedConfig,ExtendedConfig);var current_global_map=BUILD_TIME_GLUESTACK_STYLESHEET.getStyleMap();var orderedResolvedTheme=[];current_global_map==null?void 0:current_global_map.forEach(function(styledResolved){var _styledResolved$meta;if(styledIds.includes(styledResolved==null?void 0:(_styledResolved$meta=styledResolved.meta)==null?void 0:_styledResolved$meta.cssId)){orderedResolvedTheme.push(styledResolved);}});var styleIdsAst=generateObjectAst(verbosedStyleIds);var toBeInjectedAst=generateObjectAst(toBeInjected);var orderedResolvedAst=generateArrayAst(orderedResolvedTheme);var orderedStyleIdsArrayAst=t.arrayExpression(styledIds==null?void 0:styledIds.map(function(cssId){return t.stringLiteral(cssId);}));var resultParamsNode=t.objectExpression([t.objectProperty(t.stringLiteral('orderedResolved'),orderedResolvedAst),t.objectProperty(t.stringLiteral('toBeInjected'),toBeInjectedAst),t.objectProperty(t.stringLiteral('styledIds'),orderedStyleIdsArrayAst),t.objectProperty(t.stringLiteral('verbosedStyleIds'),styleIdsAst)]);while(args.length<4){args.push(t.objectExpression([]));}if(!args[4]){args.push(resultParamsNode);}else{args[4]=resultParamsNode;}}}}}},JSXOpeningElement:function JSXOpeningElement(jsxOpeningElementPath){if(jsxOpeningElementPath.node.name&&jsxOpeningElementPath.node.name.name&&guessingStyledComponents.includes(jsxOpeningElementPath.node.name.name)){var _ConfigDefault3,_ConfigDefault4;var propsToBePersist=[];var sxPropsWithIdentifier={};var utilityPropsWithIdentifier={};var mergedPropertyConfig=Object.assign({},(_ConfigDefault3=ConfigDefault)==null?void 0:_ConfigDefault3.propertyTokenMap,propertyTokenMap);var styledSystemProps=Object.assign({},CSSPropertiesMap,(_ConfigDefault4=ConfigDefault)==null?void 0:_ConfigDefault4.aliases);var attr=jsxOpeningElementPath.node.attributes;attr.forEach(function(attribute,index){if(t.isJSXAttribute(attribute)){var propName=attribute.name.name;var propValue=attribute.value;if(t.isJSXExpressionContainer(propValue)){if(t.isIdentifier(propValue.expression)||t.isConditionalExpression(propValue.expression)){propsToBePersist.push(attribute);}else{if(propName==='sx'){var objectProperties=propValue.expression.properties;sxPropsWithIdentifier=getIdentifiersObjectFromAstNode(propValue.expression);var _convertExpressionCon=convertExpressionContainerToStaticObject(objectProperties),sxPropsObject=_convertExpressionCon.result;componentSXProp=sxPropsObject;}else if(t.isStringLiteral(propValue.expression)||t.isNumericLiteral(propValue.expression)){if(styledSystemProps[propName]){var _componentUtilityProp;componentUtilityProps=Object.assign((_componentUtilityProp=componentUtilityProps)!=null?_componentUtilityProp:{},(0,_defineProperty2.default)({},propName,propValue.expression.value));}}else{propsToBePersist.push(attribute);}}}else if(styledSystemProps[propName]){var _componentUtilityProp2;componentUtilityProps=Object.assign((_componentUtilityProp2=componentUtilityProps)!=null?_componentUtilityProp2:{},(0,_defineProperty2.default)({},propName,propValue.value));}else{propsToBePersist.push(attribute);}}});jsxOpeningElementPath.node.attributes.splice(0,jsxOpeningElementPath.node.attributes.length);for(var key in utilityPropsWithIdentifier){if(componentSXProp[key])delete utilityPropsWithIdentifier[key];}jsxOpeningElementPath.node.attributes=propsToBePersist;var sx=Object.assign({},componentUtilityProps,componentSXProp);if(Object.keys(sx).length>0){var verbosedSx=convertSxToSxVerbosed(sx);var inlineSxTheme={baseStyle:verbosedSx};var componentExtendedConfig=merge({},Object.assign({},ConfigDefault,{propertyTokenMap:Object.assign({},mergedPropertyConfig)}));var sxHash=stableHash(sx);if(outputLibrary){sxHash=outputLibrary+'-'+sxHash;}var _updateOrderUnResolve2=updateOrderUnResolvedMap(inlineSxTheme,sxHash,'inline',{},BUILD_TIME_GLUESTACK_STYLESHEET,platform),styledIds=_updateOrderUnResolve2.styledIds,verbosedStyleIds=_updateOrderUnResolve2.verbosedStyleIds;var toBeInjected=BUILD_TIME_GLUESTACK_STYLESHEET.resolve(styledIds,componentExtendedConfig,{},true,'inline');var current_global_map=BUILD_TIME_GLUESTACK_STYLESHEET.getStyleMap();var orderedResolvedTheme=[];current_global_map==null?void 0:current_global_map.forEach(function(styledResolved){var _styledResolved$meta2;if(styledIds.includes(styledResolved==null?void 0:(_styledResolved$meta2=styledResolved.meta)==null?void 0:_styledResolved$meta2.cssId)){orderedResolvedTheme.push(styledResolved);}});var styleIdsAst=generateObjectAst(verbosedStyleIds);var toBeInjectedAst=generateObjectAst(toBeInjected);var orderResolvedArrayExpression=[];orderedResolvedTheme.forEach(function(styledResolved){if(targetPlatform==='native'){delete styledResolved.original;delete styledResolved.value;delete styledResolved.meta.cssRulesSet;delete styledResolved.meta.weight;delete styledResolved.meta.weight;delete styledResolved.type;delete styledResolved.componentHash;delete styledResolved.extendedConfig;delete styledResolved.value;}var orderedResolvedAst=generateObjectAst(styledResolved);orderResolvedArrayExpression.push(orderedResolvedAst);});var orderedStyleIdsArrayAst=t.arrayExpression(styledIds==null?void 0:styledIds.map(function(cssId){return t.stringLiteral(cssId);}));jsxOpeningElementPath.node.attributes.push(t.jsxAttribute(t.jsxIdentifier('verbosedStyleIds'),t.jsxExpressionContainer(styleIdsAst)));jsxOpeningElementPath.node.attributes.push(t.jsxAttribute(t.jsxIdentifier('orderedResolved'),t.jsxExpressionContainer(t.arrayExpression(orderResolvedArrayExpression))));}if(sxPropsWithIdentifier&&sxPropsWithIdentifier.properties&&sxPropsWithIdentifier.properties.length>0){jsxOpeningElementPath.node.attributes.push(t.jsxAttribute(t.jsxIdentifier('sx'),t.jsxExpressionContainer(sxPropsWithIdentifier)));}componentSXProp=undefined;componentUtilityProps=undefined;}}}};};
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var fs=require('fs');var path=require('path');var babel=require('@babel/parser');var generate=require('@babel/generator').default;var babelPresetTypeScript=require('@babel/preset-typescript');var traverse=require('@babel/traverse').default;var types=require('@babel/types');var _require=require('@gluestack-style/react/lib/commonjs/convertSxToSxVerbosed'),convertStyledToStyledVerbosed=_require.convertStyledToStyledVerbosed,convertSxToSxVerbosed=_require.convertSxToSxVerbosed;var _require2=require('@gluestack-style/react/lib/commonjs/propertyTokenMap'),propertyTokenMap=_require2.propertyTokenMap;var _require3=require('@gluestack-style/react/lib/commonjs/stableHash'),stableHash=_require3.stableHash;var _require4=require('@gluestack-style/react/lib/commonjs/core/styled-system'),CSSPropertiesMap=_require4.CSSPropertiesMap;var _require5=require('@gluestack-style/react/lib/commonjs/style-sheet/index'),StyleInjector=_require5.StyleInjector;var _require6=require('@gluestack-style/react/lib/commonjs/updateOrderUnResolvedMap'),updateOrderUnResolvedMap=_require6.updateOrderUnResolvedMap;var _require7=require('@gluestack-style/react/lib/commonjs/utils'),setObjectKeyValue=_require7.setObjectKeyValue;var IMPORT_NAME='@gluestack-style/react';var configThemePath=[];var BUILD_TIME_GLUESTACK_STYLESHEET=new StyleInjector();var convertExpressionContainerToStaticObject=function convertExpressionContainerToStaticObject(properties){var result=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var keyPath=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[];var propsToBePersist=arguments.length>3&&arguments[3]!==undefined?arguments[3]:{};properties==null?void 0:properties.forEach(function(property,index){var _property$key$name;var nodeName=(_property$key$name=property.key.name)!=null?_property$key$name:property.key.value;if(property.value.type==='ObjectExpression'){keyPath.push(nodeName);convertExpressionContainerToStaticObject(property.value.properties,result,keyPath,propsToBePersist);keyPath.pop();}else if(property.value.type==='Identifier'){if(property.key.value){setObjectKeyValue(propsToBePersist,[].concat((0,_toConsumableArray2.default)(keyPath),[nodeName]),property.value.name);}if(property.key.name){setObjectKeyValue(propsToBePersist,[].concat((0,_toConsumableArray2.default)(keyPath),[nodeName]),property.value.name);}}else{if(property.key.value){setObjectKeyValue(result,[].concat((0,_toConsumableArray2.default)(keyPath),[property.key.value]),property.value.value);}if(property.key.name){setObjectKeyValue(result,[].concat((0,_toConsumableArray2.default)(keyPath),[property.key.name]),property.value.value);}}});return{result:result,propsToBePersist:propsToBePersist};};function findThemeAndComponentConfig(node){var themeNode=null;var componentConfigNode=null;node.forEach(function(prop){var propKey=prop.key.name?prop.key.name:prop.key.value;if(propKey==='theme'){themeNode=prop;}else if(propKey==='componentConfig'){componentConfigNode=prop;}});return{themeNode:themeNode,componentConfigNode:componentConfigNode};}function addQuotesToObjectKeys(code){var ast=babel.parse("var a = "+code,{presets:[babelPresetTypeScript],plugins:['typescript'],sourceType:'module'});traverse(ast,{ObjectProperty:function ObjectProperty(objectPropertyPath){if(types.isTemplateLiteral(objectPropertyPath.node.value)){objectPropertyPath.node.value=types.stringLiteral(objectPropertyPath.node.value.quasis[0].value.raw);}if(types.isIdentifier(objectPropertyPath.node.key)){objectPropertyPath.node.key=types.stringLiteral(objectPropertyPath.node.key.name);}if(types.isNumericLiteral(objectPropertyPath.node.key)){objectPropertyPath.node.key=types.stringLiteral(objectPropertyPath.node.key.extra.raw);}if(types.isStringLiteral(objectPropertyPath.node.value)){objectPropertyPath.node.value=types.stringLiteral(objectPropertyPath.node.value.value);}}});var initAst;traverse(ast,{ObjectProperty:function ObjectProperty(objectPropertyPath){var _objectPropertyPath$n,_objectPropertyPath$n2,_objectPropertyPath$n3,_objectPropertyPath$n4;if(types.isArrayExpression(objectPropertyPath==null?void 0:(_objectPropertyPath$n=objectPropertyPath.node)==null?void 0:_objectPropertyPath$n.value)){var arrayElements=objectPropertyPath.node.value.elements;var dynamicElementsIndex=[];arrayElements.forEach(function(element,index){if(types.isNewExpression(element)||types.isIdentifier(element)||types.isTemplateLiteral(element)){dynamicElementsIndex.push(index);}});arrayElements=arrayElements.filter(function(element,index){return!dynamicElementsIndex.includes(index);});objectPropertyPath.node.value.elements=arrayElements;}else if(types.isIdentifier(objectPropertyPath==null?void 0:(_objectPropertyPath$n2=objectPropertyPath.node)==null?void 0:_objectPropertyPath$n2.value)||types.isTemplateLiteral(objectPropertyPath==null?void 0:(_objectPropertyPath$n3=objectPropertyPath.node)==null?void 0:_objectPropertyPath$n3.value)||types.isConditionalExpression(objectPropertyPath==null?void 0:(_objectPropertyPath$n4=objectPropertyPath.node)==null?void 0:_objectPropertyPath$n4.value)){objectPropertyPath.remove();}}});traverse(ast,{VariableDeclarator:function VariableDeclarator(variableDeclaratorPath){initAst=variableDeclaratorPath.node.init;}});var _generate=generate(initAst,{sourceType:'module',presets:[babelPresetTypeScript],plugins:['typescript']}),output=_generate.code;return output;}var merge=require('lodash.merge');var _require8=require('process'),exit=_require8.exit;var checkIfPathIsAbsolute=function checkIfPathIsAbsolute(path){return path.startsWith('/');};function getConfig(configPath){if(configPath){return fs.readFileSync(path.join(!checkIfPathIsAbsolute(configPath)?process.cwd():'',configPath),'utf8');}var isConfigJSExist=fs.existsSync(path.join(process.cwd(),'./gluestack-style.config.js'));var isGlueStackUIConfigJSExist=fs.existsSync(path.join(process.cwd(),'./gluestack-ui.config.js'));var isConfigTSExist=fs.existsSync(path.join(process.cwd(),'./gluestack-style.config.ts'));var isGlueStackUIConfigTSExist=fs.existsSync(path.join(process.cwd(),'./gluestack-ui.config.ts'));if(isConfigTSExist){return fs.readFileSync(path.join(process.cwd(),'./gluestack-style.config.ts'),'utf8');}if(isConfigJSExist){return fs.readFileSync(path.join(process.cwd(),'./gluestack-style.config.js'),'utf8');}if(isGlueStackUIConfigJSExist){configThemePath=['theme'];return fs.readFileSync(path.join(process.cwd(),'./gluestack-ui.config.js'),'utf8');}if(isGlueStackUIConfigTSExist){configThemePath=['theme'];return fs.readFileSync(path.join(process.cwd(),'./gluestack-ui.config.ts'),'utf8');}}function getBuildTimeParams(theme,componentConfig,extendedConfig,outputLibrary,platform,type){var _ConfigDefault;var mergedPropertyConfig=Object.assign({},(_ConfigDefault=ConfigDefault)==null?void 0:_ConfigDefault.propertyTokenMap,propertyTokenMap);var componentExtendedConfig=merge({},Object.assign({},ConfigDefault,{propertyTokenMap:Object.assign({},mergedPropertyConfig)}));if(theme&&Object.keys(theme).length>0){var verbosedTheme=convertStyledToStyledVerbosed(theme);var componentHash=stableHash(Object.assign({},theme,componentConfig));if(outputLibrary){componentHash=outputLibrary+'-'+componentHash;}var _updateOrderUnResolve=updateOrderUnResolvedMap(verbosedTheme,componentHash,type,componentConfig,BUILD_TIME_GLUESTACK_STYLESHEET,platform),styledIds=_updateOrderUnResolve.styledIds,verbosedStyleIds=_updateOrderUnResolve.verbosedStyleIds;var toBeInjected=BUILD_TIME_GLUESTACK_STYLESHEET.resolve(styledIds,componentExtendedConfig,{});var current_global_map=BUILD_TIME_GLUESTACK_STYLESHEET.getStyleMap();var orderedResolvedTheme=[];current_global_map==null?void 0:current_global_map.forEach(function(styledResolved){var _styledResolved$meta;if(styledIds.includes(styledResolved==null?void 0:(_styledResolved$meta=styledResolved.meta)==null?void 0:_styledResolved$meta.cssId)){orderedResolvedTheme.push(styledResolved);}});var styleIdsAst=generateObjectAst(verbosedStyleIds);var toBeInjectedAst=generateObjectAst(toBeInjected);var orderedResolvedAst=generateArrayAst(orderedResolvedTheme);var orderedStyleIdsArrayAst=types.arrayExpression(styledIds==null?void 0:styledIds.map(function(cssId){return types.stringLiteral(cssId);}));var resultParamsNode=types.objectExpression([types.objectProperty(types.stringLiteral('orderedResolved'),orderedResolvedAst),types.objectProperty(types.stringLiteral('toBeInjected'),toBeInjectedAst),types.objectProperty(types.stringLiteral('styledIds'),orderedStyleIdsArrayAst),types.objectProperty(types.stringLiteral('verbosedStyleIds'),styleIdsAst)]);return resultParamsNode;}return null;}function getExportedConfigFromFileString(fileData){var _fileData,_objectCode,_addQuotesToObjectKey;if(!fileData){return{};}fileData=(_fileData=fileData)==null?void 0:_fileData.replace(/as const/g,'');var ast=babel.parse(fileData,{presets:[babelPresetTypeScript],plugins:['typescript'],sourceType:'module',comments:false});var config={};traverse(ast,{CallExpression:function CallExpression(path){var _path$node=path.node,callee=_path$node.callee,args=_path$node.arguments;if(types.isIdentifier(callee,{name:'createConfig'})&&args.length===1&&types.isObjectExpression(args[0])){path.replaceWith(args[0]);}}});traverse(ast,{ExportNamedDeclaration:function ExportNamedDeclaration(path){path.traverse({VariableDeclarator:function VariableDeclarator(variableDeclaratorPath){config=variableDeclaratorPath.node.init;}});},Identifier:function Identifier(path){if(path.node.name==='undefined'){path.node.name='null';}}});var objectCode=generate(config).code;objectCode=(_objectCode=objectCode)==null?void 0:_objectCode.replace(/\/\/.*|\/\*[\s\S]*?\*\//g,'');objectCode=(_addQuotesToObjectKey=addQuotesToObjectKeys(objectCode))==null?void 0:_addQuotesToObjectKey.replace(/'/g,'"');return JSON.parse(objectCode);}function replaceSingleQuotes(str){var inDoubleQuotes=false;var newStr='';for(var i=0;i<str.length;i++){if(str[i]==='"'){inDoubleQuotes=!inDoubleQuotes;}if(str[i]==="'"&&!inDoubleQuotes){newStr+='"';}else{newStr+=str[i];}}return newStr;}function getObjectFromAstNode(node){var _objectCode2;var objectCode=generate(node).code;objectCode=(_objectCode2=objectCode)==null?void 0:_objectCode2.replace(/as const/g,'');objectCode=addQuotesToObjectKeys(objectCode.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,function(m,g){return g?'':m;}));objectCode=replaceSingleQuotes(objectCode);return JSON.parse(objectCode);}function removeLiteralPropertiesFromObjectProperties(code){var ast=babel.parse("var a = "+code,{presets:[babelPresetTypeScript],plugins:['typescript'],sourceType:'module'});traverse(ast,{ObjectExpression:function ObjectExpression(path){path.traverse({ObjectProperty:function ObjectProperty(path){var value=path.node.value;path.traverse({StringLiteral:function StringLiteral(stringPath){stringPath;}});if(value.type==='StringLiteral'||value.type==='NumericLiteral'){path.remove();}}});}});var initAst;traverse(ast,{VariableDeclarator:function VariableDeclarator(path){initAst=path.node.init;}});return initAst;}function getIdentifiersObjectFromAstNode(node){var objectCode=generate(node).code;return removeLiteralPropertiesFromObjectProperties(objectCode.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,function(m,g){return g?'':m;}));}function generateObjectAst(obj){var properties=Object.entries(obj).map(function(_ref){var _ref2=(0,_slicedToArray2.default)(_ref,2),key=_ref2[0],value=_ref2[1];if(typeof value==='undefined'){return;}else if(typeof value==='object'&&!Array.isArray(value)){return types.objectProperty(types.stringLiteral(key),generateObjectAst(value));}else if(typeof value==='object'&&Array.isArray(value)){var elements=value.map(function(obj){if(typeof obj==='string'){return types.stringLiteral(obj);}else{return generateObjectAst(obj);}});return types.objectProperty(types.stringLiteral(key),types.arrayExpression(elements));}else if(typeof value==='boolean'){return types.objectProperty(types.stringLiteral(key),types.booleanLiteral(value));}else{return types.objectProperty(types.stringLiteral(key),typeof value==='number'?types.numericLiteral(value):types.stringLiteral(value));}});return types.objectExpression(properties.filter(function(property){return property;}));}function generateArrayAst(arr){return types.arrayExpression(arr.map(function(obj){return generateObjectAst(obj);}));}function isImportedFromLibrary(libraries,importName){if(libraries.includes(importName)){return true;}return false;}function isImportFromAbsolutePath(absolutePaths,filePath,importedAbsolutePath){filePath.pop();var finalAbsolutePath=path.resolve(filePath.join('/'),importedAbsolutePath);if(absolutePaths.includes(finalAbsolutePath)){return true;}return false;}var CONFIG=getExportedConfigFromFileString(getConfig());var ConfigDefault=CONFIG;module.exports=function(b){var t=b.types;function checkWebFileExists(filePath){if(filePath.includes('node_modules')){return false;}var ext=path.extname(filePath);var dirname=path.dirname(filePath);var basename=path.basename(filePath,ext);var webFilePath=path.join(dirname,basename+".web"+ext);return fs.existsSync(webFilePath);}var styledImportName='';var styledAlias='';var styledAliasImportedName='';var tempPropertyResolverNode;var isValidConfig=true;var platform='all';var currentFileName='file not found!';var configPath;var outputLibrary;var componentSXProp;var componentUtilityProps;var guessingStyledComponents=[];var styled=['@gluestack-style/react','@gluestack-ui/themed'];var components=['@gluestack-ui/themed'];var isStyledPathConfigured=false;var isComponentsPathConfigured=false;var targetPlatform=process.env.GLUESTACK_STYLE_TARGET;var createStyleImportedName='';var createComponentsImportedName='';var CREATE_STYLE='createStyle';var CREATE_COMPONENTS='createComponents';return{name:'ast-transform',visitor:{ImportDeclaration:function ImportDeclaration(importPath,state){var _state$opts,_state$opts2,_state$opts3,_state$opts5,_state$opts7,_state$opts9,_state$opts10,_state$opts12,_state$opts13;currentFileName=state.file.opts.filename;styledAlias=state==null?void 0:(_state$opts=state.opts)==null?void 0:_state$opts.styledAlias;outputLibrary=(state==null?void 0:(_state$opts2=state.opts)==null?void 0:_state$opts2.outputLibrary)||outputLibrary;if(state!=null&&(_state$opts3=state.opts)!=null&&_state$opts3.configPath){var _state$opts4;configPath=state==null?void 0:(_state$opts4=state.opts)==null?void 0:_state$opts4.configPath;}if(state!=null&&(_state$opts5=state.opts)!=null&&_state$opts5.configThemePath){var _state$opts6;configThemePath=state==null?void 0:(_state$opts6=state.opts)==null?void 0:_state$opts6.configThemePath;}if(state!=null&&(_state$opts7=state.opts)!=null&&_state$opts7.platform){var _state$opts8;platform=state==null?void 0:(_state$opts8=state.opts)==null?void 0:_state$opts8.platform;}else{platform='all';}if(configPath){ConfigDefault=getExportedConfigFromFileString(getConfig(configPath));}configThemePath.forEach(function(path){var _ConfigDefault2;ConfigDefault=(_ConfigDefault2=ConfigDefault)==null?void 0:_ConfigDefault2[path];});configThemePath=[];if(!currentFileName.includes('node_modules')){if(currentFileName.includes('.web.')){platform='web';}else if(checkWebFileExists(currentFileName)){platform='native';}}if(state!=null&&(_state$opts9=state.opts)!=null&&_state$opts9.styled&&Array.isArray(state==null?void 0:(_state$opts10=state.opts)==null?void 0:_state$opts10.styled)&&!isStyledPathConfigured){var _state$opts11;styled.push.apply(styled,(0,_toConsumableArray2.default)(state==null?void 0:(_state$opts11=state.opts)==null?void 0:_state$opts11.styled));isStyledPathConfigured=true;}if(state!=null&&(_state$opts12=state.opts)!=null&&_state$opts12.components&&Array.isArray(state==null?void 0:(_state$opts13=state.opts)==null?void 0:_state$opts13.components)&&!isComponentsPathConfigured){var _state$opts14;components.push.apply(components,(0,_toConsumableArray2.default)(state==null?void 0:(_state$opts14=state.opts)==null?void 0:_state$opts14.components));isComponentsPathConfigured=true;}var importName=importPath.node.source.value;var filePath=state.file.opts.filename.split('/');if(isImportFromAbsolutePath(components,filePath,importName)||isImportedFromLibrary(components,importName)){importPath.traverse({ImportSpecifier:function ImportSpecifier(importSpecifierPath){guessingStyledComponents.push(importSpecifierPath.node.local.name);}});}if(isImportFromAbsolutePath(styled,filePath,importName)||isImportedFromLibrary(styled,importName)){importPath.traverse({ImportSpecifier:function ImportSpecifier(importSpecifierPath){if(importSpecifierPath.node.imported.name==='styled'){styledImportName=importSpecifierPath.node.local.name;}if(importSpecifierPath.node.imported.name===CREATE_STYLE){createStyleImportedName=importSpecifierPath.node.local.name;}if(importSpecifierPath.node.imported.name===CREATE_COMPONENTS){createComponentsImportedName=importSpecifierPath.node.local.name;}if(importSpecifierPath.node.imported.name===styledAlias){styledAliasImportedName=importSpecifierPath.node.local.name;}}});}},AssignmentExpression:function AssignmentExpression(expressionPath,state){var _expressionPath$node,_expressionPath$node$,_expressionPath$node$2,_expressionPath$node2,_expressionPath$node3,_expressionPath$node4;if((expressionPath==null?void 0:(_expressionPath$node=expressionPath.node)==null?void 0:(_expressionPath$node$=_expressionPath$node.right)==null?void 0:(_expressionPath$node$2=_expressionPath$node$.callee)==null?void 0:_expressionPath$node$2.name)===styledAliasImportedName||(expressionPath==null?void 0:(_expressionPath$node2=expressionPath.node)==null?void 0:(_expressionPath$node3=_expressionPath$node2.right)==null?void 0:(_expressionPath$node4=_expressionPath$node3.callee)==null?void 0:_expressionPath$node4.name)===styledImportName){var _expressionPath$paren,_expressionPath$paren2;var componentName=expressionPath==null?void 0:(_expressionPath$paren=expressionPath.parent)==null?void 0:(_expressionPath$paren2=_expressionPath$paren.id)==null?void 0:_expressionPath$paren2.name;if(componentName){guessingStyledComponents.push(componentName);}}},CallExpression:function CallExpression(callExpressionPath){if(isValidConfig){var calleeName=callExpressionPath.node.callee.name;if(calleeName===styledAliasImportedName||calleeName===styledImportName||calleeName===createComponentsImportedName||calleeName===createStyleImportedName){callExpressionPath.traverse({ObjectProperty:function ObjectProperty(ObjectPath){if(t.isIdentifier(ObjectPath.node.value)){if(ObjectPath.node.value.name==='undefined'){ObjectPath.remove();}}}});}if(calleeName===styledAliasImportedName||calleeName===styledImportName){var _callExpressionPath$p,_callExpressionPath$p2,_args$,_args$2;var componentName=callExpressionPath==null?void 0:(_callExpressionPath$p=callExpressionPath.parent)==null?void 0:(_callExpressionPath$p2=_callExpressionPath$p.id)==null?void 0:_callExpressionPath$p2.name;if(componentName){guessingStyledComponents.push(componentName);}var args=callExpressionPath.node.arguments;var componentThemeNode=args[1];var componentConfigNode=(_args$=args[2])!=null?_args$:t.objectExpression([]);var extendedThemeNode=(_args$2=args[3])!=null?_args$2:t.objectExpression([]);if(!(t.isIdentifier(componentThemeNode)||t.isIdentifier(componentConfigNode)||t.isIdentifier(extendedThemeNode))){var extendedThemeNodeProps=[];if(extendedThemeNode&&extendedThemeNode!=null&&extendedThemeNode.properties){extendedThemeNode==null?void 0:extendedThemeNode.properties.forEach(function(prop){if(prop.key.name==='propertyResolver'){tempPropertyResolverNode=prop;}else{extendedThemeNodeProps.push(prop);}});extendedThemeNode.properties=extendedThemeNodeProps;}var theme=getObjectFromAstNode(componentThemeNode);var ExtendedConfig=getObjectFromAstNode(extendedThemeNode);var componentConfig=getObjectFromAstNode(componentConfigNode);if(extendedThemeNode&&tempPropertyResolverNode){extendedThemeNode.properties.push(tempPropertyResolverNode);}var resultParamsNode=getBuildTimeParams(theme,componentConfig,ExtendedConfig,outputLibrary,platform,'boot');if(resultParamsNode){while(args.length<4){args.push(t.objectExpression([]));}if(!args[4]){args.push(resultParamsNode);}else{args[4]=resultParamsNode;}}}}if(calleeName===createStyleImportedName){var _args$3;var _args=callExpressionPath.node.arguments;var _componentThemeNode=_args[0];var _componentConfigNode=(_args$3=_args[1])!=null?_args$3:t.objectExpression([]);if(!(t.isIdentifier(_componentThemeNode)||t.isIdentifier(_componentConfigNode))){var _theme=getObjectFromAstNode(_componentThemeNode);var _componentConfig=getObjectFromAstNode(_componentConfigNode);var _resultParamsNode=getBuildTimeParams(_theme,_componentConfig,{},outputLibrary,platform,'extended');if(_resultParamsNode){while(_args.length<3){_args.push(t.objectExpression([]));}if(!_args[2]){_args.push(_resultParamsNode);}else{_args[2]=_resultParamsNode;}}}}if(calleeName===createComponentsImportedName){var extendedThemeComponents=callExpressionPath.node.arguments[0].properties;extendedThemeComponents.forEach(function(property){if(!t.isIdentifier(property.value)&&!t.isTemplateLiteral(property.value)&&!t.isConditionalExpression(property.value)){var _findThemeAndComponen=findThemeAndComponentConfig(property.value.properties),themeNode=_findThemeAndComponen.themeNode,_componentConfigNode2=_findThemeAndComponen.componentConfigNode;var _theme2=themeNode?getObjectFromAstNode(themeNode==null?void 0:themeNode.value):{};var _componentConfig2=_componentConfigNode2?getObjectFromAstNode(_componentConfigNode2==null?void 0:_componentConfigNode2.value):{};var _resultParamsNode2=getBuildTimeParams(_theme2,_componentConfig2,{},outputLibrary,platform,'extended');if(_resultParamsNode2){property.value.properties.push(t.objectProperty(t.stringLiteral('BUILD_TIME_PARAMS'),_resultParamsNode2));}}});}}},JSXOpeningElement:function JSXOpeningElement(jsxOpeningElementPath){if(jsxOpeningElementPath.node.name&&jsxOpeningElementPath.node.name.name&&guessingStyledComponents.includes(jsxOpeningElementPath.node.name.name)){var _ConfigDefault3,_ConfigDefault4;var propsToBePersist=[];var sxPropsWithIdentifier={};var utilityPropsWithIdentifier={};var mergedPropertyConfig=Object.assign({},(_ConfigDefault3=ConfigDefault)==null?void 0:_ConfigDefault3.propertyTokenMap,propertyTokenMap);var styledSystemProps=Object.assign({},CSSPropertiesMap,(_ConfigDefault4=ConfigDefault)==null?void 0:_ConfigDefault4.aliases);var attr=jsxOpeningElementPath.node.attributes;attr.forEach(function(attribute,index){if(t.isJSXAttribute(attribute)){var propName=attribute.name.name;var propValue=attribute.value;if(t.isJSXExpressionContainer(propValue)){if(t.isIdentifier(propValue.expression)||t.isConditionalExpression(propValue.expression)){propsToBePersist.push(attribute);}else{if(propName==='sx'){var objectProperties=propValue.expression.properties;sxPropsWithIdentifier=getIdentifiersObjectFromAstNode(propValue.expression);var _convertExpressionCon=convertExpressionContainerToStaticObject(objectProperties),sxPropsObject=_convertExpressionCon.result;componentSXProp=sxPropsObject;}else if(t.isStringLiteral(propValue.expression)||t.isNumericLiteral(propValue.expression)){if(styledSystemProps[propName]){var _componentUtilityProp;componentUtilityProps=Object.assign((_componentUtilityProp=componentUtilityProps)!=null?_componentUtilityProp:{},(0,_defineProperty2.default)({},propName,propValue.expression.value));}}else{propsToBePersist.push(attribute);}}}else if(styledSystemProps[propName]){var _componentUtilityProp2;componentUtilityProps=Object.assign((_componentUtilityProp2=componentUtilityProps)!=null?_componentUtilityProp2:{},(0,_defineProperty2.default)({},propName,propValue.value));}else{propsToBePersist.push(attribute);}}});jsxOpeningElementPath.node.attributes.splice(0,jsxOpeningElementPath.node.attributes.length);for(var key in utilityPropsWithIdentifier){if(componentSXProp[key])delete utilityPropsWithIdentifier[key];}jsxOpeningElementPath.node.attributes=propsToBePersist;var sx=Object.assign({},componentUtilityProps,componentSXProp);if(Object.keys(sx).length>0){var verbosedSx=convertSxToSxVerbosed(sx);var inlineSxTheme={baseStyle:verbosedSx};var componentExtendedConfig=merge({},Object.assign({},ConfigDefault,{propertyTokenMap:Object.assign({},mergedPropertyConfig)}));var sxHash=stableHash(sx);if(outputLibrary){sxHash=outputLibrary+'-'+sxHash;}var _updateOrderUnResolve2=updateOrderUnResolvedMap(inlineSxTheme,sxHash,'inline',{},BUILD_TIME_GLUESTACK_STYLESHEET,platform),styledIds=_updateOrderUnResolve2.styledIds,verbosedStyleIds=_updateOrderUnResolve2.verbosedStyleIds;var toBeInjected=BUILD_TIME_GLUESTACK_STYLESHEET.resolve(styledIds,componentExtendedConfig,{},true,'inline');var current_global_map=BUILD_TIME_GLUESTACK_STYLESHEET.getStyleMap();var orderedResolvedTheme=[];current_global_map==null?void 0:current_global_map.forEach(function(styledResolved){var _styledResolved$meta2;if(styledIds.includes(styledResolved==null?void 0:(_styledResolved$meta2=styledResolved.meta)==null?void 0:_styledResolved$meta2.cssId)){orderedResolvedTheme.push(styledResolved);}});var styleIdsAst=generateObjectAst(verbosedStyleIds);var toBeInjectedAst=generateObjectAst(toBeInjected);var orderResolvedArrayExpression=[];orderedResolvedTheme.forEach(function(styledResolved){if(targetPlatform==='native'){delete styledResolved.original;delete styledResolved.value;delete styledResolved.meta.cssRulesSet;delete styledResolved.meta.weight;delete styledResolved.meta.weight;delete styledResolved.type;delete styledResolved.componentHash;delete styledResolved.extendedConfig;delete styledResolved.value;}var orderedResolvedAst=generateObjectAst(styledResolved);orderResolvedArrayExpression.push(orderedResolvedAst);});var orderedStyleIdsArrayAst=t.arrayExpression(styledIds==null?void 0:styledIds.map(function(cssId){return t.stringLiteral(cssId);}));jsxOpeningElementPath.node.attributes.push(t.jsxAttribute(t.jsxIdentifier('verbosedStyleIds'),t.jsxExpressionContainer(styleIdsAst)));jsxOpeningElementPath.node.attributes.push(t.jsxAttribute(t.jsxIdentifier('orderedResolved'),t.jsxExpressionContainer(t.arrayExpression(orderResolvedArrayExpression))));}if(sxPropsWithIdentifier&&sxPropsWithIdentifier.properties&&sxPropsWithIdentifier.properties.length>0){jsxOpeningElementPath.node.attributes.push(t.jsxAttribute(t.jsxIdentifier('sx'),t.jsxExpressionContainer(sxPropsWithIdentifier)));}componentSXProp=undefined;componentUtilityProps=undefined;}}}};};
{
"name": "@gluestack-style/babel-plugin-styled-resolver",
"version": "0.2.6",
"version": "0.2.7-alpha.0",
"description": "A gluestack-style babel plugin that transpiles your styled function calls and resolves the component styling in build time.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -92,2 +92,20 @@ const fs = require('fs');

function findThemeAndComponentConfig(node) {
let themeNode = null;
let componentConfigNode = null;
node.forEach((prop) => {
const propKey = prop.key.name ? prop.key.name : prop.key.value;
if (propKey === 'theme') {
themeNode = prop;
} else if (propKey === 'componentConfig') {
componentConfigNode = prop;
}
});
return {
themeNode,
componentConfigNode,
};
}
function addQuotesToObjectKeys(code) {

@@ -226,7 +244,93 @@ const ast = babel.parse(`var a = ${code}`, {

}
function getSurroundingCharacters(string, index) {
let start = Math.max(0, index - 5);
let end = Math.min(string.length, index + 6);
return string.slice(start, end);
function getBuildTimeParams(
theme,
componentConfig,
extendedConfig,
outputLibrary,
platform,
type
) {
let mergedPropertyConfig = {
...ConfigDefault?.propertyTokenMap,
...propertyTokenMap,
};
let componentExtendedConfig = merge(
{},
{
...ConfigDefault,
propertyTokenMap: { ...mergedPropertyConfig },
}
);
if (theme && Object.keys(theme).length > 0) {
const verbosedTheme = convertStyledToStyledVerbosed(theme);
let componentHash = stableHash({
...theme,
...componentConfig,
});
if (outputLibrary) {
componentHash = outputLibrary + '-' + componentHash;
}
const { styledIds, verbosedStyleIds } = updateOrderUnResolvedMap(
verbosedTheme,
componentHash,
type,
componentConfig,
BUILD_TIME_GLUESTACK_STYLESHEET,
platform
);
const toBeInjected = BUILD_TIME_GLUESTACK_STYLESHEET.resolve(
styledIds,
componentExtendedConfig,
{}
);
const current_global_map = BUILD_TIME_GLUESTACK_STYLESHEET.getStyleMap();
const orderedResolvedTheme = [];
current_global_map?.forEach((styledResolved) => {
if (styledIds.includes(styledResolved?.meta?.cssId)) {
orderedResolvedTheme.push(styledResolved);
}
});
const styleIdsAst = generateObjectAst(verbosedStyleIds);
const toBeInjectedAst = generateObjectAst(toBeInjected);
const orderedResolvedAst = generateArrayAst(orderedResolvedTheme);
const orderedStyleIdsArrayAst = types.arrayExpression(
styledIds?.map((cssId) => types.stringLiteral(cssId))
);
const resultParamsNode = types.objectExpression([
types.objectProperty(
types.stringLiteral('orderedResolved'),
orderedResolvedAst
),
types.objectProperty(
types.stringLiteral('toBeInjected'),
toBeInjectedAst
),
types.objectProperty(
types.stringLiteral('styledIds'),
orderedStyleIdsArrayAst
),
types.objectProperty(
types.stringLiteral('verbosedStyleIds'),
styleIdsAst
),
]);
return resultParamsNode;
}
return null;
}
function getExportedConfigFromFileString(fileData) {

@@ -380,2 +484,44 @@ if (!fileData) {

function generateObjectAst(obj) {
let properties = Object.entries(obj).map(([key, value]) => {
if (typeof value === 'undefined') {
return;
} else if (typeof value === 'object' && !Array.isArray(value)) {
return types.objectProperty(
types.stringLiteral(key),
generateObjectAst(value)
);
} else if (typeof value === 'object' && Array.isArray(value)) {
let elements = value.map((obj) => {
if (typeof obj === 'string') {
return types.stringLiteral(obj);
} else {
return generateObjectAst(obj);
}
});
return types.objectProperty(
types.stringLiteral(key),
types.arrayExpression(elements)
);
} else if (typeof value === 'boolean') {
return types.objectProperty(
types.stringLiteral(key),
types.booleanLiteral(value)
);
} else {
return types.objectProperty(
types.stringLiteral(key),
typeof value === 'number'
? types.numericLiteral(value)
: types.stringLiteral(value)
);
}
});
return types.objectExpression(properties.filter((property) => property));
}
function generateArrayAst(arr) {
return types.arrayExpression(arr.map((obj) => generateObjectAst(obj)));
}
function isImportedFromLibrary(libraries, importName) {

@@ -412,37 +558,2 @@ if (libraries.includes(importName)) {

function generateObjectAst(obj) {
let properties = Object.entries(obj).map(([key, value]) => {
if (typeof value === 'undefined') {
return;
} else if (typeof value === 'object' && !Array.isArray(value)) {
return t.objectProperty(t.stringLiteral(key), generateObjectAst(value));
} else if (typeof value === 'object' && Array.isArray(value)) {
let elements = value.map((obj) => {
if (typeof obj === 'string') {
return t.stringLiteral(obj);
} else {
return generateObjectAst(obj);
}
});
return t.objectProperty(
t.stringLiteral(key),
t.arrayExpression(elements)
);
} else if (typeof value === 'boolean') {
return t.objectProperty(t.stringLiteral(key), t.booleanLiteral(value));
} else {
return t.objectProperty(
t.stringLiteral(key),
typeof value === 'number'
? t.numericLiteral(value)
: t.stringLiteral(value)
);
}
});
return t.objectExpression(properties.filter((property) => property));
}
function generateArrayAst(arr) {
return t.arrayExpression(arr.map((obj) => generateObjectAst(obj)));
}
function checkWebFileExists(filePath) {

@@ -476,2 +587,6 @@ if (filePath.includes('node_modules')) {

let targetPlatform = process.env.GLUESTACK_STYLE_TARGET;
let createStyleImportedName = '';
let createComponentsImportedName = '';
const CREATE_STYLE = 'createStyle';
const CREATE_COMPONENTS = 'createComponents';

@@ -562,2 +677,11 @@ return {

}
if (importSpecifierPath.node.imported.name === CREATE_STYLE) {
createStyleImportedName = importSpecifierPath.node.local.name;
}
if (
importSpecifierPath.node.imported.name === CREATE_COMPONENTS
) {
createComponentsImportedName =
importSpecifierPath.node.local.name;
}
if (importSpecifierPath.node.imported.name === styledAlias) {

@@ -584,24 +708,31 @@ styledAliasImportedName = importSpecifierPath.node.local.name;

},
CallExpression(callExpressionPath) {
if (
callExpressionPath.node.callee.name === styledAliasImportedName ||
callExpressionPath.node.callee.name === styledImportName
) {
let componentName = callExpressionPath?.parent?.id?.name;
if (componentName) {
guessingStyledComponents.push(componentName);
if (isValidConfig) {
const calleeName = callExpressionPath.node.callee.name;
if (
calleeName === styledAliasImportedName ||
calleeName === styledImportName ||
calleeName === createComponentsImportedName ||
calleeName === createStyleImportedName
) {
callExpressionPath.traverse({
ObjectProperty(ObjectPath) {
if (t.isIdentifier(ObjectPath.node.value)) {
if (ObjectPath.node.value.name === 'undefined') {
ObjectPath.remove();
}
}
},
});
}
callExpressionPath.traverse({
ObjectProperty(ObjectPath) {
if (t.isIdentifier(ObjectPath.node.value)) {
if (ObjectPath.node.value.name === 'undefined') {
ObjectPath.remove();
}
}
},
});
if (
calleeName === styledAliasImportedName ||
calleeName === styledImportName
) {
let componentName = callExpressionPath?.parent?.id?.name;
if (isValidConfig) {
if (componentName) {
guessingStyledComponents.push(componentName);
}
let args = callExpressionPath.node.arguments;

@@ -643,85 +774,12 @@

// getExportedConfigFromFileString(ConfigDefault);
let mergedPropertyConfig = {
...ConfigDefault?.propertyTokenMap,
...propertyTokenMap,
};
let componentExtendedConfig = merge(
{},
{
...ConfigDefault,
propertyTokenMap: { ...mergedPropertyConfig },
},
ExtendedConfig
const resultParamsNode = getBuildTimeParams(
theme,
componentConfig,
ExtendedConfig,
outputLibrary,
platform,
'boot'
);
if (theme && Object.keys(theme).length > 0) {
const verbosedTheme = convertStyledToStyledVerbosed(theme);
let componentHash = stableHash({
...theme,
...componentConfig,
...ExtendedConfig,
});
if (outputLibrary) {
componentHash = outputLibrary + '-' + componentHash;
}
const { styledIds, verbosedStyleIds } =
updateOrderUnResolvedMap(
verbosedTheme,
componentHash,
'boot',
componentConfig,
BUILD_TIME_GLUESTACK_STYLESHEET,
platform
);
const toBeInjected = BUILD_TIME_GLUESTACK_STYLESHEET.resolve(
styledIds,
componentExtendedConfig,
ExtendedConfig
);
const current_global_map =
BUILD_TIME_GLUESTACK_STYLESHEET.getStyleMap();
const orderedResolvedTheme = [];
current_global_map?.forEach((styledResolved) => {
if (styledIds.includes(styledResolved?.meta?.cssId)) {
orderedResolvedTheme.push(styledResolved);
}
});
let styleIdsAst = generateObjectAst(verbosedStyleIds);
let toBeInjectedAst = generateObjectAst(toBeInjected);
let orderedResolvedAst = generateArrayAst(orderedResolvedTheme);
let orderedStyleIdsArrayAst = t.arrayExpression(
styledIds?.map((cssId) => t.stringLiteral(cssId))
);
let resultParamsNode = t.objectExpression([
t.objectProperty(
t.stringLiteral('orderedResolved'),
orderedResolvedAst
),
t.objectProperty(
t.stringLiteral('toBeInjected'),
toBeInjectedAst
),
t.objectProperty(
t.stringLiteral('styledIds'),
orderedStyleIdsArrayAst
),
t.objectProperty(
t.stringLiteral('verbosedStyleIds'),
styleIdsAst
),
]);
if (resultParamsNode) {
while (args.length < 4) {

@@ -757,2 +815,88 @@ args.push(t.objectExpression([]));

}
if (calleeName === createStyleImportedName) {
let args = callExpressionPath.node.arguments;
let componentThemeNode = args[0];
let componentConfigNode = args[1] ?? t.objectExpression([]);
if (
!(
t.isIdentifier(componentThemeNode) ||
t.isIdentifier(componentConfigNode)
)
) {
let theme = getObjectFromAstNode(componentThemeNode);
let componentConfig = getObjectFromAstNode(componentConfigNode);
const resultParamsNode = getBuildTimeParams(
theme,
componentConfig,
{},
outputLibrary,
platform,
'extended'
);
if (resultParamsNode) {
while (args.length < 3) {
args.push(t.objectExpression([]));
}
if (!args[2]) {
args.push(resultParamsNode);
} else {
args[2] = resultParamsNode;
}
}
}
}
if (calleeName === createComponentsImportedName) {
/*
extended theme components AST
{
box: {
theme: {},
},
button: {
theme: {},
},
}
*/
const extendedThemeComponents =
callExpressionPath.node.arguments[0].properties;
extendedThemeComponents.forEach((property) => {
if (
!t.isIdentifier(property.value) &&
!t.isTemplateLiteral(property.value) &&
!t.isConditionalExpression(property.value)
) {
const { themeNode, componentConfigNode } =
findThemeAndComponentConfig(property.value.properties);
let theme = themeNode
? getObjectFromAstNode(themeNode?.value)
: {};
let componentConfig = componentConfigNode
? getObjectFromAstNode(componentConfigNode?.value)
: {};
const resultParamsNode = getBuildTimeParams(
theme,
componentConfig,
{},
outputLibrary,
platform,
'extended'
);
if (resultParamsNode) {
property.value.properties.push(
t.objectProperty(
t.stringLiteral('BUILD_TIME_PARAMS'),
resultParamsNode
)
);
}
}
});
}
}

@@ -759,0 +903,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc