@tamagui/babel-plugin 1.100.6 → 1.101.1
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/index.js +3 -279
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/index.native.js +3 -297
- package/dist/cjs/index.native.js.map +2 -2
- package/dist/esm/index.js +2 -280
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +2 -208
- package/dist/esm/index.native.js +2 -292
- package/dist/esm/index.native.js.map +2 -2
- package/package.json +3 -3
- package/src/index.ts +2 -469
- package/types/index.d.ts.map +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
5
|
var __export = (target, all) => {
|
|
7
6
|
for (var name in all)
|
|
8
7
|
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
@@ -12,286 +11,11 @@ var __export = (target, all) => {
|
|
|
12
11
|
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
12
|
return to;
|
|
14
13
|
};
|
|
15
|
-
var
|
|
16
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
-
mod
|
|
22
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
15
|
var src_exports = {};
|
|
24
16
|
__export(src_exports, {
|
|
25
17
|
default: () => src_default
|
|
26
18
|
});
|
|
27
19
|
module.exports = __toCommonJS(src_exports);
|
|
28
|
-
var
|
|
29
|
-
const importNativeView = (0, import_template.default)(`
|
|
30
|
-
const __ReactNativeView = require('react-native').View;
|
|
31
|
-
const __ReactNativeText = require('react-native').Text;
|
|
32
|
-
`), importStyleSheet = (0, import_template.default)(`
|
|
33
|
-
const __ReactNativeStyleSheet = require('react-native').StyleSheet;
|
|
34
|
-
`), importWithStyle = (0, import_template.default)(`
|
|
35
|
-
const __withStableStyle = require('@tamagui/core')._withStableStyle;
|
|
36
|
-
`), extractor = (0, import_static.createExtractor)({ platform: "native" });
|
|
37
|
-
var src_default = (0, import_helper_plugin_utils.declare)(function(api, options) {
|
|
38
|
-
return api.assertVersion(7), {
|
|
39
|
-
name: "tamagui",
|
|
40
|
-
visitor: {
|
|
41
|
-
Program: {
|
|
42
|
-
enter(root) {
|
|
43
|
-
let sourcePath = this.file.opts.filename;
|
|
44
|
-
if (sourcePath?.includes("node_modules") || !sourcePath?.endsWith(".jsx") && !sourcePath?.endsWith(".tsx"))
|
|
45
|
-
return;
|
|
46
|
-
process.env.SOURCE_ROOT?.endsWith("ios") && (sourcePath = sourcePath.replace("/ios", ""));
|
|
47
|
-
let hasImportedView = !1, hasImportedViewWrapper = !1;
|
|
48
|
-
const sheetStyles = {}, sheetIdentifier = root.scope.generateUidIdentifier("sheet"), firstCommentContents = (
|
|
49
|
-
// join because you can join together multiple pragmas
|
|
50
|
-
root.node.body[0]?.leadingComments?.map((comment) => comment?.value || " ").join(" ") ?? ""
|
|
51
|
-
), firstComment = firstCommentContents ? `//${firstCommentContents}` : "", { shouldPrintDebug, shouldDisable } = (0, import_static.getPragmaOptions)({
|
|
52
|
-
source: firstComment,
|
|
53
|
-
path: sourcePath
|
|
54
|
-
});
|
|
55
|
-
if (shouldDisable)
|
|
56
|
-
return;
|
|
57
|
-
const finalOptions = {
|
|
58
|
-
// @ts-ignore just in case they leave it out
|
|
59
|
-
platform: "native",
|
|
60
|
-
...options
|
|
61
|
-
}, printLog = (0, import_static.createLogger)(sourcePath, finalOptions);
|
|
62
|
-
function addSheetStyle(style, node) {
|
|
63
|
-
let key = `${`${Object.keys(sheetStyles).length}`}`;
|
|
64
|
-
if (process.env.NODE_ENV === "development") {
|
|
65
|
-
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
66
|
-
key += `:${(0, import_node_path.basename)(sourcePath)}:${lineNumbers}`;
|
|
67
|
-
}
|
|
68
|
-
return sheetStyles[key] = style, readStyleExpr(key);
|
|
69
|
-
}
|
|
70
|
-
function readStyleExpr(key) {
|
|
71
|
-
return (0, import_template.default)("SHEET['KEY']")({
|
|
72
|
-
SHEET: sheetIdentifier.name,
|
|
73
|
-
KEY: key
|
|
74
|
-
}).expression;
|
|
75
|
-
}
|
|
76
|
-
let res;
|
|
77
|
-
try {
|
|
78
|
-
res = extractor.parseSync(root, {
|
|
79
|
-
importsWhitelist: ["constants.js", "colors.js"],
|
|
80
|
-
extractStyledDefinitions: options.forceExtractStyleDefinitions,
|
|
81
|
-
excludeProps: /* @__PURE__ */ new Set([
|
|
82
|
-
"className",
|
|
83
|
-
"userSelect",
|
|
84
|
-
"whiteSpace",
|
|
85
|
-
"textOverflow",
|
|
86
|
-
"cursor",
|
|
87
|
-
"contain"
|
|
88
|
-
]),
|
|
89
|
-
shouldPrintDebug,
|
|
90
|
-
...finalOptions,
|
|
91
|
-
// disable this extraction for now at least, need to figure out merging theme vs non-theme
|
|
92
|
-
// because theme need to stay in render(), whereas non-theme can be extracted
|
|
93
|
-
// for now just turn it off entirely at a small perf loss
|
|
94
|
-
disableExtractInlineMedia: !0,
|
|
95
|
-
// disable extracting variables as no native concept of them (only theme values)
|
|
96
|
-
disableExtractVariables: options.experimentalFlattenThemesOnNative ? !1 : "theme",
|
|
97
|
-
sourcePath,
|
|
98
|
-
// disabling flattening for now
|
|
99
|
-
// it's flattening a plain <Paragraph>hello</Paragraph> which breaks things because themes
|
|
100
|
-
// thinking it's not really worth the effort to do much compilation on native
|
|
101
|
-
// for now just disable flatten as it can only run in narrow places on native
|
|
102
|
-
// disableFlattening: 'styled',
|
|
103
|
-
getFlattenedNode({ isTextView }) {
|
|
104
|
-
return hasImportedView || (hasImportedView = !0, root.unshiftContainer("body", importNativeView())), isTextView ? "__ReactNativeText" : "__ReactNativeView";
|
|
105
|
-
},
|
|
106
|
-
onExtractTag(props) {
|
|
107
|
-
const { isFlattened } = props;
|
|
108
|
-
if (!isFlattened)
|
|
109
|
-
return;
|
|
110
|
-
assertValidTag(props.node);
|
|
111
|
-
const stylesExpr = t.arrayExpression([]), hocStylesExpr = t.arrayExpression([]), expressions = [], finalAttrs = [], themeKeysUsed = /* @__PURE__ */ new Set();
|
|
112
|
-
function getStyleExpression(style) {
|
|
113
|
-
if (!style) return;
|
|
114
|
-
const { plain, themed } = splitThemeStyles(style);
|
|
115
|
-
let themeExpr = null;
|
|
116
|
-
if (themed && options.experimentalFlattenThemesOnNative) {
|
|
117
|
-
for (const key in themed)
|
|
118
|
-
themeKeysUsed.add(themed[key].split("$")[1]);
|
|
119
|
-
themeExpr = getThemedStyleExpression(themed);
|
|
120
|
-
}
|
|
121
|
-
const ident = addSheetStyle(plain, props.node);
|
|
122
|
-
return themeExpr ? (addStyleExpression(ident), addStyleExpression(ident, !0), themeExpr) : ident;
|
|
123
|
-
}
|
|
124
|
-
function addStyleExpression(expr, HOC = !1) {
|
|
125
|
-
Array.isArray(expr) ? (HOC ? hocStylesExpr : stylesExpr).elements.push(...expr) : (HOC ? hocStylesExpr : stylesExpr).elements.push(expr);
|
|
126
|
-
}
|
|
127
|
-
function getThemedStyleExpression(styles) {
|
|
128
|
-
const themedStylesAst = (0, import_static.literalToAst)(styles);
|
|
129
|
-
return themedStylesAst.properties.forEach((_) => {
|
|
130
|
-
const prop = _;
|
|
131
|
-
prop.value.type === "StringLiteral" && (prop.value = t.memberExpression(
|
|
132
|
-
t.identifier("theme"),
|
|
133
|
-
t.identifier(prop.value.value.slice(1) + ".get()")
|
|
134
|
-
));
|
|
135
|
-
}), themedStylesAst;
|
|
136
|
-
}
|
|
137
|
-
let hasDynamicStyle = !1;
|
|
138
|
-
for (const attr of props.attrs)
|
|
139
|
-
switch (attr.type) {
|
|
140
|
-
case "style": {
|
|
141
|
-
let styleExpr = getStyleExpression(attr.value);
|
|
142
|
-
addStyleExpression(styleExpr), options.experimentalFlattenThemesOnNative && addStyleExpression(styleExpr, !0);
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
case "ternary": {
|
|
146
|
-
const { consequent, alternate } = attr.value, consExpr = getStyleExpression(consequent), altExpr = getStyleExpression(alternate);
|
|
147
|
-
options.experimentalFlattenThemesOnNative && (expressions.push(attr.value.test), addStyleExpression(
|
|
148
|
-
t.conditionalExpression(
|
|
149
|
-
t.identifier(`_expressions[${expressions.length - 1}]`),
|
|
150
|
-
consExpr || t.nullLiteral(),
|
|
151
|
-
altExpr || t.nullLiteral()
|
|
152
|
-
),
|
|
153
|
-
!0
|
|
154
|
-
));
|
|
155
|
-
const styleExpr = t.conditionalExpression(
|
|
156
|
-
attr.value.test,
|
|
157
|
-
consExpr || t.nullLiteral(),
|
|
158
|
-
altExpr || t.nullLiteral()
|
|
159
|
-
);
|
|
160
|
-
addStyleExpression(
|
|
161
|
-
styleExpr
|
|
162
|
-
// TODO: what is this for ?
|
|
163
|
-
// isFlattened ? simpleHash(JSON.stringify({ consequent, alternate })) : undefined
|
|
164
|
-
);
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
case "dynamic-style": {
|
|
168
|
-
hasDynamicStyle = !0, expressions.push(attr.value), options.experimentalFlattenDynamicValues ? addStyleExpression(
|
|
169
|
-
t.objectExpression([
|
|
170
|
-
t.objectProperty(
|
|
171
|
-
t.identifier(attr.name),
|
|
172
|
-
t.identifier(`_expressions[${expressions.length - 1}]`)
|
|
173
|
-
)
|
|
174
|
-
]),
|
|
175
|
-
!0
|
|
176
|
-
) : addStyleExpression(
|
|
177
|
-
t.objectExpression([
|
|
178
|
-
t.objectProperty(
|
|
179
|
-
t.identifier(attr.name),
|
|
180
|
-
attr.value
|
|
181
|
-
)
|
|
182
|
-
])
|
|
183
|
-
);
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
|
-
case "attr": {
|
|
187
|
-
t.isJSXSpreadAttribute(attr.value) && (0, import_static.isSimpleSpread)(attr.value) && (stylesExpr.elements.push(
|
|
188
|
-
t.memberExpression(attr.value.argument, t.identifier("style"))
|
|
189
|
-
), options.experimentalFlattenThemesOnNative && hocStylesExpr.elements.push(
|
|
190
|
-
t.memberExpression(
|
|
191
|
-
attr.value.argument,
|
|
192
|
-
t.identifier("style")
|
|
193
|
-
)
|
|
194
|
-
)), finalAttrs.push(attr.value);
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
if (props.node.attributes = finalAttrs, props.isFlattened)
|
|
199
|
-
if (options.experimentalFlattenThemesOnNative && (themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle)) {
|
|
200
|
-
hasImportedViewWrapper || (root.unshiftContainer("body", importWithStyle()), hasImportedViewWrapper = !0);
|
|
201
|
-
const name = props.node.name.name, WrapperIdentifier = root.scope.generateUidIdentifier(
|
|
202
|
-
name + "Wrapper"
|
|
203
|
-
);
|
|
204
|
-
root.pushContainer(
|
|
205
|
-
"body",
|
|
206
|
-
t.variableDeclaration("const", [
|
|
207
|
-
t.variableDeclarator(
|
|
208
|
-
WrapperIdentifier,
|
|
209
|
-
t.callExpression(t.identifier("__withStableStyle"), [
|
|
210
|
-
t.identifier(name),
|
|
211
|
-
t.arrowFunctionExpression(
|
|
212
|
-
[t.identifier("theme"), t.identifier("_expressions")],
|
|
213
|
-
t.blockStatement([
|
|
214
|
-
t.returnStatement(
|
|
215
|
-
t.callExpression(
|
|
216
|
-
t.memberExpression(
|
|
217
|
-
t.identifier("React"),
|
|
218
|
-
t.identifier("useMemo")
|
|
219
|
-
),
|
|
220
|
-
[
|
|
221
|
-
t.arrowFunctionExpression(
|
|
222
|
-
[],
|
|
223
|
-
t.blockStatement([
|
|
224
|
-
t.returnStatement(
|
|
225
|
-
t.arrayExpression([...hocStylesExpr.elements])
|
|
226
|
-
)
|
|
227
|
-
])
|
|
228
|
-
),
|
|
229
|
-
t.arrayExpression([
|
|
230
|
-
t.spreadElement(t.identifier("_expressions"))
|
|
231
|
-
])
|
|
232
|
-
]
|
|
233
|
-
)
|
|
234
|
-
)
|
|
235
|
-
])
|
|
236
|
-
)
|
|
237
|
-
])
|
|
238
|
-
)
|
|
239
|
-
])
|
|
240
|
-
), props.node.name = WrapperIdentifier, props.jsxPath.node.closingElement && (props.jsxPath.node.closingElement.name = WrapperIdentifier), expressions.length && props.node.attributes.push(
|
|
241
|
-
t.jsxAttribute(
|
|
242
|
-
t.jsxIdentifier("expressions"),
|
|
243
|
-
t.jsxExpressionContainer(t.arrayExpression(expressions))
|
|
244
|
-
)
|
|
245
|
-
);
|
|
246
|
-
} else
|
|
247
|
-
props.node.attributes.push(
|
|
248
|
-
t.jsxAttribute(
|
|
249
|
-
t.jsxIdentifier("style"),
|
|
250
|
-
t.jsxExpressionContainer(
|
|
251
|
-
stylesExpr.elements.length === 1 ? stylesExpr.elements[0] : stylesExpr
|
|
252
|
-
)
|
|
253
|
-
)
|
|
254
|
-
);
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
} catch (err) {
|
|
258
|
-
if (err instanceof Error) {
|
|
259
|
-
let message = `${shouldPrintDebug === "verbose" ? err : err.message}`;
|
|
260
|
-
message.includes("Unexpected return value from visitor method") && (message = "Unexpected return value from visitor method"), console.warn("Error in Tamagui parse, skipping", message, err.stack);
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
if (!Object.keys(sheetStyles).length) {
|
|
265
|
-
shouldPrintDebug && console.info("END no styles"), res && printLog(res);
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
const sheetObject = (0, import_static.literalToAst)(sheetStyles), sheetOuter = (0, import_template.default)(
|
|
269
|
-
"const SHEET = __ReactNativeStyleSheet.create(null)"
|
|
270
|
-
)({
|
|
271
|
-
SHEET: sheetIdentifier.name
|
|
272
|
-
});
|
|
273
|
-
sheetOuter.declarations[0].init.arguments[0] = sheetObject, root.unshiftContainer("body", sheetOuter), root.unshiftContainer("body", importStyleSheet()), shouldPrintDebug && (console.info(`
|
|
274
|
-
-------- output code -------
|
|
275
|
-
`), console.info(
|
|
276
|
-
(0, import_generator.default)(root.parent).code.split(`
|
|
277
|
-
`).filter((x) => !x.startsWith("//")).join(`
|
|
278
|
-
`)
|
|
279
|
-
)), res && printLog(res);
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
});
|
|
285
|
-
function assertValidTag(node) {
|
|
286
|
-
node.attributes.find((x) => x.type === "JSXAttribute" && x.name.name === "style") && process.env.DEBUG?.startsWith("tamagui") && console.warn("\u26A0\uFE0F Cannot pass style attribute to extracted style");
|
|
287
|
-
}
|
|
288
|
-
function splitThemeStyles(style) {
|
|
289
|
-
const themed = {}, plain = {};
|
|
290
|
-
let noTheme = !0;
|
|
291
|
-
for (const key in style) {
|
|
292
|
-
const val = style[key];
|
|
293
|
-
val && val[0] === "$" ? (themed[key] = val, noTheme = !1) : plain[key] = val;
|
|
294
|
-
}
|
|
295
|
-
return { themed: noTheme ? null : themed, plain };
|
|
296
|
-
}
|
|
20
|
+
var import_static = require("@tamagui/static"), src_default = (0, import_static.getBabelPlugin)();
|
|
297
21
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": [
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA+B,4BAExB,kBAAQ,8BAAe;",
|
|
5
|
+
"names": []
|
|
6
6
|
}
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
6
|
var __export = (target, all) => {
|
|
8
7
|
for (var name in all)
|
|
9
8
|
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
@@ -13,304 +12,11 @@ var __export = (target, all) => {
|
|
|
13
12
|
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
13
|
return to;
|
|
15
14
|
};
|
|
16
|
-
var
|
|
17
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
22
|
-
mod
|
|
23
|
-
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
24
16
|
var src_exports = {};
|
|
25
17
|
__export(src_exports, {
|
|
26
18
|
default: () => src_default
|
|
27
19
|
});
|
|
28
20
|
module.exports = __toCommonJS(src_exports);
|
|
29
|
-
var
|
|
30
|
-
function _array_like_to_array(arr, len) {
|
|
31
|
-
(len == null || len > arr.length) && (len = arr.length);
|
|
32
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
33
|
-
return arr2;
|
|
34
|
-
}
|
|
35
|
-
function _array_without_holes(arr) {
|
|
36
|
-
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
37
|
-
}
|
|
38
|
-
function _define_property(obj, key, value) {
|
|
39
|
-
return key in obj ? Object.defineProperty(obj, key, {
|
|
40
|
-
value,
|
|
41
|
-
enumerable: !0,
|
|
42
|
-
configurable: !0,
|
|
43
|
-
writable: !0
|
|
44
|
-
}) : obj[key] = value, obj;
|
|
45
|
-
}
|
|
46
|
-
function _instanceof(left, right) {
|
|
47
|
-
return right != null && typeof Symbol < "u" && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof right;
|
|
48
|
-
}
|
|
49
|
-
function _iterable_to_array(iter) {
|
|
50
|
-
if (typeof Symbol < "u" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
51
|
-
}
|
|
52
|
-
function _non_iterable_spread() {
|
|
53
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
54
|
-
}
|
|
55
|
-
function _object_spread(target) {
|
|
56
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
57
|
-
var source = arguments[i] != null ? arguments[i] : {}, ownKeys2 = Object.keys(source);
|
|
58
|
-
typeof Object.getOwnPropertySymbols == "function" && (ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
59
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
60
|
-
}))), ownKeys2.forEach(function(key) {
|
|
61
|
-
_define_property(target, key, source[key]);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
return target;
|
|
65
|
-
}
|
|
66
|
-
function ownKeys(object, enumerableOnly) {
|
|
67
|
-
var keys = Object.keys(object);
|
|
68
|
-
if (Object.getOwnPropertySymbols) {
|
|
69
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
70
|
-
enumerableOnly && (symbols = symbols.filter(function(sym) {
|
|
71
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
72
|
-
})), keys.push.apply(keys, symbols);
|
|
73
|
-
}
|
|
74
|
-
return keys;
|
|
75
|
-
}
|
|
76
|
-
function _object_spread_props(target, source) {
|
|
77
|
-
return source = source ?? {}, Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
|
|
78
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
79
|
-
}), target;
|
|
80
|
-
}
|
|
81
|
-
function _to_consumable_array(arr) {
|
|
82
|
-
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
83
|
-
}
|
|
84
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
85
|
-
if (o) {
|
|
86
|
-
if (typeof o == "string") return _array_like_to_array(o, minLen);
|
|
87
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
88
|
-
if (n === "Object" && o.constructor && (n = o.constructor.name), n === "Map" || n === "Set") return Array.from(n);
|
|
89
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
var importNativeView = (0, import_template.default)(`
|
|
93
|
-
const __ReactNativeView = require('react-native').View;
|
|
94
|
-
const __ReactNativeText = require('react-native').Text;
|
|
95
|
-
`), importStyleSheet = (0, import_template.default)(`
|
|
96
|
-
const __ReactNativeStyleSheet = require('react-native').StyleSheet;
|
|
97
|
-
`), importWithStyle = (0, import_template.default)(`
|
|
98
|
-
const __withStableStyle = require('@tamagui/core')._withStableStyle;
|
|
99
|
-
`), extractor = (0, import_static.createExtractor)({
|
|
100
|
-
platform: "native"
|
|
101
|
-
}), src_default = (0, import_helper_plugin_utils.declare)(function(api, options) {
|
|
102
|
-
return api.assertVersion(7), {
|
|
103
|
-
name: "tamagui",
|
|
104
|
-
visitor: {
|
|
105
|
-
Program: {
|
|
106
|
-
enter: function(root) {
|
|
107
|
-
var _process_env_SOURCE_ROOT, _root_node_body__leadingComments, _root_node_body_, sourcePath = this.file.opts.filename;
|
|
108
|
-
if (sourcePath != null && sourcePath.includes("node_modules") || !(sourcePath != null && sourcePath.endsWith(".jsx")) && !(sourcePath != null && sourcePath.endsWith(".tsx")))
|
|
109
|
-
return;
|
|
110
|
-
!((_process_env_SOURCE_ROOT = process.env.SOURCE_ROOT) === null || _process_env_SOURCE_ROOT === void 0) && _process_env_SOURCE_ROOT.endsWith("ios") && (sourcePath = sourcePath.replace("/ios", ""));
|
|
111
|
-
var hasImportedView = !1, hasImportedViewWrapper = !1, sheetStyles = {}, sheetIdentifier = root.scope.generateUidIdentifier("sheet"), _root_node_body__leadingComments_map_join, firstCommentContents = (_root_node_body__leadingComments_map_join = (_root_node_body_ = root.node.body[0]) === null || _root_node_body_ === void 0 || (_root_node_body__leadingComments = _root_node_body_.leadingComments) === null || _root_node_body__leadingComments === void 0 ? void 0 : _root_node_body__leadingComments.map(function(comment) {
|
|
112
|
-
return (comment == null ? void 0 : comment.value) || " ";
|
|
113
|
-
}).join(" ")) !== null && _root_node_body__leadingComments_map_join !== void 0 ? _root_node_body__leadingComments_map_join : "", firstComment = firstCommentContents ? "//".concat(firstCommentContents) : "", _getPragmaOptions = (0, import_static.getPragmaOptions)({
|
|
114
|
-
source: firstComment,
|
|
115
|
-
path: sourcePath
|
|
116
|
-
}), shouldPrintDebug = _getPragmaOptions.shouldPrintDebug, shouldDisable = _getPragmaOptions.shouldDisable;
|
|
117
|
-
if (shouldDisable)
|
|
118
|
-
return;
|
|
119
|
-
var finalOptions = _object_spread({
|
|
120
|
-
// @ts-ignore just in case they leave it out
|
|
121
|
-
platform: "native"
|
|
122
|
-
}, options), printLog = (0, import_static.createLogger)(sourcePath, finalOptions);
|
|
123
|
-
function addSheetStyle(style, node) {
|
|
124
|
-
var styleIndex = "".concat(Object.keys(sheetStyles).length), key = "".concat(styleIndex);
|
|
125
|
-
if (process.env.NODE_ENV === "development") {
|
|
126
|
-
var lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? "-".concat(node.loc.end.line) : "") : "";
|
|
127
|
-
key += ":".concat((0, import_node_path.basename)(sourcePath), ":").concat(lineNumbers);
|
|
128
|
-
}
|
|
129
|
-
return sheetStyles[key] = style, readStyleExpr(key);
|
|
130
|
-
}
|
|
131
|
-
function readStyleExpr(key) {
|
|
132
|
-
return (0, import_template.default)("SHEET['KEY']")({
|
|
133
|
-
SHEET: sheetIdentifier.name,
|
|
134
|
-
KEY: key
|
|
135
|
-
}).expression;
|
|
136
|
-
}
|
|
137
|
-
var res;
|
|
138
|
-
try {
|
|
139
|
-
res = extractor.parseSync(root, _object_spread_props(_object_spread({
|
|
140
|
-
importsWhitelist: [
|
|
141
|
-
"constants.js",
|
|
142
|
-
"colors.js"
|
|
143
|
-
],
|
|
144
|
-
extractStyledDefinitions: options.forceExtractStyleDefinitions,
|
|
145
|
-
excludeProps: /* @__PURE__ */ new Set([
|
|
146
|
-
"className",
|
|
147
|
-
"userSelect",
|
|
148
|
-
"whiteSpace",
|
|
149
|
-
"textOverflow",
|
|
150
|
-
"cursor",
|
|
151
|
-
"contain"
|
|
152
|
-
]),
|
|
153
|
-
shouldPrintDebug
|
|
154
|
-
}, finalOptions), {
|
|
155
|
-
// disable this extraction for now at least, need to figure out merging theme vs non-theme
|
|
156
|
-
// because theme need to stay in render(), whereas non-theme can be extracted
|
|
157
|
-
// for now just turn it off entirely at a small perf loss
|
|
158
|
-
disableExtractInlineMedia: !0,
|
|
159
|
-
// disable extracting variables as no native concept of them (only theme values)
|
|
160
|
-
disableExtractVariables: options.experimentalFlattenThemesOnNative ? !1 : "theme",
|
|
161
|
-
sourcePath,
|
|
162
|
-
// disabling flattening for now
|
|
163
|
-
// it's flattening a plain <Paragraph>hello</Paragraph> which breaks things because themes
|
|
164
|
-
// thinking it's not really worth the effort to do much compilation on native
|
|
165
|
-
// for now just disable flatten as it can only run in narrow places on native
|
|
166
|
-
// disableFlattening: 'styled',
|
|
167
|
-
getFlattenedNode: function(param) {
|
|
168
|
-
var isTextView = param.isTextView;
|
|
169
|
-
return hasImportedView || (hasImportedView = !0, root.unshiftContainer("body", importNativeView())), isTextView ? "__ReactNativeText" : "__ReactNativeView";
|
|
170
|
-
},
|
|
171
|
-
onExtractTag: function(props) {
|
|
172
|
-
var isFlattened = props.isFlattened;
|
|
173
|
-
if (!isFlattened)
|
|
174
|
-
return;
|
|
175
|
-
assertValidTag(props.node);
|
|
176
|
-
var stylesExpr = t.arrayExpression([]), hocStylesExpr = t.arrayExpression([]), expressions = [], finalAttrs = [], themeKeysUsed = /* @__PURE__ */ new Set();
|
|
177
|
-
function getStyleExpression(style) {
|
|
178
|
-
if (style) {
|
|
179
|
-
var _splitThemeStyles = splitThemeStyles(style), plain = _splitThemeStyles.plain, themed = _splitThemeStyles.themed, themeExpr = null;
|
|
180
|
-
if (themed && options.experimentalFlattenThemesOnNative) {
|
|
181
|
-
for (var key in themed)
|
|
182
|
-
themeKeysUsed.add(themed[key].split("$")[1]);
|
|
183
|
-
themeExpr = getThemedStyleExpression(themed);
|
|
184
|
-
}
|
|
185
|
-
var ident = addSheetStyle(plain, props.node);
|
|
186
|
-
return themeExpr ? (addStyleExpression(ident), addStyleExpression(ident, !0), themeExpr) : ident;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
function addStyleExpression(expr) {
|
|
190
|
-
var HOC = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : !1;
|
|
191
|
-
if (Array.isArray(expr)) {
|
|
192
|
-
var _elements;
|
|
193
|
-
(_elements = (HOC ? hocStylesExpr : stylesExpr).elements).push.apply(_elements, _to_consumable_array(expr));
|
|
194
|
-
} else
|
|
195
|
-
(HOC ? hocStylesExpr : stylesExpr).elements.push(expr);
|
|
196
|
-
}
|
|
197
|
-
function getThemedStyleExpression(styles) {
|
|
198
|
-
var themedStylesAst = (0, import_static.literalToAst)(styles);
|
|
199
|
-
return themedStylesAst.properties.forEach(function(_) {
|
|
200
|
-
var prop = _;
|
|
201
|
-
prop.value.type === "StringLiteral" && (prop.value = t.memberExpression(t.identifier("theme"), t.identifier(prop.value.value.slice(1) + ".get()")));
|
|
202
|
-
}), themedStylesAst;
|
|
203
|
-
}
|
|
204
|
-
var hasDynamicStyle = !1, _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
|
|
205
|
-
try {
|
|
206
|
-
for (var _iterator = props.attrs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
207
|
-
var attr = _step.value;
|
|
208
|
-
switch (attr.type) {
|
|
209
|
-
case "style": {
|
|
210
|
-
var styleExpr = getStyleExpression(attr.value);
|
|
211
|
-
addStyleExpression(styleExpr), options.experimentalFlattenThemesOnNative && addStyleExpression(styleExpr, !0);
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
case "ternary": {
|
|
215
|
-
var _attr_value = attr.value, consequent = _attr_value.consequent, alternate = _attr_value.alternate, consExpr = getStyleExpression(consequent), altExpr = getStyleExpression(alternate);
|
|
216
|
-
options.experimentalFlattenThemesOnNative && (expressions.push(attr.value.test), addStyleExpression(t.conditionalExpression(t.identifier("_expressions[".concat(expressions.length - 1, "]")), consExpr || t.nullLiteral(), altExpr || t.nullLiteral()), !0));
|
|
217
|
-
var styleExpr1 = t.conditionalExpression(attr.value.test, consExpr || t.nullLiteral(), altExpr || t.nullLiteral());
|
|
218
|
-
addStyleExpression(styleExpr1);
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
case "dynamic-style": {
|
|
222
|
-
hasDynamicStyle = !0, expressions.push(attr.value), options.experimentalFlattenDynamicValues ? addStyleExpression(t.objectExpression([
|
|
223
|
-
t.objectProperty(t.identifier(attr.name), t.identifier("_expressions[".concat(expressions.length - 1, "]")))
|
|
224
|
-
]), !0) : addStyleExpression(t.objectExpression([
|
|
225
|
-
t.objectProperty(t.identifier(attr.name), attr.value)
|
|
226
|
-
]));
|
|
227
|
-
break;
|
|
228
|
-
}
|
|
229
|
-
case "attr": {
|
|
230
|
-
t.isJSXSpreadAttribute(attr.value) && (0, import_static.isSimpleSpread)(attr.value) && (stylesExpr.elements.push(t.memberExpression(attr.value.argument, t.identifier("style"))), options.experimentalFlattenThemesOnNative && hocStylesExpr.elements.push(t.memberExpression(attr.value.argument, t.identifier("style")))), finalAttrs.push(attr.value);
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
} catch (err) {
|
|
236
|
-
_didIteratorError = !0, _iteratorError = err;
|
|
237
|
-
} finally {
|
|
238
|
-
try {
|
|
239
|
-
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
240
|
-
} finally {
|
|
241
|
-
if (_didIteratorError)
|
|
242
|
-
throw _iteratorError;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
if (props.node.attributes = finalAttrs, props.isFlattened)
|
|
246
|
-
if (options.experimentalFlattenThemesOnNative && (themeKeysUsed.size || hocStylesExpr.elements.length > 1 || hasDynamicStyle)) {
|
|
247
|
-
hasImportedViewWrapper || (root.unshiftContainer("body", importWithStyle()), hasImportedViewWrapper = !0);
|
|
248
|
-
var name = props.node.name.name, WrapperIdentifier = root.scope.generateUidIdentifier(name + "Wrapper");
|
|
249
|
-
root.pushContainer("body", t.variableDeclaration("const", [
|
|
250
|
-
t.variableDeclarator(WrapperIdentifier, t.callExpression(t.identifier("__withStableStyle"), [
|
|
251
|
-
t.identifier(name),
|
|
252
|
-
t.arrowFunctionExpression([
|
|
253
|
-
t.identifier("theme"),
|
|
254
|
-
t.identifier("_expressions")
|
|
255
|
-
], t.blockStatement([
|
|
256
|
-
t.returnStatement(t.callExpression(t.memberExpression(t.identifier("React"), t.identifier("useMemo")), [
|
|
257
|
-
t.arrowFunctionExpression([], t.blockStatement([
|
|
258
|
-
t.returnStatement(t.arrayExpression(_to_consumable_array(hocStylesExpr.elements)))
|
|
259
|
-
])),
|
|
260
|
-
t.arrayExpression([
|
|
261
|
-
t.spreadElement(t.identifier("_expressions"))
|
|
262
|
-
])
|
|
263
|
-
]))
|
|
264
|
-
]))
|
|
265
|
-
]))
|
|
266
|
-
])), props.node.name = WrapperIdentifier, props.jsxPath.node.closingElement && (props.jsxPath.node.closingElement.name = WrapperIdentifier), expressions.length && props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("expressions"), t.jsxExpressionContainer(t.arrayExpression(expressions))));
|
|
267
|
-
} else
|
|
268
|
-
props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("style"), t.jsxExpressionContainer(stylesExpr.elements.length === 1 ? stylesExpr.elements[0] : stylesExpr)));
|
|
269
|
-
}
|
|
270
|
-
}));
|
|
271
|
-
} catch (err) {
|
|
272
|
-
if (_instanceof(err, Error)) {
|
|
273
|
-
var message = "".concat(shouldPrintDebug === "verbose" ? err : err.message);
|
|
274
|
-
message.includes("Unexpected return value from visitor method") && (message = "Unexpected return value from visitor method"), console.warn("Error in Tamagui parse, skipping", message, err.stack);
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
if (!Object.keys(sheetStyles).length) {
|
|
279
|
-
shouldPrintDebug && console.info("END no styles"), res && printLog(res);
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
var sheetObject = (0, import_static.literalToAst)(sheetStyles), sheetOuter = (0, import_template.default)("const SHEET = __ReactNativeStyleSheet.create(null)")({
|
|
283
|
-
SHEET: sheetIdentifier.name
|
|
284
|
-
});
|
|
285
|
-
sheetOuter.declarations[0].init.arguments[0] = sheetObject, root.unshiftContainer("body", sheetOuter), root.unshiftContainer("body", importStyleSheet()), shouldPrintDebug && (console.info(`
|
|
286
|
-
-------- output code -------
|
|
287
|
-
`), console.info((0, import_generator.default)(root.parent).code.split(`
|
|
288
|
-
`).filter(function(x) {
|
|
289
|
-
return !x.startsWith("//");
|
|
290
|
-
}).join(`
|
|
291
|
-
`))), res && printLog(res);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
};
|
|
296
|
-
});
|
|
297
|
-
function assertValidTag(node) {
|
|
298
|
-
if (node.attributes.find(function(x) {
|
|
299
|
-
return x.type === "JSXAttribute" && x.name.name === "style";
|
|
300
|
-
})) {
|
|
301
|
-
var _process_env_DEBUG;
|
|
302
|
-
!((_process_env_DEBUG = process.env.DEBUG) === null || _process_env_DEBUG === void 0) && _process_env_DEBUG.startsWith("tamagui") && console.warn("\u26A0\uFE0F Cannot pass style attribute to extracted style");
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
function splitThemeStyles(style) {
|
|
306
|
-
var themed = {}, plain = {}, noTheme = !0;
|
|
307
|
-
for (var key in style) {
|
|
308
|
-
var val = style[key];
|
|
309
|
-
val && val[0] === "$" ? (themed[key] = val, noTheme = !1) : plain[key] = val;
|
|
310
|
-
}
|
|
311
|
-
return {
|
|
312
|
-
themed: noTheme ? null : themed,
|
|
313
|
-
plain
|
|
314
|
-
};
|
|
315
|
-
}
|
|
21
|
+
var import_static = require("@tamagui/static"), src_default = (0, import_static.getBabelPlugin)();
|
|
316
22
|
//# sourceMappingURL=index.js.map
|