@tamagui/size 0.0.0-bootstrap.0 → 3.0.0-beta.1097.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nate Wienert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,130 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ SizeContext: () => SizeContext,
24
+ createSizeContext: () => createSizeContext,
25
+ oneSizeSmaller: () => oneSizeSmaller,
26
+ resolveSize: () => resolveSize
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ var import_web = require("@tamagui/web");
30
+ const createSizeContext = (defaultSize) => {
31
+ return (0, import_web.createStyledContext)({ size: defaultSize });
32
+ };
33
+ const SizeContext = createSizeContext();
34
+ const configEnv = () => {
35
+ const conf = (0, import_web.getConfig)();
36
+ return {
37
+ tokens: conf.tokensParsed,
38
+ font: conf.fontsParsed[conf.defaultFontToken],
39
+ fonts: conf.fontsParsed,
40
+ sizes: conf.sizes
41
+ };
42
+ };
43
+ let warnedNoDefault = false;
44
+ const px = (value) => {
45
+ const n = Number.parseFloat(String((0, import_web.getVariableValue)(value)));
46
+ return Number.isFinite(n) ? n : 0;
47
+ };
48
+ const resolveSize = (value, env = configEnv()) => {
49
+ const { tokens, font: fontIn, fonts, sizes } = env;
50
+ let key;
51
+ if (value === true || value == null) {
52
+ key = sizes?.default;
53
+ } else if (typeof value === "number") {
54
+ if (process.env.NODE_ENV === "development") {
55
+ console.error(`size={${value}} is not a control size. Use a named size (${Object.keys(sizes ?? {}).filter((k) => k !== "default").join(", ") || "none configured"}) or a token key. Falling back to the default.`);
56
+ }
57
+ key = sizes?.default;
58
+ } else {
59
+ key = String(value);
60
+ if (key[0] === "$") key = key.slice(1);
61
+ }
62
+ if (key == null) {
63
+ if (process.env.NODE_ENV === "development" && !warnedNoDefault) {
64
+ warnedNoDefault = true;
65
+ console.error(`No default size: pass "sizes" to createTamagui (see @tamagui/config/v6 "sizes"). Falling back to token "4".`);
66
+ }
67
+ key = "4";
68
+ }
69
+ let spec = key === "default" ? void 0 : sizes?.[key];
70
+ for (let attempt = 0; attempt < 2 && !(spec && typeof spec === "object") && tokens.size[key] == null && fontIn?.size[key] == null && fonts?.body?.size[key] == null; attempt++) {
71
+ if (process.env.NODE_ENV === "development" && attempt === 0) {
72
+ console.error(`Unknown size "${key}": not a named size (${Object.keys(sizes ?? {}).filter((k) => k !== "default").join(", ") || "none configured"}) and not a token key. Falling back to the default.`);
73
+ }
74
+ key = attempt === 0 ? sizes?.default || "4" : "4";
75
+ spec = key === "default" ? void 0 : sizes?.[key];
76
+ }
77
+ if (spec && typeof spec === "object") {
78
+ const font2 = fontIn?.size[spec.fontSize] != null ? fontIn : fonts?.body;
79
+ const fontSize2 = font2?.size[spec.fontSize] ?? 0;
80
+ const lineHeight = font2?.lineHeight?.[spec.fontSize];
81
+ const paddingVertical = tokens.space[spec.paddingY];
82
+ const fontPx = px(fontSize2);
83
+ return {
84
+ name: key,
85
+ fontSizeKey: spec.fontSize,
86
+ frame: {
87
+ paddingHorizontal: tokens.space[spec.paddingX],
88
+ paddingVertical,
89
+ gap: tokens.space[spec.gap ?? spec.paddingY],
90
+ borderRadius: tokens.radius[spec.radius]
91
+ },
92
+ text: {
93
+ fontSize: fontSize2,
94
+ lineHeight
95
+ },
96
+ icon: spec.icon ?? Math.ceil(fontPx / 4) * 4,
97
+ controlHeight: (lineHeight ? px(lineHeight) : Math.round(fontPx * 1.5)) + px(paddingVertical) * 2
98
+ };
99
+ }
100
+ const size = tokens.size[key];
101
+ const font = fontIn?.size[key] != null ? fontIn : fonts?.body;
102
+ const fontSize = font?.size[key];
103
+ const sizePx = px(size);
104
+ return {
105
+ name: key,
106
+ fontSizeKey: key,
107
+ frame: {
108
+ paddingHorizontal: tokens.space[key],
109
+ gap: Math.round(sizePx * .2),
110
+ borderRadius: tokens.radius[key],
111
+ minHeight: size
112
+ },
113
+ text: {
114
+ fontSize: fontSize ?? sizePx,
115
+ lineHeight: font?.lineHeight?.[key]
116
+ },
117
+ icon: px(fontSize ?? sizePx),
118
+ controlHeight: sizePx
119
+ };
120
+ };
121
+ const oneSizeSmaller = (value, sizes) => {
122
+ const key = value === true || value == null ? sizes?.default : String(value).replace(/^\$/, "");
123
+ if (key == null) return "3";
124
+ const names = Object.keys(sizes ?? {}).filter((name) => name !== "default");
125
+ const index = names.indexOf(key);
126
+ if (index !== -1) return names[Math.max(0, index - 1)];
127
+ const n = Number(key);
128
+ if (Number.isNaN(n)) return key;
129
+ return `${Math.max(1, Math.round(n) - 1)}`;
130
+ };
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var index_exports = {};
24
+ __export(index_exports, {
25
+ SizeContext: () => SizeContext,
26
+ createSizeContext: () => createSizeContext,
27
+ oneSizeSmaller: () => oneSizeSmaller,
28
+ resolveSize: () => resolveSize
29
+ });
30
+ module.exports = __toCommonJS(index_exports);
31
+ var import_web = require("@tamagui/web");
32
+ var createSizeContext = function(defaultSize) {
33
+ return (0, import_web.createStyledContext)({ size: defaultSize });
34
+ };
35
+ var SizeContext = createSizeContext();
36
+ var configEnv = function() {
37
+ var conf = (0, import_web.getConfig)();
38
+ return {
39
+ tokens: conf.tokensParsed,
40
+ font: conf.fontsParsed[conf.defaultFontToken],
41
+ fonts: conf.fontsParsed,
42
+ sizes: conf.sizes
43
+ };
44
+ };
45
+ var warnedNoDefault = false;
46
+ var px = function(value) {
47
+ var n = Number.parseFloat(String((0, import_web.getVariableValue)(value)));
48
+ return Number.isFinite(n) ? n : 0;
49
+ };
50
+ var resolveSize = function(value) {
51
+ var env = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : configEnv();
52
+ var _fonts_body, _font_lineHeight;
53
+ var { tokens, font: fontIn, fonts, sizes } = env;
54
+ var key;
55
+ if (value === true || value == null) {
56
+ key = sizes === null || sizes === void 0 ? void 0 : sizes.default;
57
+ } else if (typeof value === "number") {
58
+ if (process.env.NODE_ENV === "development") {
59
+ console.error(`size={${value}} is not a control size. Use a named size (${Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(k) {
60
+ return k !== "default";
61
+ }).join(", ") || "none configured"}) or a token key. Falling back to the default.`);
62
+ }
63
+ key = sizes === null || sizes === void 0 ? void 0 : sizes.default;
64
+ } else {
65
+ key = String(value);
66
+ if (key[0] === "$") key = key.slice(1);
67
+ }
68
+ if (key == null) {
69
+ if (process.env.NODE_ENV === "development" && !warnedNoDefault) {
70
+ warnedNoDefault = true;
71
+ console.error(`No default size: pass "sizes" to createTamagui (see @tamagui/config/v6 "sizes"). Falling back to token "4".`);
72
+ }
73
+ key = "4";
74
+ }
75
+ var spec = key === "default" ? void 0 : sizes === null || sizes === void 0 ? void 0 : sizes[key];
76
+ for (var attempt = 0; attempt < 2 && !(spec && typeof spec === "object") && tokens.size[key] == null && (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[key]) == null && (fonts === null || fonts === void 0 ? void 0 : (_fonts_body = fonts.body) === null || _fonts_body === void 0 ? void 0 : _fonts_body.size[key]) == null; attempt++) {
77
+ if (process.env.NODE_ENV === "development" && attempt === 0) {
78
+ console.error(`Unknown size "${key}": not a named size (${Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(k) {
79
+ return k !== "default";
80
+ }).join(", ") || "none configured"}) and not a token key. Falling back to the default.`);
81
+ }
82
+ key = attempt === 0 ? (sizes === null || sizes === void 0 ? void 0 : sizes.default) || "4" : "4";
83
+ spec = key === "default" ? void 0 : sizes === null || sizes === void 0 ? void 0 : sizes[key];
84
+ }
85
+ if (spec && typeof spec === "object") {
86
+ var _font_lineHeight1;
87
+ var font = (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[spec.fontSize]) != null ? fontIn : fonts === null || fonts === void 0 ? void 0 : fonts.body;
88
+ var _font_size_spec_fontSize;
89
+ var fontSize = (_font_size_spec_fontSize = font === null || font === void 0 ? void 0 : font.size[spec.fontSize]) !== null && _font_size_spec_fontSize !== void 0 ? _font_size_spec_fontSize : 0;
90
+ var lineHeight = font === null || font === void 0 ? void 0 : (_font_lineHeight1 = font.lineHeight) === null || _font_lineHeight1 === void 0 ? void 0 : _font_lineHeight1[spec.fontSize];
91
+ var paddingVertical = tokens.space[spec.paddingY];
92
+ var fontPx = px(fontSize);
93
+ var _spec_gap, _spec_icon;
94
+ return {
95
+ name: key,
96
+ fontSizeKey: spec.fontSize,
97
+ frame: {
98
+ paddingHorizontal: tokens.space[spec.paddingX],
99
+ paddingVertical,
100
+ gap: tokens.space[(_spec_gap = spec.gap) !== null && _spec_gap !== void 0 ? _spec_gap : spec.paddingY],
101
+ borderRadius: tokens.radius[spec.radius]
102
+ },
103
+ text: {
104
+ fontSize,
105
+ lineHeight
106
+ },
107
+ icon: (_spec_icon = spec.icon) !== null && _spec_icon !== void 0 ? _spec_icon : Math.ceil(fontPx / 4) * 4,
108
+ controlHeight: (lineHeight ? px(lineHeight) : Math.round(fontPx * 1.5)) + px(paddingVertical) * 2
109
+ };
110
+ }
111
+ var size = tokens.size[key];
112
+ var font1 = (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[key]) != null ? fontIn : fonts === null || fonts === void 0 ? void 0 : fonts.body;
113
+ var fontSize1 = font1 === null || font1 === void 0 ? void 0 : font1.size[key];
114
+ var sizePx = px(size);
115
+ return {
116
+ name: key,
117
+ fontSizeKey: key,
118
+ frame: {
119
+ paddingHorizontal: tokens.space[key],
120
+ gap: Math.round(sizePx * .2),
121
+ borderRadius: tokens.radius[key],
122
+ minHeight: size
123
+ },
124
+ text: {
125
+ fontSize: fontSize1 !== null && fontSize1 !== void 0 ? fontSize1 : sizePx,
126
+ lineHeight: font1 === null || font1 === void 0 ? void 0 : (_font_lineHeight = font1.lineHeight) === null || _font_lineHeight === void 0 ? void 0 : _font_lineHeight[key]
127
+ },
128
+ icon: px(fontSize1 !== null && fontSize1 !== void 0 ? fontSize1 : sizePx),
129
+ controlHeight: sizePx
130
+ };
131
+ };
132
+ var oneSizeSmaller = function(value, sizes) {
133
+ var key = value === true || value == null ? sizes === null || sizes === void 0 ? void 0 : sizes.default : String(value).replace(/^\$/, "");
134
+ if (key == null) return "3";
135
+ var names = Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(name) {
136
+ return name !== "default";
137
+ });
138
+ var index = names.indexOf(key);
139
+ if (index !== -1) return names[Math.max(0, index - 1)];
140
+ var n = Number(key);
141
+ if (Number.isNaN(n)) return key;
142
+ return `${Math.max(1, Math.round(n) - 1)}`;
143
+ };
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: () => from[key],
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
23
+ var index_exports = {};
24
+ __export(index_exports, {
25
+ SizeContext: () => SizeContext,
26
+ createSizeContext: () => createSizeContext,
27
+ oneSizeSmaller: () => oneSizeSmaller,
28
+ resolveSize: () => resolveSize
29
+ });
30
+ module.exports = __toCommonJS(index_exports);
31
+ var import_web = require("@tamagui/web");
32
+ var createSizeContext = function(defaultSize) {
33
+ return (0, import_web.createStyledContext)({ size: defaultSize });
34
+ };
35
+ var SizeContext = createSizeContext();
36
+ var configEnv = function() {
37
+ var conf = (0, import_web.getConfig)();
38
+ return {
39
+ tokens: conf.tokensParsed,
40
+ font: conf.fontsParsed[conf.defaultFontToken],
41
+ fonts: conf.fontsParsed,
42
+ sizes: conf.sizes
43
+ };
44
+ };
45
+ var warnedNoDefault = false;
46
+ var px = function(value) {
47
+ var n = Number.parseFloat(String((0, import_web.getVariableValue)(value)));
48
+ return Number.isFinite(n) ? n : 0;
49
+ };
50
+ var resolveSize = function(value) {
51
+ var env = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : configEnv();
52
+ var _fonts_body, _font_lineHeight;
53
+ var { tokens, font: fontIn, fonts, sizes } = env;
54
+ var key;
55
+ if (value === true || value == null) {
56
+ key = sizes === null || sizes === void 0 ? void 0 : sizes.default;
57
+ } else if (typeof value === "number") {
58
+ if (process.env.NODE_ENV === "development") {
59
+ console.error(`size={${value}} is not a control size. Use a named size (${Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(k) {
60
+ return k !== "default";
61
+ }).join(", ") || "none configured"}) or a token key. Falling back to the default.`);
62
+ }
63
+ key = sizes === null || sizes === void 0 ? void 0 : sizes.default;
64
+ } else {
65
+ key = String(value);
66
+ if (key[0] === "$") key = key.slice(1);
67
+ }
68
+ if (key == null) {
69
+ if (process.env.NODE_ENV === "development" && !warnedNoDefault) {
70
+ warnedNoDefault = true;
71
+ console.error(`No default size: pass "sizes" to createTamagui (see @tamagui/config/v6 "sizes"). Falling back to token "4".`);
72
+ }
73
+ key = "4";
74
+ }
75
+ var spec = key === "default" ? void 0 : sizes === null || sizes === void 0 ? void 0 : sizes[key];
76
+ for (var attempt = 0; attempt < 2 && !(spec && typeof spec === "object") && tokens.size[key] == null && (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[key]) == null && (fonts === null || fonts === void 0 ? void 0 : (_fonts_body = fonts.body) === null || _fonts_body === void 0 ? void 0 : _fonts_body.size[key]) == null; attempt++) {
77
+ if (process.env.NODE_ENV === "development" && attempt === 0) {
78
+ console.error(`Unknown size "${key}": not a named size (${Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(k) {
79
+ return k !== "default";
80
+ }).join(", ") || "none configured"}) and not a token key. Falling back to the default.`);
81
+ }
82
+ key = attempt === 0 ? (sizes === null || sizes === void 0 ? void 0 : sizes.default) || "4" : "4";
83
+ spec = key === "default" ? void 0 : sizes === null || sizes === void 0 ? void 0 : sizes[key];
84
+ }
85
+ if (spec && typeof spec === "object") {
86
+ var _font_lineHeight1;
87
+ var font = (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[spec.fontSize]) != null ? fontIn : fonts === null || fonts === void 0 ? void 0 : fonts.body;
88
+ var _font_size_spec_fontSize;
89
+ var fontSize = (_font_size_spec_fontSize = font === null || font === void 0 ? void 0 : font.size[spec.fontSize]) !== null && _font_size_spec_fontSize !== void 0 ? _font_size_spec_fontSize : 0;
90
+ var lineHeight = font === null || font === void 0 ? void 0 : (_font_lineHeight1 = font.lineHeight) === null || _font_lineHeight1 === void 0 ? void 0 : _font_lineHeight1[spec.fontSize];
91
+ var paddingVertical = tokens.space[spec.paddingY];
92
+ var fontPx = px(fontSize);
93
+ var _spec_gap, _spec_icon;
94
+ return {
95
+ name: key,
96
+ fontSizeKey: spec.fontSize,
97
+ frame: {
98
+ paddingHorizontal: tokens.space[spec.paddingX],
99
+ paddingVertical,
100
+ gap: tokens.space[(_spec_gap = spec.gap) !== null && _spec_gap !== void 0 ? _spec_gap : spec.paddingY],
101
+ borderRadius: tokens.radius[spec.radius]
102
+ },
103
+ text: {
104
+ fontSize,
105
+ lineHeight
106
+ },
107
+ icon: (_spec_icon = spec.icon) !== null && _spec_icon !== void 0 ? _spec_icon : Math.ceil(fontPx / 4) * 4,
108
+ controlHeight: (lineHeight ? px(lineHeight) : Math.round(fontPx * 1.5)) + px(paddingVertical) * 2
109
+ };
110
+ }
111
+ var size = tokens.size[key];
112
+ var font1 = (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[key]) != null ? fontIn : fonts === null || fonts === void 0 ? void 0 : fonts.body;
113
+ var fontSize1 = font1 === null || font1 === void 0 ? void 0 : font1.size[key];
114
+ var sizePx = px(size);
115
+ return {
116
+ name: key,
117
+ fontSizeKey: key,
118
+ frame: {
119
+ paddingHorizontal: tokens.space[key],
120
+ gap: Math.round(sizePx * .2),
121
+ borderRadius: tokens.radius[key],
122
+ minHeight: size
123
+ },
124
+ text: {
125
+ fontSize: fontSize1 !== null && fontSize1 !== void 0 ? fontSize1 : sizePx,
126
+ lineHeight: font1 === null || font1 === void 0 ? void 0 : (_font_lineHeight = font1.lineHeight) === null || _font_lineHeight === void 0 ? void 0 : _font_lineHeight[key]
127
+ },
128
+ icon: px(fontSize1 !== null && fontSize1 !== void 0 ? fontSize1 : sizePx),
129
+ controlHeight: sizePx
130
+ };
131
+ };
132
+ var oneSizeSmaller = function(value, sizes) {
133
+ var key = value === true || value == null ? sizes === null || sizes === void 0 ? void 0 : sizes.default : String(value).replace(/^\$/, "");
134
+ if (key == null) return "3";
135
+ var names = Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(name) {
136
+ return name !== "default";
137
+ });
138
+ var index = names.indexOf(key);
139
+ if (index !== -1) return names[Math.max(0, index - 1)];
140
+ var n = Number(key);
141
+ if (Number.isNaN(n)) return key;
142
+ return `${Math.max(1, Math.round(n) - 1)}`;
143
+ };
144
+
145
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.native.js","names":[],"sources":["cjs/index.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar index_exports = {};\n__export(index_exports, {\n SizeContext: () => SizeContext,\n createSizeContext: () => createSizeContext,\n oneSizeSmaller: () => oneSizeSmaller,\n resolveSize: () => resolveSize\n});\nmodule.exports = __toCommonJS(index_exports);\nvar import_web = require(\"@tamagui/web\");\nvar createSizeContext = function(defaultSize) {\n return (0, import_web.createStyledContext)({\n size: defaultSize\n });\n};\nvar SizeContext = createSizeContext();\nvar configEnv = function() {\n var conf = (0, import_web.getConfig)();\n return {\n tokens: conf.tokensParsed,\n font: conf.fontsParsed[conf.defaultFontToken],\n fonts: conf.fontsParsed,\n sizes: conf.sizes\n };\n};\nvar warnedNoDefault = false;\nvar px = function(value) {\n var n = Number.parseFloat(String((0, import_web.getVariableValue)(value)));\n return Number.isFinite(n) ? n : 0;\n};\nvar resolveSize = function(value) {\n var env = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : configEnv();\n var _fonts_body, _font_lineHeight;\n var { tokens, font: fontIn, fonts, sizes } = env;\n var key;\n if (value === true || value == null) {\n key = sizes === null || sizes === void 0 ? void 0 : sizes.default;\n } else if (typeof value === \"number\") {\n if (process.env.NODE_ENV === \"development\") {\n console.error(`size={${value}} is not a control size. Use a named size (${Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(k) {\n return k !== \"default\";\n }).join(\", \") || \"none configured\"}) or a token key. Falling back to the default.`);\n }\n key = sizes === null || sizes === void 0 ? void 0 : sizes.default;\n } else {\n key = String(value);\n if (key[0] === \"$\") key = key.slice(1);\n }\n if (key == null) {\n if (process.env.NODE_ENV === \"development\" && !warnedNoDefault) {\n warnedNoDefault = true;\n console.error(`No default size: pass \"sizes\" to createTamagui (see @tamagui/config/v6 \"sizes\"). Falling back to token \"4\".`);\n }\n key = \"4\";\n }\n var spec = key === \"default\" ? void 0 : sizes === null || sizes === void 0 ? void 0 : sizes[key];\n for (var attempt = 0; attempt < 2 && !(spec && typeof spec === \"object\") && tokens.size[key] == null && (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[key]) == null && (fonts === null || fonts === void 0 ? void 0 : (_fonts_body = fonts.body) === null || _fonts_body === void 0 ? void 0 : _fonts_body.size[key]) == null; attempt++) {\n if (process.env.NODE_ENV === \"development\" && attempt === 0) {\n console.error(`Unknown size \"${key}\": not a named size (${Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(k) {\n return k !== \"default\";\n }).join(\", \") || \"none configured\"}) and not a token key. Falling back to the default.`);\n }\n key = attempt === 0 ? (sizes === null || sizes === void 0 ? void 0 : sizes.default) || \"4\" : \"4\";\n spec = key === \"default\" ? void 0 : sizes === null || sizes === void 0 ? void 0 : sizes[key];\n }\n if (spec && typeof spec === \"object\") {\n var _font_lineHeight1;\n var font = (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[spec.fontSize]) != null ? fontIn : fonts === null || fonts === void 0 ? void 0 : fonts.body;\n var _font_size_spec_fontSize;\n var fontSize = (_font_size_spec_fontSize = font === null || font === void 0 ? void 0 : font.size[spec.fontSize]) !== null && _font_size_spec_fontSize !== void 0 ? _font_size_spec_fontSize : 0;\n var lineHeight = font === null || font === void 0 ? void 0 : (_font_lineHeight1 = font.lineHeight) === null || _font_lineHeight1 === void 0 ? void 0 : _font_lineHeight1[spec.fontSize];\n var paddingVertical = tokens.space[spec.paddingY];\n var fontPx = px(fontSize);\n var _spec_gap, _spec_icon;\n return {\n name: key,\n fontSizeKey: spec.fontSize,\n frame: {\n paddingHorizontal: tokens.space[spec.paddingX],\n paddingVertical,\n gap: tokens.space[(_spec_gap = spec.gap) !== null && _spec_gap !== void 0 ? _spec_gap : spec.paddingY],\n borderRadius: tokens.radius[spec.radius]\n },\n text: {\n fontSize,\n lineHeight\n },\n icon: (_spec_icon = spec.icon) !== null && _spec_icon !== void 0 ? _spec_icon : Math.ceil(fontPx / 4) * 4,\n controlHeight: (lineHeight ? px(lineHeight) : Math.round(fontPx * 1.5)) + px(paddingVertical) * 2\n };\n }\n var size = tokens.size[key];\n var font1 = (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[key]) != null ? fontIn : fonts === null || fonts === void 0 ? void 0 : fonts.body;\n var fontSize1 = font1 === null || font1 === void 0 ? void 0 : font1.size[key];\n var sizePx = px(size);\n return {\n name: key,\n fontSizeKey: key,\n frame: {\n paddingHorizontal: tokens.space[key],\n gap: Math.round(sizePx * 0.2),\n borderRadius: tokens.radius[key],\n minHeight: size\n },\n text: {\n fontSize: fontSize1 !== null && fontSize1 !== void 0 ? fontSize1 : sizePx,\n lineHeight: font1 === null || font1 === void 0 ? void 0 : (_font_lineHeight = font1.lineHeight) === null || _font_lineHeight === void 0 ? void 0 : _font_lineHeight[key]\n },\n icon: px(fontSize1 !== null && fontSize1 !== void 0 ? fontSize1 : sizePx),\n controlHeight: sizePx\n };\n};\nvar oneSizeSmaller = function(value, sizes) {\n var key = value === true || value == null ? sizes === null || sizes === void 0 ? void 0 : sizes.default : String(value).replace(/^\\$/, \"\");\n if (key == null) return \"3\";\n var names = Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(name) {\n return name !== \"default\";\n });\n var index = names.indexOf(key);\n if (index !== -1) return names[Math.max(0, index - 1)];\n var n = Number(key);\n if (Number.isNaN(n)) return key;\n return `${Math.max(1, Math.round(n) - 1)}`;\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,gBAAgB,CAAC;AACrB,SAAS,eAAe;CACtB,mBAAmB;CACnB,yBAAyB;CACzB,sBAAsB;CACtB,mBAAmB;AACrB,CAAC;AACD,OAAO,UAAU,aAAa,aAAa;AAC3C,IAAI,aAAa,QAAQ,cAAc;AACvC,IAAI,oBAAoB,SAAS,aAAa;CAC5C,QAAQ,GAAG,WAAW,oBAAmB,CAAE,EACzC,MAAM,YACR,CAAC;AACH;AACA,IAAI,cAAc,kBAAkB;AACpC,IAAI,YAAY,WAAW;CACzB,IAAI,QAAQ,GAAG,WAAW,UAAS,CAAE;CACrC,OAAO;EACL,QAAQ,KAAK;EACb,MAAM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MAAM,UAAU,QAAQ,SAAS,OAAO,UAAU,QAAQ,UAAU,KAAK,IAAI,KAAK,IAAI,MAAM,UAAU,OAAO,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE;CACzI,IAAI,OAAO,MAAM,OAAO;CACxB,IAAI,QAAQ,OAAO,KAAK,UAAU,QAAQ,UAAU,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,SAAS,MAAM;EAC7F,OAAO,SAAS;CAClB,CAAC;CACD,IAAI,QAAQ,MAAM,QAAQ,GAAG;CAC7B,IAAI,UAAU,CAAC,GAAG,OAAO,MAAM,KAAK,IAAI,GAAG,QAAQ,CAAC;CACpD,IAAI,IAAI,OAAO,GAAG;CAClB,IAAI,OAAO,MAAM,CAAC,GAAG,OAAO;CAC5B,OAAO,GAAG,KAAK,IAAI,GAAG,KAAK,MAAM,CAAC,IAAI,CAAC;AACzC"}
@@ -0,0 +1,106 @@
1
+ import { createStyledContext, getConfig, getVariableValue } from "@tamagui/web";
2
+
3
+ const createSizeContext = (defaultSize) => {
4
+ return createStyledContext({ size: defaultSize });
5
+ };
6
+ const SizeContext = createSizeContext();
7
+ const configEnv = () => {
8
+ const conf = getConfig();
9
+ return {
10
+ tokens: conf.tokensParsed,
11
+ font: conf.fontsParsed[conf.defaultFontToken],
12
+ fonts: conf.fontsParsed,
13
+ sizes: conf.sizes
14
+ };
15
+ };
16
+ let warnedNoDefault = false;
17
+ const px = (value) => {
18
+ const n = Number.parseFloat(String(getVariableValue(value)));
19
+ return Number.isFinite(n) ? n : 0;
20
+ };
21
+ const resolveSize = (value, env = configEnv()) => {
22
+ const { tokens, font: fontIn, fonts, sizes } = env;
23
+ let key;
24
+ if (value === true || value == null) {
25
+ key = sizes?.default;
26
+ } else if (typeof value === "number") {
27
+ if (process.env.NODE_ENV === "development") {
28
+ console.error(`size={${value}} is not a control size. Use a named size (${Object.keys(sizes ?? {}).filter((k) => k !== "default").join(", ") || "none configured"}) or a token key. Falling back to the default.`);
29
+ }
30
+ key = sizes?.default;
31
+ } else {
32
+ key = String(value);
33
+ if (key[0] === "$") key = key.slice(1);
34
+ }
35
+ if (key == null) {
36
+ if (process.env.NODE_ENV === "development" && !warnedNoDefault) {
37
+ warnedNoDefault = true;
38
+ console.error(`No default size: pass "sizes" to createTamagui (see @tamagui/config/v6 "sizes"). Falling back to token "4".`);
39
+ }
40
+ key = "4";
41
+ }
42
+ let spec = key === "default" ? void 0 : sizes?.[key];
43
+ for (let attempt = 0; attempt < 2 && !(spec && typeof spec === "object") && tokens.size[key] == null && fontIn?.size[key] == null && fonts?.body?.size[key] == null; attempt++) {
44
+ if (process.env.NODE_ENV === "development" && attempt === 0) {
45
+ console.error(`Unknown size "${key}": not a named size (${Object.keys(sizes ?? {}).filter((k) => k !== "default").join(", ") || "none configured"}) and not a token key. Falling back to the default.`);
46
+ }
47
+ key = attempt === 0 ? sizes?.default || "4" : "4";
48
+ spec = key === "default" ? void 0 : sizes?.[key];
49
+ }
50
+ if (spec && typeof spec === "object") {
51
+ const font2 = fontIn?.size[spec.fontSize] != null ? fontIn : fonts?.body;
52
+ const fontSize2 = font2?.size[spec.fontSize] ?? 0;
53
+ const lineHeight = font2?.lineHeight?.[spec.fontSize];
54
+ const paddingVertical = tokens.space[spec.paddingY];
55
+ const fontPx = px(fontSize2);
56
+ return {
57
+ name: key,
58
+ fontSizeKey: spec.fontSize,
59
+ frame: {
60
+ paddingHorizontal: tokens.space[spec.paddingX],
61
+ paddingVertical,
62
+ gap: tokens.space[spec.gap ?? spec.paddingY],
63
+ borderRadius: tokens.radius[spec.radius]
64
+ },
65
+ text: {
66
+ fontSize: fontSize2,
67
+ lineHeight
68
+ },
69
+ icon: spec.icon ?? Math.ceil(fontPx / 4) * 4,
70
+ controlHeight: (lineHeight ? px(lineHeight) : Math.round(fontPx * 1.5)) + px(paddingVertical) * 2
71
+ };
72
+ }
73
+ const size = tokens.size[key];
74
+ const font = fontIn?.size[key] != null ? fontIn : fonts?.body;
75
+ const fontSize = font?.size[key];
76
+ const sizePx = px(size);
77
+ return {
78
+ name: key,
79
+ fontSizeKey: key,
80
+ frame: {
81
+ paddingHorizontal: tokens.space[key],
82
+ gap: Math.round(sizePx * .2),
83
+ borderRadius: tokens.radius[key],
84
+ minHeight: size
85
+ },
86
+ text: {
87
+ fontSize: fontSize ?? sizePx,
88
+ lineHeight: font?.lineHeight?.[key]
89
+ },
90
+ icon: px(fontSize ?? sizePx),
91
+ controlHeight: sizePx
92
+ };
93
+ };
94
+ const oneSizeSmaller = (value, sizes) => {
95
+ const key = value === true || value == null ? sizes?.default : String(value).replace(/^\$/, "");
96
+ if (key == null) return "3";
97
+ const names = Object.keys(sizes ?? {}).filter((name) => name !== "default");
98
+ const index = names.indexOf(key);
99
+ if (index !== -1) return names[Math.max(0, index - 1)];
100
+ const n = Number(key);
101
+ if (Number.isNaN(n)) return key;
102
+ return `${Math.max(1, Math.round(n) - 1)}`;
103
+ };
104
+
105
+ export { SizeContext, createSizeContext, oneSizeSmaller, resolveSize };
106
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import {\n createStyledContext,\n getConfig,\n getVariableValue\n} from \"@tamagui/web\";\nconst createSizeContext = (defaultSize) => {\n return createStyledContext({ size: defaultSize });\n};\nconst SizeContext = createSizeContext();\nconst configEnv = () => {\n const conf = getConfig();\n return {\n tokens: conf.tokensParsed,\n font: conf.fontsParsed[conf.defaultFontToken],\n fonts: conf.fontsParsed,\n sizes: conf.sizes\n };\n};\nlet warnedNoDefault = false;\nconst px = (value) => {\n const n = Number.parseFloat(String(getVariableValue(value)));\n return Number.isFinite(n) ? n : 0;\n};\nconst resolveSize = (value, env = configEnv()) => {\n const { tokens, font: fontIn, fonts, sizes } = env;\n let key;\n if (value === true || value == null) {\n key = sizes?.default;\n } else if (typeof value === \"number\") {\n if (process.env.NODE_ENV === \"development\") {\n console.error(\n `size={${value}} is not a control size. Use a named size (${Object.keys(sizes ?? {}).filter((k) => k !== \"default\").join(\", \") || \"none configured\"}) or a token key. Falling back to the default.`\n );\n }\n key = sizes?.default;\n } else {\n key = String(value);\n if (key[0] === \"$\") key = key.slice(1);\n }\n if (key == null) {\n if (process.env.NODE_ENV === \"development\" && !warnedNoDefault) {\n warnedNoDefault = true;\n console.error(\n `No default size: pass \"sizes\" to createTamagui (see @tamagui/config/v6 \"sizes\"). Falling back to token \"4\".`\n );\n }\n key = \"4\";\n }\n let spec = key === \"default\" ? void 0 : sizes?.[key];\n for (let attempt = 0; attempt < 2 && !(spec && typeof spec === \"object\") && tokens.size[key] == null && fontIn?.size[key] == null && fonts?.body?.size[key] == null; attempt++) {\n if (process.env.NODE_ENV === \"development\" && attempt === 0) {\n console.error(\n `Unknown size \"${key}\": not a named size (${Object.keys(sizes ?? {}).filter((k) => k !== \"default\").join(\", \") || \"none configured\"}) and not a token key. Falling back to the default.`\n );\n }\n key = attempt === 0 ? sizes?.default || \"4\" : \"4\";\n spec = key === \"default\" ? void 0 : sizes?.[key];\n }\n if (spec && typeof spec === \"object\") {\n const font2 = fontIn?.size[spec.fontSize] != null ? fontIn : fonts?.body;\n const fontSize2 = font2?.size[spec.fontSize] ?? 0;\n const lineHeight = font2?.lineHeight?.[spec.fontSize];\n const paddingVertical = tokens.space[spec.paddingY];\n const fontPx = px(fontSize2);\n return {\n name: key,\n fontSizeKey: spec.fontSize,\n frame: {\n paddingHorizontal: tokens.space[spec.paddingX],\n paddingVertical,\n gap: tokens.space[spec.gap ?? spec.paddingY],\n borderRadius: tokens.radius[spec.radius]\n },\n text: { fontSize: fontSize2, lineHeight },\n icon: spec.icon ?? Math.ceil(fontPx / 4) * 4,\n controlHeight: (lineHeight ? px(lineHeight) : Math.round(fontPx * 1.5)) + px(paddingVertical) * 2\n };\n }\n const size = tokens.size[key];\n const font = fontIn?.size[key] != null ? fontIn : fonts?.body;\n const fontSize = font?.size[key];\n const sizePx = px(size);\n return {\n name: key,\n fontSizeKey: key,\n frame: {\n paddingHorizontal: tokens.space[key],\n gap: Math.round(sizePx * 0.2),\n borderRadius: tokens.radius[key],\n minHeight: size\n },\n text: { fontSize: fontSize ?? sizePx, lineHeight: font?.lineHeight?.[key] },\n icon: px(fontSize ?? sizePx),\n controlHeight: sizePx\n };\n};\nconst oneSizeSmaller = (value, sizes) => {\n const key = value === true || value == null ? sizes?.default : String(value).replace(/^\\$/, \"\");\n if (key == null) return \"3\";\n const names = Object.keys(sizes ?? {}).filter((name) => name !== \"default\");\n const index = names.indexOf(key);\n if (index !== -1) return names[Math.max(0, index - 1)];\n const n = Number(key);\n if (Number.isNaN(n)) return key;\n return `${Math.max(1, Math.round(n) - 1)}`;\n};\nexport {\n SizeContext,\n createSizeContext,\n oneSizeSmaller,\n resolveSize\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;AAKA,MAAM,qBAAqB,gBAAgB;CACzC,OAAO,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD;AACA,MAAM,cAAc,kBAAkB;AACtC,MAAM,kBAAkB;CACtB,MAAM,OAAO,UAAU;CACvB,OAAO;EACL,QAAQ,KAAK;EACb,MAAM,KAAK,YAAY,KAAK;EAC5B,OAAO,KAAK;EACZ,OAAO,KAAK;CACd;AACF;AACA,IAAI,kBAAkB;AACtB,MAAM,MAAM,UAAU;CACpB,MAAM,IAAI,OAAO,WAAW,OAAO,iBAAiB,KAAK,CAAC,CAAC;CAC3D,OAAO,OAAO,SAAS,CAAC,IAAI,IAAI;AAClC;AACA,MAAM,eAAe,OAAO,MAAM,UAAU,MAAM;CAChD,MAAM,EAAE,QAAQ,MAAM,QAAQ,OAAO,UAAU;CAC/C,IAAI;CACJ,IAAI,UAAU,QAAQ,SAAS,MAAM;EACnC,MAAM,OAAO;CACf,OAAO,IAAI,OAAO,UAAU,UAAU;EACpC,IAAI,QAAQ,IAAI,aAAa,eAAe;GAC1C,QAAQ,MACN,SAAS,MAAM,6CAA6C,OAAO,KAAK,SAAS,CAA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createSizeContext = (defaultSize) => {
4
+ return createStyledContext({ size: defaultSize });
5
+ };
6
+ const SizeContext = createSizeContext();
7
+ const configEnv = () => {
8
+ const conf = getConfig();
9
+ return {
10
+ tokens: conf.tokensParsed,
11
+ font: conf.fontsParsed[conf.defaultFontToken],
12
+ fonts: conf.fontsParsed,
13
+ sizes: conf.sizes
14
+ };
15
+ };
16
+ let warnedNoDefault = false;
17
+ const px = (value) => {
18
+ const n = Number.parseFloat(String(getVariableValue(value)));
19
+ return Number.isFinite(n) ? n : 0;
20
+ };
21
+ const resolveSize = (value, env = configEnv()) => {
22
+ const { tokens, font: fontIn, fonts, sizes } = env;
23
+ let key;
24
+ if (value === true || value == null) {
25
+ key = sizes?.default;
26
+ } else if (typeof value === "number") {
27
+ if (process.env.NODE_ENV === "development") {
28
+ console.error(`size={${value}} is not a control size. Use a named size (${Object.keys(sizes ?? {}).filter((k) => k !== "default").join(", ") || "none configured"}) or a token key. Falling back to the default.`);
29
+ }
30
+ key = sizes?.default;
31
+ } else {
32
+ key = String(value);
33
+ if (key[0] === "$") key = key.slice(1);
34
+ }
35
+ if (key == null) {
36
+ if (process.env.NODE_ENV === "development" && !warnedNoDefault) {
37
+ warnedNoDefault = true;
38
+ console.error(`No default size: pass "sizes" to createTamagui (see @tamagui/config/v6 "sizes"). Falling back to token "4".`);
39
+ }
40
+ key = "4";
41
+ }
42
+ let spec = key === "default" ? void 0 : sizes?.[key];
43
+ for (let attempt = 0; attempt < 2 && !(spec && typeof spec === "object") && tokens.size[key] == null && fontIn?.size[key] == null && fonts?.body?.size[key] == null; attempt++) {
44
+ if (process.env.NODE_ENV === "development" && attempt === 0) {
45
+ console.error(`Unknown size "${key}": not a named size (${Object.keys(sizes ?? {}).filter((k) => k !== "default").join(", ") || "none configured"}) and not a token key. Falling back to the default.`);
46
+ }
47
+ key = attempt === 0 ? sizes?.default || "4" : "4";
48
+ spec = key === "default" ? void 0 : sizes?.[key];
49
+ }
50
+ if (spec && typeof spec === "object") {
51
+ const font2 = fontIn?.size[spec.fontSize] != null ? fontIn : fonts?.body;
52
+ const fontSize2 = font2?.size[spec.fontSize] ?? 0;
53
+ const lineHeight = font2?.lineHeight?.[spec.fontSize];
54
+ const paddingVertical = tokens.space[spec.paddingY];
55
+ const fontPx = px(fontSize2);
56
+ return {
57
+ name: key,
58
+ fontSizeKey: spec.fontSize,
59
+ frame: {
60
+ paddingHorizontal: tokens.space[spec.paddingX],
61
+ paddingVertical,
62
+ gap: tokens.space[spec.gap ?? spec.paddingY],
63
+ borderRadius: tokens.radius[spec.radius]
64
+ },
65
+ text: {
66
+ fontSize: fontSize2,
67
+ lineHeight
68
+ },
69
+ icon: spec.icon ?? Math.ceil(fontPx / 4) * 4,
70
+ controlHeight: (lineHeight ? px(lineHeight) : Math.round(fontPx * 1.5)) + px(paddingVertical) * 2
71
+ };
72
+ }
73
+ const size = tokens.size[key];
74
+ const font = fontIn?.size[key] != null ? fontIn : fonts?.body;
75
+ const fontSize = font?.size[key];
76
+ const sizePx = px(size);
77
+ return {
78
+ name: key,
79
+ fontSizeKey: key,
80
+ frame: {
81
+ paddingHorizontal: tokens.space[key],
82
+ gap: Math.round(sizePx * .2),
83
+ borderRadius: tokens.radius[key],
84
+ minHeight: size
85
+ },
86
+ text: {
87
+ fontSize: fontSize ?? sizePx,
88
+ lineHeight: font?.lineHeight?.[key]
89
+ },
90
+ icon: px(fontSize ?? sizePx),
91
+ controlHeight: sizePx
92
+ };
93
+ };
94
+ const oneSizeSmaller = (value, sizes) => {
95
+ const key = value === true || value == null ? sizes?.default : String(value).replace(/^\$/, "");
96
+ if (key == null) return "3";
97
+ const names = Object.keys(sizes ?? {}).filter((name) => name !== "default");
98
+ const index = names.indexOf(key);
99
+ if (index !== -1) return names[Math.max(0, index - 1)];
100
+ const n = Number(key);
101
+ if (Number.isNaN(n)) return key;
102
+ return `${Math.max(1, Math.round(n) - 1)}`;
103
+ };
104
+
105
+ export { SizeContext, createSizeContext, oneSizeSmaller, resolveSize };
106
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import {\n createStyledContext,\n getConfig,\n getVariableValue\n} from \"@tamagui/web\";\nconst createSizeContext = (defaultSize) => {\n return createStyledContext({ size: defaultSize });\n};\nconst SizeContext = createSizeContext();\nconst configEnv = () => {\n const conf = getConfig();\n return {\n tokens: conf.tokensParsed,\n font: conf.fontsParsed[conf.defaultFontToken],\n fonts: conf.fontsParsed,\n sizes: conf.sizes\n };\n};\nlet warnedNoDefault = false;\nconst px = (value) => {\n const n = Number.parseFloat(String(getVariableValue(value)));\n return Number.isFinite(n) ? n : 0;\n};\nconst resolveSize = (value, env = configEnv()) => {\n const { tokens, font: fontIn, fonts, sizes } = env;\n let key;\n if (value === true || value == null) {\n key = sizes?.default;\n } else if (typeof value === \"number\") {\n if (process.env.NODE_ENV === \"development\") {\n console.error(\n `size={${value}} is not a control size. Use a named size (${Object.keys(sizes ?? {}).filter((k) => k !== \"default\").join(\", \") || \"none configured\"}) or a token key. Falling back to the default.`\n );\n }\n key = sizes?.default;\n } else {\n key = String(value);\n if (key[0] === \"$\") key = key.slice(1);\n }\n if (key == null) {\n if (process.env.NODE_ENV === \"development\" && !warnedNoDefault) {\n warnedNoDefault = true;\n console.error(\n `No default size: pass \"sizes\" to createTamagui (see @tamagui/config/v6 \"sizes\"). Falling back to token \"4\".`\n );\n }\n key = \"4\";\n }\n let spec = key === \"default\" ? void 0 : sizes?.[key];\n for (let attempt = 0; attempt < 2 && !(spec && typeof spec === \"object\") && tokens.size[key] == null && fontIn?.size[key] == null && fonts?.body?.size[key] == null; attempt++) {\n if (process.env.NODE_ENV === \"development\" && attempt === 0) {\n console.error(\n `Unknown size \"${key}\": not a named size (${Object.keys(sizes ?? {}).filter((k) => k !== \"default\").join(\", \") || \"none configured\"}) and not a token key. Falling back to the default.`\n );\n }\n key = attempt === 0 ? sizes?.default || \"4\" : \"4\";\n spec = key === \"default\" ? void 0 : sizes?.[key];\n }\n if (spec && typeof spec === \"object\") {\n const font2 = fontIn?.size[spec.fontSize] != null ? fontIn : fonts?.body;\n const fontSize2 = font2?.size[spec.fontSize] ?? 0;\n const lineHeight = font2?.lineHeight?.[spec.fontSize];\n const paddingVertical = tokens.space[spec.paddingY];\n const fontPx = px(fontSize2);\n return {\n name: key,\n fontSizeKey: spec.fontSize,\n frame: {\n paddingHorizontal: tokens.space[spec.paddingX],\n paddingVertical,\n gap: tokens.space[spec.gap ?? spec.paddingY],\n borderRadius: tokens.radius[spec.radius]\n },\n text: { fontSize: fontSize2, lineHeight },\n icon: spec.icon ?? Math.ceil(fontPx / 4) * 4,\n controlHeight: (lineHeight ? px(lineHeight) : Math.round(fontPx * 1.5)) + px(paddingVertical) * 2\n };\n }\n const size = tokens.size[key];\n const font = fontIn?.size[key] != null ? fontIn : fonts?.body;\n const fontSize = font?.size[key];\n const sizePx = px(size);\n return {\n name: key,\n fontSizeKey: key,\n frame: {\n paddingHorizontal: tokens.space[key],\n gap: Math.round(sizePx * 0.2),\n borderRadius: tokens.radius[key],\n minHeight: size\n },\n text: { fontSize: fontSize ?? sizePx, lineHeight: font?.lineHeight?.[key] },\n icon: px(fontSize ?? sizePx),\n controlHeight: sizePx\n };\n};\nconst oneSizeSmaller = (value, sizes) => {\n const key = value === true || value == null ? sizes?.default : String(value).replace(/^\\$/, \"\");\n if (key == null) return \"3\";\n const names = Object.keys(sizes ?? {}).filter((name) => name !== \"default\");\n const index = names.indexOf(key);\n if (index !== -1) return names[Math.max(0, index - 1)];\n const n = Number(key);\n if (Number.isNaN(n)) return key;\n return `${Math.max(1, Math.round(n) - 1)}`;\n};\nexport {\n SizeContext,\n createSizeContext,\n oneSizeSmaller,\n resolveSize\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;AAKA,MAAM,qBAAqB,gBAAgB;CACzC,OAAO,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD;AACA,MAAM,cAAc,kBAAkB;A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Ae;CACjB;AACF;AACA,MAAM,kBAAkB,OAAO,UAAU;CACvC,MAAM,MAAM,UAAU,QAAQ,SAAS,OAAO,OAAO,UAAU,OAAO,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE;CAC9F,IAAI,OAAO,MAAM,OAAO;CACxB,MAAM,QAAQ,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,SAAS,SAAS,SAAS;CAC1E,MAAM,QAAQ,MAAM,QAAQ,GAAG;CAC/B,IAAI,UAAU,CAAC,GAAG,OAAO,MAAM,KAAK,IAAI,GAAG,QAAQ,CAAC;CACpD,MAAM,IAAI,OAAO,GAAG;CACpB,IAAI,OAAO,MAAM,CAAC,GAAG,OAAO;CAC5B,OAAO,GAAG,KAAK,IAAI,GAAG,KAAK,MAAM,CAAC,IAAI,CAAC;AACzC"}
@@ -0,0 +1,117 @@
1
+ import { createStyledContext, getConfig, getVariableValue } from "@tamagui/web";
2
+
3
+ var createSizeContext = function(defaultSize) {
4
+ return createStyledContext({ size: defaultSize });
5
+ };
6
+ var SizeContext = createSizeContext();
7
+ var configEnv = function() {
8
+ var conf = getConfig();
9
+ return {
10
+ tokens: conf.tokensParsed,
11
+ font: conf.fontsParsed[conf.defaultFontToken],
12
+ fonts: conf.fontsParsed,
13
+ sizes: conf.sizes
14
+ };
15
+ };
16
+ var warnedNoDefault = false;
17
+ var px = function(value) {
18
+ var n = Number.parseFloat(String(getVariableValue(value)));
19
+ return Number.isFinite(n) ? n : 0;
20
+ };
21
+ var resolveSize = function(value) {
22
+ var env = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : configEnv();
23
+ var _fonts_body, _font_lineHeight;
24
+ var { tokens, font: fontIn, fonts, sizes } = env;
25
+ var key;
26
+ if (value === true || value == null) {
27
+ key = sizes === null || sizes === void 0 ? void 0 : sizes.default;
28
+ } else if (typeof value === "number") {
29
+ if (process.env.NODE_ENV === "development") {
30
+ console.error(`size={${value}} is not a control size. Use a named size (${Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(k) {
31
+ return k !== "default";
32
+ }).join(", ") || "none configured"}) or a token key. Falling back to the default.`);
33
+ }
34
+ key = sizes === null || sizes === void 0 ? void 0 : sizes.default;
35
+ } else {
36
+ key = String(value);
37
+ if (key[0] === "$") key = key.slice(1);
38
+ }
39
+ if (key == null) {
40
+ if (process.env.NODE_ENV === "development" && !warnedNoDefault) {
41
+ warnedNoDefault = true;
42
+ console.error(`No default size: pass "sizes" to createTamagui (see @tamagui/config/v6 "sizes"). Falling back to token "4".`);
43
+ }
44
+ key = "4";
45
+ }
46
+ var spec = key === "default" ? void 0 : sizes === null || sizes === void 0 ? void 0 : sizes[key];
47
+ for (var attempt = 0; attempt < 2 && !(spec && typeof spec === "object") && tokens.size[key] == null && (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[key]) == null && (fonts === null || fonts === void 0 ? void 0 : (_fonts_body = fonts.body) === null || _fonts_body === void 0 ? void 0 : _fonts_body.size[key]) == null; attempt++) {
48
+ if (process.env.NODE_ENV === "development" && attempt === 0) {
49
+ console.error(`Unknown size "${key}": not a named size (${Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(k) {
50
+ return k !== "default";
51
+ }).join(", ") || "none configured"}) and not a token key. Falling back to the default.`);
52
+ }
53
+ key = attempt === 0 ? (sizes === null || sizes === void 0 ? void 0 : sizes.default) || "4" : "4";
54
+ spec = key === "default" ? void 0 : sizes === null || sizes === void 0 ? void 0 : sizes[key];
55
+ }
56
+ if (spec && typeof spec === "object") {
57
+ var _font_lineHeight1;
58
+ var font = (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[spec.fontSize]) != null ? fontIn : fonts === null || fonts === void 0 ? void 0 : fonts.body;
59
+ var _font_size_spec_fontSize;
60
+ var fontSize = (_font_size_spec_fontSize = font === null || font === void 0 ? void 0 : font.size[spec.fontSize]) !== null && _font_size_spec_fontSize !== void 0 ? _font_size_spec_fontSize : 0;
61
+ var lineHeight = font === null || font === void 0 ? void 0 : (_font_lineHeight1 = font.lineHeight) === null || _font_lineHeight1 === void 0 ? void 0 : _font_lineHeight1[spec.fontSize];
62
+ var paddingVertical = tokens.space[spec.paddingY];
63
+ var fontPx = px(fontSize);
64
+ var _spec_gap, _spec_icon;
65
+ return {
66
+ name: key,
67
+ fontSizeKey: spec.fontSize,
68
+ frame: {
69
+ paddingHorizontal: tokens.space[spec.paddingX],
70
+ paddingVertical,
71
+ gap: tokens.space[(_spec_gap = spec.gap) !== null && _spec_gap !== void 0 ? _spec_gap : spec.paddingY],
72
+ borderRadius: tokens.radius[spec.radius]
73
+ },
74
+ text: {
75
+ fontSize,
76
+ lineHeight
77
+ },
78
+ icon: (_spec_icon = spec.icon) !== null && _spec_icon !== void 0 ? _spec_icon : Math.ceil(fontPx / 4) * 4,
79
+ controlHeight: (lineHeight ? px(lineHeight) : Math.round(fontPx * 1.5)) + px(paddingVertical) * 2
80
+ };
81
+ }
82
+ var size = tokens.size[key];
83
+ var font1 = (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[key]) != null ? fontIn : fonts === null || fonts === void 0 ? void 0 : fonts.body;
84
+ var fontSize1 = font1 === null || font1 === void 0 ? void 0 : font1.size[key];
85
+ var sizePx = px(size);
86
+ return {
87
+ name: key,
88
+ fontSizeKey: key,
89
+ frame: {
90
+ paddingHorizontal: tokens.space[key],
91
+ gap: Math.round(sizePx * .2),
92
+ borderRadius: tokens.radius[key],
93
+ minHeight: size
94
+ },
95
+ text: {
96
+ fontSize: fontSize1 !== null && fontSize1 !== void 0 ? fontSize1 : sizePx,
97
+ lineHeight: font1 === null || font1 === void 0 ? void 0 : (_font_lineHeight = font1.lineHeight) === null || _font_lineHeight === void 0 ? void 0 : _font_lineHeight[key]
98
+ },
99
+ icon: px(fontSize1 !== null && fontSize1 !== void 0 ? fontSize1 : sizePx),
100
+ controlHeight: sizePx
101
+ };
102
+ };
103
+ var oneSizeSmaller = function(value, sizes) {
104
+ var key = value === true || value == null ? sizes === null || sizes === void 0 ? void 0 : sizes.default : String(value).replace(/^\$/, "");
105
+ if (key == null) return "3";
106
+ var names = Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(name) {
107
+ return name !== "default";
108
+ });
109
+ var index = names.indexOf(key);
110
+ if (index !== -1) return names[Math.max(0, index - 1)];
111
+ var n = Number(key);
112
+ if (Number.isNaN(n)) return key;
113
+ return `${Math.max(1, Math.round(n) - 1)}`;
114
+ };
115
+
116
+ export { SizeContext, createSizeContext, oneSizeSmaller, resolveSize };
117
+ //# sourceMappingURL=index.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.native.js","names":[],"sources":["esm/index.native.js"],"sourcesContent":["import { createStyledContext, getConfig, getVariableValue } from \"@tamagui/web\";\nvar createSizeContext = function(defaultSize) {\n return createStyledContext({\n size: defaultSize\n });\n};\nvar SizeContext = createSizeContext();\nvar configEnv = function() {\n var conf = getConfig();\n return {\n tokens: conf.tokensParsed,\n font: conf.fontsParsed[conf.defaultFontToken],\n fonts: conf.fontsParsed,\n sizes: conf.sizes\n };\n};\nvar warnedNoDefault = false;\nvar px = function(value) {\n var n = Number.parseFloat(String(getVariableValue(value)));\n return Number.isFinite(n) ? n : 0;\n};\nvar resolveSize = function(value) {\n var env = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : configEnv();\n var _fonts_body, _font_lineHeight;\n var { tokens, font: fontIn, fonts, sizes } = env;\n var key;\n if (value === true || value == null) {\n key = sizes === null || sizes === void 0 ? void 0 : sizes.default;\n } else if (typeof value === \"number\") {\n if (process.env.NODE_ENV === \"development\") {\n console.error(`size={${value}} is not a control size. Use a named size (${Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(k) {\n return k !== \"default\";\n }).join(\", \") || \"none configured\"}) or a token key. Falling back to the default.`);\n }\n key = sizes === null || sizes === void 0 ? void 0 : sizes.default;\n } else {\n key = String(value);\n if (key[0] === \"$\") key = key.slice(1);\n }\n if (key == null) {\n if (process.env.NODE_ENV === \"development\" && !warnedNoDefault) {\n warnedNoDefault = true;\n console.error(`No default size: pass \"sizes\" to createTamagui (see @tamagui/config/v6 \"sizes\"). Falling back to token \"4\".`);\n }\n key = \"4\";\n }\n var spec = key === \"default\" ? void 0 : sizes === null || sizes === void 0 ? void 0 : sizes[key];\n for (var attempt = 0; attempt < 2 && !(spec && typeof spec === \"object\") && tokens.size[key] == null && (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[key]) == null && (fonts === null || fonts === void 0 ? void 0 : (_fonts_body = fonts.body) === null || _fonts_body === void 0 ? void 0 : _fonts_body.size[key]) == null; attempt++) {\n if (process.env.NODE_ENV === \"development\" && attempt === 0) {\n console.error(`Unknown size \"${key}\": not a named size (${Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(k) {\n return k !== \"default\";\n }).join(\", \") || \"none configured\"}) and not a token key. Falling back to the default.`);\n }\n key = attempt === 0 ? (sizes === null || sizes === void 0 ? void 0 : sizes.default) || \"4\" : \"4\";\n spec = key === \"default\" ? void 0 : sizes === null || sizes === void 0 ? void 0 : sizes[key];\n }\n if (spec && typeof spec === \"object\") {\n var _font_lineHeight1;\n var font = (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[spec.fontSize]) != null ? fontIn : fonts === null || fonts === void 0 ? void 0 : fonts.body;\n var _font_size_spec_fontSize;\n var fontSize = (_font_size_spec_fontSize = font === null || font === void 0 ? void 0 : font.size[spec.fontSize]) !== null && _font_size_spec_fontSize !== void 0 ? _font_size_spec_fontSize : 0;\n var lineHeight = font === null || font === void 0 ? void 0 : (_font_lineHeight1 = font.lineHeight) === null || _font_lineHeight1 === void 0 ? void 0 : _font_lineHeight1[spec.fontSize];\n var paddingVertical = tokens.space[spec.paddingY];\n var fontPx = px(fontSize);\n var _spec_gap, _spec_icon;\n return {\n name: key,\n fontSizeKey: spec.fontSize,\n frame: {\n paddingHorizontal: tokens.space[spec.paddingX],\n paddingVertical,\n gap: tokens.space[(_spec_gap = spec.gap) !== null && _spec_gap !== void 0 ? _spec_gap : spec.paddingY],\n borderRadius: tokens.radius[spec.radius]\n },\n text: {\n fontSize,\n lineHeight\n },\n icon: (_spec_icon = spec.icon) !== null && _spec_icon !== void 0 ? _spec_icon : Math.ceil(fontPx / 4) * 4,\n controlHeight: (lineHeight ? px(lineHeight) : Math.round(fontPx * 1.5)) + px(paddingVertical) * 2\n };\n }\n var size = tokens.size[key];\n var font1 = (fontIn === null || fontIn === void 0 ? void 0 : fontIn.size[key]) != null ? fontIn : fonts === null || fonts === void 0 ? void 0 : fonts.body;\n var fontSize1 = font1 === null || font1 === void 0 ? void 0 : font1.size[key];\n var sizePx = px(size);\n return {\n name: key,\n fontSizeKey: key,\n frame: {\n paddingHorizontal: tokens.space[key],\n gap: Math.round(sizePx * 0.2),\n borderRadius: tokens.radius[key],\n minHeight: size\n },\n text: {\n fontSize: fontSize1 !== null && fontSize1 !== void 0 ? fontSize1 : sizePx,\n lineHeight: font1 === null || font1 === void 0 ? void 0 : (_font_lineHeight = font1.lineHeight) === null || _font_lineHeight === void 0 ? void 0 : _font_lineHeight[key]\n },\n icon: px(fontSize1 !== null && fontSize1 !== void 0 ? fontSize1 : sizePx),\n controlHeight: sizePx\n };\n};\nvar oneSizeSmaller = function(value, sizes) {\n var key = value === true || value == null ? sizes === null || sizes === void 0 ? void 0 : sizes.default : String(value).replace(/^\\$/, \"\");\n if (key == null) return \"3\";\n var names = Object.keys(sizes !== null && sizes !== void 0 ? sizes : {}).filter(function(name) {\n return name !== \"default\";\n });\n var index = names.indexOf(key);\n if (index !== -1) return names[Math.max(0, index - 1)];\n var n = Number(key);\n if (Number.isNaN(n)) return key;\n return `${Math.max(1, Math.round(n) - 1)}`;\n};\nexport {\n SizeContext,\n createSizeContext,\n oneSizeSmaller,\n resolveSize\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;AACA,IAAI,oBAAoB,SAAS,aAAa;CAC5C,OAAO,oBAAoB,EACzB,MAAM,YACR,CAAC;AACH;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K,IAAI,YAAY,MAAM;EACxE,eAAe;CACjB;AACF;AACA,IAAI,iBAAiB,SAAS,OAAO,OAAO;CAC1C,IAAI,MAAM,UAAU,QAAQ,SAAS,OAAO,UAAU,QAAQ,UAAU,KAAK,IAAI,KAAK,IAAI,MAAM,UAAU,OAAO,KAAK,CAAC,CAAC,QAAQ,OAAO,EAAE;CACzI,IAAI,OAAO,MAAM,OAAO;CACxB,IAAI,QAAQ,OAAO,KAAK,UAAU,QAAQ,UAAU,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,SAAS,MAAM;EAC7F,OAAO,SAAS;CAClB,CAAC;CACD,IAAI,QAAQ,MAAM,QAAQ,GAAG;CAC7B,IAAI,UAAU,CAAC,GAAG,OAAO,MAAM,KAAK,IAAI,GAAG,QAAQ,CAAC;CACpD,IAAI,IAAI,OAAO,GAAG;CAClB,IAAI,OAAO,MAAM,CAAC,GAAG,OAAO;CAC5B,OAAO,GAAG,KAAK,IAAI,GAAG,KAAK,MAAM,CAAC,IAAI,CAAC;AACzC"}
package/package.json CHANGED
@@ -1,13 +1,55 @@
1
1
  {
2
2
  "name": "@tamagui/size",
3
- "version": "0.0.0-bootstrap.0",
4
- "description": "Tamagui v3 package bootstrap",
5
- "repository": "https://github.com/tamagui/tamagui",
3
+ "version": "3.0.0-beta.1097.1",
4
+ "description": "Component-agnostic size context and skin table helpers",
6
5
  "license": "MIT",
6
+ "source": "src/index.ts",
7
7
  "files": [
8
- "README.md"
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
+ },
39
+ "dependencies": {
40
+ "@tamagui/web": "3.0.0-beta.1097.1"
41
+ },
42
+ "devDependencies": {
43
+ "@tamagui/build": "3.0.0-beta.1097.1",
44
+ "react": "19.2.3",
45
+ "vitest": "4.1.0"
46
+ },
47
+ "peerDependencies": {
48
+ "react": ">=19"
49
+ },
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/tamagui/tamagui.git",
53
+ "directory": "code/core/size"
12
54
  }
