@tamagui/static 1.0.0-beta.202 → 1.0.0-beta.205

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/extractor/loadTamagui.ts"],
4
- "sourcesContent": ["import { join } from 'path'\n\nimport type { TamaguiComponent, TamaguiInternalConfig } from '@tamagui/core'\nimport { createTamagui } from '@tamagui/core-node'\n\nlet loadedTamagui: any = null\n\nexport function loadTamagui(props: { components: string[]; config: string }): {\n components: Record<string, TamaguiComponent>\n tamaguiConfig: TamaguiInternalConfig\n} {\n if (loadedTamagui) {\n return loadedTamagui\n }\n\n // lets shim require and avoid importing react-native + react-native-web\n // we just need to read the config around them\n process.env.IS_STATIC = 'is_static'\n const proxyWorm = require('@tamagui/proxy-worm')\n const rnw = require('react-native-web')\n const Mod = require('module')\n const og = Mod.prototype.require\n Mod.prototype.require = function (path: string) {\n if (path.endsWith('.css')) {\n return {}\n }\n if (path === '@gorhom/bottom-sheet' || path.startsWith('react-native-reanimated')) {\n return proxyWorm\n }\n if (\n path.startsWith('react-native') &&\n // allow our rnw.tsx imports through\n !path.startsWith('react-native-web/dist/cjs/exports')\n ) {\n return rnw\n }\n try {\n return og.apply(this, arguments)\n } catch (err: any) {\n console.error('Tamagui error loading file:\\n')\n console.log(' ', path, '\\n')\n console.log(err.message)\n console.log(err.stack)\n // avoid infinite loops\n process.exit(1)\n }\n }\n\n // import config\n const configPath = join(process.cwd(), props.config)\n const tamaguiConfigExport = require(configPath)\n const tamaguiConfig = (tamaguiConfigExport['default'] ||\n tamaguiConfigExport) as TamaguiInternalConfig\n\n if (!tamaguiConfig || !tamaguiConfig.parsed) {\n try {\n const confPath = require.resolve(configPath)\n console.log(`Received:`, tamaguiConfigExport)\n throw new Error(`Can't find valid config in ${confPath}`)\n } catch (err) {\n throw err\n }\n }\n\n // import components\n const components = {}\n for (const module of props.components) {\n const exported = require(module)\n Object.assign(components, exported)\n }\n\n // undo shims\n process.env.IS_STATIC = undefined\n Mod.prototype.require = og\n\n // set up core-node\n createTamagui(tamaguiConfig)\n\n loadedTamagui = {\n components,\n tamaguiConfig,\n }\n\n return loadedTamagui\n}\n"],
5
- "mappings": ";;AAAA;AAGA;AAEA,IAAI,gBAAqB;AAElB,qBAAqB,OAG1B;AACA,MAAI,eAAe;AACjB,WAAO;AAAA,EACT;AAIA,UAAQ,IAAI,YAAY;AACxB,QAAM,YAAY,QAAQ,qBAAqB;AAC/C,QAAM,MAAM,QAAQ,kBAAkB;AACtC,QAAM,MAAM,QAAQ,QAAQ;AAC5B,QAAM,KAAK,IAAI,UAAU;AACzB,MAAI,UAAU,UAAU,SAAU,MAAc;AAC9C,QAAI,KAAK,SAAS,MAAM,GAAG;AACzB,aAAO,CAAC;AAAA,IACV;AACA,QAAI,SAAS,0BAA0B,KAAK,WAAW,yBAAyB,GAAG;AACjF,aAAO;AAAA,IACT;AACA,QACE,KAAK,WAAW,cAAc,KAE9B,CAAC,KAAK,WAAW,mCAAmC,GACpD;AACA,aAAO;AAAA,IACT;AACA,QAAI;AACF,aAAO,GAAG,MAAM,MAAM,SAAS;AAAA,IACjC,SAAS,KAAP;AACA,cAAQ,MAAM,+BAA+B;AAC7C,cAAQ,IAAI,OAAO,MAAM,IAAI;AAC7B,cAAQ,IAAI,IAAI,OAAO;AACvB,cAAQ,IAAI,IAAI,KAAK;AAErB,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AAGA,QAAM,aAAa,KAAK,QAAQ,IAAI,GAAG,MAAM,MAAM;AACnD,QAAM,sBAAsB,QAAQ,UAAU;AAC9C,QAAM,gBAAiB,oBAAoB,cACzC;AAEF,MAAI,CAAC,iBAAiB,CAAC,cAAc,QAAQ;AAC3C,QAAI;AACF,YAAM,WAA2B,AAAhB,QAAQ,QAAQ;AACjC,cAAQ,IAAI,aAAa,mBAAmB;AAC5C,YAAM,IAAI,MAAM,8BAA8B,UAAU;AAAA,IAC1D,SAAS,KAAP;AACA,YAAM;AAAA,IACR;AAAA,EACF;AAGA,QAAM,aAAa,CAAC;AACpB,aAAW,UAAU,MAAM,YAAY;AACrC,UAAM,WAAW,QAAQ,MAAM;AAC/B,WAAO,OAAO,YAAY,QAAQ;AAAA,EACpC;AAGA,UAAQ,IAAI,YAAY;AACxB,MAAI,UAAU,UAAU;AAGxB,gBAAc,aAAa;AAE3B,kBAAgB;AAAA,IACd;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;AA7EgB;",
4
+ "sourcesContent": ["import { join } from 'path'\n\nimport type { TamaguiComponent, TamaguiInternalConfig } from '@tamagui/core'\nimport { createTamagui } from '@tamagui/core-node'\n\nlet loadedTamagui: any = null\n\nexport function loadTamagui(props: { components: string[]; config: string }): {\n components: Record<string, TamaguiComponent>\n tamaguiConfig: TamaguiInternalConfig\n} {\n if (loadedTamagui) {\n return loadedTamagui\n }\n\n // lets shim require and avoid importing react-native + react-native-web\n // we just need to read the config around them\n process.env.IS_STATIC = 'is_static'\n const proxyWorm = require('@tamagui/proxy-worm')\n const rnw = require('react-native-web')\n const Mod = require('module')\n const og = Mod.prototype.require\n Mod.prototype.require = function (path: string) {\n if (path.endsWith('.css')) {\n return {}\n }\n if (path === '@gorhom/bottom-sheet' || path.startsWith('react-native-reanimated')) {\n return proxyWorm\n }\n if (\n path.startsWith('react-native') &&\n // allow our rnw.tsx imports through\n !path.startsWith('react-native-web/dist/cjs/exports')\n ) {\n return rnw\n }\n try {\n return og.apply(this, arguments)\n } catch (err: any) {\n console.error('Tamagui error loading file:\\n')\n console.log(' ', path, '\\n')\n console.log(err.message)\n console.log(err.stack)\n // avoid infinite loops\n process.exit(1)\n }\n }\n\n // import config\n const configPath = join(process.cwd(), props.config)\n const tamaguiConfigExport = require(configPath)\n const tamaguiConfig = (tamaguiConfigExport['default'] ||\n tamaguiConfigExport) as TamaguiInternalConfig\n\n if (!tamaguiConfig || !tamaguiConfig.parsed) {\n try {\n const confPath = require.resolve(configPath)\n console.log(`Received:`, tamaguiConfigExport)\n throw new Error(`Can't find valid config in ${confPath}`)\n } catch (err) {\n throw err\n }\n }\n\n // import components\n const components = {}\n for (const module of props.components) {\n const exported = require(module)\n Object.assign(components, exported)\n }\n\n // undo shims\n process.env.IS_STATIC = undefined\n Mod.prototype.require = og\n\n // set up core-node\n createTamagui(tamaguiConfig as any)\n\n loadedTamagui = {\n components,\n tamaguiConfig,\n }\n\n return loadedTamagui\n}\n"],
5
+ "mappings": ";;AAAA;AAGA;AAEA,IAAI,gBAAqB;AAElB,qBAAqB,OAG1B;AACA,MAAI,eAAe;AACjB,WAAO;AAAA,EACT;AAIA,UAAQ,IAAI,YAAY;AACxB,QAAM,YAAY,QAAQ,qBAAqB;AAC/C,QAAM,MAAM,QAAQ,kBAAkB;AACtC,QAAM,MAAM,QAAQ,QAAQ;AAC5B,QAAM,KAAK,IAAI,UAAU;AACzB,MAAI,UAAU,UAAU,SAAU,MAAc;AAC9C,QAAI,KAAK,SAAS,MAAM,GAAG;AACzB,aAAO,CAAC;AAAA,IACV;AACA,QAAI,SAAS,0BAA0B,KAAK,WAAW,yBAAyB,GAAG;AACjF,aAAO;AAAA,IACT;AACA,QACE,KAAK,WAAW,cAAc,KAE9B,CAAC,KAAK,WAAW,mCAAmC,GACpD;AACA,aAAO;AAAA,IACT;AACA,QAAI;AACF,aAAO,GAAG,MAAM,MAAM,SAAS;AAAA,IACjC,SAAS,KAAP;AACA,cAAQ,MAAM,+BAA+B;AAC7C,cAAQ,IAAI,OAAO,MAAM,IAAI;AAC7B,cAAQ,IAAI,IAAI,OAAO;AACvB,cAAQ,IAAI,IAAI,KAAK;AAErB,cAAQ,KAAK,CAAC;AAAA,IAChB;AAAA,EACF;AAGA,QAAM,aAAa,KAAK,QAAQ,IAAI,GAAG,MAAM,MAAM;AACnD,QAAM,sBAAsB,QAAQ,UAAU;AAC9C,QAAM,gBAAiB,oBAAoB,cACzC;AAEF,MAAI,CAAC,iBAAiB,CAAC,cAAc,QAAQ;AAC3C,QAAI;AACF,YAAM,WAA2B,AAAhB,QAAQ,QAAQ;AACjC,cAAQ,IAAI,aAAa,mBAAmB;AAC5C,YAAM,IAAI,MAAM,8BAA8B,UAAU;AAAA,IAC1D,SAAS,KAAP;AACA,YAAM;AAAA,IACR;AAAA,EACF;AAGA,QAAM,aAAa,CAAC;AACpB,aAAW,UAAU,MAAM,YAAY;AACrC,UAAM,WAAW,QAAQ,MAAM;AAC/B,WAAO,OAAO,YAAY,QAAQ;AAAA,EACpC;AAGA,UAAQ,IAAI,YAAY;AACxB,MAAI,UAAU,UAAU;AAGxB,gBAAc,aAAoB;AAElC,kBAAgB;AAAA,IACd;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AACT;AA7EgB;",
6
6
  "names": []
