@tamagui/static 3.0.12 → 3.0.14

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.
@@ -1904,7 +1904,28 @@ function createTamaguiCompilerHost(options) {
1904
1904
  if (!isSerializableNativeStyle(nativeStyle)) {
1905
1905
  return bailout(input, "local/unsupported-target", "Native style output is not a static serializable value");
1906
1906
  }
1907
+ if (component.staticConfig.isText && staticObject(nativeStyleResolved)) {
1908
+ const conf = core.getConfig();
1909
+ const family = String(split.fontFamily || conf.defaultFontToken).replace(/^\$/, "");
1910
+ if (Object.keys(nativeStyleResolved).some((key) => key.startsWith("font") || key === "lineHeight" || key === "letterSpacing") && Object.keys(conf.fontsParsed).some((name) => name.startsWith(`${family}_`))) {
1911
+ return bailout(input, "local/dynamic-style-value", `Font ${family} has FontLanguage variants, so its values resolve at runtime`);
1912
+ }
1913
+ }
1907
1914
  const nativeStyleLocal = unusedIdentifier(input.source, `__TamaguiNativeStyle${input.element.span.start}`);
1915
+ const pressable = input.element.entries.some((entry) => entry.kind === "prop" && /^on[A-Z]/.test(entry.name));
1916
+ const defaultViewProps = component.domTag ? [] : Object.keys(staticDefaultProps).filter((name) => name !== "style" && split.viewProps && name in split.viewProps && (name !== "suppressHighlighting" || pressable) && !input.element.entries.some((entry) => entry.kind === "prop" && entry.name === name));
1917
+ for (const name of defaultViewProps) {
1918
+ const value = split.viewProps[name];
1919
+ if (input.element.form !== "jsx" || !(value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value))) {
1920
+ return bailout(input, "local/unsupported-target", `Default prop ${name} cannot be written onto the flattened host`);
1921
+ }
1922
+ }
1923
+ const defaultPropEdits = defaultViewProps.length ? [{
1924
+ start: input.element.component.span.end,
1925
+ end: input.element.component.span.end,
1926
+ content: defaultViewProps.map((name) => ` ${name}={${JSON.stringify(split.viewProps[name])}}`).join(""),
1927
+ origin: input.element.component.span
1928
+ }] : [];
1908
1929
  const usesNativeFastPath = !!themedStyleKeys && !!options.experimentalNativeFastPath && dynamicStyleEntries.length === 0 && !input.element.entries.some((entry) => entry.kind === "spread");
