@tamagui/static 1.0.0-alpha.60 → 1.0.0-alpha.64
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/cjs/extractor/createExtractor.js +54 -18
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/extractHelpers.js +15 -5
- package/dist/cjs/extractor/extractHelpers.js.map +2 -2
- package/dist/cjs/extractor/extractMediaStyle.js.map +1 -1
- package/dist/cjs/extractor/extractToClassNames.js +27 -17
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/extractor/getPrefixLogs.js +34 -0
- package/dist/cjs/extractor/getPrefixLogs.js.map +7 -0
- package/dist/cjs/extractor/literalToAst.js +59 -0
- package/dist/cjs/extractor/literalToAst.js.map +2 -2
- package/dist/cjs/patchReactNativeWeb.js +1 -1
- package/dist/cjs/patchReactNativeWeb.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/extractor/createExtractor.js +53 -16
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/extractHelpers.js +16 -5
- package/dist/esm/extractor/extractHelpers.js.map +2 -2
- package/dist/esm/extractor/extractMediaStyle.js.map +1 -1
- package/dist/esm/extractor/extractToClassNames.js +29 -19
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/getPrefixLogs.js +12 -0
- package/dist/esm/extractor/getPrefixLogs.js.map +7 -0
- package/dist/esm/extractor/literalToAst.js +46 -0
- package/dist/esm/extractor/literalToAst.js.map +2 -2
- package/dist/esm/patchReactNativeWeb.js +1 -1
- package/dist/esm/patchReactNativeWeb.js.map +1 -1
- package/dist/jsx/extractor/createExtractor.js +53 -16
- package/dist/jsx/extractor/extractHelpers.js +16 -5
- package/dist/jsx/extractor/extractToClassNames.js +29 -19
- package/dist/jsx/extractor/getPrefixLogs.js +11 -0
- package/dist/jsx/extractor/literalToAst.js +46 -0
- package/dist/jsx/patchReactNativeWeb.js +1 -1
- package/package.json +7 -7
- package/types/extractor/createExtractor.d.ts +1 -1
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/extractHelpers.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/getPrefixLogs.d.ts +3 -0
- package/types/extractor/getPrefixLogs.d.ts.map +1 -0
- package/types/extractor/literalToAst.d.ts +1 -0
- package/types/extractor/literalToAst.d.ts.map +1 -1
- package/types/types.d.ts +2 -0
- package/types/types.d.ts.map +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/extractMediaStyle.ts"],
|
|
4
|
-
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { TamaguiInternalConfig } from '@tamagui/core'\nimport { getStylesAtomic, mediaObjectToString } from '@tamagui/core-node'\nimport { ViewStyle } from 'react-native'\n\nimport { MEDIA_SEP } from '../constants'\nimport { StyleObject, Ternary } from '../types'\nimport { isInsideTamagui, isPresent } from './extractHelpers'\n\nexport function extractMediaStyle(\n ternary: Ternary,\n jsxPath: NodePath<t.JSXElement>,\n tamaguiConfig: TamaguiInternalConfig,\n sourcePath: string,\n importance = 0,\n shouldPrintDebug = false\n) {\n const mt = getMediaQueryTernary(ternary, jsxPath, sourcePath)\n if (!mt) {\n return null\n }\n const { key } = mt\n const mq = tamaguiConfig.media[key]\n if (!mq) {\n console.error(`Media query \"${key}\" not found: ${Object.keys(tamaguiConfig.media)}`)\n return null\n }\n const getStyleObj = (styleObj: ViewStyle | null, negate = false) => {\n return styleObj ? { styleObj, negate } : null\n }\n const styleOpts = [\n getStyleObj(ternary.consequent, false),\n getStyleObj(ternary.alternate, true),\n ].filter(isPresent)\n if (shouldPrintDebug && !styleOpts.length) {\n console.log(' media query, no styles?')\n return null\n }\n // for now order first strongest\n const mediaKeys = Object.keys(tamaguiConfig.media)\n const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {\n acc[cur] = new Array(importance + 1).fill(':root').join('')\n return acc\n }, {})\n let mediaStyles: StyleObject[] = []\n for (const { styleObj, negate } of styleOpts) {\n const styles = getStylesAtomic(styleObj)\n const singleMediaStyles = styles.map((style) => {\n const negKey = negate ? '0' : ''\n const ogPrefix = style.identifier.slice(0, style.identifier.indexOf('-') + 1)\n // adds an extra separator before and after to detect later in concatClassName\n // so it goes from: \"_f-[hash]\"\n // to: \"_f-_sm0_[hash]\" or \"_f-_sm_[hash]\"\n const identifier = `${style.identifier.replace(\n ogPrefix,\n `${ogPrefix}${MEDIA_SEP}${key}${negKey}${MEDIA_SEP}`\n )}`\n const className = `.${identifier}`\n const mediaSelector = mediaObjectToString(tamaguiConfig.media[key])\n const screenStr = negate ? 'not all' : 'screen'\n const mediaQuery = `${screenStr} and ${mediaSelector}`\n const precendencePrefix = mediaKeyPrecendence[key]\n const styleInner = style.rules[0].replace(style.identifier, identifier)\n // combines media queries if they already exist\n let styleRule = ''\n if (styleInner.includes('@media')) {\n // combine\n styleRule = styleInner.replace('{', ` and ${mediaQuery} {`)\n } else {\n styleRule = `@media ${mediaQuery} { ${precendencePrefix} ${styleInner} }`\n }\n return {\n ...style,\n identifier,\n className,\n rules: [styleRule],\n }\n })\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' media styles:', importance, singleMediaStyles.map(x => x.identifier).join(', '))\n }\n // add to output\n mediaStyles = [...mediaStyles, ...singleMediaStyles]\n }\n // filter out\n ternary.remove()\n return { mediaStyles, ternaryWithoutMedia: mt.ternaryWithoutMedia }\n}\n\nfunction getMediaQueryTernary(\n ternary: Ternary,\n jsxPath: NodePath<t.JSXElement>,\n sourcePath: string\n): null | {\n key: string\n bindingName: string\n ternaryWithoutMedia: Ternary | null\n} {\n // this handles unwrapping logical && media query ternarys\n // first, unwrap if it has media logicalExpression\n if (t.isLogicalExpression(ternary.test) && ternary.test.operator === '&&') {\n // *should* be normalized to always be on left side
|
|
4
|
+
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { TamaguiInternalConfig } from '@tamagui/core'\nimport { getStylesAtomic, mediaObjectToString } from '@tamagui/core-node'\nimport { ViewStyle } from 'react-native'\n\nimport { MEDIA_SEP } from '../constants'\nimport { StyleObject, Ternary } from '../types'\nimport { isInsideTamagui, isPresent } from './extractHelpers'\n\nexport function extractMediaStyle(\n ternary: Ternary,\n jsxPath: NodePath<t.JSXElement>,\n tamaguiConfig: TamaguiInternalConfig,\n sourcePath: string,\n importance = 0,\n shouldPrintDebug = false\n) {\n const mt = getMediaQueryTernary(ternary, jsxPath, sourcePath)\n if (!mt) {\n return null\n }\n const { key } = mt\n const mq = tamaguiConfig.media[key]\n if (!mq) {\n console.error(`Media query \"${key}\" not found: ${Object.keys(tamaguiConfig.media)}`)\n return null\n }\n const getStyleObj = (styleObj: ViewStyle | null, negate = false) => {\n return styleObj ? { styleObj, negate } : null\n }\n const styleOpts = [\n getStyleObj(ternary.consequent, false),\n getStyleObj(ternary.alternate, true),\n ].filter(isPresent)\n if (shouldPrintDebug && !styleOpts.length) {\n console.log(' media query, no styles?')\n return null\n }\n // for now order first strongest\n const mediaKeys = Object.keys(tamaguiConfig.media)\n const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {\n acc[cur] = new Array(importance + 1).fill(':root').join('')\n return acc\n }, {})\n let mediaStyles: StyleObject[] = []\n for (const { styleObj, negate } of styleOpts) {\n const styles = getStylesAtomic(styleObj)\n const singleMediaStyles = styles.map((style) => {\n const negKey = negate ? '0' : ''\n const ogPrefix = style.identifier.slice(0, style.identifier.indexOf('-') + 1)\n // adds an extra separator before and after to detect later in concatClassName\n // so it goes from: \"_f-[hash]\"\n // to: \"_f-_sm0_[hash]\" or \"_f-_sm_[hash]\"\n const identifier = `${style.identifier.replace(\n ogPrefix,\n `${ogPrefix}${MEDIA_SEP}${key}${negKey}${MEDIA_SEP}`\n )}`\n const className = `.${identifier}`\n const mediaSelector = mediaObjectToString(tamaguiConfig.media[key])\n const screenStr = negate ? 'not all' : 'screen'\n const mediaQuery = `${screenStr} and ${mediaSelector}`\n const precendencePrefix = mediaKeyPrecendence[key]\n const styleInner = style.rules[0].replace(style.identifier, identifier)\n // combines media queries if they already exist\n let styleRule = ''\n if (styleInner.includes('@media')) {\n // combine\n styleRule = styleInner.replace('{', ` and ${mediaQuery} {`)\n } else {\n styleRule = `@media ${mediaQuery} { ${precendencePrefix} ${styleInner} }`\n }\n return {\n ...style,\n identifier,\n className,\n rules: [styleRule],\n }\n })\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' media styles:', importance, singleMediaStyles.map(x => x.identifier).join(', '))\n }\n // add to output\n mediaStyles = [...mediaStyles, ...singleMediaStyles]\n }\n // filter out\n ternary.remove()\n return { mediaStyles, ternaryWithoutMedia: mt.ternaryWithoutMedia }\n}\n\nfunction getMediaQueryTernary(\n ternary: Ternary,\n jsxPath: NodePath<t.JSXElement>,\n sourcePath: string\n): null | {\n key: string\n bindingName: string\n ternaryWithoutMedia: Ternary | null\n} {\n // this handles unwrapping logical && media query ternarys\n // first, unwrap if it has media logicalExpression\n if (t.isLogicalExpression(ternary.test) && ternary.test.operator === '&&') {\n // *should* be normalized to always be on left side\n const mediaLeft = getMediaInfoFromExpression(\n ternary.test.left,\n jsxPath,\n sourcePath,\n ternary.inlineMediaQuery\n )\n if (mediaLeft) {\n return {\n ...mediaLeft,\n ternaryWithoutMedia: {\n ...ternary,\n test: ternary.test.right,\n },\n }\n }\n }\n // const media = useMedia()\n // ... media.sm\n const result = getMediaInfoFromExpression(\n ternary.test,\n jsxPath,\n sourcePath,\n ternary.inlineMediaQuery\n )\n if (result) {\n return {\n ...result,\n ternaryWithoutMedia: null,\n }\n }\n return null\n}\n\nfunction getMediaInfoFromExpression(\n test: t.Expression,\n jsxPath: NodePath<t.JSXElement>,\n sourcePath: string,\n inlineMediaQuery?: string\n) {\n if (inlineMediaQuery) {\n return {\n key: inlineMediaQuery,\n bindingName: inlineMediaQuery,\n }\n }\n if (t.isMemberExpression(test) && t.isIdentifier(test.object) && t.isIdentifier(test.property)) {\n const name = test.object['name']\n const key = test.property['name']\n const bindings = jsxPath.scope.getAllBindings()\n const binding = bindings[name]\n if (!binding) return false\n const bindingNode = binding.path?.node\n if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init) return false\n if (!isValidMediaCall(jsxPath, bindingNode.init, sourcePath)) return false\n return { key, bindingName: name }\n }\n if (t.isIdentifier(test)) {\n const key = test.name\n const node = jsxPath.scope.getBinding(test.name)?.path?.node\n if (!t.isVariableDeclarator(node)) return false\n if (!node.init || !isValidMediaCall(jsxPath, node.init, sourcePath)) return false\n return { key, bindingName: key }\n }\n return null\n}\n\nexport function isValidMediaCall(\n jsxPath: NodePath<t.JSXElement>,\n init: t.Expression,\n sourcePath: string\n) {\n if (!t.isCallExpression(init)) return false\n if (!t.isIdentifier(init.callee)) return false\n // TODO could support renaming useMedia by looking up import first\n if (init.callee.name !== 'useMedia') return false\n const bindings = jsxPath.scope.getAllBindings()\n const mediaBinding = bindings['useMedia']\n if (!mediaBinding) return false\n const useMediaImport = mediaBinding.path.parent\n if (!t.isImportDeclaration(useMediaImport)) return false\n if (useMediaImport.source.value !== 'tamagui') {\n if (!isInsideTamagui(sourcePath)) {\n return false\n }\n }\n return true\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,QAAmB;AAEnB,uBAAqD;AAGrD,uBAA0B;AAE1B,4BAA2C;AAEpC,2BACL,SACA,SACA,eACA,YACA,aAAa,GACb,mBAAmB,OACnB;AACA,QAAM,KAAK,qBAAqB,SAAS,SAAS;AAClD,MAAI,CAAC,IAAI;AACP,WAAO;AAAA;AAET,QAAM,EAAE,QAAQ;AAChB,QAAM,KAAK,cAAc,MAAM;AAC/B,MAAI,CAAC,IAAI;AACP,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7B,MAAI,EAAE,aAAa,OAAO;AACxB,UAAM,MAAM,KAAK;AACjB,UAAM,OAAO,oBAAQ,MAAM,WAAW,KAAK,UAA9B,mBAAqC,SAArC,mBAA2C;AACxD,QAAI,CAAC,EAAE,qBAAqB;AAAO,aAAO;AAC1C,QAAI,CAAC,KAAK,QAAQ,CAAC,iBAAiB,SAAS,KAAK,MAAM;AAAa,aAAO;AAC5E,WAAO,EAAE,KAAK,aAAa;AAAA;AAE7B,SAAO;AAAA;AA9BA;AAiCF,0BACL,SACA,MACA,YACA;AACA,MAAI,CAAC,EAAE,iBAAiB;AAAO,WAAO;AACtC,MAAI,CAAC,EAAE,aAAa,KAAK;AAAS,WAAO;AAEzC,MAAI,KAAK,OAAO,SAAS;AAAY,WAAO;AAC5C,QAAM,WAAW,QAAQ,MAAM;AAC/B,QAAM,eAAe,SAAS;AAC9B,MAAI,CAAC;AAAc,WAAO;AAC1B,QAAM,iBAAiB,aAAa,KAAK;AACzC,MAAI,CAAC,EAAE,oBAAoB;AAAiB,WAAO;AACnD,MAAI,eAAe,OAAO,UAAU,WAAW;AAC7C,QAAI,CAAC,2CAAgB,aAAa;AAChC,aAAO;AAAA;AAAA;AAGX,SAAO;AAAA;AAnBO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -62,6 +62,7 @@ var import_buildClassName = require("./buildClassName");
|
|
|
62
62
|
var import_ensureImportingConcat = require("./ensureImportingConcat");
|
|
63
63
|
var import_extractHelpers = require("./extractHelpers");
|
|
64
64
|
var import_extractMediaStyle = require("./extractMediaStyle");
|
|
65
|
+
var import_getPrefixLogs = require("./getPrefixLogs");
|
|
65
66
|
var import_hoistClassNames = require("./hoistClassNames");
|
|
66
67
|
var import_logLines = require("./logLines");
|
|
67
68
|
const mergeStyleGroups = {
|
|
@@ -115,6 +116,7 @@ function extractToClassNames({
|
|
|
115
116
|
lineNumbers,
|
|
116
117
|
programPath
|
|
117
118
|
}) => {
|
|
119
|
+
var _a;
|
|
118
120
|
let finalClassNames = [];
|
|
119
121
|
let finalAttrs = [];
|
|
120
122
|
let finalStyles = [];
|
|
@@ -184,30 +186,38 @@ function extractToClassNames({
|
|
|
184
186
|
break;
|
|
185
187
|
case "ternary":
|
|
186
188
|
const mediaExtraction = (0, import_extractMediaStyle.extractMediaStyle)(attr.value, jsxPath, extractor.getTamagui(), sourcePath, lastMediaImportance, shouldPrintDebug);
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
+
if (shouldPrintDebug) {
|
|
190
|
+
console.log("ternary (mediaStyles)", ((_a = mediaExtraction == null ? void 0 : mediaExtraction.ternaryWithoutMedia) == null ? void 0 : _a.inlineMediaQuery) ?? "", mediaExtraction == null ? void 0 : mediaExtraction.mediaStyles.map((x) => x.identifier).join("."));
|
|
191
|
+
}
|
|
192
|
+
if (!mediaExtraction) {
|
|
193
|
+
addTernaryStyle(attr.value, addStyles(attr.value.consequent), addStyles(attr.value.alternate));
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
lastMediaImportance++;
|
|
197
|
+
if (mediaExtraction.mediaStyles) {
|
|
189
198
|
finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles];
|
|
199
|
+
}
|
|
200
|
+
if (mediaExtraction.ternaryWithoutMedia) {
|
|
201
|
+
addTernaryStyle(mediaExtraction.ternaryWithoutMedia, mediaExtraction.mediaStyles, []);
|
|
202
|
+
} else {
|
|
190
203
|
finalClassNames = [
|
|
191
204
|
...finalClassNames,
|
|
192
205
|
...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier))
|
|
193
206
|
];
|
|
194
|
-
if (!mediaExtraction.ternaryWithoutMedia) {
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
const ternary = (mediaExtraction == null ? void 0 : mediaExtraction.ternaryWithoutMedia) || attr.value;
|
|
199
|
-
const consInfo = addStyles(ternary.consequent);
|
|
200
|
-
const altInfo = addStyles(ternary.alternate);
|
|
201
|
-
const cCN = consInfo.map((x) => x.identifier).join(" ");
|
|
202
|
-
const aCN = altInfo.map((x) => x.identifier).join(" ");
|
|
203
|
-
if (consInfo.length && altInfo.length) {
|
|
204
|
-
finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN)));
|
|
205
|
-
} else {
|
|
206
|
-
finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(" " + cCN), t.stringLiteral(" " + aCN)));
|
|
207
207
|
}
|
|
208
208
|
break;
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
|
+
function addTernaryStyle(ternary, a, b) {
|
|
212
|
+
const cCN = a.map((x) => x.identifier).join(" ");
|
|
213
|
+
const aCN = b.map((x) => x.identifier).join(" ");
|
|
214
|
+
if (a.length && b.length) {
|
|
215
|
+
finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN)));
|
|
216
|
+
} else {
|
|
217
|
+
finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(" " + cCN), t.stringLiteral(" " + aCN)));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
__name(addTernaryStyle, "addTernaryStyle");
|
|
211
221
|
node.attributes = finalAttrs;
|
|
212
222
|
if (finalClassNames.length) {
|
|
213
223
|
const names = (0, import_buildClassName.buildClassName)(finalClassNames);
|
|
@@ -274,10 +284,10 @@ function extractToClassNames({
|
|
|
274
284
|
if (shouldLogTiming) {
|
|
275
285
|
const memUsed = mem ? Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10 : 0;
|
|
276
286
|
const timing = `${Date.now() - start}`.padStart(3);
|
|
277
|
-
const path2 = (0, import_path.basename)(sourcePath).padStart(
|
|
287
|
+
const path2 = (0, import_path.basename)(sourcePath).padStart(30);
|
|
278
288
|
const numOptimized = `${res.optimized}`.padStart(4);
|
|
279
289
|
const memory = memUsed > 10 ? `used ${memUsed}MB` : "";
|
|
280
|
-
console.log(
|
|
290
|
+
console.log(`${(0, import_getPrefixLogs.getPrefixLogs)(options)} ${path2} ${timing}ms \u05C1\xB7 ${numOptimized} optimized \xB7 ${res.flattened} flattened ${memory}`);
|
|
281
291
|
}
|
|
282
292
|
return {
|
|
283
293
|
ast,
|
|
@@ -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 { CONCAT_CLASSNAME_IMPORT } from '../constants'\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'\nimport { logLines } from './logLines'\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 = options.logTimings ?? true\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 hasFlattened = false\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => {\n hasFlattened = true\n return tag\n },\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 // 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)\\n', logLines(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 if (!hasFlattened) {\n // not flat\n } else {\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\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 && !res.optimized && !res.flattened)) {\n if (shouldPrintDebug) {\n console.log('no res or none modified', res)\n }\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) {\n const memUsed = mem\n ? Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10\n : 0\n const timing = `${Date.now() - start}`.padStart(3)\n const path = basename(sourcePath).padStart(40)\n const numOptimized = `${res.optimized}`.padStart(4)\n const memory = memUsed > 10 ? `used ${memUsed}MB` : ''\n console.log(\n ` \uD83E\uDD5A ${path} ${timing}ms \u05C1\u00B7 ${numOptimized} optimized \u00B7 ${res.flattened} flattened ${memory}`\n )\n }\n\n return {\n ast,\n styles,\n js: result.code,\n map: result.map,\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,WAAsB;AACtB,kBAAyB;AACzB,WAAsB;AAEtB,uBAAqB;AACrB,QAAmB;AACnB,uBAAgC;AAChC,qBAAgC;AAChC,uBAAsB;AACtB,0BAAoC;AAGpC,uBAAwC;AAExC,wBAA2B;AAC3B,4BAA+B;AAE/B,mCAAsC;AACtC,4BAA+B;AAC/B,+BAAkC;AAClC,6BAAgC;AAChC,sBAAyB;AAEzB,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,gCACE,OAAO,eAAe,YAAY,KAAK,WAAW,aAClD;AAGF,QAAM,kBAAkB,QAAQ,cAAc;AAC9C,QAAM,QAAQ,KAAK;AACnB,QAAM,MAAM,kBAAkB,QAAQ,gBAAgB;AAGtD,MAAI;AAEJ,MAAI;AAEF,UAAM,kCAAW;AAAA,WACV,KAAP;AACA,YAAQ,MAAM,sBAAsB;AACpC,UAAM;AAAA;AAGR,QAAM,SAAS,oBAAI;AACnB,QAAM,iBAAkD;AAExD,MAAI,eAAe;AAEnB,QAAM,MAAM,UAAU,MAAM,KAAK;AAAA,IAC/B;AAAA,IACA;AAAA,KACG,UAH4B;AAAA,IAI/B,kBAAkB,CAAC,EAAE,UAAU;AAC7B,qBAAe;AACf,aAAO;AAAA;AAAA,IAET,cAAc,CAAC;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,UACI;
|
|
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 { CONCAT_CLASSNAME_IMPORT } from '../constants'\nimport { ClassNameObject, StyleObject, TamaguiOptions, Ternary } 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 { getPrefixLogs } from './getPrefixLogs'\nimport { hoistClassNames } from './hoistClassNames'\nimport { logLines } from './logLines'\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 = options.logTimings ?? true\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 hasFlattened = false\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => {\n hasFlattened = true\n return tag\n },\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): StyleObject[] => {\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 // 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)\\n', logLines(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 (shouldPrintDebug) {\n // prettier-ignore\n console.log('ternary (mediaStyles)', mediaExtraction?.ternaryWithoutMedia?.inlineMediaQuery ?? '', mediaExtraction?.mediaStyles.map((x) => x.identifier).join('.'))\n }\n if (!mediaExtraction) {\n addTernaryStyle(\n attr.value,\n addStyles(attr.value.consequent),\n addStyles(attr.value.alternate)\n )\n continue\n }\n lastMediaImportance++\n if (mediaExtraction.mediaStyles) {\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n }\n if (mediaExtraction.ternaryWithoutMedia) {\n addTernaryStyle(mediaExtraction.ternaryWithoutMedia, mediaExtraction.mediaStyles, [])\n } else {\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n }\n break\n }\n }\n\n function addTernaryStyle(ternary: Ternary, a: any, b: any) {\n const cCN = a.map((x) => x.identifier).join(' ')\n const aCN = b.map((x) => x.identifier).join(' ')\n if (a.length && b.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 }\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 if (!hasFlattened) {\n // not flat\n } else {\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\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 && !res.optimized && !res.flattened)) {\n if (shouldPrintDebug) {\n console.log('no res or none modified', res)\n }\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) {\n const memUsed = mem\n ? Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10\n : 0\n const timing = `${Date.now() - start}`.padStart(3)\n const path = basename(sourcePath).padStart(30)\n const numOptimized = `${res.optimized}`.padStart(4)\n const memory = memUsed > 10 ? `used ${memUsed}MB` : ''\n console.log(\n `${getPrefixLogs(options)} ${path} ${timing}ms \u05C1\u00B7 ${numOptimized} optimized \u00B7 ${\n res.flattened\n } flattened ${memory}`\n )\n }\n\n return {\n ast,\n styles,\n js: result.code,\n map: result.map,\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,WAAsB;AACtB,kBAAyB;AACzB,WAAsB;AAEtB,uBAAqB;AACrB,QAAmB;AACnB,uBAAgC;AAChC,qBAAgC;AAChC,uBAAsB;AACtB,0BAAoC;AAGpC,uBAAwC;AAExC,wBAA2B;AAC3B,4BAA+B;AAE/B,mCAAsC;AACtC,4BAA+B;AAC/B,+BAAkC;AAClC,2BAA8B;AAC9B,6BAAgC;AAChC,sBAAyB;AAEzB,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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N,wCACA,OAAO,KACJ,MAAM,MACN,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,OAC5B,KAAK;AAEV,YAAQ,IAAI,0CAA0C;AAAA;AAGxD,MAAI,iBAAiB;AACnB,UAAM,UAAU,MACZ,KAAK,MAAQ,SAAQ,cAAc,WAAW,IAAI,YAAY,OAAO,OAAQ,MAAM,KACnF;AACJ,UAAM,SAAS,GAAG,KAAK,QAAQ,QAAQ,SAAS;AAChD,UAAM,QAAO,0BAAS,YAAY,SAAS;AAC3C,UAAM,eAAe,GAAG,IAAI,YAAY,SAAS;AACjD,UAAM,SAAS,UAAU,KAAK,QAAQ,cAAc;AACpD,YAAQ,IACN,GAAG,wCAAc,YAAY,SAAQ,uBAAe,+BAClD,IAAI,uBACQ;AAAA;AAIlB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA;AAAA;AAjUA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
12
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(module2))
|
|
14
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
15
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return target;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
20
|
+
return (module2, temp) => {
|
|
21
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
22
|
+
};
|
|
23
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
24
|
+
var getPrefixLogs_exports = {};
|
|
25
|
+
__export(getPrefixLogs_exports, {
|
|
26
|
+
getPrefixLogs: () => getPrefixLogs
|
|
27
|
+
});
|
|
28
|
+
function getPrefixLogs(options) {
|
|
29
|
+
const { TAMAGUI_TARGET } = process.env;
|
|
30
|
+
return (options == null ? void 0 : options.prefixLogs) ?? `[${TAMAGUI_TARGET}] \xBB `;
|
|
31
|
+
}
|
|
32
|
+
__name(getPrefixLogs, "getPrefixLogs");
|
|
33
|
+
module.exports = __toCommonJS(getPrefixLogs_exports);
|
|
34
|
+
//# sourceMappingURL=getPrefixLogs.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/getPrefixLogs.ts"],
|
|
4
|
+
"sourcesContent": ["import { TamaguiOptions } from '../types'\n\nexport function getPrefixLogs(options?: TamaguiOptions) {\n const { TAMAGUI_TARGET } = process.env\n return options?.prefixLogs ?? `[${TAMAGUI_TARGET}] \u00BB `\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAEO,uBAAuB,SAA0B;AACtD,QAAM,EAAE,mBAAmB,QAAQ;AACnC,SAAO,oCAAS,eAAc,IAAI;AAAA;AAFpB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
7
24
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
25
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
26
|
var __export = (target, all) => {
|
|
@@ -28,6 +45,7 @@ var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
|
28
45
|
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
29
46
|
var literalToAst_exports = {};
|
|
30
47
|
__export(literalToAst_exports, {
|
|
48
|
+
astToLiteral: () => astToLiteral,
|
|
31
49
|
literalToAst: () => literalToAst
|
|
32
50
|
});
|
|
33
51
|
var t = __toESM(require("@babel/types"));
|
|
@@ -58,5 +76,46 @@ function literalToAst(literal) {
|
|
|
58
76
|
}
|
|
59
77
|
}
|
|
60
78
|
__name(literalToAst, "literalToAst");
|
|
79
|
+
const easyPeasies = ["BooleanLiteral", "StringLiteral", "NumericLiteral"];
|
|
80
|
+
function astToLiteral(node) {
|
|
81
|
+
if (!node) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (easyPeasies.includes(node.type)) {
|
|
85
|
+
return node.value;
|
|
86
|
+
}
|
|
87
|
+
if (node.name === "undefined" && !node.value) {
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
if (t.isNullLiteral(node)) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
if (t.isObjectExpression(node)) {
|
|
94
|
+
return computeProps(node.properties);
|
|
95
|
+
}
|
|
96
|
+
if (t.isArrayExpression(node)) {
|
|
97
|
+
return node.elements.reduce((acc, element) => [
|
|
98
|
+
...acc,
|
|
99
|
+
...(element == null ? void 0 : element.type) === "SpreadElement" ? astToLiteral(element.argument) : [astToLiteral(element)]
|
|
100
|
+
], []);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
__name(astToLiteral, "astToLiteral");
|
|
104
|
+
function computeProps(props) {
|
|
105
|
+
return props.reduce((acc, prop) => {
|
|
106
|
+
if (prop.type === "SpreadElement") {
|
|
107
|
+
return __spreadValues(__spreadValues({}, acc), astToLiteral(prop.argument));
|
|
108
|
+
} else if (prop.type !== "ObjectMethod") {
|
|
109
|
+
const val = astToLiteral(prop.value);
|
|
110
|
+
if (val !== void 0) {
|
|
111
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
112
|
+
[prop.key.name]: val
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return acc;
|
|
117
|
+
}, {});
|
|
118
|
+
}
|
|
119
|
+
__name(computeProps, "computeProps");
|
|
61
120
|
module.exports = __toCommonJS(literalToAst_exports);
|
|
62
121
|
//# sourceMappingURL=literalToAst.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/literalToAst.ts"],
|
|
4
|
-
"sourcesContent": ["import * as t from '@babel/types'\n\nexport function literalToAst(literal: any): t.Expression {\n if (literal === null) {\n return t.nullLiteral()\n }\n switch (typeof literal) {\n case 'function':\n throw new Error('Unsupported')\n case 'number':\n return t.numericLiteral(literal)\n case 'string':\n return t.stringLiteral(literal)\n case 'boolean':\n return t.booleanLiteral(literal)\n case 'undefined':\n return t.unaryExpression('void', t.numericLiteral(0), true)\n default:\n if (Array.isArray(literal)) {\n return t.arrayExpression(literal.map(literalToAst))\n }\n return t.objectExpression(\n Object.keys(literal)\n .filter((k) => {\n return typeof literal[k] !== 'undefined'\n })\n .map((k) => {\n return t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]))\n })\n )\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import * as t from '@babel/types'\n\nexport function literalToAst(literal: any): t.Expression {\n if (literal === null) {\n return t.nullLiteral()\n }\n switch (typeof literal) {\n case 'function':\n throw new Error('Unsupported')\n case 'number':\n return t.numericLiteral(literal)\n case 'string':\n return t.stringLiteral(literal)\n case 'boolean':\n return t.booleanLiteral(literal)\n case 'undefined':\n return t.unaryExpression('void', t.numericLiteral(0), true)\n default:\n if (Array.isArray(literal)) {\n return t.arrayExpression(literal.map(literalToAst))\n }\n return t.objectExpression(\n Object.keys(literal)\n .filter((k) => {\n return typeof literal[k] !== 'undefined'\n })\n .map((k) => {\n return t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]))\n })\n )\n }\n}\n\nconst easyPeasies = ['BooleanLiteral', 'StringLiteral', 'NumericLiteral']\n\nexport function astToLiteral(node: any) {\n if (!node) {\n return\n }\n if (easyPeasies.includes(node.type)) {\n return node.value\n }\n if (node.name === 'undefined' && !node.value) {\n return undefined\n }\n if (t.isNullLiteral(node)) {\n return null\n }\n if (t.isObjectExpression(node)) {\n return computeProps(node.properties)\n }\n if (t.isArrayExpression(node)) {\n return node.elements.reduce(\n // @ts-ignore\n (acc, element) => [\n ...acc,\n ...(element?.type === 'SpreadElement'\n ? astToLiteral(element.argument)\n : [astToLiteral(element)]),\n ],\n []\n )\n }\n}\n\nfunction computeProps(props) {\n return props.reduce((acc, prop) => {\n if (prop.type === 'SpreadElement') {\n return {\n ...acc,\n ...astToLiteral(prop.argument),\n }\n } else if (prop.type !== 'ObjectMethod') {\n const val = astToLiteral(prop.value)\n if (val !== undefined) {\n return {\n ...acc,\n [prop.key.name]: val,\n }\n }\n }\n return acc\n }, {})\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAAmB;AAEZ,sBAAsB,SAA4B;AACvD,MAAI,YAAY,MAAM;AACpB,WAAO,EAAE;AAAA;AAEX,UAAQ,OAAO;AAAA,SACR;AACH,YAAM,IAAI,MAAM;AAAA,SACb;AACH,aAAO,EAAE,eAAe;AAAA,SACrB;AACH,aAAO,EAAE,cAAc;AAAA,SACpB;AACH,aAAO,EAAE,eAAe;AAAA,SACrB;AACH,aAAO,EAAE,gBAAgB,QAAQ,EAAE,eAAe,IAAI;AAAA;AAEtD,UAAI,MAAM,QAAQ,UAAU;AAC1B,eAAO,EAAE,gBAAgB,QAAQ,IAAI;AAAA;AAEvC,aAAO,EAAE,iBACP,OAAO,KAAK,SACT,OAAO,CAAC,MAAM;AACb,eAAO,OAAO,QAAQ,OAAO;AAAA,SAE9B,IAAI,CAAC,MAAM;AACV,eAAO,EAAE,eAAe,EAAE,cAAc,IAAI,aAAa,QAAQ;AAAA;AAAA;AAAA;AAzB7D;AA+BhB,MAAM,cAAc,CAAC,kBAAkB,iBAAiB;AAEjD,sBAAsB,MAAW;AACtC,MAAI,CAAC,MAAM;AACT;AAAA;AAEF,MAAI,YAAY,SAAS,KAAK,OAAO;AACnC,WAAO,KAAK;AAAA;AAEd,MAAI,KAAK,SAAS,eAAe,CAAC,KAAK,OAAO;AAC5C,WAAO;AAAA;AAET,MAAI,EAAE,cAAc,OAAO;AACzB,WAAO;AAAA;AAET,MAAI,EAAE,mBAAmB,OAAO;AAC9B,WAAO,aAAa,KAAK;AAAA;AAE3B,MAAI,EAAE,kBAAkB,OAAO;AAC7B,WAAO,KAAK,SAAS,OAEnB,CAAC,KAAK,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,GAAI,oCAAS,UAAS,kBAClB,aAAa,QAAQ,YACrB,CAAC,aAAa;AAAA,OAEpB;AAAA;AAAA;AAzBU;AA8BhB,sBAAsB,OAAO;AAC3B,SAAO,MAAM,OAAO,CAAC,KAAK,SAAS;AACjC,QAAI,KAAK,SAAS,iBAAiB;AACjC,aAAO,kCACF,MACA,aAAa,KAAK;AAAA,eAEd,KAAK,SAAS,gBAAgB;AACvC,YAAM,MAAM,aAAa,KAAK;AAC9B,UAAI,QAAQ,QAAW;AACrB,eAAO,iCACF,MADE;AAAA,WAEJ,KAAK,IAAI,OAAO;AAAA;AAAA;AAAA;AAIvB,WAAO;AAAA,KACN;AAAA;AAjBI;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -46,7 +46,7 @@ function patchReactNativeWeb() {
|
|
|
46
46
|
return res;
|
|
47
47
|
})();
|
|
48
48
|
if (!isEqual) {
|
|
49
|
-
console.log("\
|
|
49
|
+
console.log("\xBB Tamagui patching react-native-web to share atomic styling primitives");
|
|
50
50
|
console.log(" > adding", modulePath);
|
|
51
51
|
console.log(" > adding", cjsPath);
|
|
52
52
|
fs.writeFileSync(modulePath, moduleExports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/patchReactNativeWeb.ts"],
|
|
4
|
-
"sourcesContent": ["import * as fs from 'fs'\nimport path from 'path'\n\n// were patching react-native-web so we can use some internal methods\n// we do it this way because we need to rely on webpack or bundler config to determine cjs vs esm\n// so we can't just require it all directly\n// would be nice in the future to be able to eject from react-native-web entirely optionally\n\n// keep it sync\nexport function patchReactNativeWeb() {\n const rootDir = require.resolve('react-native-web').replace(/\\/dist.*/, '')\n const modulePath = path.join(rootDir, 'dist', 'tamagui-exports.js')\n const cjsPath = path.join(rootDir, 'dist', 'cjs', 'tamagui-exports.js')\n\n const isEqual = (() => {\n let res = false\n try {\n res =\n fs.readFileSync(modulePath, 'utf-8') === moduleExports &&\n fs.readFileSync(cjsPath, 'utf-8') == cjsExports\n } catch {\n res = false\n }\n return res\n })()\n\n if (!isEqual) {\n console.log('\
|
|
4
|
+
"sourcesContent": ["import * as fs from 'fs'\nimport path from 'path'\n\n// were patching react-native-web so we can use some internal methods\n// we do it this way because we need to rely on webpack or bundler config to determine cjs vs esm\n// so we can't just require it all directly\n// would be nice in the future to be able to eject from react-native-web entirely optionally\n\n// keep it sync\nexport function patchReactNativeWeb() {\n const rootDir = require.resolve('react-native-web').replace(/\\/dist.*/, '')\n const modulePath = path.join(rootDir, 'dist', 'tamagui-exports.js')\n const cjsPath = path.join(rootDir, 'dist', 'cjs', 'tamagui-exports.js')\n\n const isEqual = (() => {\n let res = false\n try {\n res =\n fs.readFileSync(modulePath, 'utf-8') === moduleExports &&\n fs.readFileSync(cjsPath, 'utf-8') == cjsExports\n } catch {\n res = false\n }\n return res\n })()\n\n if (!isEqual) {\n console.log('\u00BB Tamagui patching react-native-web to share atomic styling primitives')\n console.log(' > adding', modulePath)\n console.log(' > adding', cjsPath)\n fs.writeFileSync(modulePath, moduleExports)\n fs.writeFileSync(cjsPath, cjsExports)\n }\n\n // patch to allow className prop\n const classNamePatch = `if (props.dataSet && props.dataSet['__className']) { domProps.className = className ? className + ' ' + props.dataSet['__className'] : props.dataSet['__className']; delete props.dataSet['__className'] }`\n const domPropsPath = ['modules', 'createDOMProps', 'index.js']\n const domPropsModulePath = path.join(rootDir, 'dist', ...domPropsPath)\n const domPropsCjsPath = path.join(rootDir, 'dist', 'cjs', ...domPropsPath)\n const patchClassName = (file: string) => {\n const contents = fs.readFileSync(file, 'utf-8')\n if (!contents.includes(classNamePatch)) {\n const needle = `domProps.className = className`\n const patchLocation = contents.indexOf(needle) + needle.length + 5\n // its far down the file\n if (patchLocation < 100) {\n console.warn(\n `\u26A0\uFE0F Couldn't apply className patch! Maybe using incompatible react-native-web version.`\n )\n } else {\n const before = contents.slice(0, patchLocation)\n const after = contents.slice(patchLocation)\n const patched = before + '\\n' + classNamePatch + '\\n' + after\n console.log(' > adding className support to react-native-web', file)\n fs.writeFileSync(file, patched)\n }\n }\n }\n patchClassName(domPropsModulePath)\n patchClassName(domPropsCjsPath)\n\n // if (props.className) {\n // domProps.className = className ? className + ' ' + props.className : props.className\n // }\n\n // if entry files not patched, patch them:\n const moduleEntry = path.join(rootDir, 'dist', 'index.js')\n const moduleEntrySrc = fs.readFileSync(moduleEntry, 'utf-8')\n if (!moduleEntrySrc.includes('// tamagui-patch-v4')) {\n fs.writeFileSync(\n moduleEntry,\n `${removePatch(moduleEntrySrc)}\n\n// tamagui-patch-v4\nimport * as TExports from './tamagui-exports'\nexport const TamaguiExports = TExports\n// tamagui-patch-end\n`\n )\n }\n const cjsEntry = path.join(rootDir, 'dist', 'cjs', 'index.js')\n const cjsEntrySrc = fs.readFileSync(cjsEntry, 'utf-8')\n if (!cjsEntrySrc.includes('// tamagui-patch-v4')) {\n fs.writeFileSync(\n cjsEntry,\n `${removePatch(cjsEntrySrc)}\n\n// tamagui-patch-v4\nexports.TamaguiExports = _interopRequireDefault(require(\"./tamagui-exports\"));\n// tamagui-patch-end\n`\n )\n }\n}\n\nfunction removePatch(source: string) {\n return source.replace(/\\/\\/ tamagui-patch([.\\s\\S]*)/g, '')\n}\n\n// view exports/View.ts\nconst forwardedPropsObj = `{\n ...fwdProps.defaultProps,\n ...fwdProps.accessibilityProps,\n ...fwdProps.clickProps,\n ...fwdProps.focusProps,\n ...fwdProps.keyboardProps,\n ...fwdProps.mouseProps,\n ...fwdProps.touchProps,\n ...fwdProps.styleProps,\n href: true,\n lang: true,\n onScroll: true,\n onWheel: true,\n pointerEvents: true\n}\n`\n\nconst moduleExports = `\nexport { atomic } from './exports/StyleSheet/compile'\nexport { default as createCompileableStyle } from './exports/StyleSheet/createCompileableStyle'\nexport { default as createReactDOMStyle } from './exports/StyleSheet/createReactDOMStyle'\nexport { default as i18Style } from './exports/StyleSheet/i18nStyle'\nexport { default as createDOMProps } from './modules/createDOMProps'\nexport { default as AccessibilityUtil } from './modules/AccessibilityUtil'\nexport { default as createElement } from './exports/createElement'\nexport { default as css } from './exports/StyleSheet/css'\nexport { default as TextAncestorContext } from './exports/Text/TextAncestorContext'\nexport { default as pick } from './modules/pick'\nexport { default as useElementLayout } from './modules/useElementLayout'\nexport { default as useMergeRefs } from './modules/useMergeRefs'\nexport { default as usePlatformMethods } from './modules/usePlatformMethods'\nexport { default as useResponderEvents } from './modules/useResponderEvents'\nimport * as fwdProps from './modules/forwardedProps'\nexport const forwardedProps = ${forwardedPropsObj}\n`\n\nconst cjsExports = `\nexports.atomic = require('./exports/StyleSheet/compile').atomic\nexports.createCompileableStyle = require('./exports/StyleSheet/createCompileableStyle')\nexports.createReactDOMStyle = require('./exports/StyleSheet/createReactDOMStyle')\nexports.i18Style = require('./exports/StyleSheet/i18nStyle')\nexports.createDOMProps = require('./modules/createDOMProps')\nexports.AccessibilityUtil = require('./modules/AccessibilityUtil')\nexports.createElement = require('./exports/createElement')\nexports.css = require('./exports/StyleSheet/css')\nexports.TextAncestorContext = require('./exports/Text/TextAncestorContext')\nexports.pick = require('./modules/pick')\nexports.useElementLayout = require('./modules/useElementLayout')\nexports.useMergeRefs = require('./modules/useMergeRefs')\nexports.usePlatformMethods = require('./modules/usePlatformMethods')\nexports.useResponderEvents = require('./modules/useResponderEvents')\nconst fwdProps = require('./modules/forwardedProps')\nexports.forwardedProps = ${forwardedPropsObj}\n`\n"],
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AK,SAAS,QAAQ;AAC/C,QAAM,iBAAiB,GAAG,aAAa,aAAa;AACpD,MAAI,CAAC,eAAe,SAAS,wBAAwB;AACnD,OAAG,cACD,aACA,GAAG,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASnB,QAAM,WAAW,oBAAK,KAAK,SAAS,QAAQ,OAAO;AACnD,QAAM,cAAc,GAAG,aAAa,UAAU;AAC9C,MAAI,CAAC,YAAY,SAAS,wBAAwB;AAChD,OAAG,cACD,UACA,GAAG,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA5EL;AAsFhB,qBAAqB,QAAgB;AACnC,SAAO,OAAO,QAAQ,iCAAiC;AAAA;AADhD;AAKT,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiB1B,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAgBU;AAAA;AAGhC,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAgBQ;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nexport type ClassNameObject = t.StringLiteral | t.Expression\n\nexport interface CacheObject {\n [key: string]: any\n}\n\nexport interface TamaguiOptions {\n // module paths you want to compile with tamagui (for example ['tamagui'])\n components: string[]\n // your tamagui.config.ts\n config?: string\n evaluateVars?: boolean\n importsWhitelist?: string[]\n disableExtraction?: boolean\n disableDebugAttr?: boolean\n disableExtractInlineMedia?: boolean\n disableExtractVariables?: boolean\n exclude?: RegExp\n logTimings?: boolean\n\n // probably non user options\n cssPath?: string\n cssData?: any\n deoptProps?: Set<string>\n excludeProps?: string[]\n}\n\nexport type ExtractedAttrAttr = {\n type: 'attr'\n value: t.JSXAttribute | t.JSXSpreadAttribute\n}\n\nexport type ExtractedAttrStyle = {\n type: 'style'\n value: Object\n attr?: t.JSXAttribute | t.JSXSpreadAttribute\n name?: string\n}\n\nexport type ExtractedAttr =\n | ExtractedAttrAttr\n | { type: 'ternary'; value: Ternary }\n | ExtractedAttrStyle\n\nexport type ExtractTagProps = {\n attrs: ExtractedAttr[]\n node: t.JSXOpeningElement\n attemptEval: (exprNode: t.Node, evalFn?: ((node: t.Node) => any) | undefined) => any\n jsxPath: NodePath<t.JSXElement>\n programPath: NodePath<t.Program>\n originalNodeName: string\n lineNumbers: string\n filePath: string\n isFlattened: boolean\n}\n\nexport type ExtractorParseProps = TamaguiOptions & {\n sourcePath?: string\n shouldPrintDebug?: boolean\n onExtractTag: (props: ExtractTagProps) => void\n getFlattenedNode: (props: { isTextView: boolean; tag: string }) => string\n}\n\nexport interface Ternary {\n test: t.Expression\n // shorthand props that don't use hooks\n inlineMediaQuery?: string\n remove: Function\n consequent: Object | null\n alternate: Object | null\n}\n\nexport type StyleObject = {\n property: string\n value: string\n className: string\n identifier: string\n rules: string[]\n}\n\nexport type ClassNameToStyleObj = {\n [key: string]: StyleObject\n}\n\nexport interface PluginContext {\n write: (path: string, rules: { [key: string]: string }) => any\n}\n"],
|
|
4
|
+
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nexport type ClassNameObject = t.StringLiteral | t.Expression\n\nexport interface CacheObject {\n [key: string]: any\n}\n\nexport interface TamaguiOptions {\n // module paths you want to compile with tamagui (for example ['tamagui'])\n components: string[]\n // your tamagui.config.ts\n config?: string\n evaluateVars?: boolean\n importsWhitelist?: string[]\n disableExtraction?: boolean\n disableDebugAttr?: boolean\n disableExtractInlineMedia?: boolean\n disableExtractVariables?: boolean\n excludeReactNativeWebExports?: string[]\n exclude?: RegExp\n logTimings?: boolean\n prefixLogs?: string\n\n // probably non user options\n cssPath?: string\n cssData?: any\n deoptProps?: Set<string>\n excludeProps?: string[]\n}\n\nexport type ExtractedAttrAttr = {\n type: 'attr'\n value: t.JSXAttribute | t.JSXSpreadAttribute\n}\n\nexport type ExtractedAttrStyle = {\n type: 'style'\n value: Object\n attr?: t.JSXAttribute | t.JSXSpreadAttribute\n name?: string\n}\n\nexport type ExtractedAttr =\n | ExtractedAttrAttr\n | { type: 'ternary'; value: Ternary }\n | ExtractedAttrStyle\n\nexport type ExtractTagProps = {\n attrs: ExtractedAttr[]\n node: t.JSXOpeningElement\n attemptEval: (exprNode: t.Node, evalFn?: ((node: t.Node) => any) | undefined) => any\n jsxPath: NodePath<t.JSXElement>\n programPath: NodePath<t.Program>\n originalNodeName: string\n lineNumbers: string\n filePath: string\n isFlattened: boolean\n}\n\nexport type ExtractorParseProps = TamaguiOptions & {\n sourcePath?: string\n shouldPrintDebug?: boolean\n onExtractTag: (props: ExtractTagProps) => void\n getFlattenedNode: (props: { isTextView: boolean; tag: string }) => string\n}\n\nexport interface Ternary {\n test: t.Expression\n // shorthand props that don't use hooks\n inlineMediaQuery?: string\n remove: Function\n consequent: Object | null\n alternate: Object | null\n}\n\nexport type StyleObject = {\n property: string\n value: string\n className: string\n identifier: string\n rules: string[]\n}\n\nexport type ClassNameToStyleObj = {\n [key: string]: StyleObject\n}\n\nexport interface PluginContext {\n write: (path: string, rules: { [key: string]: string }) => any\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -51,6 +51,7 @@ function createExtractor() {
|
|
|
51
51
|
disableExtractInlineMedia,
|
|
52
52
|
disableExtractVariables,
|
|
53
53
|
disableDebugAttr,
|
|
54
|
+
prefixLogs,
|
|
54
55
|
...props
|
|
55
56
|
}) => {
|
|
56
57
|
if (sourcePath === "") {
|
|
@@ -156,7 +157,7 @@ function createExtractor() {
|
|
|
156
157
|
}
|
|
157
158
|
if (disableExtraction) {
|
|
158
159
|
if (!hasLogged) {
|
|
159
|
-
console.log("
|
|
160
|
+
console.log(prefixLogs, "Tamagui disableExtraction set: no CSS or optimizations will be run");
|
|
160
161
|
hasLogged = true;
|
|
161
162
|
}
|
|
162
163
|
return;
|
|
@@ -325,6 +326,29 @@ function createExtractor() {
|
|
|
325
326
|
if (!t.isObjectProperty(property)) {
|
|
326
327
|
throw new Error("expected object property");
|
|
327
328
|
}
|
|
329
|
+
if (t.isIdentifier(property.key)) {
|
|
330
|
+
const key = property.key.name;
|
|
331
|
+
const mediaQueryKey = key.slice(1);
|
|
332
|
+
const isMediaQuery = key[0] === "$" && mediaQueryConfig[mediaQueryKey];
|
|
333
|
+
if (isMediaQuery) {
|
|
334
|
+
if (t.isExpression(property.value)) {
|
|
335
|
+
const ternaries2 = createTernariesFromObjectProperties(t.stringLiteral(mediaQueryKey), property.value, {
|
|
336
|
+
inlineMediaQuery: mediaQueryKey
|
|
337
|
+
});
|
|
338
|
+
if (ternaries2) {
|
|
339
|
+
return ternaries2.map((value) => ({
|
|
340
|
+
...ternaryPartial,
|
|
341
|
+
...value,
|
|
342
|
+
test: t.logicalExpression("&&", value.test, test)
|
|
343
|
+
}));
|
|
344
|
+
} else {
|
|
345
|
+
console.log("\u26A0\uFE0F no ternaries?", property);
|
|
346
|
+
}
|
|
347
|
+
} else {
|
|
348
|
+
console.log("\u26A0\uFE0F not expression", property);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
328
352
|
if (t.isConditionalExpression(property.value)) {
|
|
329
353
|
const [truthy, falsy] = [
|
|
330
354
|
t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
|
|
@@ -388,10 +412,16 @@ function createExtractor() {
|
|
|
388
412
|
}
|
|
389
413
|
}
|
|
390
414
|
if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
|
|
415
|
+
if (shouldPrintDebug) {
|
|
416
|
+
console.log(" ! inlining, spread attr");
|
|
417
|
+
}
|
|
391
418
|
inlinePropCount++;
|
|
392
419
|
return attr;
|
|
393
420
|
}
|
|
394
421
|
const name = attribute.name.name;
|
|
422
|
+
if (name.startsWith("data-")) {
|
|
423
|
+
return attr;
|
|
424
|
+
}
|
|
395
425
|
if (isExcludedProp(name)) {
|
|
396
426
|
return null;
|
|
397
427
|
}
|
|
@@ -452,7 +482,7 @@ function createExtractor() {
|
|
|
452
482
|
if (value) {
|
|
453
483
|
if (value.type === "StringLiteral" && value.value[0] === "$") {
|
|
454
484
|
if (shouldPrintDebug) {
|
|
455
|
-
console.log(`
|
|
485
|
+
console.log(` ! inlining, native disable extract: ${name} =`, value.value);
|
|
456
486
|
}
|
|
457
487
|
inlinePropCount++;
|
|
458
488
|
return attr;
|
|
@@ -470,6 +500,9 @@ function createExtractor() {
|
|
|
470
500
|
}
|
|
471
501
|
for (const key of keys) {
|
|
472
502
|
if (!isStaticAttributeName(key)) {
|
|
503
|
+
if (shouldPrintDebug) {
|
|
504
|
+
console.log(" ! inlining, non-static", key);
|
|
505
|
+
}
|
|
473
506
|
inlinePropCount++;
|
|
474
507
|
}
|
|
475
508
|
}
|
|
@@ -713,12 +746,14 @@ function createExtractor() {
|
|
|
713
746
|
cur.value = { [nonShortKey]: value };
|
|
714
747
|
key = nonShortKey;
|
|
715
748
|
}
|
|
716
|
-
if (!shouldFlatten
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
749
|
+
if (!shouldFlatten) {
|
|
750
|
+
if (stylePropsTransform[key] || !validStyles[key] && !pseudos[key] && !key.startsWith("data-")) {
|
|
751
|
+
acc.push({
|
|
752
|
+
type: "attr",
|
|
753
|
+
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : literalToAst(value)))
|
|
754
|
+
});
|
|
755
|
+
return acc;
|
|
756
|
+
}
|
|
722
757
|
}
|
|
723
758
|
if (disableExtractVariables) {
|
|
724
759
|
if (value[0] === "$") {
|
|
@@ -758,6 +793,8 @@ function createExtractor() {
|
|
|
758
793
|
var _a2;
|
|
759
794
|
if (!props2)
|
|
760
795
|
return;
|
|
796
|
+
if (!Object.keys(props2).length)
|
|
797
|
+
return;
|
|
761
798
|
if (!!excludeProps.size) {
|
|
762
799
|
for (const key in props2) {
|
|
763
800
|
if (isExcludedProp(key))
|
|
@@ -767,9 +804,9 @@ function createExtractor() {
|
|
|
767
804
|
const out = postProcessStyles(props2, staticConfig, defaultTheme);
|
|
768
805
|
const next = (_a2 = out == null ? void 0 : out.style) != null ? _a2 : props2;
|
|
769
806
|
if (shouldPrintDebug) {
|
|
770
|
-
console.log("
|
|
771
|
-
console.log("
|
|
772
|
-
console.log("
|
|
807
|
+
console.log(" -- getStyles (viewProps):\n", logLines(objToStr(out.viewProps)));
|
|
808
|
+
console.log(" -- getStyles (props):\n", logLines(objToStr(props2)));
|
|
809
|
+
console.log(" -- getStyles (next):\n", logLines(objToStr(next)));
|
|
773
810
|
}
|
|
774
811
|
for (const key in next) {
|
|
775
812
|
if (staticConfig.validStyles) {
|
|
@@ -798,12 +835,14 @@ function createExtractor() {
|
|
|
798
835
|
}
|
|
799
836
|
}
|
|
800
837
|
if (shouldPrintDebug) {
|
|
801
|
-
console.log(" completeStaticProps
|
|
802
|
-
console.log(" completeStylesProcessed
|
|
838
|
+
console.log(" -- completeStaticProps:\n", logLines(objToStr(completeStaticProps)));
|
|
839
|
+
console.log(" -- completeStylesProcessed:\n", logLines(objToStr(completeStylesProcessed)));
|
|
803
840
|
}
|
|
804
841
|
let getStyleError = null;
|
|
805
842
|
for (const attr of attrs) {
|
|
806
843
|
try {
|
|
844
|
+
if (shouldPrintDebug)
|
|
845
|
+
console.log(" *", attrStr(attr));
|
|
807
846
|
switch (attr.type) {
|
|
808
847
|
case "ternary":
|
|
809
848
|
const a = getStyles(attr.value.alternate);
|
|
@@ -823,8 +862,6 @@ function createExtractor() {
|
|
|
823
862
|
return [keyIn, (_a2 = completeStylesProcessed[keyIn]) != null ? _a2 : attr.value[keyIn]];
|
|
824
863
|
}
|
|
825
864
|
})();
|
|
826
|
-
if (shouldPrintDebug)
|
|
827
|
-
console.log("style", { keyIn, key, value });
|
|
828
865
|
delete attr.value[keyIn];
|
|
829
866
|
attr.value[key] = value;
|
|
830
867
|
}
|
|
@@ -854,7 +891,7 @@ function createExtractor() {
|
|
|
854
891
|
}
|
|
855
892
|
}
|
|
856
893
|
if (shouldPrintDebug) {
|
|
857
|
-
console.log(
|
|
894
|
+
console.log(` \u274A\u274A inline props (${inlinePropCount}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
|
|
858
895
|
console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
859
896
|
}
|
|
860
897
|
res.optimized++;
|