7
7
  }
@@ -42,6 +42,10 @@ const validHooks = {
42
42
  };
43
43
  const createTernary = /* @__PURE__ */ __name((x) => x, "createTernary");
44
44
  function createExtractor() {
45
+ if (!process.env.TAMAGUI_TARGET) {
46
+ console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"');
47
+ process.exit(1);
48
+ }
45
49
  const shouldAddDebugProp = !process.env.npm_package_dependencies_next && process.env.TAMAGUI_TARGET !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.DEBUG || process.env.IDENTIFY_TAGS);
46
50
  require("esbuild-register/dist/node").register({
47
51
  target: "es2019",
@@ -166,16 +170,17 @@ function createExtractor() {
166
170
  }
167
171
  const originalNodeName = node.name.name;
168
172
  res.found++;
173
+ const filePath = sourcePath.replace(process.cwd(), ".");
174
+ const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
175
+ const preName = componentName ? `${componentName}.` : "";
176
+ const tagId = `${preName}${node.name.name}@${filePath.replace("./", "")}:${lineNumbers}`;
169
177
  if (shouldPrintDebug) {
170
178
  console.log(`
171
- <${originalNodeName} />`);
179
+ <${originalNodeName} /> (${tagId})`);
172
180
  }
173
- const filePath = sourcePath.replace(process.cwd(), ".");
174
- const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
175
181
  if (shouldAddDebugProp && !disableDebugAttr) {
176
- const preName = componentName ? `${componentName}.` : "";
177
182
  res.modified++;
178
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(`${preName}${node.name.name}@${filePath.replace("./", "")}:${lineNumbers}`)));
183
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(tagId)));
179
184
  }
180
185
  const shouldLog = !hasLogged;
181
186
  if (shouldLog) {
@@ -212,6 +217,7 @@ function createExtractor() {
212
217
  ...staticConfig.inlineProps || []
213
218
  ]);
214
219
  const deoptProps = /* @__PURE__ */ new Set([
220
+ "animation",
215
221
  ...props.deoptProps || [],
216
222
  ...staticConfig.deoptProps || []
217
223
  ]);
@@ -436,7 +442,7 @@ function createExtractor() {
436
442
  let keys = [name];
437
443
  let out = null;
438
444
  if (staticConfig.propMapper) {
439
- out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, staticConfig);
445
+ out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, "auto");
440
446
  if (out) {
441
447
  out = rnw.createDOMProps(isTextView ? "span" : "div", out);
442
448
  delete out.className;
@@ -446,6 +452,10 @@ function createExtractor() {
446
452
  let didInline = false;
447
453
  const attributes = keys.map((key) => {
448
454
  const val = out[key];
455
+ if (key === "theme") {
456
+ inlined.set(key, val);
457
+ return attr;
458
+ }
449
459
  if (isValidStyleKey(key)) {
450
460
  return {
451
461
  type: "style",
@@ -455,10 +465,7 @@ function createExtractor() {
455
465
  };
456
466
  }
457
467
  if (validHTMLAttributes[key]) {
458
- return {
459
- type: "attr",
460
- value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(literalToAst(val)))
461
- };
468
+ return attr;
462
469
  }
463
470
  if (shouldPrintDebug) {
464
471
  console.log(" ! inlining, non-static", key);
@@ -468,7 +475,9 @@ function createExtractor() {
468
475
  return val;
469
476
  });
470
477
  if (didInline) {
471
- console.log("we inlined something off", { attributes });
478
+ if (shouldPrintDebug) {
479
+ console.log(" bailing flattening due to attributes", attributes);
480
+ }
472
481
  return attr;
473
482
  }
474
483
  return attributes;
@@ -773,28 +782,24 @@ function createExtractor() {
773
782
  const themeVal = inlined.get("theme");
774
783
  inlined.delete("theme");
775
784
  const allOtherPropsExtractable = [...inlined].every(([k, v]) => INLINE_EXTRACTABLE[k]);
776
- const shouldWrapInnerTheme = !!(hasOnlyStringChildren && themeVal);
777
- const canFlattenProps = inlined.size === 0 || allOtherPropsExtractable && shouldWrapInnerTheme || allOtherPropsExtractable;
785
+ const shouldWrapInnerTheme = allOtherPropsExtractable && !!(hasOnlyStringChildren && themeVal);
786
+ const canFlattenProps = inlined.size === 0 || shouldWrapInnerTheme || allOtherPropsExtractable;
778
787
  let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
779
- if (shouldWrapInnerTheme) {
780
- const parents = traversePath.parentPath.node;
781
- if (!t.isJSXElement(parents) && !t.isJSXFragment(parents)) {
782
- shouldFlatten = false;
783
- } else {
784
- if (typeof themeVal === "string") {
785
- if (!hasImportedTheme) {
786
- hasImportedTheme = true;
787
- programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/core")));
788
- }
789
- const children = parents.children;
790
- parents.children = [
791
- t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
792
- t.jsxAttribute(t.jsxIdentifier("name"), t.stringLiteral(`${themeVal}`))
793
- ]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), children)
794
- ];
795
- } else {
796
- }
788
+ if (shouldFlatten && shouldWrapInnerTheme) {
789
+ if (typeof themeVal !== "string") {
790
+ console.warn("??");
791
+ return;
792
+ }
793
+ if (shouldPrintDebug) {
794
+ console.log(" - wrapping theme", allOtherPropsExtractable, themeVal);
797
795
  }
796
+ if (!hasImportedTheme) {
797
+ hasImportedTheme = true;
798
+ programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/core")));
799
+ }
800
+ traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
801
+ t.jsxAttribute(t.jsxIdentifier("name"), t.stringLiteral(`${themeVal}`))
802
+ ]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
798
803
  }
799
804
  if (shouldFlatten && staticConfig.defaultProps) {
800
805
  const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
@@ -933,6 +938,10 @@ function createExtractor() {
933
938
  if (shouldPrintDebug) {
934
939
  console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
935
940
  }
941
+ const completeProps = {
942
+ ...staticConfig.defaultProps,
943
+ ...completeStaticProps
944
+ };
936
945
  const getStyles = /* @__PURE__ */ __name((props2, debugName = "") => {
937
946
  if (!props2)
938
947
  return;
@@ -946,12 +955,25 @@ function createExtractor() {
946
955
  }
947
956
  }
948
957
  const out = getSplitStyles(props2, staticConfig, defaultTheme, {
949
- noClassNames: true
958
+ noClassNames: true,
959
+ fallbackProps: completeProps,
960
+ focus: false,
961
+ hover: false,
962
+ mounted: true,
963
+ press: false,
964
+ pressIn: false
950
965
  });
951
966
  const outStyle = {
952
967
  ...out.style,
953
968
  ...out.pseudos
954
969
  };
970
+ for (const key in outStyle) {
971
+ if (staticConfig.validStyles) {
972
+ if (!staticConfig.validStyles[key] && !pseudos[key]) {
973
+ delete outStyle[key];
974
+ }
975
+ }
976
+ }
955
977
  if (shouldPrintDebug === "verbose") {
956
978
  console.log(` getStyles ${debugName} (props):
957
979
  `, logLines(objToStr(props2)));
@@ -960,19 +982,9 @@ function createExtractor() {
960
982
  console.log(` getStyles ${debugName} (out.style):
961
983
  `, logLines(objToStr(outStyle || {}), true));
962
984
  }
963
- for (const key in outStyle) {
964
- if (staticConfig.validStyles) {
965
- if (!staticConfig.validStyles[key] && !pseudos[key]) {
966
- delete outStyle[key];
967
- }
968
- }
969
- }
970
985
  return outStyle;
971
986
  }, "getStyles");
972
- const completeStylesProcessed = getStyles({
973
- ...staticConfig.defaultProps,
974
- ...completeStaticProps
975
- }, "completeStylesProcessed");
987
+ const completeStylesProcessed = getStyles(completeProps, "completeStylesProcessed");
976
988
  if (!completeStylesProcessed) {
977
989
  throw new Error(`Impossible, no styles`);
978
990
  }
@@ -1053,9 +1065,6 @@ function createExtractor() {
1053
1065
  }
1054
1066
  }
1055
1067
  }
1056
- if (shouldPrintDebug) {
1057
- console.log(" - attrs (after):\n", logLines(attrs.map(attrStr).join(", ")));
1058
- }
1059
1068
  if (shouldFlatten) {
1060
1069
  if (shouldPrintDebug) {
1061
1070
  console.log(" [\u2705] flattening", originalNodeName, flatNode);
@@ -57,8 +57,8 @@ function extractMediaStyle(ternary, jsxPath, tamaguiConfig, sourcePath, importan
57
57
  rules: [styleRule]
58
58
  };
59
59
  });
60
- if (shouldPrintDebug) {
61
- console.log(" media styles:", importance, singleMediaStyles.map((x) => x.identifier).join(", "));
60
+ if (shouldPrintDebug === "verbose") {
61
+ console.log(" media styles:", importance, styleObj, singleMediaStyles.map((x) => x.identifier).join(", "));
62
62
  }
63
63
  mediaStyles = [...mediaStyles, ...singleMediaStyles];
64
64
  }
@@ -109,9 +109,6 @@ function extractToClassNames({
109
109
  switch (attr.type) {
110
110
  case "style":
111
111
  if (!isFlattened) {
112
- if (!attr.name) {
113
- throw new Error(`No name`);
114
- }
115
112
  const { hoverStyle, pressStyle, focusStyle } = attr.value;
116
113
  const pseudos = [
117
114
  ["hoverStyle", hoverStyle],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/static",
3
- "version": "1.0.0-beta.202+a1a54793",
3
+ "version": "1.0.0-beta.205+6a67c74d",
4
4
  "source": "src/index.ts",
5
5
  "typings": "types",
6
6
  "main": "dist/cjs",
@@ -57,10 +57,10 @@
57
57
  "@babel/parser": "^7.15.7",
58
58
  "@babel/traverse": "^7.15.4",
59
59
  "@expo/match-media": "^0.1.0",
60
- "@tamagui/build": "^1.0.0-beta.202+a1a54793",
61
- "@tamagui/core-node": "^1.0.0-beta.202+a1a54793",
62
- "@tamagui/fake-react-native": "^1.0.0-beta.202+a1a54793",
63
- "@tamagui/helpers": "^1.0.0-beta.202+a1a54793",
60
+ "@tamagui/build": "^1.0.0-beta.205+6a67c74d",
61
+ "@tamagui/core-node": "^1.0.0-beta.205+6a67c74d",
62
+ "@tamagui/fake-react-native": "^1.0.0-beta.205+6a67c74d",
63
+ "@tamagui/helpers": "^1.0.0-beta.205+6a67c74d",
64
64
  "babel-literal-to-ast": "^2.1.0",
65
65
  "esbuild": "^0.14.36",
66
66
  "esbuild-register": "^3.1.2",
@@ -68,10 +68,10 @@
68
68
  "fs-extra": "^9.1.0",
69
69
  "invariant": "^2.2.4",
70
70
  "lodash": "^4.17.21",
71
- "tamagui": "^1.0.0-beta.202+a1a54793"
71
+ "tamagui": "^1.0.0-beta.205+6a67c74d"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "react-native-web": "*"
75
75
  },
76
- "gitHead": "a1a54793ee1890507fc934f42f2eb3a4020b57c5"
76
+ "gitHead": "6a67c74d67416b6c81169e1cc25e239ab935f651"
77
77
  }