1909
1930
  const nativeStyleImports = [{
1910
1931
  content: `
@@ -2075,8 +2096,8 @@ import { createElement as ${createElementLocal} } from "react"
2075
2096
  };
2076
2097
  }
2077
2098
  const nativeName = component.staticConfig.isText ? "Text" : "View";
2078
- const useHostView = options.experimentalNativeFastPath && nativeName === "View" && isBareHostView(input.element, !!nativeFastPath);
2079
- const useHostText = options.experimentalNativeFastPath && nativeName === "Text" && !!nativeFastPath && isBareHostText(input.element);
2099
+ const useHostView = options.experimentalNativeFastPath && nativeName === "View" && isBareHostView(input.element, !!nativeFastPath) && !defaultViewProps.some((name) => VIEW_WRAPPER_PROPS.test(name));
2100
+ const useHostText = options.experimentalNativeFastPath && nativeName === "Text" && !!nativeFastPath && isBareHostText(input.element) && !defaultViewProps.some((name) => TEXT_WRAPPER_PROPS.test(name));
2080
2101
  const nativeExport = useHostView ? "unstable_NativeView" : nativeName;
2081
2102
  const nativeLocal = unusedIdentifier(input.source, `__TamaguiNative${useHostView ? "HostView" : nativeName}`);
2082
2103
  if (themedStyleKeys && options.disablePartialExtraction) {
@@ -2123,6 +2144,7 @@ import { createElement as ${createElementLocal} } from "react"
2123
2144
  edits: [
2124
2145
  ...inlineEdits,
2125
2146
  ...tagEdits4,
2147
+ ...defaultPropEdits,
2126
2148
  ...styleEdits
2127
2149
  ],
2128
2150
  css: [],
@@ -2284,7 +2306,11 @@ const ${fastLocal} = require('@tamagui/core')._withNativeStyle(${nativeLocal}, $
2284
2306
  }
2285
2307
  return {
2286
2308
  ok: true,
2287
- edits: [...tagEdits3, ...expressionEdits],
2309
+ edits: [
2310
+ ...tagEdits3,
2311
+ ...defaultPropEdits,
2312
+ ...expressionEdits
2313
+ ],
2288
2314
  css: [],
2289
2315
  imports: [
2290
2316
  ...nativeStyleImports,
@@ -2329,12 +2355,16 @@ const ${nativeLocal} = require('react-native').${nativeExport};`,
2329
2355
  if (styleEntries.length === 0) {
2330
2356
  return {
2331
2357
  ok: true,
2332
- edits: [...tagEdits2, {
2333
- start: input.element.component.span.end,
2334
- end: input.element.component.span.end,
2335
- content: ` style={${nativeStyleSource}}`,
2336
- origin: input.element.component.span
2337
- }],
2358
+ edits: [
2359
+ ...tagEdits2,
2360
+ ...defaultPropEdits,
2361
+ {
2362
+ start: input.element.component.span.end,
2363
+ end: input.element.component.span.end,
2364
+ content: ` style={${nativeStyleSource}}`,
2365
+ origin: input.element.component.span
2366
+ }
2367
+ ],
2338
2368
  css: [],
2339
2369
  imports: [...nativeStyleImports, {
2340
2370
  content: `
@@ -2350,6 +2380,7 @@ const ${nativeLocal} = require('react-native').${nativeExport};`,
2350
2380
  ok: true,
2351
2381
  edits: [
2352
2382
  ...tagEdits2,
2383
+ ...defaultPropEdits,
2353
2384
  ...webPropEdits,
2354
2385
  {
2355
2386
  start: first2.span.start,
@@ -1879,7 +1879,28 @@ function createTamaguiCompilerHost(options) {
1879
1879
  if (!isSerializableNativeStyle(nativeStyle)) {
1880
1880
  return bailout(input, "local/unsupported-target", "Native style output is not a static serializable value");
1881
1881
  }
1882
+ if (component.staticConfig.isText && staticObject(nativeStyleResolved)) {
1883
+ const conf = core.getConfig();
1884
+ const family = String(split.fontFamily || conf.defaultFontToken).replace(/^\$/, "");
1885
+ if (Object.keys(nativeStyleResolved).some((key) => key.startsWith("font") || key === "lineHeight" || key === "letterSpacing") && Object.keys(conf.fontsParsed).some((name) => name.startsWith(`${family}_`))) {
1886
+ return bailout(input, "local/dynamic-style-value", `Font ${family} has FontLanguage variants, so its values resolve at runtime`);
1887
+ }
1888
+ }
1882
1889
  const nativeStyleLocal = unusedIdentifier(input.source, `__TamaguiNativeStyle${input.element.span.start}`);
1890
+ const pressable = input.element.entries.some((entry) => entry.kind === "prop" && /^on[A-Z]/.test(entry.name));
1891
+ const defaultViewProps = component.domTag ? [] : Object.keys(staticDefaultProps).filter((name) => name !== "style" && split.viewProps && name in split.viewProps && (name !== "suppressHighlighting" || pressable) && !input.element.entries.some((entry) => entry.kind === "prop" && entry.name === name));
1892
+ for (const name of defaultViewProps) {
1893
+ const value = split.viewProps[name];
1894
+ if (input.element.form !== "jsx" || !(value === null || typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value))) {
1895
+ return bailout(input, "local/unsupported-target", `Default prop ${name} cannot be written onto the flattened host`);
1896
+ }
1897
+ }
1898
+ const defaultPropEdits = defaultViewProps.length ? [{
1899
+ start: input.element.component.span.end,
1900
+ end: input.element.component.span.end,
1901
+ content: defaultViewProps.map((name) => ` ${name}={${JSON.stringify(split.viewProps[name])}}`).join(""),
1902
+ origin: input.element.component.span
1903
+ }] : [];
1883
1904
  const usesNativeFastPath = !!themedStyleKeys && !!options.experimentalNativeFastPath && dynamicStyleEntries.length === 0 && !input.element.entries.some((entry) => entry.kind === "spread");
1884
1905
  const nativeStyleImports = [{
1885
1906
  content: `
@@ -2050,8 +2071,8 @@ import { createElement as ${createElementLocal} } from "react"
2050
2071
  };
2051
2072
  }
2052
2073
  const nativeName = component.staticConfig.isText ? "Text" : "View";
2053
- const useHostView = options.experimentalNativeFastPath && nativeName === "View" && isBareHostView(input.element, !!nativeFastPath);
2054
- const useHostText = options.experimentalNativeFastPath && nativeName === "Text" && !!nativeFastPath && isBareHostText(input.element);
2074
+ const useHostView = options.experimentalNativeFastPath && nativeName === "View" && isBareHostView(input.element, !!nativeFastPath) && !defaultViewProps.some((name) => VIEW_WRAPPER_PROPS.test(name));
2075
+ const useHostText = options.experimentalNativeFastPath && nativeName === "Text" && !!nativeFastPath && isBareHostText(input.element) && !defaultViewProps.some((name) => TEXT_WRAPPER_PROPS.test(name));
2055
2076
  const nativeExport = useHostView ? "unstable_NativeView" : nativeName;
2056
2077
  const nativeLocal = unusedIdentifier(input.source, `__TamaguiNative${useHostView ? "HostView" : nativeName}`);
2057
2078
  if (themedStyleKeys && options.disablePartialExtraction) {
@@ -2098,6 +2119,7 @@ import { createElement as ${createElementLocal} } from "react"
2098
2119
  edits: [
2099
2120
  ...inlineEdits,
2100
2121
  ...tagEdits4,
2122
+ ...defaultPropEdits,
2101
2123
  ...styleEdits
2102
2124
  ],
2103
2125
  css: [],
@@ -2259,7 +2281,11 @@ const ${fastLocal} = require('@tamagui/core')._withNativeStyle(${nativeLocal}, $
2259
2281
  }
2260
2282
  return {
2261
2283
  ok: true,
2262
- edits: [...tagEdits3, ...expressionEdits],
2284
+ edits: [
2285
+ ...tagEdits3,
2286
+ ...defaultPropEdits,
2287
+ ...expressionEdits
2288
+ ],
2263
2289
  css: [],
2264
2290
  imports: [
2265
2291
  ...nativeStyleImports,
@@ -2304,12 +2330,16 @@ const ${nativeLocal} = require('react-native').${nativeExport};`,
2304
2330
  if (styleEntries.length === 0) {
2305
2331
  return {
2306
2332
  ok: true,
2307
- edits: [...tagEdits2, {
2308
- start: input.element.component.span.end,
2309
- end: input.element.component.span.end,
2310
- content: ` style={${nativeStyleSource}}`,
2311
- origin: input.element.component.span
2312
- }],
2333
+ edits: [
2334
+ ...tagEdits2,
2335
+ ...defaultPropEdits,
2336
+ {
2337
+ start: input.element.component.span.end,
2338
+ end: input.element.component.span.end,
2339
+ content: ` style={${nativeStyleSource}}`,
2340
+ origin: input.element.component.span
2341
+ }
2342
+ ],
2313
2343
  css: [],
2314
2344
  imports: [...nativeStyleImports, {
2315
2345
  content: `
@@ -2325,6 +2355,7 @@ const ${nativeLocal} = require('react-native').${nativeExport};`,
2325
2355
  ok: true,
2326
2356
  edits: [
2327
2357
  ...tagEdits2,
2358
+ ...defaultPropEdits,
2328
2359
  ...webPropEdits,
2329
2360
  {
2330
2361
  start: first2.span.start,