@tamagui/static 1.0.0-alpha.4 → 1.0.0-alpha.8
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/dist/extractor/createExtractor.js +58 -36
- package/dist/extractor/createExtractor.js.map +2 -2
- package/dist/extractor/extractToClassNames.js +9 -17
- package/dist/extractor/extractToClassNames.js.map +2 -2
- package/dist/index.cjs +89 -58
- package/dist/index.cjs.map +2 -2
- package/dist/patchReactNativeWeb.js +18 -3
- package/dist/patchReactNativeWeb.js.map +2 -2
- package/package.json +9 -7
- package/src/extractor/createExtractor.ts +78 -55
- package/src/extractor/extractToClassNames.ts +5 -16
- package/src/patchReactNativeWeb.ts +21 -5
- package/src/types.ts +12 -3
- package/types.d.ts +219 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/extractor/extractToClassNames.ts"],
|
|
4
|
-
"sourcesContent": ["import * as path from 'path'\nimport { basename } from 'path'\nimport * as util from 'util'\n\nimport generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport { getStylesAtomic } from '@tamagui/core-node'\nimport { concatClassName } from '@tamagui/helpers'\nimport invariant from 'invariant'\nimport { getRemainingRequest } from 'loader-utils'\nimport { ViewStyle } from 'react-native'\n\nimport { ClassNameObject, StyleObject, TamaguiOptions } from '../types'\nimport { babelParse } from './babelParse'\nimport { buildClassName } from './buildClassName'\nimport { Extractor } from './createExtractor'\nimport { ensureImportingConcat } from './ensureImportingConcat'\nimport { isSimpleSpread } from './extractHelpers'\nimport { extractMediaStyle } from './extractMediaStyle'\nimport { hoistClassNames } from './hoistClassNames'\n\nexport const CONCAT_CLASSNAME_IMPORT = 'concatClassName'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport function extractToClassNames({\n loader,\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n threaded,\n cssPath,\n}: {\n loader: any\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean\n cssPath: string\n threaded?: boolean\n}): null | {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n} {\n if (typeof source !== 'string') {\n throw new Error('`source` must be a string of javascript')\n }\n invariant(\n typeof sourcePath === 'string' && path.isAbsolute(sourcePath),\n '`sourcePath` must be an absolute path to a .js file'\n )\n\n const shouldLogTiming = shouldPrintDebug || options.logTimings\n const start = Date.now()\n const mem = shouldLogTiming ? process.memoryUsage() : null\n\n // Using a map for (officially supported) guaranteed insertion order\n let ast: t.File\n\n try {\n // @ts-ignore\n ast = babelParse(source)\n } catch (err) {\n console.error('babel parse error:', sourcePath)\n throw err\n }\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n let flattened = 0\n let optimized = 0\n\n extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => tag,\n onDidFlatten() {\n flattened++\n },\n onExtractTag: ({\n attrs,\n node,\n attemptEval,\n jsxPath,\n originalNodeName,\n filePath,\n lineNumbers,\n programPath,\n }) => {\n optimized++\n\n let finalClassNames: ClassNameObject[] = []\n let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []\n let finalStyles: StyleObject[] = []\n\n const viewStyles = {}\n for (const attr of attrs) {\n if (attr.type === 'style') {\n Object.assign(viewStyles, attr.value)\n }\n }\n\n const ensureNeededPrevStyle = (style: ViewStyle) => {\n // ensure all group keys are merged\n const keys = Object.keys(style)\n if (!keys.some((key) => mergeStyleGroups[key])) {\n return style\n }\n for (const k in mergeStyleGroups) {\n if (k in viewStyles) {\n style[k] = style[k] ?? viewStyles[k]\n }\n }\n return style\n }\n\n const addStyles = (style: ViewStyle | null) => {\n if (!style) return []\n const styleWithPrev = ensureNeededPrevStyle(style)\n const res = getStylesAtomic(styleWithPrev)\n if (res.length) {\n finalStyles = [...finalStyles, ...res]\n }\n return res\n }\n\n // 1 to start above any :hover styles\n let lastMediaImportance = 1\n for (const attr of attrs) {\n switch (attr.type) {\n case 'style':\n const styles = addStyles(attr.value)\n const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))\n if (shouldPrintDebug) {\n // console.log(' style', attr.value)\n console.log(' classnames', newClassNames, finalClassNames)\n }\n // prettier-ignore\n const existing = finalClassNames.find((x) => x.type == 'StringLiteral') as t.StringLiteral | null\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' classnames (after)', finalClassNames.map(x => x['value']).join(' '))\n }\n break\n case 'attr':\n const val = attr.value\n if (t.isJSXSpreadAttribute(val)) {\n if (isSimpleSpread(val)) {\n finalClassNames.push(\n t.logicalExpression(\n '&&',\n val.argument,\n t.memberExpression(val.argument, t.identifier('className'))\n )\n )\n }\n } else if (val.name.name === 'className') {\n const value = val.value\n if (value) {\n try {\n const evaluatedValue = attemptEval(value)\n finalClassNames.push(t.stringLiteral(evaluatedValue))\n } catch (e) {\n finalClassNames.push(value['expression'])\n }\n }\n continue\n }\n finalAttrs.push(val)\n break\n case 'ternary':\n const mediaExtraction = extractMediaStyle(\n attr.value,\n jsxPath,\n extractor.getTamaguiConfig(),\n sourcePath,\n lastMediaImportance,\n shouldPrintDebug\n )\n if (mediaExtraction) {\n lastMediaImportance++\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n if (!mediaExtraction.ternaryWithoutMedia) {\n continue\n }\n }\n const ternary = mediaExtraction?.ternaryWithoutMedia || attr.value\n const consInfo = addStyles(ternary.consequent)\n const altInfo = addStyles(ternary.alternate)\n const cCN = consInfo.map((x) => x.identifier).join(' ')\n const aCN = altInfo.map((x) => x.identifier).join(' ')\n if (consInfo.length && altInfo.length) {\n finalClassNames.push(\n t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN))\n )\n } else {\n finalClassNames.push(\n t.conditionalExpression(\n ternary.test,\n t.stringLiteral(' ' + cCN),\n t.stringLiteral(' ' + aCN)\n )\n )\n }\n break\n }\n }\n\n node.attributes = finalAttrs\n\n if (finalClassNames.length) {\n // inserts the _cn variable and uses it for className\n const names = buildClassName(finalClassNames)\n const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null\n let expr = nameExpr\n\n // if has some spreads, use concat helper\n if (nameExpr && !t.isIdentifier(nameExpr)) {\n ensureImportingConcat(programPath)\n const simpleSpreads = attrs.filter(\n (x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)\n )\n expr = t.callExpression(t.identifier(CONCAT_CLASSNAME_IMPORT), [\n expr,\n ...simpleSpreads.map((val) => val.value['argument']),\n ])\n }\n\n node.attributes.push(\n t.jsxAttribute(t.jsxIdentifier('className'), t.jsxExpressionContainer(expr))\n )\n }\n\n const comment = util.format('/* %s:%s (%s) */', filePath, lineNumbers, originalNodeName)\n\n for (const { className, rules } of finalStyles) {\n if (cssMap.has(className)) {\n if (comment) {\n const val = cssMap.get(className)!\n val.commentTexts.push(comment)\n cssMap.set(className, val)\n }\n } else if (rules.length) {\n if (rules.length > 1) {\n console.log(' rules error', { rules })\n throw new Error(`Shouldn't have more than one rule`)\n }\n cssMap.set(className, {\n css: rules[0],\n commentTexts: [comment],\n })\n }\n }\n },\n })\n\n if (!optimized) {\n return null\n }\n\n const styles = Array.from(cssMap.values())\n .map((x) => {\n // remove comments\n return x.css //shouldInternalDedupe ? x.css : `${x.commentTexts.join('\\n')}\\n${x.css}`\n })\n .join('\\n')\n .trim()\n\n if (styles) {\n const cssQuery = threaded\n ? `cssData=${Buffer.from(styles).toString('base64')}`\n : `cssPath=${cssPath}`\n const remReq = getRemainingRequest(loader)\n const importPath = `${cssPath}!=!tamagui-loader?${cssQuery}!${remReq}`\n ast.program.body.unshift(t.importDeclaration([], t.stringLiteral(importPath)))\n }\n\n const result = generate(\n ast,\n {\n concise: false,\n filename: sourcePath,\n retainLines: false,\n sourceFileName: sourcePath,\n sourceMaps: true,\n },\n source\n )\n\n if (shouldPrintDebug) {\n console.log(\n '\\n -------- output code ------- \\n\\n',\n result.code\n .split('\\n')\n .filter((x) => !x.startsWith('//'))\n .join('\\n')\n )\n console.log('\\n -------- output style -------- \\n\\n', styles)\n }\n\n if (shouldLogTiming && mem) {\n // console.log(`${parseTime} / ${traverseTime} / ${generateTime}`)\n const memUsed =\n Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10\n // prettier-ignore\n console.log(` \uD83E\uDD5A ${basename(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms \u05C1\u00B7 ${`${optimized}`.padStart(4)} optimized \u00B7 ${flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ''}`)\n }\n\n return {\n ast,\n styles,\n js: result.code,\n map: result.map,\n }\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAIA;AACA;AAEA;AACA;AACA;AACA;AAEO,MAAM,0BAA0B;AAEvC,MAAM,mBAAmB;AAAA,EACvB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAAA;AAGT,6BAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAgBA;AACA,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI,MAAM;AAAA;AAElB,YACE,OAAO,eAAe,YAAY,KAAK,WAAW,aAClD;AAGF,QAAM,kBAAkB,oBAAoB,QAAQ;AACpD,QAAM,QAAQ,KAAK;AACnB,QAAM,MAAM,kBAAkB,QAAQ,gBAAgB;AAGtD,MAAI;AAEJ,MAAI;AAEF,UAAM,WAAW;AAAA,WACV,KAAP;AACA,YAAQ,MAAM,sBAAsB;AACpC,UAAM;AAAA;AAGR,QAAM,SAAS,IAAI;AACnB,QAAM,iBAAkD;AAExD,
|
|
4
|
+
"sourcesContent": ["import * as path from 'path'\nimport { basename } from 'path'\nimport * as util from 'util'\n\nimport generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport { getStylesAtomic } from '@tamagui/core-node'\nimport { concatClassName } from '@tamagui/helpers'\nimport invariant from 'invariant'\nimport { getRemainingRequest } from 'loader-utils'\nimport { ViewStyle } from 'react-native'\n\nimport { ClassNameObject, StyleObject, TamaguiOptions } from '../types'\nimport { babelParse } from './babelParse'\nimport { buildClassName } from './buildClassName'\nimport { Extractor } from './createExtractor'\nimport { ensureImportingConcat } from './ensureImportingConcat'\nimport { isSimpleSpread } from './extractHelpers'\nimport { extractMediaStyle } from './extractMediaStyle'\nimport { hoistClassNames } from './hoistClassNames'\n\nexport const CONCAT_CLASSNAME_IMPORT = 'concatClassName'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport function extractToClassNames({\n loader,\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n threaded,\n cssPath,\n}: {\n loader: any\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean\n cssPath: string\n threaded?: boolean\n}): null | {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n} {\n if (typeof source !== 'string') {\n throw new Error('`source` must be a string of javascript')\n }\n invariant(\n typeof sourcePath === 'string' && path.isAbsolute(sourcePath),\n '`sourcePath` must be an absolute path to a .js file'\n )\n\n const shouldLogTiming = shouldPrintDebug || options.logTimings\n const start = Date.now()\n const mem = shouldLogTiming ? process.memoryUsage() : null\n\n // Using a map for (officially supported) guaranteed insertion order\n let ast: t.File\n\n try {\n // @ts-ignore\n ast = babelParse(source)\n } catch (err) {\n console.error('babel parse error:', sourcePath)\n throw err\n }\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => tag,\n onExtractTag: ({\n attrs,\n node,\n attemptEval,\n jsxPath,\n originalNodeName,\n filePath,\n lineNumbers,\n programPath,\n }) => {\n let finalClassNames: ClassNameObject[] = []\n let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []\n let finalStyles: StyleObject[] = []\n\n const viewStyles = {}\n for (const attr of attrs) {\n if (attr.type === 'style') {\n Object.assign(viewStyles, attr.value)\n }\n }\n\n const ensureNeededPrevStyle = (style: ViewStyle) => {\n // ensure all group keys are merged\n const keys = Object.keys(style)\n if (!keys.some((key) => mergeStyleGroups[key])) {\n return style\n }\n for (const k in mergeStyleGroups) {\n if (k in viewStyles) {\n style[k] = style[k] ?? viewStyles[k]\n }\n }\n return style\n }\n\n const addStyles = (style: ViewStyle | null) => {\n if (!style) return []\n const styleWithPrev = ensureNeededPrevStyle(style)\n const res = getStylesAtomic(styleWithPrev)\n if (res.length) {\n finalStyles = [...finalStyles, ...res]\n }\n return res\n }\n\n // 1 to start above any :hover styles\n let lastMediaImportance = 1\n for (const attr of attrs) {\n switch (attr.type) {\n case 'style':\n const styles = addStyles(attr.value)\n const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))\n if (shouldPrintDebug) {\n // console.log(' style', attr.value)\n console.log(' classnames', newClassNames, finalClassNames)\n }\n // prettier-ignore\n const existing = finalClassNames.find((x) => x.type == 'StringLiteral') as t.StringLiteral | null\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' classnames (after)', finalClassNames.map(x => x['value']).join(' '))\n }\n break\n case 'attr':\n const val = attr.value\n if (t.isJSXSpreadAttribute(val)) {\n if (isSimpleSpread(val)) {\n finalClassNames.push(\n t.logicalExpression(\n '&&',\n val.argument,\n t.memberExpression(val.argument, t.identifier('className'))\n )\n )\n }\n } else if (val.name.name === 'className') {\n const value = val.value\n if (value) {\n try {\n const evaluatedValue = attemptEval(value)\n finalClassNames.push(t.stringLiteral(evaluatedValue))\n } catch (e) {\n finalClassNames.push(value['expression'])\n }\n }\n continue\n }\n finalAttrs.push(val)\n break\n case 'ternary':\n const mediaExtraction = extractMediaStyle(\n attr.value,\n jsxPath,\n extractor.getTamagui(),\n sourcePath,\n lastMediaImportance,\n shouldPrintDebug\n )\n if (mediaExtraction) {\n lastMediaImportance++\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n if (!mediaExtraction.ternaryWithoutMedia) {\n continue\n }\n }\n const ternary = mediaExtraction?.ternaryWithoutMedia || attr.value\n const consInfo = addStyles(ternary.consequent)\n const altInfo = addStyles(ternary.alternate)\n const cCN = consInfo.map((x) => x.identifier).join(' ')\n const aCN = altInfo.map((x) => x.identifier).join(' ')\n if (consInfo.length && altInfo.length) {\n finalClassNames.push(\n t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN))\n )\n } else {\n finalClassNames.push(\n t.conditionalExpression(\n ternary.test,\n t.stringLiteral(' ' + cCN),\n t.stringLiteral(' ' + aCN)\n )\n )\n }\n break\n }\n }\n\n node.attributes = finalAttrs\n\n if (finalClassNames.length) {\n // inserts the _cn variable and uses it for className\n const names = buildClassName(finalClassNames)\n const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null\n let expr = nameExpr\n\n // if has some spreads, use concat helper\n if (nameExpr && !t.isIdentifier(nameExpr)) {\n ensureImportingConcat(programPath)\n const simpleSpreads = attrs.filter(\n (x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)\n )\n expr = t.callExpression(t.identifier(CONCAT_CLASSNAME_IMPORT), [\n expr,\n ...simpleSpreads.map((val) => val.value['argument']),\n ])\n }\n\n node.attributes.push(\n t.jsxAttribute(t.jsxIdentifier('className'), t.jsxExpressionContainer(expr))\n )\n }\n\n const comment = util.format('/* %s:%s (%s) */', filePath, lineNumbers, originalNodeName)\n\n for (const { className, rules } of finalStyles) {\n if (cssMap.has(className)) {\n if (comment) {\n const val = cssMap.get(className)!\n val.commentTexts.push(comment)\n cssMap.set(className, val)\n }\n } else if (rules.length) {\n if (rules.length > 1) {\n console.log(' rules error', { rules })\n throw new Error(`Shouldn't have more than one rule`)\n }\n cssMap.set(className, {\n css: rules[0],\n commentTexts: [comment],\n })\n }\n }\n },\n })\n\n if (!res || !res.modified) {\n return null\n }\n\n const styles = Array.from(cssMap.values())\n .map((x) => x.css)\n .join('\\n')\n .trim()\n\n if (styles) {\n const cssQuery = threaded\n ? `cssData=${Buffer.from(styles).toString('base64')}`\n : `cssPath=${cssPath}`\n const remReq = getRemainingRequest(loader)\n const importPath = `${cssPath}!=!tamagui-loader?${cssQuery}!${remReq}`\n ast.program.body.unshift(t.importDeclaration([], t.stringLiteral(importPath)))\n }\n\n const result = generate(\n ast,\n {\n concise: false,\n filename: sourcePath,\n retainLines: false,\n sourceFileName: sourcePath,\n sourceMaps: true,\n },\n source\n )\n\n if (shouldPrintDebug) {\n console.log(\n '\\n -------- output code ------- \\n\\n',\n result.code\n .split('\\n')\n .filter((x) => !x.startsWith('//'))\n .join('\\n')\n )\n console.log('\\n -------- output style -------- \\n\\n', styles)\n }\n\n if (shouldLogTiming && mem) {\n // console.log(`${parseTime} / ${traverseTime} / ${generateTime}`)\n const memUsed =\n Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10\n // prettier-ignore\n console.log(` \uD83E\uDD5A ${basename(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms \u05C1\u00B7 ${`${res.optimized}`.padStart(4)} optimized \u00B7 ${res.flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ''}`)\n }\n\n return {\n ast,\n styles,\n js: result.code,\n map: result.map,\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAIA;AACA;AAEA;AACA;AACA;AACA;AAEO,MAAM,0BAA0B;AAEvC,MAAM,mBAAmB;AAAA,EACvB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAAA;AAGT,6BAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAgBA;AACA,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI,MAAM;AAAA;AAElB,YACE,OAAO,eAAe,YAAY,KAAK,WAAW,aAClD;AAGF,QAAM,kBAAkB,oBAAoB,QAAQ;AACpD,QAAM,QAAQ,KAAK;AACnB,QAAM,MAAM,kBAAkB,QAAQ,gBAAgB;AAGtD,MAAI;AAEJ,MAAI;AAEF,UAAM,WAAW;AAAA,WACV,KAAP;AACA,YAAQ,MAAM,sBAAsB;AACpC,UAAM;AAAA;AAGR,QAAM,SAAS,IAAI;AACnB,QAAM,iBAAkD;AAExD,QAAM,MAAM,UAAU,MAAM,KAAK;AAAA,IAC/B;AAAA,IACA;AAAA,OACG;AAAA,IACH,kBAAkB,CAAC,EAAE,UAAU;AAAA,IAC/B,cAAc,CAAC;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,UACI;AACJ,UAAI,kBAAqC;AACzC,UAAI,aAAwD;AAC5D,UAAI,cAA6B;AAEjC,YAAM,aAAa;AACnB,iBAAW,QAAQ,OAAO;AACxB,YAA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;AAAA,IACb,gBAAgB;AAAA,IAChB,YAAY;AAAA,KAEd;AAGF,MAAI,kBAAkB;AACpB,YAAQ,IACN,wCACA,OAAO,KACJ,MAAM,MACN,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,OAC5B,KAAK;AAEV,YAAQ,IAAI,0CAA0C;AAAA;AAGxD,MAAI,mBAAmB,KAAK;AAE1B,UAAM,UACJ,KAAK,MAAQ,SAAQ,cAAc,WAAW,IAAI,YAAY,OAAO,OAAQ,MAAM;AAErF,YAAQ,IAAI,eAAQ,SAAS,YAAY,SAAS,OAAO,GAAG,KAAK,QAAQ,QAAQ,SAAS,mBAAW,GAAG,IAAI,YAAY,SAAS,qBAAkB,IAAI,uBAAuB,UAAU,KAAK,QAAQ,cAAc;AAAA;AAGrN,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA;AAAA;AArSA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -717,8 +717,9 @@ function createExtractor() {
|
|
|
717
717
|
format: "cjs"
|
|
718
718
|
});
|
|
719
719
|
let loadedTamaguiConfig;
|
|
720
|
+
let hasLogged = false;
|
|
720
721
|
return {
|
|
721
|
-
|
|
722
|
+
getTamagui() {
|
|
722
723
|
return loadedTamaguiConfig;
|
|
723
724
|
},
|
|
724
725
|
parse: (fileOrPath, _a) => {
|
|
@@ -730,7 +731,9 @@ function createExtractor() {
|
|
|
730
731
|
sourcePath = "",
|
|
731
732
|
onExtractTag,
|
|
732
733
|
getFlattenedNode,
|
|
733
|
-
|
|
734
|
+
disableExtraction,
|
|
735
|
+
disableExtractInlineMedia,
|
|
736
|
+
disableDebugAttr
|
|
734
737
|
} = _b, props = __objRest(_b, [
|
|
735
738
|
"config",
|
|
736
739
|
"importsWhitelist",
|
|
@@ -739,7 +742,9 @@ function createExtractor() {
|
|
|
739
742
|
"sourcePath",
|
|
740
743
|
"onExtractTag",
|
|
741
744
|
"getFlattenedNode",
|
|
742
|
-
"
|
|
745
|
+
"disableExtraction",
|
|
746
|
+
"disableExtractInlineMedia",
|
|
747
|
+
"disableDebugAttr"
|
|
743
748
|
]);
|
|
744
749
|
if (sourcePath === "") {
|
|
745
750
|
throw new Error(`Must provide a source file name`);
|
|
@@ -753,16 +758,16 @@ function createExtractor() {
|
|
|
753
758
|
});
|
|
754
759
|
loadedTamaguiConfig = tamaguiConfig;
|
|
755
760
|
const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
|
|
756
|
-
let doesUseValidImport = false;
|
|
757
761
|
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
758
762
|
const isInternalImport = /* @__PURE__ */ __name((importStr) => isInsideTamagui(sourcePath) && importStr[0] === ".", "isInternalImport");
|
|
759
763
|
const validComponents = Object.keys(components).filter((key) => {
|
|
760
764
|
var _a2;
|
|
761
|
-
return !!((_a2 = components[key]) == null ? void 0 : _a2.staticConfig);
|
|
765
|
+
return key[0].toUpperCase() === key[0] && !!((_a2 = components[key]) == null ? void 0 : _a2.staticConfig);
|
|
762
766
|
}).reduce((obj, name) => {
|
|
763
767
|
obj[name] = components[name];
|
|
764
768
|
return obj;
|
|
765
769
|
}, {});
|
|
770
|
+
let doesUseValidImport = false;
|
|
766
771
|
for (const bodyPath of body) {
|
|
767
772
|
if (bodyPath.type !== "ImportDeclaration")
|
|
768
773
|
continue;
|
|
@@ -791,6 +796,11 @@ function createExtractor() {
|
|
|
791
796
|
return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
|
|
792
797
|
}, "callTraverse");
|
|
793
798
|
let programPath;
|
|
799
|
+
const res = {
|
|
800
|
+
flattened: 0,
|
|
801
|
+
optimized: 0,
|
|
802
|
+
modified: 0
|
|
803
|
+
};
|
|
794
804
|
callTraverse({
|
|
795
805
|
Program: {
|
|
796
806
|
enter(path3) {
|
|
@@ -823,8 +833,26 @@ function createExtractor() {
|
|
|
823
833
|
if (!component || !component.staticConfig) {
|
|
824
834
|
return;
|
|
825
835
|
}
|
|
826
|
-
const { staticConfig } = component;
|
|
827
836
|
const originalNodeName = node.name.name;
|
|
837
|
+
if (shouldPrintDebug) {
|
|
838
|
+
console.log(`
|
|
839
|
+
<${originalNodeName} />`);
|
|
840
|
+
}
|
|
841
|
+
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
842
|
+
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
843
|
+
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
844
|
+
const preName = componentName ? `${componentName}:` : "";
|
|
845
|
+
res.modified++;
|
|
846
|
+
node.attributes.unshift(t9.jsxAttribute(t9.jsxIdentifier("data-is"), t9.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `)));
|
|
847
|
+
}
|
|
848
|
+
if (disableExtraction) {
|
|
849
|
+
if (!hasLogged) {
|
|
850
|
+
console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
|
|
851
|
+
hasLogged = true;
|
|
852
|
+
}
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
const { staticConfig } = component;
|
|
828
856
|
const isTextView = staticConfig.isText || false;
|
|
829
857
|
const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
|
|
830
858
|
let tagName = ((_a2 = staticConfig.defaultProps) == null ? void 0 : _a2.tag) ?? (isTextView ? "span" : "div");
|
|
@@ -846,21 +874,17 @@ function createExtractor() {
|
|
|
846
874
|
]);
|
|
847
875
|
const excludeProps = new Set(props.excludeProps ?? []);
|
|
848
876
|
const isExcludedProp = /* @__PURE__ */ __name((name) => {
|
|
849
|
-
const
|
|
850
|
-
if (
|
|
877
|
+
const res2 = excludeProps.has(name);
|
|
878
|
+
if (res2 && shouldPrintDebug)
|
|
851
879
|
console.log(` excluding ${name}`);
|
|
852
|
-
return
|
|
880
|
+
return res2;
|
|
853
881
|
}, "isExcludedProp");
|
|
854
882
|
const isDeoptedProp = /* @__PURE__ */ __name((name) => {
|
|
855
|
-
const
|
|
856
|
-
if (
|
|
883
|
+
const res2 = deoptProps.has(name);
|
|
884
|
+
if (res2 && shouldPrintDebug)
|
|
857
885
|
console.log(` deopting ${name}`);
|
|
858
|
-
return
|
|
886
|
+
return res2;
|
|
859
887
|
}, "isDeoptedProp");
|
|
860
|
-
if (shouldPrintDebug) {
|
|
861
|
-
console.log(`
|
|
862
|
-
<${originalNodeName} />`);
|
|
863
|
-
}
|
|
864
888
|
const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
865
889
|
const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
|
|
866
890
|
tamaguiConfig,
|
|
@@ -933,11 +957,11 @@ function createExtractor() {
|
|
|
933
957
|
let isFlattened = false;
|
|
934
958
|
attrs = traversePath.get("openingElement").get("attributes").flatMap((path3) => {
|
|
935
959
|
try {
|
|
936
|
-
const
|
|
937
|
-
if (!
|
|
960
|
+
const res2 = evaluateAttribute(path3);
|
|
961
|
+
if (!res2) {
|
|
938
962
|
path3.remove();
|
|
939
963
|
}
|
|
940
|
-
return
|
|
964
|
+
return res2;
|
|
941
965
|
} catch (err) {
|
|
942
966
|
console.log("Error extracting attribute", err.message, err.stack);
|
|
943
967
|
console.log("node", path3.node);
|
|
@@ -1060,6 +1084,9 @@ function createExtractor() {
|
|
|
1060
1084
|
return attr;
|
|
1061
1085
|
}
|
|
1062
1086
|
if (name[0] === "$" && t9.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
1087
|
+
if (disableExtractInlineMedia) {
|
|
1088
|
+
return attr;
|
|
1089
|
+
}
|
|
1063
1090
|
const shortname = name.slice(1);
|
|
1064
1091
|
if (mediaQueryConfig[shortname]) {
|
|
1065
1092
|
const expression = attribute.value.expression;
|
|
@@ -1119,7 +1146,9 @@ function createExtractor() {
|
|
|
1119
1146
|
if (styleValue !== FAILED_EVAL) {
|
|
1120
1147
|
return {
|
|
1121
1148
|
type: "style",
|
|
1122
|
-
value: { [name]: styleValue }
|
|
1149
|
+
value: { [name]: styleValue },
|
|
1150
|
+
name,
|
|
1151
|
+
attr: path3.node
|
|
1123
1152
|
};
|
|
1124
1153
|
}
|
|
1125
1154
|
if (t9.isBinaryExpression(value)) {
|
|
@@ -1246,8 +1275,6 @@ function createExtractor() {
|
|
|
1246
1275
|
if (parentFn) {
|
|
1247
1276
|
modifiedComponents.add(parentFn);
|
|
1248
1277
|
}
|
|
1249
|
-
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
1250
|
-
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
1251
1278
|
let ternaries = [];
|
|
1252
1279
|
attrs = attrs.reduce((out, cur) => {
|
|
1253
1280
|
const next = attrs[attrs.indexOf(cur) + 1];
|
|
@@ -1306,17 +1333,19 @@ function createExtractor() {
|
|
|
1306
1333
|
const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
1307
1334
|
if (!shouldFlatten) {
|
|
1308
1335
|
attrs = attrs.reduce((acc, cur) => {
|
|
1309
|
-
var _a3;
|
|
1336
|
+
var _a3, _b2;
|
|
1310
1337
|
if (cur.type === "style") {
|
|
1311
1338
|
for (const key in cur.value) {
|
|
1312
|
-
const
|
|
1339
|
+
const shouldEnsureOverridden = !!((_a3 = staticConfig.ensureOverriddenProp) == null ? void 0 : _a3[key]);
|
|
1313
1340
|
const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1341
|
+
if (!isSetInAttrsAlready) {
|
|
1342
|
+
const isVariant = !!((_b2 = staticConfig.variants) == null ? void 0 : _b2[cur.name || ""]);
|
|
1343
|
+
if (isVariant || shouldEnsureOverridden) {
|
|
1344
|
+
acc.push({
|
|
1345
|
+
type: "attr",
|
|
1346
|
+
value: cur.attr || t9.jsxAttribute(t9.jsxIdentifier(key), t9.jsxExpressionContainer(t9.nullLiteral()))
|
|
1347
|
+
});
|
|
1348
|
+
}
|
|
1320
1349
|
}
|
|
1321
1350
|
}
|
|
1322
1351
|
}
|
|
@@ -1442,20 +1471,13 @@ function createExtractor() {
|
|
|
1442
1471
|
if (shouldPrintDebug) {
|
|
1443
1472
|
console.log(" - attrs (after): ", attrs.map(attrStr).join(", "));
|
|
1444
1473
|
}
|
|
1445
|
-
if (shouldAddDebugProp) {
|
|
1446
|
-
const preName = componentName ? `${componentName}:` : "";
|
|
1447
|
-
attrs.unshift({
|
|
1448
|
-
type: "attr",
|
|
1449
|
-
value: t9.jsxAttribute(t9.jsxIdentifier("data-is"), t9.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `))
|
|
1450
|
-
});
|
|
1451
|
-
}
|
|
1452
1474
|
if (shouldFlatten) {
|
|
1453
1475
|
if (shouldPrintDebug) {
|
|
1454
1476
|
console.log(" [\u2705] flattening", originalNodeName, flatNode);
|
|
1455
1477
|
}
|
|
1456
1478
|
isFlattened = true;
|
|
1457
1479
|
node.name.name = flatNode;
|
|
1458
|
-
|
|
1480
|
+
res.flattened++;
|
|
1459
1481
|
if (closingElement) {
|
|
1460
1482
|
closingElement.name.name = flatNode;
|
|
1461
1483
|
}
|
|
@@ -1464,6 +1486,7 @@ function createExtractor() {
|
|
|
1464
1486
|
console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
|
|
1465
1487
|
console.log(" - attrs (end): ", attrs.map(attrStr).join(", "));
|
|
1466
1488
|
}
|
|
1489
|
+
res.optimized++;
|
|
1467
1490
|
onExtractTag({
|
|
1468
1491
|
attrs,
|
|
1469
1492
|
node,
|
|
@@ -1486,6 +1509,7 @@ function createExtractor() {
|
|
|
1486
1509
|
removeUnusedHooks(comp, shouldPrintDebug);
|
|
1487
1510
|
}
|
|
1488
1511
|
}
|
|
1512
|
+
return res;
|
|
1489
1513
|
}
|
|
1490
1514
|
};
|
|
1491
1515
|
}
|
|
@@ -1803,16 +1827,11 @@ function extractToClassNames({
|
|
|
1803
1827
|
}
|
|
1804
1828
|
const cssMap = new Map();
|
|
1805
1829
|
const existingHoists = {};
|
|
1806
|
-
|
|
1807
|
-
let optimized = 0;
|
|
1808
|
-
extractor.parse(ast, __spreadProps(__spreadValues({
|
|
1830
|
+
const res = extractor.parse(ast, __spreadProps(__spreadValues({
|
|
1809
1831
|
sourcePath,
|
|
1810
1832
|
shouldPrintDebug
|
|
1811
1833
|
}, options), {
|
|
1812
1834
|
getFlattenedNode: ({ tag }) => tag,
|
|
1813
|
-
onDidFlatten() {
|
|
1814
|
-
flattened++;
|
|
1815
|
-
},
|
|
1816
1835
|
onExtractTag: ({
|
|
1817
1836
|
attrs,
|
|
1818
1837
|
node,
|
|
@@ -1823,7 +1842,6 @@ function extractToClassNames({
|
|
|
1823
1842
|
lineNumbers,
|
|
1824
1843
|
programPath
|
|
1825
1844
|
}) => {
|
|
1826
|
-
optimized++;
|
|
1827
1845
|
let finalClassNames = [];
|
|
1828
1846
|
let finalAttrs = [];
|
|
1829
1847
|
let finalStyles = [];
|
|
@@ -1849,11 +1867,11 @@ function extractToClassNames({
|
|
|
1849
1867
|
if (!style)
|
|
1850
1868
|
return [];
|
|
1851
1869
|
const styleWithPrev = ensureNeededPrevStyle(style);
|
|
1852
|
-
const
|
|
1853
|
-
if (
|
|
1854
|
-
finalStyles = [...finalStyles, ...
|
|
1870
|
+
const res2 = (0, import_core_node3.getStylesAtomic)(styleWithPrev);
|
|
1871
|
+
if (res2.length) {
|
|
1872
|
+
finalStyles = [...finalStyles, ...res2];
|
|
1855
1873
|
}
|
|
1856
|
-
return
|
|
1874
|
+
return res2;
|
|
1857
1875
|
}, "addStyles");
|
|
1858
1876
|
let lastMediaImportance = 1;
|
|
1859
1877
|
for (const attr of attrs) {
|
|
@@ -1895,7 +1913,7 @@ function extractToClassNames({
|
|
|
1895
1913
|
finalAttrs.push(val);
|
|
1896
1914
|
break;
|
|
1897
1915
|
case "ternary":
|
|
1898
|
-
const mediaExtraction = extractMediaStyle(attr.value, jsxPath, extractor.
|
|
1916
|
+
const mediaExtraction = extractMediaStyle(attr.value, jsxPath, extractor.getTamagui(), sourcePath, lastMediaImportance, shouldPrintDebug);
|
|
1899
1917
|
if (mediaExtraction) {
|
|
1900
1918
|
lastMediaImportance++;
|
|
1901
1919
|
finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles];
|
|
@@ -1956,12 +1974,10 @@ function extractToClassNames({
|
|
|
1956
1974
|
}
|
|
1957
1975
|
}
|
|
1958
1976
|
}));
|
|
1959
|
-
if (!
|
|
1977
|
+
if (!res || !res.modified) {
|
|
1960
1978
|
return null;
|
|
1961
1979
|
}
|
|
1962
|
-
const styles = Array.from(cssMap.values()).map((x) =>
|
|
1963
|
-
return x.css;
|
|
1964
|
-
}).join("\n").trim();
|
|
1980
|
+
const styles = Array.from(cssMap.values()).map((x) => x.css).join("\n").trim();
|
|
1965
1981
|
if (styles) {
|
|
1966
1982
|
const cssQuery = threaded ? `cssData=${Buffer.from(styles).toString("base64")}` : `cssPath=${cssPath}`;
|
|
1967
1983
|
const remReq = (0, import_loader_utils.getRemainingRequest)(loader);
|
|
@@ -1981,7 +1997,7 @@ function extractToClassNames({
|
|
|
1981
1997
|
}
|
|
1982
1998
|
if (shouldLogTiming && mem) {
|
|
1983
1999
|
const memUsed = Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10;
|
|
1984
|
-
console.log(` \u{1F95A} ${(0, import_path3.basename)(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms \u05C1\xB7 ${`${optimized}`.padStart(4)} optimized \xB7 ${flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ""}`);
|
|
2000
|
+
console.log(` \u{1F95A} ${(0, import_path3.basename)(sourcePath).padStart(40)} ${`${Date.now() - start}`.padStart(3)}ms \u05C1\xB7 ${`${res.optimized}`.padStart(4)} optimized \xB7 ${res.flattened} flattened ${memUsed > 10 ? `used ${memUsed}MB` : ""}`);
|
|
1985
2001
|
}
|
|
1986
2002
|
return {
|
|
1987
2003
|
ast,
|
|
@@ -1997,8 +2013,24 @@ var fs = __toModule(require("fs"));
|
|
|
1997
2013
|
var import_path4 = __toModule(require("path"));
|
|
1998
2014
|
function patchReactNativeWeb() {
|
|
1999
2015
|
const rootDir = require.resolve("react-native-web").replace(/\/dist.*/, "");
|
|
2000
|
-
|
|
2001
|
-
|
|
2016
|
+
const modulePath = import_path4.default.join(rootDir, "dist", "tamagui-exports.js");
|
|
2017
|
+
const cjsPath = import_path4.default.join(rootDir, "dist", "cjs", "tamagui-exports.js");
|
|
2018
|
+
const isEqual = (() => {
|
|
2019
|
+
let res = false;
|
|
2020
|
+
try {
|
|
2021
|
+
res = fs.readFileSync(modulePath, "utf-8") === moduleExports && fs.readFileSync(cjsPath, "utf-8") == cjsExports;
|
|
2022
|
+
} catch {
|
|
2023
|
+
res = false;
|
|
2024
|
+
}
|
|
2025
|
+
return res;
|
|
2026
|
+
})();
|
|
2027
|
+
if (!isEqual) {
|
|
2028
|
+
console.log("\u{1F95A} Tamagui patching react-native-web to share atomic styling primitives");
|
|
2029
|
+
console.log(" > adding", modulePath);
|
|
2030
|
+
console.log(" > adding", cjsPath);
|
|
2031
|
+
fs.writeFileSync(modulePath, moduleExports);
|
|
2032
|
+
fs.writeFileSync(cjsPath, cjsExports);
|
|
2033
|
+
}
|
|
2002
2034
|
const moduleEntry = import_path4.default.join(rootDir, "dist", "index.js");
|
|
2003
2035
|
const moduleEntrySrc = fs.readFileSync(moduleEntry, "utf-8");
|
|
2004
2036
|
if (!moduleEntrySrc.includes("// tamagui-patch-v4")) {
|
|
@@ -2019,7 +2051,6 @@ export const TamaguiExports = TExports
|
|
|
2019
2051
|
exports.TamaguiExports = _interopRequireDefault(require("./tamagui-exports"));
|
|
2020
2052
|
// tamagui-patch-end
|
|
2021
2053
|
`);
|
|
2022
|
-
console.log(`Tamagui patched react-native-web`);
|
|
2023
2054
|
}
|
|
2024
2055
|
}
|
|
2025
2056
|
__name(patchReactNativeWeb, "patchReactNativeWeb");
|