13
55
  }
package/src/index.ts ADDED
@@ -0,0 +1,216 @@
1
+ import {
2
+ createStyledContext,
3
+ getConfig,
4
+ getVariableValue,
5
+ type FontSizeTokens,
6
+ type GenericFont,
7
+ type GenericSizes,
8
+ type SizeSpec,
9
+ type SizeTokens,
10
+ type StyledContext,
11
+ type TokensParsed,
12
+ type Variable,
13
+ } from '@tamagui/web'
14
+
15
+ export type { GenericSizes, SizeSpec }
16
+
17
+ export type TokenSize = SizeTokens | FontSizeTokens | number | true
18
+
19
+ export type SizeContextValue<Value extends TokenSize = TokenSize> = {
20
+ size: Value | undefined
21
+ }
22
+
23
+ export type CreatedSizeContext<Value extends TokenSize = TokenSize> = StyledContext<
24
+ SizeContextValue<Value>,
25
+ 'size'
26
+ >
27
+
28
+ export const createSizeContext = <Value extends TokenSize = TokenSize>(
29
+ defaultSize?: Value
30
+ ): CreatedSizeContext<Value> => {
31
+ return createStyledContext<SizeContextValue<Value>>({ size: defaultSize })
32
+ }
33
+
34
+ export const SizeContext: CreatedSizeContext = createSizeContext()
35
+
36
+ export type SizeResolverEnv = {
37
+ tokens: Pick<TokensParsed, 'size' | 'space' | 'radius'>
38
+ /** the component's font; a key it lacks falls back to `fonts.body` */
39
+ font?: GenericFont
40
+ fonts?: { body?: GenericFont; [name: string]: GenericFont | undefined }
41
+ sizes?: GenericSizes
42
+ }
43
+
44
+ export type ResolvedSize = {
45
+ /** the named size, or the token key */
46
+ name: string
47
+ /** the font.size key the text was sized against */
48
+ fontSizeKey: string
49
+ /** spread onto the frame */
50
+ frame: {
51
+ paddingHorizontal: number | Variable
52
+ paddingVertical?: number | Variable
53
+ gap: number | Variable
54
+ borderRadius: number | Variable
55
+ /** token keys only: v2's "size is the control height" */
56
+ minHeight?: number | Variable
57
+ }
58
+ /** spread onto the text */
59
+ text: {
60
+ fontSize: number | Variable
61
+ lineHeight?: number | Variable
62
+ }
63
+ /** px: the recipe's icon, or the font size rounded up to the 4px grid; a token key's font size as is */
64
+ icon: number
65
+ /** px, without border: line-height plus vertical padding for a name, tokens.size for a key */
66
+ controlHeight: number
67
+ }
68
+
69
+ /** outside a style pass (icons, imperative measurements): the config's default font */
70
+ const configEnv = (): SizeResolverEnv => {
71
+ const conf = getConfig()
72
+ return {
73
+ tokens: conf.tokensParsed,
74
+ font: conf.fontsParsed[conf.defaultFontToken],
75
+ fonts: conf.fontsParsed,
76
+ sizes: conf.sizes,
77
+ }
78
+ }
79
+
80
+ let warnedNoDefault = false
81
+
82
+ const px = (value: unknown) => {
83
+ const n = Number.parseFloat(String(getVariableValue(value)))
84
+ return Number.isFinite(n) ? n : 0
85
+ }
86
+
87
+ /**
88
+ * A `size` prop is one of three things, checked in this order:
89
+ *
90
+ * - `true` (or nothing): the config's default named size
91
+ * - a name in `config.sizes`: a recipe of token keys, never a height
92
+ * - a token key like `4` or `$4`: v2's index into every scale at once
93
+ *
94
+ * A named size never sets a height. The control ends up line-height plus
95
+ * padding tall, so the frame, its text and its icon agree by construction.
96
+ * Icons default to the font size rounded up to the 4px grid (12, 16, 16, 20).
97
+ */
98
+ export const resolveSize = (
99
+ value: TokenSize | null | undefined,
100
+ env: SizeResolverEnv = configEnv()
101
+ ): ResolvedSize => {
102
+ const { tokens, font: fontIn, fonts, sizes } = env
103
+ let key: string | undefined
104
+ if (value === true || value == null) {
105
+ key = sizes?.default
106
+ } else if (typeof value === 'number') {
107
+ if (process.env.NODE_ENV === 'development') {
108
+ console.error(
109
+ `size={${value}} is not a control size. Use a named size (${
110
+ Object.keys(sizes ?? {})
111
+ .filter((k) => k !== 'default')
112
+ .join(', ') || 'none configured'
113
+ }) or a token key. Falling back to the default.`
114
+ )
115
+ }
116
+ key = sizes?.default
117
+ } else {
118
+ key = String(value)
119
+ if (key[0] === '$') key = key.slice(1)
120
+ }
121
+
122
+ if (key == null) {
123
+ if (process.env.NODE_ENV === 'development' && !warnedNoDefault) {
124
+ warnedNoDefault = true
125
+ console.error(
126
+ `No default size: pass "sizes" to createTamagui (see @tamagui/config/v6 "sizes"). Falling back to token "4".`
127
+ )
128
+ }
129
+ key = '4'
130
+ }
131
+
132
+ let spec = key === 'default' ? undefined : sizes?.[key]
133
+ // Try the authored key, then the configured default, then token 4. Reuse
134
+ // one validity check and bound retries even when the default is invalid.
135
+ for (
136
+ let attempt = 0;
137
+ attempt < 2 &&
138
+ !(spec && typeof spec === 'object') &&
139
+ tokens.size[key] == null &&
140
+ fontIn?.size[key] == null &&
141
+ fonts?.body?.size[key] == null;
142
+ attempt++
143
+ ) {
144
+ if (process.env.NODE_ENV === 'development' && attempt === 0) {
145
+ console.error(
146
+ `Unknown size "${key}": not a named size (${
147
+ Object.keys(sizes ?? {})
148
+ .filter((k) => k !== 'default')
149
+ .join(', ') || 'none configured'
150
+ }) and not a token key. Falling back to the default.`
151
+ )
152
+ }
153
+ key = attempt === 0 ? sizes?.default || '4' : '4'
154
+ spec = key === 'default' ? undefined : sizes?.[key]
155
+ }
156
+
157
+ if (spec && typeof spec === 'object') {
158
+ const font = fontIn?.size[spec.fontSize] != null ? fontIn : fonts?.body
159
+ const fontSize = font?.size[spec.fontSize] ?? 0
160
+ const lineHeight = font?.lineHeight?.[spec.fontSize]
161
+ const paddingVertical = tokens.space[spec.paddingY]
162
+ const fontPx = px(fontSize)
163
+ return {
164
+ name: key,
165
+ fontSizeKey: spec.fontSize,
166
+ frame: {
167
+ paddingHorizontal: tokens.space[spec.paddingX],
168
+ paddingVertical,
169
+ gap: tokens.space[spec.gap ?? spec.paddingY],
170
+ borderRadius: tokens.radius[spec.radius],
171
+ },
172
+ text: { fontSize, lineHeight },
173
+ icon: spec.icon ?? Math.ceil(fontPx / 4) * 4,
174
+ controlHeight:
175
+ (lineHeight ? px(lineHeight) : Math.round(fontPx * 1.5)) +
176
+ px(paddingVertical) * 2,
177
+ }
178
+ }
179
+
180
+ const size = tokens.size[key]
181
+ const font = fontIn?.size[key] != null ? fontIn : fonts?.body
182
+ const fontSize = font?.size[key]
183
+ const sizePx = px(size)
184
+ return {
185
+ name: key,
186
+ fontSizeKey: key,
187
+ frame: {
188
+ paddingHorizontal: tokens.space[key],
189
+ gap: Math.round(sizePx * 0.2),
190
+ borderRadius: tokens.radius[key],
191
+ minHeight: size,
192
+ },
193
+ text: { fontSize: fontSize ?? sizePx, lineHeight: font?.lineHeight?.[key] },
194
+ icon: px(fontSize ?? sizePx),
195
+ controlHeight: sizePx,
196
+ }
197
+ }
198
+
199
+ /**
200
+ * One step smaller: the previous name in `sizes` (clamped at the smallest), or
201
+ * for a token key the previous whole number (clamped at 1).
202
+ */
203
+ export const oneSizeSmaller = (
204
+ value: TokenSize | null | undefined,
205
+ sizes: GenericSizes | undefined
206
+ ): string => {
207
+ const key =
208
+ value === true || value == null ? sizes?.default : String(value).replace(/^\$/, '')
209
+ if (key == null) return '3'
210
+ const names = Object.keys(sizes ?? {}).filter((name) => name !== 'default')
211
+ const index = names.indexOf(key)
212
+ if (index !== -1) return names[Math.max(0, index - 1)]
213
+ const n = Number(key)
214
+ if (Number.isNaN(n)) return key
215
+ return `${Math.max(1, Math.round(n) - 1)}`
216
+ }
@@ -0,0 +1,62 @@
1
+ import { type FontSizeTokens, type GenericFont, type GenericSizes, type SizeSpec, type SizeTokens, type StyledContext, type TokensParsed, type Variable } from "@tamagui/web";
2
+ export type { GenericSizes, SizeSpec };
3
+ export type TokenSize = SizeTokens | FontSizeTokens | number | true;
4
+ export type SizeContextValue<Value extends TokenSize = TokenSize> = {
5
+ size: Value | undefined;
6
+ };
7
+ export type CreatedSizeContext<Value extends TokenSize = TokenSize> = StyledContext<SizeContextValue<Value>, "size">;
8
+ export declare const createSizeContext: <Value extends TokenSize = TokenSize>(defaultSize?: Value) => CreatedSizeContext<Value>;
9
+ export declare const SizeContext: CreatedSizeContext;
10
+ export type SizeResolverEnv = {
11
+ tokens: Pick<TokensParsed, "size" | "space" | "radius">;
12
+ /** the component's font; a key it lacks falls back to `fonts.body` */
13
+ font?: GenericFont;
14
+ fonts?: {
15
+ body?: GenericFont;
16
+ [name: string]: GenericFont | undefined;
17
+ };
18
+ sizes?: GenericSizes;
19
+ };
20
+ export type ResolvedSize = {
21
+ /** the named size, or the token key */
22
+ name: string;
23
+ /** the font.size key the text was sized against */
24
+ fontSizeKey: string;
25
+ /** spread onto the frame */
26
+ frame: {
27
+ paddingHorizontal: number | Variable;
28
+ paddingVertical?: number | Variable;
29
+ gap: number | Variable;
30
+ borderRadius: number | Variable;
31
+ /** token keys only: v2's "size is the control height" */
32
+ minHeight?: number | Variable;
33
+ };
34
+ /** spread onto the text */
35
+ text: {
36
+ fontSize: number | Variable;
37
+ lineHeight?: number | Variable;
38
+ };
39
+ /** px: the recipe's icon, or the font size rounded up to the 4px grid; a token key's font size as is */
40
+ icon: number;
41
+ /** px, without border: line-height plus vertical padding for a name, tokens.size for a key */
42
+ controlHeight: number;
43
+ };
44
+ /**
45
+ * A `size` prop is one of three things, checked in this order:
46
+ *
47
+ * - `true` (or nothing): the config's default named size
48
+ * - a name in `config.sizes`: a recipe of token keys, never a height
49
+ * - a token key like `4` or `$4`: v2's index into every scale at once
50
+ *
51
+ * A named size never sets a height. The control ends up line-height plus
52
+ * padding tall, so the frame, its text and its icon agree by construction.
53
+ * Icons default to the font size rounded up to the 4px grid (12, 16, 16, 20).
54
+ */
55
+ export declare const resolveSize: (value: TokenSize | null | undefined, env?: SizeResolverEnv) => ResolvedSize;
56
+ /**
57
+ * One step smaller: the previous name in `sizes` (clamped at the smallest), or
58
+ * for a token key the previous whole number (clamped at 1).
59
+ */
60
+ export declare const oneSizeSmaller: (value: TokenSize | null | undefined, sizes: GenericSizes | undefined) => string;
61
+
62
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,11 @@
1
+ {
2
+ "mappings": "AAAA,cAIO,qBACA,kBACA,mBACA,eACA,iBACA,oBACA,mBACA,gBACA;AAEP,cAAc,cAAc;AAE5B,YAAY,YAAY,aAAa,0BAA0B;AAE/D,YAAY,iBAAiB,cAAc,YAAY,aAAa;CAClE,MAAM;;AAGR,YAAY,mBAAmB,cAAc,YAAY,aAAa,cACpE,iBAAiB,QACjB;AAGF,OAAO,cAAM,oBAAqB,cAAc,YAAY,WAC1D,cAAc,UACb,mBAAmB;AAItB,OAAO,cAAM,aAAa;AAE1B,YAAY,kBAAkB;CAC5B,QAAQ,KAAK,cAAc,SAAS,UAAU;;CAE9C,OAAO;CACP,QAAQ;EAAE,OAAO;kBAA6B;;CAC9C,QAAQ;;AAGV,YAAY,eAAe;;CAEzB;;CAEA;;CAEA,OAAO;EACL,4BAA4B;EAC5B,2BAA2B;EAC3B,cAAc;EACd,uBAAuB;;EAEvB,qBAAqB;;;CAGvB,MAAM;EACJ,mBAAmB;EACnB,sBAAsB;;;CAGxB;;CAEA;;;;;;;;;;;;;AAgCF,OAAO,cAAM,cACX,OAAO,8BACP,MAAK,oBACJ;;;;;AAsGH,OAAO,cAAM,iBACX,OAAO,8BACP,OAAO",
3
+ "names": [],
4
+ "sources": [
5
+ "src/index.ts"
6
+ ],
7
+ "version": 3,
8
+ "sourcesContent": [
9
+ "import {\n createStyledContext,\n getConfig,\n getVariableValue,\n type FontSizeTokens,\n type GenericFont,\n type GenericSizes,\n type SizeSpec,\n type SizeTokens,\n type StyledContext,\n type TokensParsed,\n type Variable,\n} from '@tamagui/web'\n\nexport type { GenericSizes, SizeSpec }\n\nexport type TokenSize = SizeTokens | FontSizeTokens | number | true\n\nexport type SizeContextValue<Value extends TokenSize = TokenSize> = {\n size: Value | undefined\n}\n\nexport type CreatedSizeContext<Value extends TokenSize = TokenSize> = StyledContext<\n SizeContextValue<Value>,\n 'size'\n>\n\nexport const createSizeContext = <Value extends TokenSize = TokenSize>(\n defaultSize?: Value\n): CreatedSizeContext<Value> => {\n return createStyledContext<SizeContextValue<Value>>({ size: defaultSize })\n}\n\nexport const SizeContext: CreatedSizeContext = createSizeContext()\n\nexport type SizeResolverEnv = {\n tokens: Pick<TokensParsed, 'size' | 'space' | 'radius'>\n /** the component's font; a key it lacks falls back to `fonts.body` */\n font?: GenericFont\n fonts?: { body?: GenericFont; [name: string]: GenericFont | undefined }\n sizes?: GenericSizes\n}\n\nexport type ResolvedSize = {\n /** the named size, or the token key */\n name: string\n /** the font.size key the text was sized against */\n fontSizeKey: string\n /** spread onto the frame */\n frame: {\n paddingHorizontal: number | Variable\n paddingVertical?: number | Variable\n gap: number | Variable\n borderRadius: number | Variable\n /** token keys only: v2's \"size is the control height\" */\n minHeight?: number | Variable\n }\n /** spread onto the text */\n text: {\n fontSize: number | Variable\n lineHeight?: number | Variable\n }\n /** px: the recipe's icon, or the font size rounded up to the 4px grid; a token key's font size as is */\n icon: number\n /** px, without border: line-height plus vertical padding for a name, tokens.size for a key */\n controlHeight: number\n}\n\n/** outside a style pass (icons, imperative measurements): the config's default font */\nconst configEnv = (): SizeResolverEnv => {\n const conf = getConfig()\n return {\n tokens: conf.tokensParsed,\n font: conf.fontsParsed[conf.defaultFontToken],\n fonts: conf.fontsParsed,\n sizes: conf.sizes,\n }\n}\n\nlet warnedNoDefault = false\n\nconst px = (value: unknown) => {\n const n = Number.parseFloat(String(getVariableValue(value)))\n return Number.isFinite(n) ? n : 0\n}\n\n/**\n * A `size` prop is one of three things, checked in this order:\n *\n * - `true` (or nothing): the config's default named size\n * - a name in `config.sizes`: a recipe of token keys, never a height\n * - a token key like `4` or `$4`: v2's index into every scale at once\n *\n * A named size never sets a height. The control ends up line-height plus\n * padding tall, so the frame, its text and its icon agree by construction.\n * Icons default to the font size rounded up to the 4px grid (12, 16, 16, 20).\n */\nexport const resolveSize = (\n value: TokenSize | null | undefined,\n env: SizeResolverEnv = configEnv()\n): ResolvedSize => {\n const { tokens, font: fontIn, fonts, sizes } = env\n let key: string | undefined\n if (value === true || value == null) {\n key = sizes?.default\n } else if (typeof value === 'number') {\n if (process.env.NODE_ENV === 'development') {\n console.error(\n `size={${value}} is not a control size. Use a named size (${\n Object.keys(sizes ?? {})\n .filter((k) => k !== 'default')\n .join(', ') || 'none configured'\n }) or a token key. Falling back to the default.`\n )\n }\n key = sizes?.default\n } else {\n key = String(value)\n if (key[0] === '$') key = key.slice(1)\n }\n\n if (key == null) {\n if (process.env.NODE_ENV === 'development' && !warnedNoDefault) {\n warnedNoDefault = true\n console.error(\n `No default size: pass \"sizes\" to createTamagui (see @tamagui/config/v6 \"sizes\"). Falling back to token \"4\".`\n )\n }\n key = '4'\n }\n\n let spec = key === 'default' ? undefined : sizes?.[key]\n // Try the authored key, then the configured default, then token 4. Reuse\n // one validity check and bound retries even when the default is invalid.\n for (\n let attempt = 0;\n attempt < 2 &&\n !(spec && typeof spec === 'object') &&\n tokens.size[key] == null &&\n fontIn?.size[key] == null &&\n fonts?.body?.size[key] == null;\n attempt++\n ) {\n if (process.env.NODE_ENV === 'development' && attempt === 0) {\n console.error(\n `Unknown size \"${key}\": not a named size (${\n Object.keys(sizes ?? {})\n .filter((k) => k !== 'default')\n .join(', ') || 'none configured'\n }) and not a token key. Falling back to the default.`\n )\n }\n key = attempt === 0 ? sizes?.default || '4' : '4'\n spec = key === 'default' ? undefined : sizes?.[key]\n }\n\n if (spec && typeof spec === 'object') {\n const font = fontIn?.size[spec.fontSize] != null ? fontIn : fonts?.body\n const fontSize = font?.size[spec.fontSize] ?? 0\n const lineHeight = font?.lineHeight?.[spec.fontSize]\n const paddingVertical = tokens.space[spec.paddingY]\n const fontPx = px(fontSize)\n return {\n name: key,\n fontSizeKey: spec.fontSize,\n frame: {\n paddingHorizontal: tokens.space[spec.paddingX],\n paddingVertical,\n gap: tokens.space[spec.gap ?? spec.paddingY],\n borderRadius: tokens.radius[spec.radius],\n },\n text: { fontSize, lineHeight },\n icon: spec.icon ?? Math.ceil(fontPx / 4) * 4,\n controlHeight:\n (lineHeight ? px(lineHeight) : Math.round(fontPx * 1.5)) +\n px(paddingVertical) * 2,\n }\n }\n\n const size = tokens.size[key]\n const font = fontIn?.size[key] != null ? fontIn : fonts?.body\n const fontSize = font?.size[key]\n const sizePx = px(size)\n return {\n name: key,\n fontSizeKey: key,\n frame: {\n paddingHorizontal: tokens.space[key],\n gap: Math.round(sizePx * 0.2),\n borderRadius: tokens.radius[key],\n minHeight: size,\n },\n text: { fontSize: fontSize ?? sizePx, lineHeight: font?.lineHeight?.[key] },\n icon: px(fontSize ?? sizePx),\n controlHeight: sizePx,\n }\n}\n\n/**\n * One step smaller: the previous name in `sizes` (clamped at the smallest), or\n * for a token key the previous whole number (clamped at 1).\n */\nexport const oneSizeSmaller = (\n value: TokenSize | null | undefined,\n sizes: GenericSizes | undefined\n): string => {\n const key =\n value === true || value == null ? sizes?.default : String(value).replace(/^\\$/, '')\n if (key == null) return '3'\n const names = Object.keys(sizes ?? {}).filter((name) => name !== 'default')\n const index = names.indexOf(key)\n if (index !== -1) return names[Math.max(0, index - 1)]\n const n = Number(key)\n if (Number.isNaN(n)) return key\n return `${Math.max(1, Math.round(n) - 1)}`\n}\n"
10
+ ]
11
+ }
package/README.md DELETED
@@ -1 +0,0 @@
1
- # @tamagui/size