@tamagui/web 1.11.1 → 1.12.0
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/createComponent.js +3 -3
- package/dist/cjs/createComponent.js.map +2 -2
- package/dist/cjs/helpers/getSplitStyles.js +1 -8
- package/dist/cjs/helpers/getSplitStyles.js.map +2 -2
- package/dist/cjs/helpers/insertStyleRule.js +62 -57
- package/dist/cjs/helpers/insertStyleRule.js.map +2 -2
- package/dist/cjs/styled.js +10 -10
- package/dist/cjs/styled.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/createComponent.js +4 -3
- package/dist/esm/createComponent.js.map +2 -2
- package/dist/esm/createComponent.mjs +4 -3
- package/dist/esm/createComponent.mjs.map +2 -2
- package/dist/esm/helpers/getSplitStyles.js +1 -7
- package/dist/esm/helpers/getSplitStyles.js.map +2 -2
- package/dist/esm/helpers/getSplitStyles.mjs +1 -7
- package/dist/esm/helpers/getSplitStyles.mjs.map +2 -2
- package/dist/esm/helpers/insertStyleRule.js +59 -54
- package/dist/esm/helpers/insertStyleRule.js.map +2 -2
- package/dist/esm/helpers/insertStyleRule.mjs +59 -54
- package/dist/esm/helpers/insertStyleRule.mjs.map +2 -2
- package/dist/esm/styled.js +10 -10
- package/dist/esm/styled.js.map +2 -2
- package/dist/esm/styled.mjs +10 -10
- package/dist/esm/styled.mjs.map +2 -2
- package/package.json +9 -9
- package/src/createComponent.tsx +5 -3
- package/src/helpers/getSplitStyles.tsx +1 -7
- package/src/helpers/insertStyleRule.tsx +80 -58
- package/src/styled.tsx +18 -13
- package/src/types.tsx +2 -2
- package/types/createComponent.d.ts.map +1 -1
- package/types/helpers/getSplitStyles.d.ts +0 -1
- package/types/helpers/getSplitStyles.d.ts.map +1 -1
- package/types/helpers/insertStyleRule.d.ts +3 -3
- package/types/helpers/insertStyleRule.d.ts.map +1 -1
- package/types/styled.d.ts +1 -1
- package/types/styled.d.ts.map +1 -1
- package/types/types.d.ts +2 -2
- package/types/types.d.ts.map +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isClient } from "@tamagui/constants";
|
|
1
2
|
const allSelectors = {};
|
|
2
3
|
const allRules = {};
|
|
3
4
|
const insertedTransforms = {};
|
|
@@ -10,7 +11,7 @@ function addTransform(identifier, css, rule) {
|
|
|
10
11
|
if (process.env.NODE_ENV === "development") {
|
|
11
12
|
console.error(`\u274C Invalid transform, likely used deg/% improperly ${identifier}`);
|
|
12
13
|
}
|
|
13
|
-
return
|
|
14
|
+
return;
|
|
14
15
|
}
|
|
15
16
|
const startI = s + "transform:".length;
|
|
16
17
|
const endI = css.indexOf(";");
|
|
@@ -19,47 +20,50 @@ function addTransform(identifier, css, rule) {
|
|
|
19
20
|
insertedTransforms[identifier] = value;
|
|
20
21
|
return true;
|
|
21
22
|
}
|
|
22
|
-
return false;
|
|
23
23
|
}
|
|
24
|
-
const isClient = typeof document !== "undefined";
|
|
25
24
|
const scannedCache = /* @__PURE__ */ new WeakMap();
|
|
26
|
-
const
|
|
25
|
+
const totalSelectorsInserted = /* @__PURE__ */ new Map();
|
|
27
26
|
function listenForSheetChanges() {
|
|
28
27
|
if (!isClient)
|
|
29
28
|
return;
|
|
30
|
-
function handleNode(node, remove = false) {
|
|
31
|
-
if (node instanceof HTMLStyleElement && node.sheet) {
|
|
32
|
-
updateSheetStyles(node.sheet, remove);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
29
|
const mo = new MutationObserver((entries) => {
|
|
36
30
|
for (const entry of entries) {
|
|
37
|
-
entry.
|
|
38
|
-
|
|
31
|
+
if (entry instanceof HTMLStyleElement && entry.sheet || entry instanceof HTMLLinkElement && entry.href.endsWith(".css")) {
|
|
32
|
+
scanAllSheets();
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
39
35
|
}
|
|
40
36
|
});
|
|
41
37
|
mo.observe(document.head, {
|
|
42
38
|
childList: true
|
|
43
39
|
});
|
|
44
40
|
}
|
|
41
|
+
let lastScannedSheets = null;
|
|
45
42
|
function scanAllSheets() {
|
|
46
43
|
if (process.env.NODE_ENV === "test")
|
|
47
44
|
return;
|
|
48
45
|
if (!isClient)
|
|
49
46
|
return;
|
|
50
|
-
const sheets = document.styleSheets;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const sheet2
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
const sheets = document.styleSheets || [];
|
|
48
|
+
const prev = lastScannedSheets;
|
|
49
|
+
const current = new Set(sheets);
|
|
50
|
+
if (document.styleSheets) {
|
|
51
|
+
for (const sheet2 of current) {
|
|
52
|
+
sheet2 && updateSheetStyles(sheet2);
|
|
53
|
+
}
|
|
54
|
+
lastScannedSheets = current;
|
|
55
|
+
}
|
|
56
|
+
if (prev) {
|
|
57
|
+
for (const sheet2 of prev) {
|
|
58
|
+
if (sheet2 && !current.has(sheet2)) {
|
|
59
|
+
updateSheetStyles(sheet2, true);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
58
62
|
}
|
|
59
63
|
}
|
|
60
64
|
function track(id, remove = false) {
|
|
61
|
-
const next = (
|
|
62
|
-
|
|
65
|
+
const next = (totalSelectorsInserted.get(id) || 0) + (remove ? -1 : 1);
|
|
66
|
+
totalSelectorsInserted.set(id, next);
|
|
63
67
|
return next;
|
|
64
68
|
}
|
|
65
69
|
function updateSheetStyles(sheet2, remove = false) {
|
|
@@ -71,9 +75,6 @@ function updateSheetStyles(sheet2, remove = false) {
|
|
|
71
75
|
return;
|
|
72
76
|
}
|
|
73
77
|
const firstSelector = (_a = getTamaguiSelector(rules[0])) == null ? void 0 : _a[0];
|
|
74
|
-
if (!firstSelector) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
78
|
const lastSelector = (_b = getTamaguiSelector(rules[rules.length - 1])) == null ? void 0 : _b[0];
|
|
78
79
|
const cacheKey = `${rules.length}${firstSelector}${lastSelector}`;
|
|
79
80
|
const lastScanned = scannedCache.get(sheet2);
|
|
@@ -83,11 +84,18 @@ function updateSheetStyles(sheet2, remove = false) {
|
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
const len = rules.length;
|
|
87
|
+
let fails = 0;
|
|
86
88
|
for (let i = 0; i < len; i++) {
|
|
87
89
|
const rule = rules[i];
|
|
90
|
+
if (!(rule instanceof CSSStyleRule))
|
|
91
|
+
continue;
|
|
88
92
|
const response = getTamaguiSelector(rule);
|
|
89
93
|
if (!response) {
|
|
90
|
-
|
|
94
|
+
fails++;
|
|
95
|
+
if (fails > 5) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
continue;
|
|
91
99
|
}
|
|
92
100
|
const [identifier, cssRule] = response;
|
|
93
101
|
const total = track(identifier, remove);
|
|
@@ -95,13 +103,11 @@ function updateSheetStyles(sheet2, remove = false) {
|
|
|
95
103
|
if (total === 0) {
|
|
96
104
|
delete allSelectors[identifier];
|
|
97
105
|
}
|
|
98
|
-
} else {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
allSelectors[identifier] = cssRule.cssText;
|
|
104
|
-
}
|
|
106
|
+
} else if (!(identifier in allSelectors)) {
|
|
107
|
+
const isTransform = identifier.startsWith("_transform");
|
|
108
|
+
const shouldInsert = isTransform ? addTransform(identifier, cssRule.cssText, cssRule) : true;
|
|
109
|
+
if (shouldInsert) {
|
|
110
|
+
allSelectors[identifier] = cssRule.cssText;
|
|
105
111
|
}
|
|
106
112
|
}
|
|
107
113
|
}
|
|
@@ -126,8 +132,9 @@ function getTamaguiSelector(rule) {
|
|
|
126
132
|
const getIdentifierFromTamaguiSelector = (selector) => selector.replace(/(:root)+\s+/, "").replace(/:[a-z]+$/, "").slice(1);
|
|
127
133
|
const sheet = isClient ? document.head.appendChild(document.createElement("style")).sheet : null;
|
|
128
134
|
function updateRules(identifier, rules) {
|
|
129
|
-
if (allRules
|
|
135
|
+
if (identifier in allRules) {
|
|
130
136
|
return false;
|
|
137
|
+
}
|
|
131
138
|
allRules[identifier] = rules.join(" ");
|
|
132
139
|
if (identifier.startsWith("_transform")) {
|
|
133
140
|
return addTransform(identifier, rules[0]);
|
|
@@ -135,42 +142,40 @@ function updateRules(identifier, rules) {
|
|
|
135
142
|
return true;
|
|
136
143
|
}
|
|
137
144
|
function insertStyleRules(rulesToInsert) {
|
|
138
|
-
if (!rulesToInsert.length)
|
|
139
|
-
return;
|
|
140
|
-
if (isClient && !sheet) {
|
|
141
|
-
if (process.env.NODE_ENV === "development")
|
|
142
|
-
throw "impossible";
|
|
145
|
+
if (!rulesToInsert.length || !sheet) {
|
|
143
146
|
return;
|
|
144
147
|
}
|
|
145
148
|
for (const { identifier, rules } of rulesToInsert) {
|
|
146
|
-
if (identifier
|
|
149
|
+
if (!shouldInsertStyleRules(identifier)) {
|
|
147
150
|
continue;
|
|
148
|
-
|
|
151
|
+
}
|
|
152
|
+
allSelectors[identifier] = rules.join("\n");
|
|
153
|
+
track(identifier);
|
|
149
154
|
updateRules(identifier, rules);
|
|
150
|
-
|
|
151
|
-
|
|
155
|
+
for (const rule of rules) {
|
|
156
|
+
if (process.env.NODE_ENV === "production") {
|
|
157
|
+
sheet.insertRule(rule, sheet.cssRules.length);
|
|
158
|
+
} else {
|
|
152
159
|
try {
|
|
153
160
|
sheet.insertRule(rule, sheet.cssRules.length);
|
|
154
161
|
} catch (err) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
console.groupEnd();
|
|
162
|
-
}
|
|
162
|
+
console.groupCollapsed(
|
|
163
|
+
`Error inserting rule into CSSStyleSheet: ${String(err)}`
|
|
164
|
+
);
|
|
165
|
+
console.log({ rule, rulesToInsert });
|
|
166
|
+
console.trace();
|
|
167
|
+
console.groupEnd();
|
|
163
168
|
}
|
|
164
169
|
}
|
|
165
170
|
}
|
|
166
171
|
}
|
|
167
172
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
if (IS_STATIC) {
|
|
173
|
+
function shouldInsertStyleRules(identifier) {
|
|
174
|
+
if (process.env.IS_STATIC === "is_static") {
|
|
171
175
|
return true;
|
|
172
176
|
}
|
|
173
|
-
|
|
177
|
+
const total = totalSelectorsInserted.get(identifier);
|
|
178
|
+
return total === void 0 || total < 2;
|
|
174
179
|
}
|
|
175
180
|
export {
|
|
176
181
|
getAllRules,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/helpers/insertStyleRule.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { RulesToInsert, StyleObject } from '../types.js'\n\nconst allSelectors: Record<string, string> = {}\nconst allRules: Record<string, string> = {}\nexport const insertedTransforms = {}\n\nexport const getAllSelectors = () => allSelectors\nexport const getAllRules = () => Object.values(allRules)\nexport const getAllTransforms = () => insertedTransforms\n\n// keep transforms in map for merging later\nfunction addTransform(identifier: string, css: string, rule?: CSSRule) {\n const s = css.indexOf('transform:')\n if (s === -1) {\n if (process.env.NODE_ENV === 'development') {\n console.error(`\u274C Invalid transform, likely used deg/% improperly ${identifier}`)\n }\n return
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { isClient } from '@tamagui/constants'\n\nimport type { RulesToInsert, StyleObject } from '../types.js'\n\nconst allSelectors: Record<string, string> = {}\nconst allRules: Record<string, string> = {}\nexport const insertedTransforms = {}\n\nexport const getAllSelectors = () => allSelectors\nexport const getAllRules = () => Object.values(allRules)\nexport const getAllTransforms = () => insertedTransforms\n\n// keep transforms in map for merging later\nfunction addTransform(identifier: string, css: string, rule?: CSSRule) {\n const s = css.indexOf('transform:')\n if (s === -1) {\n if (process.env.NODE_ENV === 'development') {\n console.error(`\u274C Invalid transform, likely used deg/% improperly ${identifier}`)\n }\n return\n }\n const startI = s + 'transform:'.length\n const endI = css.indexOf(';')\n const value = css.slice(startI, endI)\n if (!insertedTransforms[identifier]) {\n insertedTransforms[identifier] = value\n return true\n }\n}\n\n// gets existing ones (client side)\n// takes ~0.1ms for a fairly large page\n// used now for three things:\n// 1. debugging at dev time\n// 2. avoid duplicate insert styles at runtime\n// 3. used now for merging transforms atomically\n\n// multiple sheets could have the same ids so we have to count\n\n// only cache tamagui styles\nconst scannedCache = new WeakMap<CSSStyleSheet, string>()\nconst totalSelectorsInserted = new Map<string, number>()\n\nexport function listenForSheetChanges() {\n if (!isClient) return\n\n const mo = new MutationObserver((entries) => {\n for (const entry of entries) {\n if (\n (entry instanceof HTMLStyleElement && entry.sheet) ||\n (entry instanceof HTMLLinkElement && entry.href.endsWith('.css'))\n ) {\n scanAllSheets()\n break\n }\n }\n })\n\n mo.observe(document.head, {\n childList: true,\n })\n}\n\nlet lastScannedSheets: Set<CSSStyleSheet> | null = null\n\nexport function scanAllSheets() {\n if (process.env.NODE_ENV === 'test') return\n if (!isClient) return\n\n const sheets = document.styleSheets || []\n const prev = lastScannedSheets\n const current = new Set(sheets as any as CSSStyleSheet[])\n if (document.styleSheets) {\n for (const sheet of current) {\n sheet && updateSheetStyles(sheet)\n }\n lastScannedSheets = current\n }\n\n if (prev) {\n for (const sheet of prev) {\n if (sheet && !current.has(sheet)) {\n updateSheetStyles(sheet, true)\n }\n }\n }\n}\n\nfunction track(id: string, remove = false) {\n const next = (totalSelectorsInserted.get(id) || 0) + (remove ? -1 : 1)\n totalSelectorsInserted.set(id, next)\n return next\n}\n\nfunction updateSheetStyles(sheet: CSSStyleSheet, remove = false) {\n // avoid errors on cross origin sheets\n // https://stackoverflow.com/questions/49993633/uncaught-domexception-failed-to-read-the-cssrules-property\n let rules: CSSRuleList\n try {\n rules = sheet.cssRules\n } catch {\n return\n }\n\n const firstSelector = getTamaguiSelector(rules[0])?.[0]\n const lastSelector = getTamaguiSelector(rules[rules.length - 1])?.[0]\n const cacheKey = `${rules.length}${firstSelector}${lastSelector}`\n const lastScanned = scannedCache.get(sheet)\n\n if (!remove) {\n // avoid re-scanning\n if (lastScanned === cacheKey) {\n return\n }\n }\n\n const len = rules.length\n let fails = 0\n\n for (let i = 0; i < len; i++) {\n const rule = rules[i]\n if (!(rule instanceof CSSStyleRule)) continue\n\n const response = getTamaguiSelector(rule)\n\n if (!response) {\n fails++\n if (fails > 5) {\n // conservatively bail out of non-tamagui sheets\n return\n }\n continue\n }\n\n const [identifier, cssRule] = response\n\n // track references\n const total = track(identifier, remove)\n\n if (remove) {\n if (total === 0) {\n delete allSelectors[identifier]\n }\n } else if (!(identifier in allSelectors)) {\n const isTransform = identifier.startsWith('_transform')\n const shouldInsert = isTransform\n ? addTransform(identifier, cssRule.cssText, cssRule)\n : true\n if (shouldInsert) {\n allSelectors[identifier] = cssRule.cssText\n }\n }\n }\n\n scannedCache.set(sheet, cacheKey)\n}\n\nfunction getTamaguiSelector(\n rule: CSSRule | null\n): readonly [string, CSSStyleRule] | null {\n if (rule instanceof CSSStyleRule) {\n const text = rule.selectorText\n if (text[0] === '.' && text[1] === '_') {\n return [text.slice(1), rule]\n }\n if (text.startsWith(':root') && text.includes('._')) {\n return [getIdentifierFromTamaguiSelector(text), rule]\n }\n } else if (rule instanceof CSSMediaRule) {\n // tamagui only ever inserts 1 rule per media\n if (rule.cssRules.length > 1) return null\n return getTamaguiSelector(rule.cssRules[0])\n }\n return null\n}\n\nconst getIdentifierFromTamaguiSelector = (selector: string) =>\n selector\n .replace(/(:root)+\\s+/, '')\n .replace(/:[a-z]+$/, '')\n .slice(1)\n\nconst sheet = isClient\n ? document.head.appendChild(document.createElement('style')).sheet\n : null\n\nexport function updateRules(identifier: string, rules: string[]) {\n if (identifier in allRules) {\n return false\n }\n allRules[identifier] = rules.join(' ')\n if (identifier.startsWith('_transform')) {\n return addTransform(identifier, rules[0])\n }\n return true\n}\n\nexport function insertStyleRules(rulesToInsert: RulesToInsert) {\n if (!rulesToInsert.length || !sheet) {\n return\n }\n\n for (const { identifier, rules } of rulesToInsert) {\n if (!shouldInsertStyleRules(identifier)) {\n continue\n }\n\n allSelectors[identifier] = rules.join('\\n')\n track(identifier)\n updateRules(identifier, rules)\n\n for (const rule of rules) {\n if (process.env.NODE_ENV === 'production') {\n sheet.insertRule(rule, sheet.cssRules.length)\n } else {\n try {\n sheet.insertRule(rule, sheet.cssRules.length)\n } catch (err) {\n console.groupCollapsed(\n `Error inserting rule into CSSStyleSheet: ${String(err)}`\n )\n console.log({ rule, rulesToInsert })\n console.trace()\n console.groupEnd()\n }\n }\n }\n }\n}\n\nexport function shouldInsertStyleRules(identifier: string) {\n if (process.env.IS_STATIC === 'is_static') {\n return true\n }\n const total = totalSelectorsInserted.get(identifier)\n // note, -1, we are being conservative and leaving some in\n return total === undefined || total < 2\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,gBAAgB;AAIzB,MAAM,eAAuC,CAAC;AAC9C,MAAM,WAAmC,CAAC;AACnC,MAAM,qBAAqB,CAAC;AAE5B,MAAM,kBAAkB,MAAM;AAC9B,MAAM,cAAc,MAAM,OAAO,OAAO,QAAQ;AAChD,MAAM,mBAAmB,MAAM;AAGtC,SAAS,aAAa,YAAoB,KAAa,MAAgB;AACrE,QAAM,IAAI,IAAI,QAAQ,YAAY;AAClC,MAAI,MAAM,IAAI;AACZ,QAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,cAAQ,MAAM,0DAAqD,YAAY;AAAA,IACjF;AACA;AAAA,EACF;AACA,QAAM,SAAS,IAAI,aAAa;AAChC,QAAM,OAAO,IAAI,QAAQ,GAAG;AAC5B,QAAM,QAAQ,IAAI,MAAM,QAAQ,IAAI;AACpC,MAAI,CAAC,mBAAmB,UAAU,GAAG;AACnC,uBAAmB,UAAU,IAAI;AACjC,WAAO;AAAA,EACT;AACF;AAYA,MAAM,eAAe,oBAAI,QAA+B;AACxD,MAAM,yBAAyB,oBAAI,IAAoB;AAEhD,SAAS,wBAAwB;AACtC,MAAI,CAAC;AAAU;AAEf,QAAM,KAAK,IAAI,iBAAiB,CAAC,YAAY;AAC3C,eAAW,SAAS,SAAS;AAC3B,UACG,i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ANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { stylePropsAll } from "@tamagui/helpers";
|
|
2
2
|
import { createComponent } from "./createComponent.js";
|
|
3
3
|
import { ReactNativeStaticConfigs } from "./setupReactNative.js";
|
|
4
|
-
function styled(
|
|
4
|
+
function styled(ComponentIn, options, staticExtractionOptions) {
|
|
5
5
|
if (process.env.NODE_ENV !== "production") {
|
|
6
|
-
if (!
|
|
6
|
+
if (!ComponentIn) {
|
|
7
7
|
throw new Error(`No component given to styled()`);
|
|
8
8
|
}
|
|
9
9
|
if (options == null ? void 0 : options.variants) {
|
|
10
10
|
for (const key in options.variants) {
|
|
11
11
|
if (key in stylePropsAll) {
|
|
12
12
|
console.error(
|
|
13
|
-
`Invalid variant key overlaps with style key: ${key}. Tamagui prevents defining variants that use valid style keys to reduce
|
|
13
|
+
`Invalid variant key overlaps with style key: ${key}. Tamagui prevents defining variants that use valid style keys to reduce complexity and confusion.`
|
|
14
14
|
);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
const parentStaticConfig = "staticConfig" in
|
|
20
|
-
const
|
|
19
|
+
const parentStaticConfig = "staticConfig" in ComponentIn ? ComponentIn.staticConfig : null;
|
|
20
|
+
const isPlainStyledComponent = !!parentStaticConfig && !(parentStaticConfig.isReactNative || parentStaticConfig.isHOC);
|
|
21
|
+
const Component = isPlainStyledComponent ? ComponentIn : (parentStaticConfig == null ? void 0 : parentStaticConfig.Component) || ComponentIn;
|
|
21
22
|
const isReactNative = Boolean(
|
|
22
23
|
ReactNativeStaticConfigs.has(Component) || (staticExtractionOptions == null ? void 0 : staticExtractionOptions.isReactNative) || ReactNativeStaticConfigs.has(parentStaticConfig == null ? void 0 : parentStaticConfig.Component) || (parentStaticConfig == null ? void 0 : parentStaticConfig.isReactNative)
|
|
23
24
|
);
|
|
@@ -33,16 +34,15 @@ function styled(Component, options, staticExtractionOptions) {
|
|
|
33
34
|
if (defaultVariants) {
|
|
34
35
|
Object.assign(defaultProps, defaultVariants);
|
|
35
36
|
}
|
|
36
|
-
const
|
|
37
|
-
const nativeConf = isReactNative && ReactNativeStaticConfigs.get(Comp) || null;
|
|
37
|
+
const nativeConf = isReactNative && ReactNativeStaticConfigs.get(Component) || null;
|
|
38
38
|
const isText = Boolean(
|
|
39
39
|
(staticExtractionOptions == null ? void 0 : staticExtractionOptions.isText) || (parentStaticConfig == null ? void 0 : parentStaticConfig.isText)
|
|
40
40
|
);
|
|
41
|
-
const acceptsClassName = acceptsClassNameProp ?? (
|
|
41
|
+
const acceptsClassName = acceptsClassNameProp ?? (isPlainStyledComponent || isReactNative);
|
|
42
42
|
const conf = {
|
|
43
43
|
...staticExtractionOptions,
|
|
44
|
-
...!
|
|
45
|
-
Component
|
|
44
|
+
...!isPlainStyledComponent && {
|
|
45
|
+
Component
|
|
46
46
|
},
|
|
47
47
|
// this type gets messed up by options?: Partial<GetProps<ParentComponent>> above
|
|
48
48
|
// take away the Partial<> and it's fine
|
package/dist/esm/styled.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/styled.tsx"],
|
|
4
|
-
"sourcesContent": ["import { stylePropsAll } from '@tamagui/helpers'\nimport { forwardRef } from 'react'\n\nimport { createComponent } from './createComponent.js'\nimport { ReactNativeStaticConfigs } from './setupReactNative.js'\nimport type {\n GetProps,\n GetVariantValues,\n MediaProps,\n PseudoProps,\n StaticConfig,\n StylableComponent,\n TamaguiComponent,\n TamaguiElement,\n VariantDefinitions,\n VariantSpreadFunction,\n} from './types.js'\n\n// TODO may be able to use this in the options?: arg below directly\nexport type StyledOptions<ParentComponent extends StylableComponent> =\n GetProps<ParentComponent> & {\n name?: string\n variants?: VariantDefinitions<ParentComponent> | undefined\n defaultVariants?: { [key: string]: any }\n }\n\ntype GetBaseProps<A extends StylableComponent> = A extends TamaguiComponent<\n any,\n any,\n infer P\n>\n ? P\n : GetProps<A>\n\ntype GetVariantProps<A extends StylableComponent> = A extends TamaguiComponent<\n any,\n any,\n any,\n infer V\n>\n ? V\n : {}\n\nexport function styled<\n ParentComponent extends StylableComponent,\n Variants extends VariantDefinitions<ParentComponent> | void = VariantDefinitions<ParentComponent> | void\n>(\n
|
|
5
|
-
"mappings": "AAAA,SAAS,qBAAqB;AAG9B,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AAuClC,SAAS,OAId,
|
|
4
|
+
"sourcesContent": ["import { stylePropsAll } from '@tamagui/helpers'\nimport { forwardRef } from 'react'\n\nimport { createComponent } from './createComponent.js'\nimport { ReactNativeStaticConfigs } from './setupReactNative.js'\nimport type {\n GetProps,\n GetVariantValues,\n MediaProps,\n PseudoProps,\n StaticConfig,\n StylableComponent,\n TamaguiComponent,\n TamaguiElement,\n VariantDefinitions,\n VariantSpreadFunction,\n} from './types.js'\n\n// TODO may be able to use this in the options?: arg below directly\nexport type StyledOptions<ParentComponent extends StylableComponent> =\n GetProps<ParentComponent> & {\n name?: string\n variants?: VariantDefinitions<ParentComponent> | undefined\n defaultVariants?: { [key: string]: any }\n }\n\ntype GetBaseProps<A extends StylableComponent> = A extends TamaguiComponent<\n any,\n any,\n infer P\n>\n ? P\n : GetProps<A>\n\ntype GetVariantProps<A extends StylableComponent> = A extends TamaguiComponent<\n any,\n any,\n any,\n infer V\n>\n ? V\n : {}\n\nexport function styled<\n ParentComponent extends StylableComponent,\n Variants extends VariantDefinitions<ParentComponent> | void = VariantDefinitions<ParentComponent> | void\n>(\n ComponentIn: ParentComponent,\n // this should be Partial<GetProps<ParentComponent>> but causes excessively deep type issues\n options?: GetProps<ParentComponent> & {\n name?: string\n variants?: Variants | undefined\n // thought i had this typed, but can't get it linked\n defaultVariants?: { [key: string]: any }\n acceptsClassName?: boolean\n },\n staticExtractionOptions?: Partial<StaticConfig>\n) {\n // validate not using a variant over an existing valid style\n if (process.env.NODE_ENV !== 'production') {\n if (!ComponentIn) {\n throw new Error(`No component given to styled()`)\n }\n if (options?.variants) {\n for (const key in options.variants) {\n if (key in stylePropsAll) {\n console.error(\n `Invalid variant key overlaps with style key: ${key}. Tamagui prevents defining variants that use valid style keys to reduce complexity and confusion.`\n )\n }\n }\n }\n }\n\n const parentStaticConfig =\n 'staticConfig' in ComponentIn ? (ComponentIn.staticConfig as StaticConfig) : null\n\n const isPlainStyledComponent =\n !!parentStaticConfig &&\n !(parentStaticConfig.isReactNative || parentStaticConfig.isHOC)\n\n const Component: any = isPlainStyledComponent\n ? ComponentIn\n : parentStaticConfig?.Component || ComponentIn\n\n const isReactNative = Boolean(\n ReactNativeStaticConfigs.has(Component) ||\n staticExtractionOptions?.isReactNative ||\n ReactNativeStaticConfigs.has(parentStaticConfig?.Component) ||\n parentStaticConfig?.isReactNative\n )\n\n const staticConfigProps = (() => {\n if (options) {\n const {\n variants,\n name,\n defaultVariants,\n acceptsClassName: acceptsClassNameProp,\n ...defaultProps\n } = options\n if (defaultVariants) {\n Object.assign(defaultProps, defaultVariants)\n }\n\n const nativeConf =\n (isReactNative && ReactNativeStaticConfigs.get(Component)) || null\n\n const isText = Boolean(\n staticExtractionOptions?.isText || parentStaticConfig?.isText\n )\n const acceptsClassName =\n acceptsClassNameProp ?? (isPlainStyledComponent || isReactNative)\n\n const conf: Partial<StaticConfig> = {\n ...staticExtractionOptions,\n ...(!isPlainStyledComponent && {\n Component,\n }),\n // this type gets messed up by options?: Partial<GetProps<ParentComponent>> above\n // take away the Partial<> and it's fine\n variants,\n defaultProps,\n defaultVariants,\n componentName: name || parentStaticConfig?.componentName,\n isReactNative,\n isText,\n acceptsClassName,\n ...nativeConf,\n }\n\n // bail on non className views as well\n if (defaultProps.children || !acceptsClassName) {\n conf.neverFlatten = true\n }\n\n return conf\n }\n })()\n\n const component = createComponent(staticConfigProps || {}, Component)\n\n // get parent props without pseudos and medias so we can rebuild both with new variants\n // get parent props without pseudos and medias so we can rebuild both with new variants\n type ParentPropsBase = GetBaseProps<ParentComponent>\n type ParentVariants = GetVariantProps<ParentComponent>\n\n type OurVariants = Variants extends void\n ? {}\n : {\n [Key in keyof Variants]?: Variants[Key] extends VariantSpreadFunction<\n any,\n infer Val\n >\n ? Val\n : GetVariantValues<keyof Variants[Key]>\n }\n\n type VariantProps = Omit<ParentVariants, keyof OurVariants> & OurVariants\n type OurPropsBase = ParentPropsBase & VariantProps\n\n type Props = Variants extends void\n ? GetProps<ParentComponent>\n : // start with base props\n OurPropsBase &\n // add in media (+ pseudos nested)\n MediaProps<Partial<OurPropsBase>> &\n // add in pseudos\n PseudoProps<Partial<OurPropsBase>>\n\n type StyledComponent = TamaguiComponent<\n Props,\n TamaguiElement,\n ParentPropsBase,\n ParentVariants & OurVariants\n >\n\n return component as StyledComponent\n}\n\n// sanity check types\n// import { Stack } from './views/Stack'\n// const X = styled(Stack, {\n// variants: {\n// size: {\n// '...size': (val) => {\n// return {\n// pointerEvents: 'auto'\n// }\n// }\n// },\n// disabled: {\n// true: {\n// alignContent: 'center',\n// opacity: 0.5,\n// pointerEvents: 'none',\n// },\n// },\n// } as const\n// })\n// // type variants = GetStyledVariants<typeof X>\n// const y = <X disabled size=\"$10\" />\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAqB;AAG9B,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AAuClC,SAAS,OAId,aAEA,SAOA,yBACA;AAEA,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,gCAAgC;AAAA,IAClD;AACA,QAAI,mCAAS,UAAU;AACrB,iBAAW,OAAO,QAAQ,UAAU;AAClC,YAAI,OAAO,eAAe;AACxB,kBAAQ;AAAA,YACN,gDAAgD;AAAA,UAClD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,qBACJ,kBAAkB,cAAe,YAAY,eAAgC;AAE/E,QAAM,yBACJ,CAAC,CAAC,sBACF,EAAE,mBAAmB,iBAAiB,mBAAmB;AAE3D,QAAM,YAAiB,yBACnB,eACA,yDAAoB,cAAa;AAErC,QAAM,gBAAgB;AAAA,IACpB,yBAAyB,IAAI,SAAS,MACpC,mEAAyB,kBACzB,yBAAyB,IAAI,yDAAoB,SAAS,MAC1D,yDAAoB;AAAA,EACxB;AAEA,QAAM,qBAAqB,MAAM;AAC/B,QAAI,SAAS;AACX,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA,kBAAkB;AAAA,QAClB,GAAG;AAAA,MACL,IAAI;AACJ,UAAI,iBAAiB;AACnB,eAAO,OAAO,cAAc,eAAe;AAAA,MAC7C;AAEA,YAAM,aACH,iBAAiB,yBAAyB,IAAI,SAAS,KAAM;AAEhE,YAAM,SAAS;AAAA,SACb,mEAAyB,YAAU,yDAAoB;AAAA,MACzD;AACA,YAAM,mBACJ,yBAAyB,0BAA0B;AAErD,YAAM,OAA8B;AAAA,QAClC,GAAG;AAAA,QACH,GAAI,CAAC,0BAA0B;AAAA,UAC7B;AAAA,QACF;AAAA;AAAA;AAAA,QAGA;AAAA,QACA;AAAA,QACA;AAAA,QACA,eAAe,SAAQ,yDAAoB;AAAA,QAC3C;AAAA,QACA;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL;AAGA,UAAI,aAAa,YAAY,CAAC,kBAAkB;AAC9C,aAAK,eAAe;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AAAA,EACF,GAAG;AAEH,QAAM,YAAY,gBAAgB,qBAAqB,CAAC,GAAG,SAAS;AAqCpE,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/styled.mjs
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import { stylePropsAll } from "@tamagui/helpers";
|
|
2
2
|
import { createComponent } from "./createComponent.js";
|
|
3
3
|
import { ReactNativeStaticConfigs } from "./setupReactNative.js";
|
|
4
|
-
function styled(
|
|
4
|
+
function styled(ComponentIn, options, staticExtractionOptions) {
|
|
5
5
|
if (process.env.NODE_ENV !== "production") {
|
|
6
|
-
if (!
|
|
6
|
+
if (!ComponentIn) {
|
|
7
7
|
throw new Error(`No component given to styled()`);
|
|
8
8
|
}
|
|
9
9
|
if (options == null ? void 0 : options.variants) {
|
|
10
10
|
for (const key in options.variants) {
|
|
11
11
|
if (key in stylePropsAll) {
|
|
12
12
|
console.error(
|
|
13
|
-
`Invalid variant key overlaps with style key: ${key}. Tamagui prevents defining variants that use valid style keys to reduce
|
|
13
|
+
`Invalid variant key overlaps with style key: ${key}. Tamagui prevents defining variants that use valid style keys to reduce complexity and confusion.`
|
|
14
14
|
);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
const parentStaticConfig = "staticConfig" in
|
|
20
|
-
const
|
|
19
|
+
const parentStaticConfig = "staticConfig" in ComponentIn ? ComponentIn.staticConfig : null;
|
|
20
|
+
const isPlainStyledComponent = !!parentStaticConfig && !(parentStaticConfig.isReactNative || parentStaticConfig.isHOC);
|
|
21
|
+
const Component = isPlainStyledComponent ? ComponentIn : (parentStaticConfig == null ? void 0 : parentStaticConfig.Component) || ComponentIn;
|
|
21
22
|
const isReactNative = Boolean(
|
|
22
23
|
ReactNativeStaticConfigs.has(Component) || (staticExtractionOptions == null ? void 0 : staticExtractionOptions.isReactNative) || ReactNativeStaticConfigs.has(parentStaticConfig == null ? void 0 : parentStaticConfig.Component) || (parentStaticConfig == null ? void 0 : parentStaticConfig.isReactNative)
|
|
23
24
|
);
|
|
@@ -33,16 +34,15 @@ function styled(Component, options, staticExtractionOptions) {
|
|
|
33
34
|
if (defaultVariants) {
|
|
34
35
|
Object.assign(defaultProps, defaultVariants);
|
|
35
36
|
}
|
|
36
|
-
const
|
|
37
|
-
const nativeConf = isReactNative && ReactNativeStaticConfigs.get(Comp) || null;
|
|
37
|
+
const nativeConf = isReactNative && ReactNativeStaticConfigs.get(Component) || null;
|
|
38
38
|
const isText = Boolean(
|
|
39
39
|
(staticExtractionOptions == null ? void 0 : staticExtractionOptions.isText) || (parentStaticConfig == null ? void 0 : parentStaticConfig.isText)
|
|
40
40
|
);
|
|
41
|
-
const acceptsClassName = acceptsClassNameProp ?? (
|
|
41
|
+
const acceptsClassName = acceptsClassNameProp ?? (isPlainStyledComponent || isReactNative);
|
|
42
42
|
const conf = {
|
|
43
43
|
...staticExtractionOptions,
|
|
44
|
-
...!
|
|
45
|
-
Component
|
|
44
|
+
...!isPlainStyledComponent && {
|
|
45
|
+
Component
|
|
46
46
|
},
|
|
47
47
|
// this type gets messed up by options?: Partial<GetProps<ParentComponent>> above
|
|
48
48
|
// take away the Partial<> and it's fine
|
package/dist/esm/styled.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/styled.tsx"],
|
|
4
|
-
"sourcesContent": ["import { stylePropsAll } from '@tamagui/helpers'\nimport { forwardRef } from 'react'\n\nimport { createComponent } from './createComponent.js'\nimport { ReactNativeStaticConfigs } from './setupReactNative.js'\nimport type {\n GetProps,\n GetVariantValues,\n MediaProps,\n PseudoProps,\n StaticConfig,\n StylableComponent,\n TamaguiComponent,\n TamaguiElement,\n VariantDefinitions,\n VariantSpreadFunction,\n} from './types.js'\n\n// TODO may be able to use this in the options?: arg below directly\nexport type StyledOptions<ParentComponent extends StylableComponent> =\n GetProps<ParentComponent> & {\n name?: string\n variants?: VariantDefinitions<ParentComponent> | undefined\n defaultVariants?: { [key: string]: any }\n }\n\ntype GetBaseProps<A extends StylableComponent> = A extends TamaguiComponent<\n any,\n any,\n infer P\n>\n ? P\n : GetProps<A>\n\ntype GetVariantProps<A extends StylableComponent> = A extends TamaguiComponent<\n any,\n any,\n any,\n infer V\n>\n ? V\n : {}\n\nexport function styled<\n ParentComponent extends StylableComponent,\n Variants extends VariantDefinitions<ParentComponent> | void = VariantDefinitions<ParentComponent> | void\n>(\n
|
|
5
|
-
"mappings": "AAAA,SAAS,qBAAqB;AAG9B,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AAuClC,SAAS,OAId,
|
|
4
|
+
"sourcesContent": ["import { stylePropsAll } from '@tamagui/helpers'\nimport { forwardRef } from 'react'\n\nimport { createComponent } from './createComponent.js'\nimport { ReactNativeStaticConfigs } from './setupReactNative.js'\nimport type {\n GetProps,\n GetVariantValues,\n MediaProps,\n PseudoProps,\n StaticConfig,\n StylableComponent,\n TamaguiComponent,\n TamaguiElement,\n VariantDefinitions,\n VariantSpreadFunction,\n} from './types.js'\n\n// TODO may be able to use this in the options?: arg below directly\nexport type StyledOptions<ParentComponent extends StylableComponent> =\n GetProps<ParentComponent> & {\n name?: string\n variants?: VariantDefinitions<ParentComponent> | undefined\n defaultVariants?: { [key: string]: any }\n }\n\ntype GetBaseProps<A extends StylableComponent> = A extends TamaguiComponent<\n any,\n any,\n infer P\n>\n ? P\n : GetProps<A>\n\ntype GetVariantProps<A extends StylableComponent> = A extends TamaguiComponent<\n any,\n any,\n any,\n infer V\n>\n ? V\n : {}\n\nexport function styled<\n ParentComponent extends StylableComponent,\n Variants extends VariantDefinitions<ParentComponent> | void = VariantDefinitions<ParentComponent> | void\n>(\n ComponentIn: ParentComponent,\n // this should be Partial<GetProps<ParentComponent>> but causes excessively deep type issues\n options?: GetProps<ParentComponent> & {\n name?: string\n variants?: Variants | undefined\n // thought i had this typed, but can't get it linked\n defaultVariants?: { [key: string]: any }\n acceptsClassName?: boolean\n },\n staticExtractionOptions?: Partial<StaticConfig>\n) {\n // validate not using a variant over an existing valid style\n if (process.env.NODE_ENV !== 'production') {\n if (!ComponentIn) {\n throw new Error(`No component given to styled()`)\n }\n if (options?.variants) {\n for (const key in options.variants) {\n if (key in stylePropsAll) {\n console.error(\n `Invalid variant key overlaps with style key: ${key}. Tamagui prevents defining variants that use valid style keys to reduce complexity and confusion.`\n )\n }\n }\n }\n }\n\n const parentStaticConfig =\n 'staticConfig' in ComponentIn ? (ComponentIn.staticConfig as StaticConfig) : null\n\n const isPlainStyledComponent =\n !!parentStaticConfig &&\n !(parentStaticConfig.isReactNative || parentStaticConfig.isHOC)\n\n const Component: any = isPlainStyledComponent\n ? ComponentIn\n : parentStaticConfig?.Component || ComponentIn\n\n const isReactNative = Boolean(\n ReactNativeStaticConfigs.has(Component) ||\n staticExtractionOptions?.isReactNative ||\n ReactNativeStaticConfigs.has(parentStaticConfig?.Component) ||\n parentStaticConfig?.isReactNative\n )\n\n const staticConfigProps = (() => {\n if (options) {\n const {\n variants,\n name,\n defaultVariants,\n acceptsClassName: acceptsClassNameProp,\n ...defaultProps\n } = options\n if (defaultVariants) {\n Object.assign(defaultProps, defaultVariants)\n }\n\n const nativeConf =\n (isReactNative && ReactNativeStaticConfigs.get(Component)) || null\n\n const isText = Boolean(\n staticExtractionOptions?.isText || parentStaticConfig?.isText\n )\n const acceptsClassName =\n acceptsClassNameProp ?? (isPlainStyledComponent || isReactNative)\n\n const conf: Partial<StaticConfig> = {\n ...staticExtractionOptions,\n ...(!isPlainStyledComponent && {\n Component,\n }),\n // this type gets messed up by options?: Partial<GetProps<ParentComponent>> above\n // take away the Partial<> and it's fine\n variants,\n defaultProps,\n defaultVariants,\n componentName: name || parentStaticConfig?.componentName,\n isReactNative,\n isText,\n acceptsClassName,\n ...nativeConf,\n }\n\n // bail on non className views as well\n if (defaultProps.children || !acceptsClassName) {\n conf.neverFlatten = true\n }\n\n return conf\n }\n })()\n\n const component = createComponent(staticConfigProps || {}, Component)\n\n // get parent props without pseudos and medias so we can rebuild both with new variants\n // get parent props without pseudos and medias so we can rebuild both with new variants\n type ParentPropsBase = GetBaseProps<ParentComponent>\n type ParentVariants = GetVariantProps<ParentComponent>\n\n type OurVariants = Variants extends void\n ? {}\n : {\n [Key in keyof Variants]?: Variants[Key] extends VariantSpreadFunction<\n any,\n infer Val\n >\n ? Val\n : GetVariantValues<keyof Variants[Key]>\n }\n\n type VariantProps = Omit<ParentVariants, keyof OurVariants> & OurVariants\n type OurPropsBase = ParentPropsBase & VariantProps\n\n type Props = Variants extends void\n ? GetProps<ParentComponent>\n : // start with base props\n OurPropsBase &\n // add in media (+ pseudos nested)\n MediaProps<Partial<OurPropsBase>> &\n // add in pseudos\n PseudoProps<Partial<OurPropsBase>>\n\n type StyledComponent = TamaguiComponent<\n Props,\n TamaguiElement,\n ParentPropsBase,\n ParentVariants & OurVariants\n >\n\n return component as StyledComponent\n}\n\n// sanity check types\n// import { Stack } from './views/Stack'\n// const X = styled(Stack, {\n// variants: {\n// size: {\n// '...size': (val) => {\n// return {\n// pointerEvents: 'auto'\n// }\n// }\n// },\n// disabled: {\n// true: {\n// alignContent: 'center',\n// opacity: 0.5,\n// pointerEvents: 'none',\n// },\n// },\n// } as const\n// })\n// // type variants = GetStyledVariants<typeof X>\n// const y = <X disabled size=\"$10\" />\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,qBAAqB;AAG9B,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AAuClC,SAAS,OAId,aAEA,SAOA,yBACA;AAEA,MAAI,QAAQ,IAAI,aAAa,cAAc;AACzC,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI,MAAM,gCAAgC;AAAA,IAClD;AACA,QAAI,mCAAS,UAAU;AACrB,iBAAW,OAAO,QAAQ,UAAU;AAClC,YAAI,OAAO,eAAe;AACxB,kBAAQ;AAAA,YACN,gDAAgD;AAAA,UAClD;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,qBACJ,kBAAkB,cAAe,YAAY,eAAgC;AAE/E,QAAM,yBACJ,CAAC,CAAC,sBACF,EAAE,mBAAmB,iBAAiB,mBAAmB;AAE3D,QAAM,YAAiB,yBACnB,eACA,yDAAoB,cAAa;AAErC,QAAM,gBAAgB;AAAA,IACpB,yBAAyB,IAAI,SAAS,MACpC,mEAAyB,kBACzB,yBAAyB,IAAI,yDAAoB,SAAS,MAC1D,yDAAoB;AAAA,EACxB;AAEA,QAAM,qBAAqB,MAAM;AAC/B,QAAI,SAAS;AACX,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA,kBAAkB;AAAA,QAClB,GAAG;AAAA,MACL,IAAI;AACJ,UAAI,iBAAiB;AACnB,eAAO,OAAO,cAAc,eAAe;AAAA,MAC7C;AAEA,YAAM,aACH,iBAAiB,yBAAyB,IAAI,SAAS,KAAM;AAEhE,YAAM,SAAS;AAAA,SACb,mEAAyB,YAAU,yDAAoB;AAAA,MACzD;AACA,YAAM,mBACJ,yBAAyB,0BAA0B;AAErD,YAAM,OAA8B;AAAA,QAClC,GAAG;AAAA,QACH,GAAI,CAAC,0BAA0B;AAAA,UAC7B;AAAA,QACF;AAAA;AAAA;AAAA,QAGA;AAAA,QACA;AAAA,QACA;AAAA,QACA,eAAe,SAAQ,yDAAoB;AAAA,QAC3C;AAAA,QACA;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL;AAGA,UAAI,aAAa,YAAY,CAAC,kBAAkB;AAC9C,aAAK,eAAe;AAAA,MACtB;AAEA,aAAO;AAAA,IACT;AAAA,EACF,GAAG;AAEH,QAAM,YAAY,gBAAgB,qBAAqB,CAAC,GAAG,SAAS;AAqCpE,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -27,19 +27,19 @@
|
|
|
27
27
|
"reset.css"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@tamagui/compose-refs": "1.
|
|
31
|
-
"@tamagui/constants": "1.
|
|
32
|
-
"@tamagui/helpers": "1.
|
|
33
|
-
"@tamagui/normalize-css-color": "1.
|
|
34
|
-
"@tamagui/use-did-finish-ssr": "1.
|
|
35
|
-
"@tamagui/use-event": "1.
|
|
36
|
-
"@tamagui/use-force-update": "1.
|
|
30
|
+
"@tamagui/compose-refs": "1.12.0",
|
|
31
|
+
"@tamagui/constants": "1.12.0",
|
|
32
|
+
"@tamagui/helpers": "1.12.0",
|
|
33
|
+
"@tamagui/normalize-css-color": "1.12.0",
|
|
34
|
+
"@tamagui/use-did-finish-ssr": "1.12.0",
|
|
35
|
+
"@tamagui/use-event": "1.12.0",
|
|
36
|
+
"@tamagui/use-force-update": "1.12.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": "*"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@tamagui/build": "1.
|
|
42
|
+
"@tamagui/build": "1.12.0",
|
|
43
43
|
"@testing-library/react": "^13.4.0",
|
|
44
44
|
"csstype": "^3.0.10",
|
|
45
45
|
"react": "^18.2.0",
|
package/src/createComponent.tsx
CHANGED
|
@@ -10,6 +10,7 @@ import React, {
|
|
|
10
10
|
useCallback,
|
|
11
11
|
useContext,
|
|
12
12
|
useEffect,
|
|
13
|
+
useId,
|
|
13
14
|
useRef,
|
|
14
15
|
} from 'react'
|
|
15
16
|
|
|
@@ -20,7 +21,6 @@ import { TextAncestorContext } from './contexts/TextAncestorContext.js'
|
|
|
20
21
|
import { didGetVariableValue, setDidGetVariableValue } from './createVariable.js'
|
|
21
22
|
import { extendStaticConfig, parseStaticConfig } from './helpers/extendStaticConfig.js'
|
|
22
23
|
import { useSplitStyles } from './helpers/getSplitStyles.js'
|
|
23
|
-
import { getAllSelectors } from './helpers/insertStyleRule.js'
|
|
24
24
|
import { mergeProps } from './helpers/mergeProps.js'
|
|
25
25
|
import { proxyThemeVariables } from './helpers/proxyThemeVariables.js'
|
|
26
26
|
import { useShallowSetState } from './helpers/useShallowSetState.js'
|
|
@@ -263,12 +263,14 @@ export function createComponent<
|
|
|
263
263
|
const isReactNative = Boolean(staticConfig.isReactNative || isAnimatedReactNative)
|
|
264
264
|
|
|
265
265
|
if (process.env.NODE_ENV === 'development') {
|
|
266
|
+
const id = useId()
|
|
267
|
+
|
|
266
268
|
if (debugProp) {
|
|
267
269
|
// prettier-ignore
|
|
268
270
|
const name = `${componentName || Component?.displayName || Component?.name || '[Unnamed Component]'}`
|
|
269
271
|
const type = isAnimatedReactNative ? '(animated)' : isReactNative ? '(rnw)' : ''
|
|
270
272
|
const dataIs = propsIn['data-is'] || ''
|
|
271
|
-
const banner = `${name}${dataIs ? ` ${dataIs}` : ''} ${type}`
|
|
273
|
+
const banner = `${name}${dataIs ? ` ${dataIs}` : ''} ${type} id ${id}`
|
|
272
274
|
console.group(`%c ${banner}`, 'background: yellow;')
|
|
273
275
|
if (!isServer) {
|
|
274
276
|
console.log('state', state)
|
|
@@ -760,7 +762,7 @@ export function createComponent<
|
|
|
760
762
|
console.groupEnd()
|
|
761
763
|
if (typeof window !== 'undefined') {
|
|
762
764
|
// prettier-ignore
|
|
763
|
-
console.log({ state, themeState, isAnimated, isAnimatedReactNativeWeb, tamaguiDefaultProps, viewProps, splitStyles, animationStyles, handlesPressEvents, isStringElement, classNamesIn: props.className?.split(' '), classNamesOut: viewProps.className?.split(' '), events, shouldAttach, styles, pseudos, content, shouldAvoidClasses, avoidClasses: avoidClassesWhileAnimating, animation: props.animation, style: splitStylesStyle, staticConfig, tamaguiConfig, shouldForcePseudo
|
|
765
|
+
console.log({ state, themeState, isAnimated, isAnimatedReactNativeWeb, tamaguiDefaultProps, viewProps, splitStyles, animationStyles, handlesPressEvents, isStringElement, classNamesIn: props.className?.split(' '), classNamesOut: viewProps.className?.split(' '), events, shouldAttach, styles, pseudos, content, shouldAvoidClasses, avoidClasses: avoidClassesWhileAnimating, animation: props.animation, style: splitStylesStyle, staticConfig, tamaguiConfig, shouldForcePseudo })
|
|
764
766
|
}
|
|
765
767
|
console.groupEnd()
|
|
766
768
|
}
|
|
@@ -1126,12 +1126,6 @@ export const getSubStyle = (
|
|
|
1126
1126
|
return styleOut
|
|
1127
1127
|
}
|
|
1128
1128
|
|
|
1129
|
-
export const insertSplitStyles: StyleSplitter = (...args) => {
|
|
1130
|
-
const res = getSplitStyles(...args)
|
|
1131
|
-
insertStyleRules(res.rulesToInsert)
|
|
1132
|
-
return res
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
1129
|
// on native no need to insert any css
|
|
1136
1130
|
const useInsertEffectCompat = isWeb
|
|
1137
1131
|
? useInsertionEffect || useIsomorphicLayoutEffect
|
|
@@ -1151,7 +1145,7 @@ export const useSplitStyles: StyleSplitter = (...args) => {
|
|
|
1151
1145
|
|
|
1152
1146
|
function addStyleToInsertRules(rulesToInsert: RulesToInsert, styleObject: StyleObject) {
|
|
1153
1147
|
if (process.env.TAMAGUI_TARGET === 'web') {
|
|
1154
|
-
if (!shouldInsertStyleRules(styleObject)) {
|
|
1148
|
+
if (!shouldInsertStyleRules(styleObject.identifier)) {
|
|
1155
1149
|
return
|
|
1156
1150
|
}
|
|
1157
1151
|
updateRules(styleObject.identifier, styleObject.rules)
|