@tamagui/size 0.0.0-bootstrap.0 → 3.0.0-beta.643.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/LICENSE +21 -0
- package/dist/cjs/index.cjs +149 -0
- package/dist/cjs/index.native.cjs +172 -0
- package/dist/cjs/index.native.js +174 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/esm/index.js +120 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +120 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +141 -0
- package/dist/esm/index.native.js.map +1 -0
- package/package.json +47 -4
- package/src/index.ts +278 -0
- package/types/index.d.ts +133 -0
- package/types/index.d.ts.map +11 -0
- package/README.md +0 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { createStyledContext } from "@tamagui/web";
|
|
2
|
+
|
|
3
|
+
const defaultTokenSizePolicy = {
|
|
4
|
+
size: 44,
|
|
5
|
+
space: "4",
|
|
6
|
+
radius: "4",
|
|
7
|
+
fontSize: "4"
|
|
8
|
+
};
|
|
9
|
+
const controlSizes = {
|
|
10
|
+
true: 44,
|
|
11
|
+
0: 0,
|
|
12
|
+
"0-25": 2,
|
|
13
|
+
"0-5": 4,
|
|
14
|
+
"0-75": 8,
|
|
15
|
+
1: 20,
|
|
16
|
+
"1-5": 24,
|
|
17
|
+
2: 28,
|
|
18
|
+
"2-5": 32,
|
|
19
|
+
3: 36,
|
|
20
|
+
"3-5": 40,
|
|
21
|
+
4: 44,
|
|
22
|
+
"4-5": 48,
|
|
23
|
+
5: 52,
|
|
24
|
+
6: 64,
|
|
25
|
+
7: 74,
|
|
26
|
+
8: 84,
|
|
27
|
+
9: 94,
|
|
28
|
+
10: 104,
|
|
29
|
+
11: 124,
|
|
30
|
+
12: 144,
|
|
31
|
+
13: 164,
|
|
32
|
+
14: 184,
|
|
33
|
+
15: 204,
|
|
34
|
+
16: 224,
|
|
35
|
+
17: 224,
|
|
36
|
+
18: 244,
|
|
37
|
+
19: 264,
|
|
38
|
+
20: 284
|
|
39
|
+
};
|
|
40
|
+
const resolveControlSize = (value, tokens) => {
|
|
41
|
+
if (typeof value === "number") return value;
|
|
42
|
+
const ramp = controlSizes[value];
|
|
43
|
+
return ramp ?? tokens.size[value];
|
|
44
|
+
};
|
|
45
|
+
const resolveSizeToken = (value, category, policy = defaultTokenSizePolicy) => {
|
|
46
|
+
return value === true ? policy[category] : value;
|
|
47
|
+
};
|
|
48
|
+
const createSizeContext = (defaultSize) => {
|
|
49
|
+
return createStyledContext({ size: defaultSize });
|
|
50
|
+
};
|
|
51
|
+
const SizeContext = createSizeContext();
|
|
52
|
+
const resolveTokenSize = (value, { tokens, font, policy = defaultTokenSizePolicy }) => {
|
|
53
|
+
if (typeof value === "number") {
|
|
54
|
+
return {
|
|
55
|
+
frame: {
|
|
56
|
+
size: value,
|
|
57
|
+
space: value,
|
|
58
|
+
radius: value
|
|
59
|
+
},
|
|
60
|
+
text: {
|
|
61
|
+
fontSize: value,
|
|
62
|
+
lineHeight: void 0
|
|
63
|
+
},
|
|
64
|
+
icon: value
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
const spaceKey = resolveSizeToken(value, "space", policy);
|
|
68
|
+
const radiusKey = resolveSizeToken(value, "radius", policy);
|
|
69
|
+
const fontKey = resolveSizeToken(value, "fontSize", policy);
|
|
70
|
+
const size = resolveControlSize(value, tokens);
|
|
71
|
+
const space = typeof spaceKey === "number" ? spaceKey : tokens.space[spaceKey];
|
|
72
|
+
const radius = typeof radiusKey === "number" ? radiusKey : tokens.radius[radiusKey];
|
|
73
|
+
const fontSize = typeof fontKey === "number" ? fontKey : font.size[fontKey];
|
|
74
|
+
const lineHeight = typeof fontKey === "number" ? void 0 : font.lineHeight?.[fontKey];
|
|
75
|
+
return {
|
|
76
|
+
frame: {
|
|
77
|
+
size,
|
|
78
|
+
space,
|
|
79
|
+
radius
|
|
80
|
+
},
|
|
81
|
+
text: {
|
|
82
|
+
fontSize,
|
|
83
|
+
lineHeight
|
|
84
|
+
},
|
|
85
|
+
icon: fontSize
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
const createSizeTable = (values, defaultSize) => {
|
|
89
|
+
const Context = createStyledContext({ size: defaultSize });
|
|
90
|
+
const frame = {};
|
|
91
|
+
const text = {};
|
|
92
|
+
const icon = {};
|
|
93
|
+
for (const name of Object.keys(values)) {
|
|
94
|
+
frame[name] = values[name].frame;
|
|
95
|
+
text[name] = values[name].text;
|
|
96
|
+
icon[name] = values[name].icon;
|
|
97
|
+
}
|
|
98
|
+
const resolve = ((name = defaultSize) => {
|
|
99
|
+
if (!(name in values)) {
|
|
100
|
+
if (process.env.NODE_ENV !== "production") {
|
|
101
|
+
console.error(`Unknown size "${String(name)}" \u2014 this size table only has: ${Object.keys(values).join(", ")}. Size tables are user-owned named scales; the default skins take size tokens instead. Falling back to "${String(defaultSize)}".`);
|
|
102
|
+
}
|
|
103
|
+
return values[defaultSize];
|
|
104
|
+
}
|
|
105
|
+
return values[name];
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
values,
|
|
109
|
+
names: Object.keys(values),
|
|
110
|
+
defaultSize,
|
|
111
|
+
Context,
|
|
112
|
+
frame,
|
|
113
|
+
text,
|
|
114
|
+
icon,
|
|
115
|
+
resolve
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export { SizeContext, controlSizes, createSizeContext, createSizeTable, defaultTokenSizePolicy, resolveControlSize, resolveSizeToken, resolveTokenSize };
|
|
120
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import {\n createStyledContext\n} from \"@tamagui/web\";\nconst defaultTokenSizePolicy = {\n // geometry consumers (Square, Circle) read the size scale directly and only\n // need a default token; control frame heights do NOT come from here, they\n // come from controlSizes below.\n size: 44,\n space: \"4\",\n radius: \"4\",\n fontSize: \"4\"\n};\nconst controlSizes = {\n true: 44,\n 0: 0,\n \"0-25\": 2,\n \"0-5\": 4,\n \"0-75\": 8,\n 1: 20,\n \"1-5\": 24,\n 2: 28,\n \"2-5\": 32,\n 3: 36,\n \"3-5\": 40,\n 4: 44,\n \"4-5\": 48,\n 5: 52,\n 6: 64,\n 7: 74,\n 8: 84,\n 9: 94,\n 10: 104,\n 11: 124,\n 12: 144,\n 13: 164,\n 14: 184,\n 15: 204,\n 16: 224,\n 17: 224,\n 18: 244,\n 19: 264,\n 20: 284\n};\nconst resolveControlSize = (value, tokens) => {\n if (typeof value === \"number\") return value;\n const ramp = controlSizes[value];\n return ramp ?? tokens.size[value];\n};\nconst resolveSizeToken = (value, category, policy = defaultTokenSizePolicy) => {\n return value === true ? policy[category] : value;\n};\nconst createSizeContext = (defaultSize) => {\n return createStyledContext({ size: defaultSize });\n};\nconst SizeContext = createSizeContext();\nconst resolveTokenSize = (value, { tokens, font, policy = defaultTokenSizePolicy }) => {\n if (typeof value === \"number\") {\n return {\n frame: { size: value, space: value, radius: value },\n text: { fontSize: value, lineHeight: void 0 },\n icon: value\n };\n }\n const spaceKey = resolveSizeToken(value, \"space\", policy);\n const radiusKey = resolveSizeToken(value, \"radius\", policy);\n const fontKey = resolveSizeToken(value, \"fontSize\", policy);\n const size = resolveControlSize(value, tokens);\n const space = typeof spaceKey === \"number\" ? spaceKey : tokens.space[spaceKey];\n const radius = typeof radiusKey === \"number\" ? radiusKey : tokens.radius[radiusKey];\n const fontSize = typeof fontKey === \"number\" ? fontKey : font.size[fontKey];\n const lineHeight = typeof fontKey === \"number\" ? void 0 : font.lineHeight?.[fontKey];\n return {\n frame: {\n size,\n space,\n radius\n },\n text: {\n fontSize,\n lineHeight\n },\n icon: fontSize\n };\n};\nconst createSizeTable = (values, defaultSize) => {\n const Context = createStyledContext({ size: defaultSize });\n const frame = {};\n const text = {};\n const icon = {};\n for (const name of Object.keys(values)) {\n frame[name] = values[name].frame;\n text[name] = values[name].text;\n icon[name] = values[name].icon;\n }\n const resolve = ((name = defaultSize) => {\n if (!(name in values)) {\n if (process.env.NODE_ENV !== \"production\") {\n console.error(\n `Unknown size \"${String(name)}\" \\u2014 this size table only has: ${Object.keys(values).join(\", \")}. Size tables are user-owned named scales; the default skins take size tokens instead. Falling back to \"${String(defaultSize)}\".`\n );\n }\n return values[defaultSize];\n }\n return values[name];\n });\n return {\n values,\n names: Object.keys(values),\n defaultSize,\n Context,\n frame,\n text,\n icon,\n resolve\n };\n};\nexport {\n SizeContext,\n controlSizes,\n createSizeContext,\n createSizeTable,\n defaultTokenSizePolicy,\n resolveControlSize,\n resolveSizeToken,\n resolveTokenSize\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;AAGA,MAAM,yBAAyB;CAI7B,MAAM;CACN,OAAO;CACP,QAAQ;CACR,UAAU;AACZ;AACA,MAAM,eAAe;CACnB,MAAM;CACN,GAAG;CACH,QAAQ;CACR,OAAO;CACP,QAAQ;CACR,GAAG;CACH,OAAO;CACP,GAAG;CACH,OAAO;CACP,GAAG;CACH,OAAO;CACP,GAAG;CACH,OAAO;CACP,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,GAAG;CACH,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;AACA,MAAM,sBAAsB,OAAO,WAAW;CAC5C,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,MAAM,OAAO,aAAa;CAC1B,OAAO,QAAQ,OAAO,KAAK;AAC7B;AACA,MAAM,oBAAoB,OAAO,UAAU,SAAS,2BAA2B;CAC7E,OAAO,UAAU,OAAO,OAAO,YAAY;AAC7C;AACA,MAAM,qBAAqB,gBAAgB;CACzC,OAAO,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD;AACA,MAAM,cAAc,kBAAkB;AACtC,M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W,EAAE,GAClO;GACF;GACA,OAAO,OAAO;EAChB;EACA,OAAO,OAAO;CAChB;CACA,OAAO;EACL;EACA,OAAO,OAAO,KAAK,MAAM;EACzB;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { createStyledContext } from "@tamagui/web";
|
|
2
|
+
|
|
3
|
+
var defaultTokenSizePolicy = {
|
|
4
|
+
size: 44,
|
|
5
|
+
space: "4",
|
|
6
|
+
radius: "4",
|
|
7
|
+
fontSize: "4"
|
|
8
|
+
};
|
|
9
|
+
var controlSizes = {
|
|
10
|
+
true: 44,
|
|
11
|
+
0: 0,
|
|
12
|
+
"0-25": 2,
|
|
13
|
+
"0-5": 4,
|
|
14
|
+
"0-75": 8,
|
|
15
|
+
1: 20,
|
|
16
|
+
"1-5": 24,
|
|
17
|
+
2: 28,
|
|
18
|
+
"2-5": 32,
|
|
19
|
+
3: 36,
|
|
20
|
+
"3-5": 40,
|
|
21
|
+
4: 44,
|
|
22
|
+
"4-5": 48,
|
|
23
|
+
5: 52,
|
|
24
|
+
6: 64,
|
|
25
|
+
7: 74,
|
|
26
|
+
8: 84,
|
|
27
|
+
9: 94,
|
|
28
|
+
10: 104,
|
|
29
|
+
11: 124,
|
|
30
|
+
12: 144,
|
|
31
|
+
13: 164,
|
|
32
|
+
14: 184,
|
|
33
|
+
15: 204,
|
|
34
|
+
16: 224,
|
|
35
|
+
17: 224,
|
|
36
|
+
18: 244,
|
|
37
|
+
19: 264,
|
|
38
|
+
20: 284
|
|
39
|
+
};
|
|
40
|
+
var resolveControlSize = function(value, tokens) {
|
|
41
|
+
if (typeof value === "number") return value;
|
|
42
|
+
var ramp = controlSizes[value];
|
|
43
|
+
return ramp !== null && ramp !== void 0 ? ramp : tokens.size[value];
|
|
44
|
+
};
|
|
45
|
+
var resolveSizeToken = function(value, category) {
|
|
46
|
+
var policy = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultTokenSizePolicy;
|
|
47
|
+
return value === true ? policy[category] : value;
|
|
48
|
+
};
|
|
49
|
+
var createSizeContext = function(defaultSize) {
|
|
50
|
+
return createStyledContext({ size: defaultSize });
|
|
51
|
+
};
|
|
52
|
+
var SizeContext = createSizeContext();
|
|
53
|
+
var resolveTokenSize = function(value, param) {
|
|
54
|
+
var { tokens, font, policy = defaultTokenSizePolicy } = param;
|
|
55
|
+
var _font_lineHeight;
|
|
56
|
+
if (typeof value === "number") {
|
|
57
|
+
return {
|
|
58
|
+
frame: {
|
|
59
|
+
size: value,
|
|
60
|
+
space: value,
|
|
61
|
+
radius: value
|
|
62
|
+
},
|
|
63
|
+
text: {
|
|
64
|
+
fontSize: value,
|
|
65
|
+
lineHeight: void 0
|
|
66
|
+
},
|
|
67
|
+
icon: value
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
var spaceKey = resolveSizeToken(value, "space", policy);
|
|
71
|
+
var radiusKey = resolveSizeToken(value, "radius", policy);
|
|
72
|
+
var fontKey = resolveSizeToken(value, "fontSize", policy);
|
|
73
|
+
var size = resolveControlSize(value, tokens);
|
|
74
|
+
var space = typeof spaceKey === "number" ? spaceKey : tokens.space[spaceKey];
|
|
75
|
+
var radius = typeof radiusKey === "number" ? radiusKey : tokens.radius[radiusKey];
|
|
76
|
+
var fontSize = typeof fontKey === "number" ? fontKey : font.size[fontKey];
|
|
77
|
+
var lineHeight = typeof fontKey === "number" ? void 0 : (_font_lineHeight = font.lineHeight) === null || _font_lineHeight === void 0 ? void 0 : _font_lineHeight[fontKey];
|
|
78
|
+
return {
|
|
79
|
+
frame: {
|
|
80
|
+
size,
|
|
81
|
+
space,
|
|
82
|
+
radius
|
|
83
|
+
},
|
|
84
|
+
text: {
|
|
85
|
+
fontSize,
|
|
86
|
+
lineHeight
|
|
87
|
+
},
|
|
88
|
+
icon: fontSize
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
var createSizeTable = function(values, defaultSize) {
|
|
92
|
+
var Context = createStyledContext({ size: defaultSize });
|
|
93
|
+
var frame = {};
|
|
94
|
+
var text = {};
|
|
95
|
+
var icon = {};
|
|
96
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
97
|
+
try {
|
|
98
|
+
for (var _iterator = Object.keys(values)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
99
|
+
var name = _step.value;
|
|
100
|
+
frame[name] = values[name].frame;
|
|
101
|
+
text[name] = values[name].text;
|
|
102
|
+
icon[name] = values[name].icon;
|
|
103
|
+
}
|
|
104
|
+
} catch (err) {
|
|
105
|
+
_didIteratorError = true;
|
|
106
|
+
_iteratorError = err;
|
|
107
|
+
} finally {
|
|
108
|
+
try {
|
|
109
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
110
|
+
_iterator.return();
|
|
111
|
+
}
|
|
112
|
+
} finally {
|
|
113
|
+
if (_didIteratorError) {
|
|
114
|
+
throw _iteratorError;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
var resolve = function() {
|
|
119
|
+
var name2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : defaultSize;
|
|
120
|
+
if (!(name2 in values)) {
|
|
121
|
+
if (process.env.NODE_ENV !== "production") {
|
|
122
|
+
console.error(`Unknown size "${String(name2)}" \u2014 this size table only has: ${Object.keys(values).join(", ")}. Size tables are user-owned named scales; the default skins take size tokens instead. Falling back to "${String(defaultSize)}".`);
|
|
123
|
+
}
|
|
124
|
+
return values[defaultSize];
|
|
125
|
+
}
|
|
126
|
+
return values[name2];
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
values,
|
|
130
|
+
names: Object.keys(values),
|
|
131
|
+
defaultSize,
|
|
132
|
+
Context,
|
|
133
|
+
frame,
|
|
134
|
+
text,
|
|
135
|
+
icon,
|
|
136
|
+
resolve
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export { SizeContext, controlSizes, createSizeContext, createSizeTable, defaultTokenSizePolicy, resolveControlSize, resolveSizeToken, resolveTokenSize };
|
|
141
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.native.js","names":[],"sources":["esm/index.native.js"],"sourcesContent":["import { createStyledContext } from \"@tamagui/web\";\nvar defaultTokenSizePolicy = {\n // geometry consumers (Square, Circle) read the size scale directly and only\n // need a default token; control frame heights do NOT come from here, they\n // come from controlSizes below.\n size: 44,\n space: \"4\",\n radius: \"4\",\n fontSize: \"4\"\n};\nvar controlSizes = {\n true: 44,\n 0: 0,\n \"0-25\": 2,\n \"0-5\": 4,\n \"0-75\": 8,\n 1: 20,\n \"1-5\": 24,\n 2: 28,\n \"2-5\": 32,\n 3: 36,\n \"3-5\": 40,\n 4: 44,\n \"4-5\": 48,\n 5: 52,\n 6: 64,\n 7: 74,\n 8: 84,\n 9: 94,\n 10: 104,\n 11: 124,\n 12: 144,\n 13: 164,\n 14: 184,\n 15: 204,\n 16: 224,\n 17: 224,\n 18: 244,\n 19: 264,\n 20: 284\n};\nvar resolveControlSize = function(value, tokens) {\n if (typeof value === \"number\") return value;\n var ramp = controlSizes[value];\n return ramp !== null && ramp !== void 0 ? ramp : tokens.size[value];\n};\nvar resolveSizeToken = function(value, category) {\n var policy = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultTokenSizePolicy;\n return value === true ? policy[category] : value;\n};\nvar createSizeContext = function(defaultSize) {\n return createStyledContext({\n size: defaultSize\n });\n};\nvar SizeContext = createSizeContext();\nvar resolveTokenSize = function(value, param) {\n var { tokens, font, policy = defaultTokenSizePolicy } = param;\n var _font_lineHeight;\n if (typeof value === \"number\") {\n return {\n frame: {\n size: value,\n space: value,\n radius: value\n },\n text: {\n fontSize: value,\n lineHeight: void 0\n },\n icon: value\n };\n }\n var spaceKey = resolveSizeToken(value, \"space\", policy);\n var radiusKey = resolveSizeToken(value, \"radius\", policy);\n var fontKey = resolveSizeToken(value, \"fontSize\", policy);\n var size = resolveControlSize(value, tokens);\n var space = typeof spaceKey === \"number\" ? spaceKey : tokens.space[spaceKey];\n var radius = typeof radiusKey === \"number\" ? radiusKey : tokens.radius[radiusKey];\n var fontSize = typeof fontKey === \"number\" ? fontKey : font.size[fontKey];\n var lineHeight = typeof fontKey === \"number\" ? void 0 : (_font_lineHeight = font.lineHeight) === null || _font_lineHeight === void 0 ? void 0 : _font_lineHeight[fontKey];\n return {\n frame: {\n size,\n space,\n radius\n },\n text: {\n fontSize,\n lineHeight\n },\n icon: fontSize\n };\n};\nvar createSizeTable = function(values, defaultSize) {\n var Context = createStyledContext({\n size: defaultSize\n });\n var frame = {};\n var text = {};\n var icon = {};\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = Object.keys(values)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var name = _step.value;\n frame[name] = values[name].frame;\n text[name] = values[name].text;\n icon[name] = values[name].icon;\n }\n } catch (err) {\n _didIteratorError = true;\n _iteratorError = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion && _iterator.return != null) {\n _iterator.return();\n }\n } finally {\n if (_didIteratorError) {\n throw _iteratorError;\n }\n }\n }\n var resolve = function() {\n var name2 = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : defaultSize;\n if (!(name2 in values)) {\n if (process.env.NODE_ENV !== \"production\") {\n console.error(`Unknown size \"${String(name2)}\" \\u2014 this size table only has: ${Object.keys(values).join(\", \")}. Size tables are user-owned named scales; the default skins take size tokens instead. Falling back to \"${String(defaultSize)}\".`);\n }\n return values[defaultSize];\n }\n return values[name2];\n };\n return {\n values,\n names: Object.keys(values),\n defaultSize,\n Context,\n frame,\n text,\n icon,\n resolve\n };\n};\nexport {\n SizeContext,\n controlSizes,\n createSizeContext,\n createSizeTable,\n defaultTokenSizePolicy,\n res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,UAAU,OAAO,KAAK,IAAI,UAAU,KAAK;EAC7E,IAAI,EAAE,SAAS,SAAS;GACtB,IAAI,QAAQ,IAAI,aAAa,cAAc;IACzC,QAAQ,MAAM,iBAAiB,OAAO,KAAK,EAAE,qCAAqC,OAAO,KAAK,MAAM,EAAE,KAAK,IAAI,EAAE,0GAA0G,OAAO,WAAW,EAAE,GAAG;GACpP;GACA,OAAO,OAAO;EAChB;EACA,OAAO,OAAO;CAChB;CACA,OAAO;EACL;EACA,OAAO,OAAO,KAAK,MAAM;EACzB;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/size",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"repository": "https://github.com/tamagui/tamagui",
|
|
3
|
+
"version": "3.0.0-beta.643.1",
|
|
4
|
+
"description": "Component-agnostic size context and skin table helpers",
|
|
6
5
|
"license": "MIT",
|
|
6
|
+
"source": "src/index.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"
|
|
8
|
+
"src",
|
|
9
|
+
"types",
|
|
10
|
+
"dist"
|
|
9
11
|
],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"main": "dist/cjs",
|
|
15
|
+
"module": "dist/esm",
|
|
16
|
+
"types": "./types/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
"./package.json": "./package.json",
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./types/index.d.ts",
|
|
21
|
+
"react-native": "./dist/esm/index.native.js",
|
|
22
|
+
"browser": "./dist/esm/index.mjs",
|
|
23
|
+
"module": "./dist/esm/index.mjs",
|
|
24
|
+
"import": "./dist/esm/index.mjs",
|
|
25
|
+
"require": "./dist/cjs/index.cjs",
|
|
26
|
+
"default": "./dist/esm/index.mjs"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
10
29
|
"publishConfig": {
|
|
11
30
|
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tamagui-build",
|
|
34
|
+
"watch": "tamagui-build --watch",
|
|
35
|
+
"clean": "tamagui-build clean",
|
|
36
|
+
"clean:build": "tamagui-build clean:build",
|
|
37
|
+
"test": "vitest --run tests/index.test.ts",
|
|
38
|
+
"test:types": "vitest --typecheck --run tests/index.test-d.ts"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@tamagui/web": "3.0.0-beta.643.1"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@tamagui/build": "3.0.0-beta.643.1",
|
|
45
|
+
"react": ">=19",
|
|
46
|
+
"vitest": "4.0.4"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=19"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/tamagui/tamagui.git",
|
|
54
|
+
"directory": "code/core/size"
|
|
12
55
|
}
|
|
13
56
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createStyledContext,
|
|
3
|
+
type FontSizeTokens,
|
|
4
|
+
type GenericFont,
|
|
5
|
+
type SizeTokens,
|
|
6
|
+
type StyledContext,
|
|
7
|
+
type TokensParsed,
|
|
8
|
+
type Variable,
|
|
9
|
+
} from '@tamagui/web'
|
|
10
|
+
|
|
11
|
+
export type TokenSize = SizeTokens | FontSizeTokens | number | true
|
|
12
|
+
|
|
13
|
+
export type TokenSizePolicy = {
|
|
14
|
+
size: Exclude<SizeTokens, true> | number
|
|
15
|
+
space: Exclude<SizeTokens, true> | number
|
|
16
|
+
radius: Exclude<SizeTokens, true> | number
|
|
17
|
+
fontSize: Exclude<FontSizeTokens, true> | number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// component defaults are intentionally owned by this opt-in package instead of
|
|
21
|
+
// the global Tamagui config, so the other metrics retain each config's
|
|
22
|
+
// token-defined platform values.
|
|
23
|
+
export const defaultTokenSizePolicy: TokenSizePolicy = {
|
|
24
|
+
// geometry consumers (Square, Circle) read the size scale directly and only
|
|
25
|
+
// need a default token; control frame heights do NOT come from here, they
|
|
26
|
+
// come from controlSizes below.
|
|
27
|
+
size: 44,
|
|
28
|
+
space: '4',
|
|
29
|
+
radius: '4',
|
|
30
|
+
fontSize: '4',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Frame heights for controls, keyed like v2's size tokens.
|
|
35
|
+
*
|
|
36
|
+
* `size` on a control is a preset, not a length. A config's size scale is a
|
|
37
|
+
* spacing scale: under v6 it is tailwind's, where `3` is 12px, so reading a
|
|
38
|
+
* frame height straight off it produced a 12px-tall Button holding 16px text.
|
|
39
|
+
* These are v2's size token values, so a migrating `size="4"` still means a
|
|
40
|
+
* 44px control rather than silently becoming a 16px one.
|
|
41
|
+
*
|
|
42
|
+
* `true` is the unsized default and is just the `4` step, so there is no
|
|
43
|
+
* separate default constant that can drift away from the ramp.
|
|
44
|
+
*/
|
|
45
|
+
export const controlSizes = {
|
|
46
|
+
true: 44,
|
|
47
|
+
0: 0,
|
|
48
|
+
'0-25': 2,
|
|
49
|
+
'0-5': 4,
|
|
50
|
+
'0-75': 8,
|
|
51
|
+
1: 20,
|
|
52
|
+
'1-5': 24,
|
|
53
|
+
2: 28,
|
|
54
|
+
'2-5': 32,
|
|
55
|
+
3: 36,
|
|
56
|
+
'3-5': 40,
|
|
57
|
+
4: 44,
|
|
58
|
+
'4-5': 48,
|
|
59
|
+
5: 52,
|
|
60
|
+
6: 64,
|
|
61
|
+
7: 74,
|
|
62
|
+
8: 84,
|
|
63
|
+
9: 94,
|
|
64
|
+
10: 104,
|
|
65
|
+
11: 124,
|
|
66
|
+
12: 144,
|
|
67
|
+
13: 164,
|
|
68
|
+
14: 184,
|
|
69
|
+
15: 204,
|
|
70
|
+
16: 224,
|
|
71
|
+
17: 224,
|
|
72
|
+
18: 244,
|
|
73
|
+
19: 264,
|
|
74
|
+
20: 284,
|
|
75
|
+
} as const
|
|
76
|
+
|
|
77
|
+
export type ControlSizeKey = keyof typeof controlSizes
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A control's frame height. Numbers stay literal pixel values, the same line
|
|
81
|
+
* resolveTokenSize and getShapeSize already draw. A size key outside the ramp
|
|
82
|
+
* (v6 carries larger ones like `24`) falls through to the config's size scale,
|
|
83
|
+
* where the value is already a sane large length.
|
|
84
|
+
*/
|
|
85
|
+
export const resolveControlSize = (
|
|
86
|
+
value: TokenSize,
|
|
87
|
+
tokens: Pick<TokensParsed, 'size'>
|
|
88
|
+
): number | Variable => {
|
|
89
|
+
if (typeof value === 'number') return value
|
|
90
|
+
const ramp = controlSizes[value as ControlSizeKey]
|
|
91
|
+
return ramp ?? tokens.size[value as keyof typeof tokens.size]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const resolveSizeToken = <Value, Category extends keyof TokenSizePolicy>(
|
|
95
|
+
value: Value,
|
|
96
|
+
category: Category,
|
|
97
|
+
policy: TokenSizePolicy = defaultTokenSizePolicy
|
|
98
|
+
): Exclude<Value, true> | TokenSizePolicy[Category] => {
|
|
99
|
+
return value === true ? policy[category] : (value as Exclude<Value, true>)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export type SizeContextValue<Value extends TokenSize = TokenSize> = {
|
|
103
|
+
size: Value | undefined
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type CreatedSizeContext<Value extends TokenSize = TokenSize> = StyledContext<
|
|
107
|
+
SizeContextValue<Value>,
|
|
108
|
+
'size'
|
|
109
|
+
>
|
|
110
|
+
|
|
111
|
+
export const createSizeContext = <Value extends TokenSize = TokenSize>(
|
|
112
|
+
defaultSize?: Value
|
|
113
|
+
): CreatedSizeContext<Value> => {
|
|
114
|
+
return createStyledContext<SizeContextValue<Value>>({ size: defaultSize })
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const SizeContext: CreatedSizeContext = createSizeContext()
|
|
118
|
+
|
|
119
|
+
export type SizeResolverExtras = {
|
|
120
|
+
tokens: Pick<TokensParsed, 'size' | 'space' | 'radius'>
|
|
121
|
+
font: GenericFont
|
|
122
|
+
policy?: TokenSizePolicy
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type ResolvedFrameMetric<Value extends TokenSize> = Value extends number
|
|
126
|
+
? Value
|
|
127
|
+
: Value extends true
|
|
128
|
+
? number | Variable
|
|
129
|
+
: Variable
|
|
130
|
+
|
|
131
|
+
export type ResolvedFontMetric<Value extends TokenSize> = Value extends number
|
|
132
|
+
? Value
|
|
133
|
+
: number | Variable
|
|
134
|
+
|
|
135
|
+
/** the ramp yields plain numbers, so a frame height is never only a Variable */
|
|
136
|
+
export type ResolvedControlMetric<Value extends TokenSize> = Value extends number
|
|
137
|
+
? Value
|
|
138
|
+
: number | Variable
|
|
139
|
+
|
|
140
|
+
export type ResolvedTokenSize<Value extends TokenSize = TokenSize> = {
|
|
141
|
+
frame: {
|
|
142
|
+
size: ResolvedControlMetric<Value>
|
|
143
|
+
space: ResolvedFrameMetric<Value>
|
|
144
|
+
radius: ResolvedFrameMetric<Value>
|
|
145
|
+
}
|
|
146
|
+
text: {
|
|
147
|
+
fontSize: ResolvedFontMetric<Value>
|
|
148
|
+
lineHeight: Value extends number ? undefined : number | Variable | undefined
|
|
149
|
+
}
|
|
150
|
+
icon: ResolvedFontMetric<Value>
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export const resolveTokenSize = <Value extends TokenSize>(
|
|
154
|
+
value: Value,
|
|
155
|
+
{ tokens, font, policy = defaultTokenSizePolicy }: SizeResolverExtras
|
|
156
|
+
): ResolvedTokenSize<Value> => {
|
|
157
|
+
if (typeof value === 'number') {
|
|
158
|
+
return {
|
|
159
|
+
frame: { size: value, space: value, radius: value },
|
|
160
|
+
text: { fontSize: value, lineHeight: undefined },
|
|
161
|
+
icon: value,
|
|
162
|
+
} as ResolvedTokenSize<Value>
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const spaceKey = resolveSizeToken(value, 'space', policy)
|
|
166
|
+
const radiusKey = resolveSizeToken(value, 'radius', policy)
|
|
167
|
+
const fontKey = resolveSizeToken(value, 'fontSize', policy)
|
|
168
|
+
|
|
169
|
+
// frame height is a control preset off the ramp, never the spacing scale
|
|
170
|
+
const size = resolveControlSize(value, tokens)
|
|
171
|
+
const space = typeof spaceKey === 'number' ? spaceKey : tokens.space[spaceKey]
|
|
172
|
+
const radius = typeof radiusKey === 'number' ? radiusKey : tokens.radius[radiusKey]
|
|
173
|
+
const fontSize = typeof fontKey === 'number' ? fontKey : font.size[fontKey]
|
|
174
|
+
const lineHeight = typeof fontKey === 'number' ? undefined : font.lineHeight?.[fontKey]
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
frame: {
|
|
178
|
+
size,
|
|
179
|
+
space,
|
|
180
|
+
radius,
|
|
181
|
+
},
|
|
182
|
+
text: {
|
|
183
|
+
fontSize,
|
|
184
|
+
lineHeight,
|
|
185
|
+
},
|
|
186
|
+
icon: fontSize,
|
|
187
|
+
} as ResolvedTokenSize<Value>
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export type SizeTableEntry = Readonly<{
|
|
191
|
+
frame: unknown
|
|
192
|
+
text: unknown
|
|
193
|
+
icon: unknown
|
|
194
|
+
}>
|
|
195
|
+
|
|
196
|
+
export type SizeTableDefinition = Readonly<Record<string, SizeTableEntry>>
|
|
197
|
+
|
|
198
|
+
export type SizeTableName<Table extends SizeTableDefinition> = Extract<
|
|
199
|
+
keyof Table,
|
|
200
|
+
string
|
|
201
|
+
>
|
|
202
|
+
|
|
203
|
+
export type SizeTableSelection<
|
|
204
|
+
Table extends SizeTableDefinition,
|
|
205
|
+
Name extends SizeTableName<Table>,
|
|
206
|
+
> = Table[Name]
|
|
207
|
+
|
|
208
|
+
export type SizeTablePart = keyof SizeTableEntry
|
|
209
|
+
|
|
210
|
+
export type SizeTableProjection<
|
|
211
|
+
Table extends SizeTableDefinition,
|
|
212
|
+
Part extends SizeTablePart,
|
|
213
|
+
> = {
|
|
214
|
+
readonly [Name in SizeTableName<Table>]: Table[Name][Part]
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export type SizeTableContextValue<Table extends SizeTableDefinition> = {
|
|
218
|
+
size: SizeTableName<Table>
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export type CreatedSizeTable<
|
|
222
|
+
Table extends SizeTableDefinition,
|
|
223
|
+
DefaultName extends SizeTableName<Table>,
|
|
224
|
+
> = {
|
|
225
|
+
values: Table
|
|
226
|
+
names: readonly SizeTableName<Table>[]
|
|
227
|
+
defaultSize: DefaultName
|
|
228
|
+
Context: StyledContext<SizeTableContextValue<Table>, 'size'>
|
|
229
|
+
frame: SizeTableProjection<Table, 'frame'>
|
|
230
|
+
text: SizeTableProjection<Table, 'text'>
|
|
231
|
+
icon: SizeTableProjection<Table, 'icon'>
|
|
232
|
+
resolve: {
|
|
233
|
+
(): SizeTableSelection<Table, DefaultName>;
|
|
234
|
+
<Name extends SizeTableName<Table>>(name: Name): SizeTableSelection<Table, Name>
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export const createSizeTable = <
|
|
239
|
+
const Table extends SizeTableDefinition,
|
|
240
|
+
const DefaultName extends SizeTableName<Table>,
|
|
241
|
+
>(
|
|
242
|
+
values: Table,
|
|
243
|
+
defaultSize: DefaultName
|
|
244
|
+
): CreatedSizeTable<Table, DefaultName> => {
|
|
245
|
+
const Context = createStyledContext<SizeTableContextValue<Table>>({ size: defaultSize })
|
|
246
|
+
const frame = {} as Record<SizeTableName<Table>, Table[SizeTableName<Table>]['frame']>
|
|
247
|
+
const text = {} as Record<SizeTableName<Table>, Table[SizeTableName<Table>]['text']>
|
|
248
|
+
const icon = {} as Record<SizeTableName<Table>, Table[SizeTableName<Table>]['icon']>
|
|
249
|
+
|
|
250
|
+
for (const name of Object.keys(values) as SizeTableName<Table>[]) {
|
|
251
|
+
frame[name] = values[name].frame
|
|
252
|
+
text[name] = values[name].text
|
|
253
|
+
icon[name] = values[name].icon
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const resolve = ((name: SizeTableName<Table> = defaultSize) => {
|
|
257
|
+
if (!(name in values)) {
|
|
258
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
259
|
+
console.error(
|
|
260
|
+
`Unknown size "${String(name)}" — this size table only has: ${Object.keys(values).join(', ')}. Size tables are user-owned named scales; the default skins take size tokens instead. Falling back to "${String(defaultSize)}".`
|
|
261
|
+
)
|
|
262
|
+
}
|
|
263
|
+
return values[defaultSize]
|
|
264
|
+
}
|
|
265
|
+
return values[name]
|
|
266
|
+
}) as CreatedSizeTable<Table, DefaultName>['resolve']
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
values,
|
|
270
|
+
names: Object.keys(values) as SizeTableName<Table>[],
|
|
271
|
+
defaultSize,
|
|
272
|
+
Context,
|
|
273
|
+
frame: frame as SizeTableProjection<Table, 'frame'>,
|
|
274
|
+
text: text as SizeTableProjection<Table, 'text'>,
|
|
275
|
+
icon: icon as SizeTableProjection<Table, 'icon'>,
|
|
276
|
+
resolve,
|
|
277
|
+
}
|
|
278
|
+
}
|