@tamagui/get-token 2.7.7 → 3.0.0-beta.1093.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +29 -73
- package/dist/cjs/index.native.cjs +53 -0
- package/dist/cjs/index.native.js +35 -118
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/index.js +18 -56
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +18 -56
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +23 -101
- package/dist/esm/index.native.js.map +1 -1
- package/package.json +6 -4
- package/src/index.ts +24 -90
- package/types/index.d.ts +4 -12
- package/types/index.d.ts.map +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,85 +3,41 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
10
|
};
|
|
11
11
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
19
|
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
21
|
var index_exports = {};
|
|
24
22
|
__export(index_exports, {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
getTokenRelative: () => getTokenRelative,
|
|
29
|
-
stepTokenUpOrDown: () => stepTokenUpOrDown
|
|
23
|
+
getRadius: () => getRadius,
|
|
24
|
+
getSize: () => getSize,
|
|
25
|
+
getSpace: () => getSpace
|
|
30
26
|
});
|
|
31
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
var import_size = require("@tamagui/size");
|
|
32
29
|
var import_web = require("@tamagui/web");
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const resolveToken = (type, input) => {
|
|
31
|
+
if (input == null || typeof input === "number") return input;
|
|
32
|
+
const tokens = (0, import_web.getTokens)()[type];
|
|
33
|
+
const key = typeof input === "object" ? input.key : String(input);
|
|
34
|
+
if (input === true || (0, import_web.getConfig)().sizes?.[key] != null) {
|
|
35
|
+
const resolved = (0, import_size.resolveSize)(input);
|
|
36
|
+
if (type === "size") return resolved.controlHeight;
|
|
37
|
+
return type === "space" ? resolved.frame.paddingHorizontal : resolved.frame.borderRadius;
|
|
38
|
+
}
|
|
39
|
+
return tokens[key] ?? input;
|
|
36
40
|
};
|
|
37
|
-
const getSize = (size
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const getSpace = (space, options) => {
|
|
41
|
-
return getTokenRelative("space", space, options);
|
|
42
|
-
};
|
|
43
|
-
const getRadius = (radius, options) => {
|
|
44
|
-
return getTokenRelative("radius", radius, options);
|
|
45
|
-
};
|
|
46
|
-
const cacheVariables = {};
|
|
47
|
-
const cacheWholeVariables = {};
|
|
48
|
-
const cacheKeys = {};
|
|
49
|
-
const cacheWholeKeys = {};
|
|
50
|
-
const stepTokenUpOrDown = (type, current, options = defaultOptions) => {
|
|
51
|
-
const tokens = (0, import_web.getTokens)({
|
|
52
|
-
prefixed: true
|
|
53
|
-
})[type];
|
|
54
|
-
if (!(type in cacheVariables)) {
|
|
55
|
-
cacheKeys[type] = [];
|
|
56
|
-
cacheVariables[type] = [];
|
|
57
|
-
cacheWholeKeys[type] = [];
|
|
58
|
-
cacheWholeVariables[type] = [];
|
|
59
|
-
const sorted = Object.keys(tokens).map(k => tokens[k]).sort((a, b) => a.val - b.val);
|
|
60
|
-
for (const token of sorted) {
|
|
61
|
-
cacheKeys[type].push(token.key);
|
|
62
|
-
cacheVariables[type].push(token);
|
|
63
|
-
}
|
|
64
|
-
const sortedExcludingHalfSteps = sorted.filter(x => !x.key.endsWith(".5"));
|
|
65
|
-
for (const token of sortedExcludingHalfSteps) {
|
|
66
|
-
cacheWholeKeys[type].push(token.key);
|
|
67
|
-
cacheWholeVariables[type].push(token);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const isString = typeof current === "string";
|
|
71
|
-
const cache = options.excludeHalfSteps ? isString ? cacheWholeKeys : cacheWholeVariables : isString ? cacheKeys : cacheVariables;
|
|
72
|
-
const tokensOrdered = cache[type];
|
|
73
|
-
const min = options.bounds?.[0] ?? 0;
|
|
74
|
-
const max = options.bounds?.[1] ?? tokensOrdered.length - 1;
|
|
75
|
-
const currentIndex = tokensOrdered.indexOf(current);
|
|
76
|
-
let shift = options.shift || 0;
|
|
77
|
-
if (shift) {
|
|
78
|
-
if (current === "$true" || (0, import_web.isVariable)(current) && current.name === "true") {
|
|
79
|
-
shift += shift > 0 ? 1 : -1;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
const index = Math.min(max, Math.max(min, currentIndex + shift));
|
|
83
|
-
const found = tokensOrdered[index];
|
|
84
|
-
const result = (typeof found === "string" ? tokens[found] : found) || tokens["$true"];
|
|
85
|
-
return result;
|
|
86
|
-
};
|
|
87
|
-
const getTokenRelative = stepTokenUpOrDown;
|
|
41
|
+
const getSize = (size) => resolveToken("size", size);
|
|
42
|
+
const getSpace = (space) => resolveToken("space", space);
|
|
43
|
+
const getRadius = (radius) => resolveToken("radius", radius);
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
getRadius: () => getRadius,
|
|
26
|
+
getSize: () => getSize,
|
|
27
|
+
getSpace: () => getSpace
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
var import_size = require("@tamagui/size");
|
|
31
|
+
var import_web = require("@tamagui/web");
|
|
32
|
+
var resolveToken = function(type, input) {
|
|
33
|
+
var _getConfig_sizes;
|
|
34
|
+
if (input == null || typeof input === "number") return input;
|
|
35
|
+
var tokens = (0, import_web.getTokens)()[type];
|
|
36
|
+
var key = typeof input === "object" ? input.key : String(input);
|
|
37
|
+
if (input === true || ((_getConfig_sizes = (0, import_web.getConfig)().sizes) === null || _getConfig_sizes === void 0 ? void 0 : _getConfig_sizes[key]) != null) {
|
|
38
|
+
var resolved = (0, import_size.resolveSize)(input);
|
|
39
|
+
if (type === "size") return resolved.controlHeight;
|
|
40
|
+
return type === "space" ? resolved.frame.paddingHorizontal : resolved.frame.borderRadius;
|
|
41
|
+
}
|
|
42
|
+
var _tokens_key;
|
|
43
|
+
return (_tokens_key = tokens[key]) !== null && _tokens_key !== void 0 ? _tokens_key : input;
|
|
44
|
+
};
|
|
45
|
+
var getSize = function(size) {
|
|
46
|
+
return resolveToken("size", size);
|
|
47
|
+
};
|
|
48
|
+
var getSpace = function(space) {
|
|
49
|
+
return resolveToken("space", space);
|
|
50
|
+
};
|
|
51
|
+
var getRadius = function(radius) {
|
|
52
|
+
return resolveToken("radius", radius);
|
|
53
|
+
};
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -5,134 +5,51 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
12
|
};
|
|
13
13
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
21
|
};
|
|
22
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
}), mod);
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
23
|
var index_exports = {};
|
|
26
24
|
__export(index_exports, {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
getTokenRelative: () => getTokenRelative,
|
|
31
|
-
stepTokenUpOrDown: () => stepTokenUpOrDown
|
|
25
|
+
getRadius: () => getRadius,
|
|
26
|
+
getSize: () => getSize,
|
|
27
|
+
getSpace: () => getSpace
|
|
32
28
|
});
|
|
33
29
|
module.exports = __toCommonJS(index_exports);
|
|
30
|
+
var import_size = require("@tamagui/size");
|
|
34
31
|
var import_web = require("@tamagui/web");
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
var resolveToken = function(type, input) {
|
|
33
|
+
var _getConfig_sizes;
|
|
34
|
+
if (input == null || typeof input === "number") return input;
|
|
35
|
+
var tokens = (0, import_web.getTokens)()[type];
|
|
36
|
+
var key = typeof input === "object" ? input.key : String(input);
|
|
37
|
+
if (input === true || ((_getConfig_sizes = (0, import_web.getConfig)().sizes) === null || _getConfig_sizes === void 0 ? void 0 : _getConfig_sizes[key]) != null) {
|
|
38
|
+
var resolved = (0, import_size.resolveSize)(input);
|
|
39
|
+
if (type === "size") return resolved.controlHeight;
|
|
40
|
+
return type === "space" ? resolved.frame.paddingHorizontal : resolved.frame.borderRadius;
|
|
41
|
+
}
|
|
42
|
+
var _tokens_key;
|
|
43
|
+
return (_tokens_key = tokens[key]) !== null && _tokens_key !== void 0 ? _tokens_key : input;
|
|
38
44
|
};
|
|
39
|
-
var getSize = function
|
|
40
|
-
|
|
45
|
+
var getSize = function(size) {
|
|
46
|
+
return resolveToken("size", size);
|
|
41
47
|
};
|
|
42
|
-
var getSpace = function
|
|
43
|
-
|
|
48
|
+
var getSpace = function(space) {
|
|
49
|
+
return resolveToken("space", space);
|
|
44
50
|
};
|
|
45
|
-
var getRadius = function
|
|
46
|
-
|
|
51
|
+
var getRadius = function(radius) {
|
|
52
|
+
return resolveToken("radius", radius);
|
|
47
53
|
};
|
|
48
|
-
|
|
49
|
-
var cacheWholeVariables = {};
|
|
50
|
-
var cacheKeys = {};
|
|
51
|
-
var cacheWholeKeys = {};
|
|
52
|
-
var stepTokenUpOrDown = function (type, current) {
|
|
53
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOptions;
|
|
54
|
-
var _options_bounds, _options_bounds1;
|
|
55
|
-
var tokens = (0, import_web.getTokens)({
|
|
56
|
-
prefixed: true
|
|
57
|
-
})[type];
|
|
58
|
-
if (!(type in cacheVariables)) {
|
|
59
|
-
cacheKeys[type] = [];
|
|
60
|
-
cacheVariables[type] = [];
|
|
61
|
-
cacheWholeKeys[type] = [];
|
|
62
|
-
cacheWholeVariables[type] = [];
|
|
63
|
-
var sorted = Object.keys(tokens).map(function (k) {
|
|
64
|
-
return tokens[k];
|
|
65
|
-
}).sort(function (a, b) {
|
|
66
|
-
return a.val - b.val;
|
|
67
|
-
});
|
|
68
|
-
var _iteratorNormalCompletion = true,
|
|
69
|
-
_didIteratorError = false,
|
|
70
|
-
_iteratorError = void 0;
|
|
71
|
-
try {
|
|
72
|
-
for (var _iterator = sorted[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
73
|
-
var token = _step.value;
|
|
74
|
-
cacheKeys[type].push(token.key);
|
|
75
|
-
cacheVariables[type].push(token);
|
|
76
|
-
}
|
|
77
|
-
} catch (err) {
|
|
78
|
-
_didIteratorError = true;
|
|
79
|
-
_iteratorError = err;
|
|
80
|
-
} finally {
|
|
81
|
-
try {
|
|
82
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
83
|
-
_iterator.return();
|
|
84
|
-
}
|
|
85
|
-
} finally {
|
|
86
|
-
if (_didIteratorError) {
|
|
87
|
-
throw _iteratorError;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
var sortedExcludingHalfSteps = sorted.filter(function (x) {
|
|
92
|
-
return !x.key.endsWith(".5");
|
|
93
|
-
});
|
|
94
|
-
var _iteratorNormalCompletion1 = true,
|
|
95
|
-
_didIteratorError1 = false,
|
|
96
|
-
_iteratorError1 = void 0;
|
|
97
|
-
try {
|
|
98
|
-
for (var _iterator1 = sortedExcludingHalfSteps[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
99
|
-
var token1 = _step1.value;
|
|
100
|
-
cacheWholeKeys[type].push(token1.key);
|
|
101
|
-
cacheWholeVariables[type].push(token1);
|
|
102
|
-
}
|
|
103
|
-
} catch (err) {
|
|
104
|
-
_didIteratorError1 = true;
|
|
105
|
-
_iteratorError1 = err;
|
|
106
|
-
} finally {
|
|
107
|
-
try {
|
|
108
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
109
|
-
_iterator1.return();
|
|
110
|
-
}
|
|
111
|
-
} finally {
|
|
112
|
-
if (_didIteratorError1) {
|
|
113
|
-
throw _iteratorError1;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
var isString = typeof current === "string";
|
|
119
|
-
var cache = options.excludeHalfSteps ? isString ? cacheWholeKeys : cacheWholeVariables : isString ? cacheKeys : cacheVariables;
|
|
120
|
-
var tokensOrdered = cache[type];
|
|
121
|
-
var _options_bounds_;
|
|
122
|
-
var min = (_options_bounds_ = (_options_bounds = options.bounds) === null || _options_bounds === void 0 ? void 0 : _options_bounds[0]) !== null && _options_bounds_ !== void 0 ? _options_bounds_ : 0;
|
|
123
|
-
var _options_bounds_1;
|
|
124
|
-
var max = (_options_bounds_1 = (_options_bounds1 = options.bounds) === null || _options_bounds1 === void 0 ? void 0 : _options_bounds1[1]) !== null && _options_bounds_1 !== void 0 ? _options_bounds_1 : tokensOrdered.length - 1;
|
|
125
|
-
var currentIndex = tokensOrdered.indexOf(current);
|
|
126
|
-
var shift = options.shift || 0;
|
|
127
|
-
if (shift) {
|
|
128
|
-
if (current === "$true" || (0, import_web.isVariable)(current) && current.name === "true") {
|
|
129
|
-
shift += shift > 0 ? 1 : -1;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
var index = Math.min(max, Math.max(min, currentIndex + shift));
|
|
133
|
-
var found = tokensOrdered[index];
|
|
134
|
-
var result = (typeof found === "string" ? tokens[found] : found) || tokens["$true"];
|
|
135
|
-
return result;
|
|
136
|
-
};
|
|
137
|
-
var getTokenRelative = stepTokenUpOrDown;
|
|
54
|
+
|
|
138
55
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","index_exports","getRadius","getSize","getSpace","getTokenRelative","stepTokenUpOrDown","module","exports","import_web","require","defaultOptions","shift","bounds","size","options","space","radius","cacheVariables","cacheWholeVariables","cacheKeys","cacheWholeKeys","type","current","arguments","length","_options_bounds","_options_bounds1","tokens","getTokens","prefixed","sorted","keys","map","k","sort","a","b","val","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Symbol","iterator","_step","next","done","token","push","err","return","sortedExcludingHalfSteps","filter","x","endsWith","_iteratorNormalCompletion1","_didIteratorError1","_iteratorError1","_iterator1","_step1","token1","isString","cache","excludeHalfSteps","tokensOrdered","_options_bounds_","min","_options_bounds_1","max","currentIndex","indexOf","isVariable","index","Math","found","result"],"sources":["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 getRadius: () => getRadius,\n getSize: () => getSize,\n getSpace: () => getSpace,\n getTokenRelative: () => getTokenRelative,\n stepTokenUpOrDown: () => stepTokenUpOrDown\n});\nmodule.exports = __toCommonJS(index_exports);\nvar import_web = require(\"@tamagui/web\");\nvar defaultOptions = {\n shift: 0,\n bounds: [\n 0\n ]\n};\nvar getSize = function(size, options) {\n return getTokenRelative(\"size\", size, options);\n};\nvar getSpace = function(space, options) {\n return getTokenRelative(\"space\", space, options);\n};\nvar getRadius = function(radius, options) {\n return getTokenRelative(\"radius\", radius, options);\n};\nvar cacheVariables = {};\nvar cacheWholeVariables = {};\nvar cacheKeys = {};\nvar cacheWholeKeys = {};\nvar stepTokenUpOrDown = function(type, current) {\n var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOptions;\n var _options_bounds, _options_bounds1;\n var tokens = (0, import_web.getTokens)({\n prefixed: true\n })[type];\n if (!(type in cacheVariables)) {\n cacheKeys[type] = [];\n cacheVariables[type] = [];\n cacheWholeKeys[type] = [];\n cacheWholeVariables[type] = [];\n var sorted = Object.keys(tokens).map(function(k) {\n return tokens[k];\n }).sort(function(a, b) {\n return a.val - b.val;\n });\n var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;\n try {\n for (var _iterator = sorted[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n var token = _step.value;\n cacheKeys[type].push(token.key);\n cacheVariables[type].push(token);\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 sortedExcludingHalfSteps = sorted.filter(function(x) {\n return !x.key.endsWith(\".5\");\n });\n var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;\n try {\n for (var _iterator1 = sortedExcludingHalfSteps[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {\n var token1 = _step1.value;\n cacheWholeKeys[type].push(token1.key);\n cacheWholeVariables[type].push(token1);\n }\n } catch (err) {\n _didIteratorError1 = true;\n _iteratorError1 = err;\n } finally {\n try {\n if (!_iteratorNormalCompletion1 && _iterator1.return != null) {\n _iterator1.return();\n }\n } finally {\n if (_didIteratorError1) {\n throw _iteratorError1;\n }\n }\n }\n }\n var isString = typeof current === \"string\";\n var cache = options.excludeHalfSteps ? isString ? cacheWholeKeys : cacheWholeVariables : isString ? cacheKeys : cacheVariables;\n var tokensOrdered = cache[type];\n var _options_bounds_;\n var min = (_options_bounds_ = (_options_bounds = options.bounds) === null || _options_bounds === void 0 ? void 0 : _options_bounds[0]) !== null && _options_bounds_ !== void 0 ? _options_bounds_ : 0;\n var _options_bounds_1;\n var max = (_options_bounds_1 = (_options_bounds1 = options.bounds) === null || _options_bounds1 === void 0 ? void 0 : _options_bounds1[1]) !== null && _options_bounds_1 !== void 0 ? _options_bounds_1 : tokensOrdered.length - 1;\n var currentIndex = tokensOrdered.indexOf(current);\n var shift = options.shift || 0;\n if (shift) {\n if (current === \"$true\" || (0, import_web.isVariable)(current) && current.name === \"true\") {\n shift += shift > 0 ? 1 : -1;\n }\n }\n var index = Math.min(max, Math.max(min, currentIndex + shift));\n var found = tokensOrdered[index];\n var result = (typeof found === \"string\" ? tokens[found] : found) || tokens[\"$true\"];\n return result;\n};\nvar getTokenRelative = stepTokenUpOrDown;\n//# sourceMappingURL=index.js.map\n"],"mappings":"AAAA,YAAY;;AACZ,IAAIA,SAAS,GAAGC,MAAM,CAACC,cAAc;AACrC,IAAIC,gBAAgB,GAAGF,MAAM,CAACG,wBAAwB;AACtD,IAAIC,iBAAiB,GAAGJ,MAAM,CAACK,mBAAmB;AAClD,IAAIC,YAAY,GAAGN,MAAM,CAACO,SAAS,CAACC,cAAc;AAClD,IAAIC,QAAQ,GAAGA,CAACC,MAAM,EAAEC,GAAG,KAAK;EAC9B,KAAK,IAAIC,IAAI,IAAID,GAAG,EAClBZ,SAAS,CAACW,MAAM,EAAEE,IAAI,EAAE;IAAEC,GAAG,EAAEF,GAAG,CAACC,IAAI,CAAC;IAAEE,UAAU,EAAE;EAAK,CAAC,CAAC;AACjE,CAAC;AACD,IAAIC,WAAW,GAAGA,CAACC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAEC,IAAI,KAAK;EAC5C,IAAIF,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,IAAI,OAAOA,IAAI,KAAK,UAAU,EAAE;IAClE,KAAK,IAAIG,GAAG,IAAIhB,iBAAiB,CAACa,IAAI,CAAC,EACrC,IAAI,CAACX,YAAY,CAACe,IAAI,CAACL,EAAE,EAAEI,GAAG,CAAC,IAAIA,GAAG,KAAKF,MAAM,EAC/CnB,SAAS,CAACiB,EAAE,EAAEI,GAAG,EAAE;MAAEP,GAAG,EAAEA,CAAA,KAAMI,IAAI,CAACG,GAAG,CAAC;MAAEN,UAAU,EAAE,EAAEK,IAAI,GAAGjB,gBAAgB,CAACe,IAAI,EAAEG,GAAG,CAAC,CAAC,IAAID,IAAI,CAACL;IAAW,CAAC,CAAC;EACxH;EACA,OAAOE,EAAE;AACX,CAAC;AACD,IAAIM,YAAY,GAAIC,GAAG,IA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,IAAI,CAAC,CAAC,EAAEd,UAAU,CAAC+D,UAAU,EAAEjD,OAAO,CAAC,IAAIA,OAAO,CAACnC,IAAI,KAAK,MAAM,EAAE;MACzFwB,KAAK,IAAIA,KAAK,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B;EACF;EACA,IAAI6D,KAAK,GAAGC,IAAI,CAACP,GAAG,CAACE,GAAG,EAAEK,IAAI,CAACL,GAAG,CAACF,GAAG,EAAEG,YAAY,GAAG1D,KAAK,CAAC,CAAC;EAC9D,IAAI+D,KAAK,GAAGV,aAAa,CAACQ,KAAK,CAAC;EAChC,IAAIG,MAAM,GAAG,CAAC,OAAOD,KAAK,KAAK,QAAQ,GAAG/C,MAAM,CAAC+C,KAAK,CAAC,GAAGA,KAAK,KAAK/C,MAAM,CAAC,OAAO,CAAC;EACnF,OAAOgD,MAAM;AACf,CAAC;AACD,IAAIvE,gBAAgB,GAAGC,iBAAiB","ignoreList":[]}
|
|
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 getRadius: () => getRadius,\n getSize: () => getSize,\n getSpace: () => getSpace\n});\nmodule.exports = __toCommonJS(index_exports);\nvar import_size = require(\"@tamagui/size\");\nvar import_web = require(\"@tamagui/web\");\nvar resolveToken = function(type, input) {\n var _getConfig_sizes;\n if (input == null || typeof input === \"number\") return input;\n var tokens = (0, import_web.getTokens)()[type];\n var key = typeof input === \"object\" ? input.key : String(input);\n if (input === true || ((_getConfig_sizes = (0, import_web.getConfig)().sizes) === null || _getConfig_sizes === void 0 ? void 0 : _getConfig_sizes[key]) != null) {\n var resolved = (0, import_size.resolveSize)(input);\n if (type === \"size\") return resolved.controlHeight;\n return type === \"space\" ? resolved.frame.paddingHorizontal : resolved.frame.borderRadius;\n }\n var _tokens_key;\n return (_tokens_key = tokens[key]) !== null && _tokens_key !== void 0 ? _tokens_key : input;\n};\nvar getSize = function(size) {\n return resolveToken(\"size\", size);\n};\nvar getSpace = function(space) {\n return resolveToken(\"space\", space);\n};\nvar getRadius = function(radius) {\n return resolveToken(\"radius\", radius);\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,iBAAiB;CACjB,eAAe;CACf,gBAAgB;AAClB,CAAC;AACD,OAAO,UAAU,aAAa,aAAa;AAC3C,IAAI,cAAc,QAAQ,eAAe;AACzC,IAAI,aAAa,QAAQ,cAAc;AACvC,IAAI,eAAe,SAAS,MAAM,OAAO;CACvC,IAAI;CACJ,IAAI,SAAS,QAAQ,OAAO,UAAU,UAAU,OAAO;CACvD,IAAI,UAAU,GAAG,WAAW,UAAS,CAAE,CAAC,CAAC;CACzC,IAAI,MAAM,OAAO,UAAU,WAAW,MAAM,MAAM,OAAO,KAAK;CAC9D,IAAI,UAAU,UAAU,oBAAoB,GAAG,WAAW,UAAS,CAAE,CAAC,CAAC,WAAW,QAAQ,qBAAqB,KAAK,IAAI,KAAK,IAAI,iBAAiB,SAAS,MAAM;EAC/J,IAAI,YAAY,GAAG,YAAY,YAAW,CAAE,KAAK;EACjD,IAAI,SAAS,QAAQ,OAAO,SAAS;EACrC,OAAO,SAAS,UAAU,SAAS,MAAM,oBAAoB,SAAS,MAAM;CAC9E;CACA,IAAI;CACJ,QAAQ,cAAc,OAAO,UAAU,QAAQ,gBAAgB,KAAK,IAAI,cAAc;AACxF;AACA,IAAI,UAAU,SAAS,MAAM;CAC3B,OAAO,aAAa,QAAQ,IAAI;AAClC;AACA,IAAI,WAAW,SAAS,OAAO;CAC7B,OAAO,aAAa,SAAS,KAAK;AACpC;AACA,IAAI,YAAY,SAAS,QAAQ;CAC/B,OAAO,aAAa,UAAU,MAAM;AACtC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,58 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { resolveSize } from "@tamagui/size";
|
|
2
|
+
import { getConfig, getTokens } from "@tamagui/web";
|
|
3
|
+
|
|
4
|
+
const resolveToken = (type, input) => {
|
|
5
|
+
if (input == null || typeof input === "number") return input;
|
|
6
|
+
const tokens = getTokens()[type];
|
|
7
|
+
const key = typeof input === "object" ? input.key : String(input);
|
|
8
|
+
if (input === true || getConfig().sizes?.[key] != null) {
|
|
9
|
+
const resolved = resolveSize(input);
|
|
10
|
+
if (type === "size") return resolved.controlHeight;
|
|
11
|
+
return type === "space" ? resolved.frame.paddingHorizontal : resolved.frame.borderRadius;
|
|
12
|
+
}
|
|
13
|
+
return tokens[key] ?? input;
|
|
5
14
|
};
|
|
6
|
-
const getSize = (size
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
const getRadius = (radius, options) => {
|
|
13
|
-
return getTokenRelative("radius", radius, options);
|
|
14
|
-
};
|
|
15
|
-
const cacheVariables = {};
|
|
16
|
-
const cacheWholeVariables = {};
|
|
17
|
-
const cacheKeys = {};
|
|
18
|
-
const cacheWholeKeys = {};
|
|
19
|
-
const stepTokenUpOrDown = (type, current, options = defaultOptions) => {
|
|
20
|
-
const tokens = getTokens({
|
|
21
|
-
prefixed: true
|
|
22
|
-
})[type];
|
|
23
|
-
if (!(type in cacheVariables)) {
|
|
24
|
-
cacheKeys[type] = [];
|
|
25
|
-
cacheVariables[type] = [];
|
|
26
|
-
cacheWholeKeys[type] = [];
|
|
27
|
-
cacheWholeVariables[type] = [];
|
|
28
|
-
const sorted = Object.keys(tokens).map(k => tokens[k]).sort((a, b) => a.val - b.val);
|
|
29
|
-
for (const token of sorted) {
|
|
30
|
-
cacheKeys[type].push(token.key);
|
|
31
|
-
cacheVariables[type].push(token);
|
|
32
|
-
}
|
|
33
|
-
const sortedExcludingHalfSteps = sorted.filter(x => !x.key.endsWith(".5"));
|
|
34
|
-
for (const token of sortedExcludingHalfSteps) {
|
|
35
|
-
cacheWholeKeys[type].push(token.key);
|
|
36
|
-
cacheWholeVariables[type].push(token);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const isString = typeof current === "string";
|
|
40
|
-
const cache = options.excludeHalfSteps ? isString ? cacheWholeKeys : cacheWholeVariables : isString ? cacheKeys : cacheVariables;
|
|
41
|
-
const tokensOrdered = cache[type];
|
|
42
|
-
const min = options.bounds?.[0] ?? 0;
|
|
43
|
-
const max = options.bounds?.[1] ?? tokensOrdered.length - 1;
|
|
44
|
-
const currentIndex = tokensOrdered.indexOf(current);
|
|
45
|
-
let shift = options.shift || 0;
|
|
46
|
-
if (shift) {
|
|
47
|
-
if (current === "$true" || isVariable(current) && current.name === "true") {
|
|
48
|
-
shift += shift > 0 ? 1 : -1;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const index = Math.min(max, Math.max(min, currentIndex + shift));
|
|
52
|
-
const found = tokensOrdered[index];
|
|
53
|
-
const result = (typeof found === "string" ? tokens[found] : found) || tokens["$true"];
|
|
54
|
-
return result;
|
|
55
|
-
};
|
|
56
|
-
const getTokenRelative = stepTokenUpOrDown;
|
|
57
|
-
export { getRadius, getSize, getSpace, getTokenRelative, stepTokenUpOrDown };
|
|
15
|
+
const getSize = (size) => resolveToken("size", size);
|
|
16
|
+
const getSpace = (space) => resolveToken("space", space);
|
|
17
|
+
const getRadius = (radius) => resolveToken("radius", radius);
|
|
18
|
+
|
|
19
|
+
export { getRadius, getSize, getSpace };
|
|
58
20
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import { resolveSize } from \"@tamagui/size\";\nimport { getConfig, getTokens } from \"@tamagui/web\";\nconst resolveToken = (type, input) => {\n if (input == null || typeof input === \"number\") return input;\n const tokens = getTokens()[type];\n const key = typeof input === \"object\" ? input.key : String(input);\n if (input === true || getConfig().sizes?.[key] != null) {\n const resolved = resolveSize(input);\n if (type === \"size\") return resolved.controlHeight;\n return type === \"space\" ? resolved.frame.paddingHorizontal : resolved.frame.borderRadius;\n }\n return tokens[key] ?? input;\n};\nconst getSize = (size) => resolveToken(\"size\", size);\nconst getSpace = (space) => resolveToken(\"space\", space);\nconst getRadius = (radius) => resolveToken(\"radius\", radius);\nexport {\n getRadius,\n getSize,\n getSpace\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;AAEA,MAAM,gBAAgB,MAAM,UAAU;CACpC,IAAI,SAAS,QAAQ,OAAO,UAAU,UAAU,OAAO;CACvD,MAAM,SAAS,UAAU,CAAC,CAAC;CAC3B,MAAM,MAAM,OAAO,UAAU,WAAW,MAAM,MAAM,OAAO,KAAK;CAChE,IAAI,UAAU,QAAQ,UAAU,CAAC,CAAC,QAAQ,QAAQ,MAAM;EACtD,MAAM,WAAW,YAAY,KAAK;EAClC,IAAI,SAAS,QAAQ,OAAO,SAAS;EACrC,OAAO,SAAS,UAAU,SAAS,MAAM,oBAAoB,SAAS,MAAM;CAC9E;CACA,OAAO,OAAO,QAAQ;AACxB;AACA,MAAM,WAAW,SAAS,aAAa,QAAQ,IAAI;AACnD,MAAM,YAAY,UAAU,aAAa,SAAS,KAAK;AACvD,MAAM,aAAa,WAAW,aAAa,UAAU,MAAM"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,58 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { resolveSize } from "@tamagui/size";
|
|
2
|
+
import { getConfig, getTokens } from "@tamagui/web";
|
|
3
|
+
|
|
4
|
+
const resolveToken = (type, input) => {
|
|
5
|
+
if (input == null || typeof input === "number") return input;
|
|
6
|
+
const tokens = getTokens()[type];
|
|
7
|
+
const key = typeof input === "object" ? input.key : String(input);
|
|
8
|
+
if (input === true || getConfig().sizes?.[key] != null) {
|
|
9
|
+
const resolved = resolveSize(input);
|
|
10
|
+
if (type === "size") return resolved.controlHeight;
|
|
11
|
+
return type === "space" ? resolved.frame.paddingHorizontal : resolved.frame.borderRadius;
|
|
12
|
+
}
|
|
13
|
+
return tokens[key] ?? input;
|
|
5
14
|
};
|
|
6
|
-
const getSize = (size
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
const getRadius = (radius, options) => {
|
|
13
|
-
return getTokenRelative("radius", radius, options);
|
|
14
|
-
};
|
|
15
|
-
const cacheVariables = {};
|
|
16
|
-
const cacheWholeVariables = {};
|
|
17
|
-
const cacheKeys = {};
|
|
18
|
-
const cacheWholeKeys = {};
|
|
19
|
-
const stepTokenUpOrDown = (type, current, options = defaultOptions) => {
|
|
20
|
-
const tokens = getTokens({
|
|
21
|
-
prefixed: true
|
|
22
|
-
})[type];
|
|
23
|
-
if (!(type in cacheVariables)) {
|
|
24
|
-
cacheKeys[type] = [];
|
|
25
|
-
cacheVariables[type] = [];
|
|
26
|
-
cacheWholeKeys[type] = [];
|
|
27
|
-
cacheWholeVariables[type] = [];
|
|
28
|
-
const sorted = Object.keys(tokens).map(k => tokens[k]).sort((a, b) => a.val - b.val);
|
|
29
|
-
for (const token of sorted) {
|
|
30
|
-
cacheKeys[type].push(token.key);
|
|
31
|
-
cacheVariables[type].push(token);
|
|
32
|
-
}
|
|
33
|
-
const sortedExcludingHalfSteps = sorted.filter(x => !x.key.endsWith(".5"));
|
|
34
|
-
for (const token of sortedExcludingHalfSteps) {
|
|
35
|
-
cacheWholeKeys[type].push(token.key);
|
|
36
|
-
cacheWholeVariables[type].push(token);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const isString = typeof current === "string";
|
|
40
|
-
const cache = options.excludeHalfSteps ? isString ? cacheWholeKeys : cacheWholeVariables : isString ? cacheKeys : cacheVariables;
|
|
41
|
-
const tokensOrdered = cache[type];
|
|
42
|
-
const min = options.bounds?.[0] ?? 0;
|
|
43
|
-
const max = options.bounds?.[1] ?? tokensOrdered.length - 1;
|
|
44
|
-
const currentIndex = tokensOrdered.indexOf(current);
|
|
45
|
-
let shift = options.shift || 0;
|
|
46
|
-
if (shift) {
|
|
47
|
-
if (current === "$true" || isVariable(current) && current.name === "true") {
|
|
48
|
-
shift += shift > 0 ? 1 : -1;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
const index = Math.min(max, Math.max(min, currentIndex + shift));
|
|
52
|
-
const found = tokensOrdered[index];
|
|
53
|
-
const result = (typeof found === "string" ? tokens[found] : found) || tokens["$true"];
|
|
54
|
-
return result;
|
|
55
|
-
};
|
|
56
|
-
const getTokenRelative = stepTokenUpOrDown;
|
|
57
|
-
export { getRadius, getSize, getSpace, getTokenRelative, stepTokenUpOrDown };
|
|
15
|
+
const getSize = (size) => resolveToken("size", size);
|
|
16
|
+
const getSpace = (space) => resolveToken("space", space);
|
|
17
|
+
const getRadius = (radius) => resolveToken("radius", radius);
|
|
18
|
+
|
|
19
|
+
export { getRadius, getSize, getSpace };
|
|
58
20
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import { resolveSize } from \"@tamagui/size\";\nimport { getConfig, getTokens } from \"@tamagui/web\";\nconst resolveToken = (type, input) => {\n if (input == null || typeof input === \"number\") return input;\n const tokens = getTokens()[type];\n const key = typeof input === \"object\" ? input.key : String(input);\n if (input === true || getConfig().sizes?.[key] != null) {\n const resolved = resolveSize(input);\n if (type === \"size\") return resolved.controlHeight;\n return type === \"space\" ? resolved.frame.paddingHorizontal : resolved.frame.borderRadius;\n }\n return tokens[key] ?? input;\n};\nconst getSize = (size) => resolveToken(\"size\", size);\nconst getSpace = (space) => resolveToken(\"space\", space);\nconst getRadius = (radius) => resolveToken(\"radius\", radius);\nexport {\n getRadius,\n getSize,\n getSpace\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;AAEA,MAAM,gBAAgB,MAAM,UAAU;CACpC,IAAI,SAAS,QAAQ,OAAO,UAAU,UAAU,OAAO;CACvD,MAAM,SAAS,UAAU,CAAC,CAAC;CAC3B,MAAM,MAAM,OAAO,UAAU,WAAW,MAAM,MAAM,OAAO,KAAK;CAChE,IAAI,UAAU,QAAQ,UAAU,CAAC,CAAC,QAAQ,QAAQ,MAAM;EACtD,MAAM,WAAW,YAAY,KAAK;EAClC,IAAI,SAAS,QAAQ,OAAO,SAAS;EACrC,OAAO,SAAS,UAAU,SAAS,MAAM,oBAAoB,SAAS,MAAM;CAC9E;CACA,OAAO,OAAO,QAAQ;AACxB;AACA,MAAM,WAAW,SAAS,aAAa,QAAQ,IAAI;AACnD,MAAM,YAAY,UAAU,aAAa,SAAS,KAAK;AACvD,MAAM,aAAa,WAAW,aAAa,UAAU,MAAM"}
|
package/dist/esm/index.native.js
CHANGED
|
@@ -1,106 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { resolveSize } from "@tamagui/size";
|
|
2
|
+
import { getConfig, getTokens } from "@tamagui/web";
|
|
3
|
+
|
|
4
|
+
var resolveToken = function(type, input) {
|
|
5
|
+
var _getConfig_sizes;
|
|
6
|
+
if (input == null || typeof input === "number") return input;
|
|
7
|
+
var tokens = getTokens()[type];
|
|
8
|
+
var key = typeof input === "object" ? input.key : String(input);
|
|
9
|
+
if (input === true || ((_getConfig_sizes = getConfig().sizes) === null || _getConfig_sizes === void 0 ? void 0 : _getConfig_sizes[key]) != null) {
|
|
10
|
+
var resolved = resolveSize(input);
|
|
11
|
+
if (type === "size") return resolved.controlHeight;
|
|
12
|
+
return type === "space" ? resolved.frame.paddingHorizontal : resolved.frame.borderRadius;
|
|
13
|
+
}
|
|
14
|
+
var _tokens_key;
|
|
15
|
+
return (_tokens_key = tokens[key]) !== null && _tokens_key !== void 0 ? _tokens_key : input;
|
|
5
16
|
};
|
|
6
|
-
var getSize = function
|
|
7
|
-
|
|
17
|
+
var getSize = function(size) {
|
|
18
|
+
return resolveToken("size", size);
|
|
8
19
|
};
|
|
9
|
-
var getSpace = function
|
|
10
|
-
|
|
20
|
+
var getSpace = function(space) {
|
|
21
|
+
return resolveToken("space", space);
|
|
11
22
|
};
|
|
12
|
-
var getRadius = function
|
|
13
|
-
|
|
23
|
+
var getRadius = function(radius) {
|
|
24
|
+
return resolveToken("radius", radius);
|
|
14
25
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var cacheKeys = {};
|
|
18
|
-
var cacheWholeKeys = {};
|
|
19
|
-
var stepTokenUpOrDown = function (type, current) {
|
|
20
|
-
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOptions;
|
|
21
|
-
var _options_bounds, _options_bounds1;
|
|
22
|
-
var tokens = getTokens({
|
|
23
|
-
prefixed: true
|
|
24
|
-
})[type];
|
|
25
|
-
if (!(type in cacheVariables)) {
|
|
26
|
-
cacheKeys[type] = [];
|
|
27
|
-
cacheVariables[type] = [];
|
|
28
|
-
cacheWholeKeys[type] = [];
|
|
29
|
-
cacheWholeVariables[type] = [];
|
|
30
|
-
var sorted = Object.keys(tokens).map(function (k) {
|
|
31
|
-
return tokens[k];
|
|
32
|
-
}).sort(function (a, b) {
|
|
33
|
-
return a.val - b.val;
|
|
34
|
-
});
|
|
35
|
-
var _iteratorNormalCompletion = true,
|
|
36
|
-
_didIteratorError = false,
|
|
37
|
-
_iteratorError = void 0;
|
|
38
|
-
try {
|
|
39
|
-
for (var _iterator = sorted[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
40
|
-
var token = _step.value;
|
|
41
|
-
cacheKeys[type].push(token.key);
|
|
42
|
-
cacheVariables[type].push(token);
|
|
43
|
-
}
|
|
44
|
-
} catch (err) {
|
|
45
|
-
_didIteratorError = true;
|
|
46
|
-
_iteratorError = err;
|
|
47
|
-
} finally {
|
|
48
|
-
try {
|
|
49
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
50
|
-
_iterator.return();
|
|
51
|
-
}
|
|
52
|
-
} finally {
|
|
53
|
-
if (_didIteratorError) {
|
|
54
|
-
throw _iteratorError;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
var sortedExcludingHalfSteps = sorted.filter(function (x) {
|
|
59
|
-
return !x.key.endsWith(".5");
|
|
60
|
-
});
|
|
61
|
-
var _iteratorNormalCompletion1 = true,
|
|
62
|
-
_didIteratorError1 = false,
|
|
63
|
-
_iteratorError1 = void 0;
|
|
64
|
-
try {
|
|
65
|
-
for (var _iterator1 = sortedExcludingHalfSteps[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
66
|
-
var token1 = _step1.value;
|
|
67
|
-
cacheWholeKeys[type].push(token1.key);
|
|
68
|
-
cacheWholeVariables[type].push(token1);
|
|
69
|
-
}
|
|
70
|
-
} catch (err) {
|
|
71
|
-
_didIteratorError1 = true;
|
|
72
|
-
_iteratorError1 = err;
|
|
73
|
-
} finally {
|
|
74
|
-
try {
|
|
75
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
76
|
-
_iterator1.return();
|
|
77
|
-
}
|
|
78
|
-
} finally {
|
|
79
|
-
if (_didIteratorError1) {
|
|
80
|
-
throw _iteratorError1;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
var isString = typeof current === "string";
|
|
86
|
-
var cache = options.excludeHalfSteps ? isString ? cacheWholeKeys : cacheWholeVariables : isString ? cacheKeys : cacheVariables;
|
|
87
|
-
var tokensOrdered = cache[type];
|
|
88
|
-
var _options_bounds_;
|
|
89
|
-
var min = (_options_bounds_ = (_options_bounds = options.bounds) === null || _options_bounds === void 0 ? void 0 : _options_bounds[0]) !== null && _options_bounds_ !== void 0 ? _options_bounds_ : 0;
|
|
90
|
-
var _options_bounds_1;
|
|
91
|
-
var max = (_options_bounds_1 = (_options_bounds1 = options.bounds) === null || _options_bounds1 === void 0 ? void 0 : _options_bounds1[1]) !== null && _options_bounds_1 !== void 0 ? _options_bounds_1 : tokensOrdered.length - 1;
|
|
92
|
-
var currentIndex = tokensOrdered.indexOf(current);
|
|
93
|
-
var shift = options.shift || 0;
|
|
94
|
-
if (shift) {
|
|
95
|
-
if (current === "$true" || isVariable(current) && current.name === "true") {
|
|
96
|
-
shift += shift > 0 ? 1 : -1;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
var index = Math.min(max, Math.max(min, currentIndex + shift));
|
|
100
|
-
var found = tokensOrdered[index];
|
|
101
|
-
var result = (typeof found === "string" ? tokens[found] : found) || tokens["$true"];
|
|
102
|
-
return result;
|
|
103
|
-
};
|
|
104
|
-
var getTokenRelative = stepTokenUpOrDown;
|
|
105
|
-
export { getRadius, getSize, getSpace, getTokenRelative, stepTokenUpOrDown };
|
|
26
|
+
|
|
27
|
+
export { getRadius, getSize, getSpace };
|
|
106
28
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.native.js","names":[],"sources":["esm/index.native.js"],"sourcesContent":["import { resolveSize } from \"@tamagui/size\";\nimport { getConfig, getTokens } from \"@tamagui/web\";\nvar resolveToken = function(type, input) {\n var _getConfig_sizes;\n if (input == null || typeof input === \"number\") return input;\n var tokens = getTokens()[type];\n var key = typeof input === \"object\" ? input.key : String(input);\n if (input === true || ((_getConfig_sizes = getConfig().sizes) === null || _getConfig_sizes === void 0 ? void 0 : _getConfig_sizes[key]) != null) {\n var resolved = resolveSize(input);\n if (type === \"size\") return resolved.controlHeight;\n return type === \"space\" ? resolved.frame.paddingHorizontal : resolved.frame.borderRadius;\n }\n var _tokens_key;\n return (_tokens_key = tokens[key]) !== null && _tokens_key !== void 0 ? _tokens_key : input;\n};\nvar getSize = function(size) {\n return resolveToken(\"size\", size);\n};\nvar getSpace = function(space) {\n return resolveToken(\"space\", space);\n};\nvar getRadius = function(radius) {\n return resolveToken(\"radius\", radius);\n};\nexport {\n getRadius,\n getSize,\n getSpace\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;AAEA,IAAI,eAAe,SAAS,MAAM,OAAO;CACvC,IAAI;CACJ,IAAI,SAAS,QAAQ,OAAO,UAAU,UAAU,OAAO;CACvD,IAAI,SAAS,UAAU,CAAC,CAAC;CACzB,IAAI,MAAM,OAAO,UAAU,WAAW,MAAM,MAAM,OAAO,KAAK;CAC9D,IAAI,UAAU,UAAU,mBAAmB,UAAU,CAAC,CAAC,WAAW,QAAQ,qBAAqB,KAAK,IAAI,KAAK,IAAI,iBAAiB,SAAS,MAAM;EAC/I,IAAI,WAAW,YAAY,KAAK;EAChC,IAAI,SAAS,QAAQ,OAAO,SAAS;EACrC,OAAO,SAAS,UAAU,SAAS,MAAM,oBAAoB,SAAS,MAAM;CAC9E;CACA,IAAI;CACJ,QAAQ,cAAc,OAAO,UAAU,QAAQ,gBAAgB,KAAK,IAAI,cAAc;AACxF;AACA,IAAI,UAAU,SAAS,MAAM;CAC3B,OAAO,aAAa,QAAQ,IAAI;AAClC;AACA,IAAI,WAAW,SAAS,OAAO;CAC7B,OAAO,aAAa,SAAS,KAAK;AACpC;AACA,IAAI,YAAY,SAAS,QAAQ;CAC/B,OAAO,aAAa,UAAU,MAAM;AACtC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/get-token",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-beta.1093.1",
|
|
4
|
+
"license": "MIT",
|
|
4
5
|
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
6
|
"files": [
|
|
6
7
|
"src",
|
|
@@ -34,11 +35,12 @@
|
|
|
34
35
|
"clean:build": "tamagui-build clean:build"
|
|
35
36
|
},
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@tamagui/
|
|
38
|
+
"@tamagui/size": "3.0.0-beta.1093.1",
|
|
39
|
+
"@tamagui/web": "3.0.0-beta.1093.1"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
|
-
"@tamagui/build": "
|
|
41
|
-
"react": "
|
|
42
|
+
"@tamagui/build": "3.0.0-beta.1093.1",
|
|
43
|
+
"react": "19.2.3"
|
|
42
44
|
},
|
|
43
45
|
"peerDependencies": {
|
|
44
46
|
"react": ">=19"
|
package/src/index.ts
CHANGED
|
@@ -1,98 +1,32 @@
|
|
|
1
1
|
import type { Variable, VariableValGeneric } from '@tamagui/web'
|
|
2
|
-
import {
|
|
2
|
+
import { resolveSize } from '@tamagui/size'
|
|
3
|
+
import { getConfig, getTokens } from '@tamagui/web'
|
|
3
4
|
|
|
4
5
|
// technically number | undefined just for compat with the generic VariableVal
|
|
5
|
-
type GetTokenBase = Variable | string | number | undefined | VariableValGeneric
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const defaultOptions: GetTokenOptions = {
|
|
14
|
-
shift: 0,
|
|
15
|
-
bounds: [0],
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export const getSize = (size: GetTokenBase, options?: GetTokenOptions) => {
|
|
19
|
-
return getTokenRelative('size', size, options)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export const getSpace = (space: GetTokenBase, options?: GetTokenOptions) => {
|
|
23
|
-
return getTokenRelative('space', space, options)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const getRadius = (radius: GetTokenBase, options?: GetTokenOptions) => {
|
|
27
|
-
return getTokenRelative('radius', radius, options)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const cacheVariables: Record<string, Variable[]> = {}
|
|
31
|
-
const cacheWholeVariables: Record<string, Variable[]> = {}
|
|
32
|
-
const cacheKeys: Record<string, string[]> = {}
|
|
33
|
-
const cacheWholeKeys: Record<string, string[]> = {}
|
|
34
|
-
|
|
35
|
-
/** @deprecated use getSize, getSpace, or getTokenRelative instead */
|
|
36
|
-
export const stepTokenUpOrDown = (
|
|
37
|
-
type: 'size' | 'space' | 'zIndex' | 'radius',
|
|
38
|
-
current: GetTokenBase,
|
|
39
|
-
options: GetTokenOptions = defaultOptions
|
|
6
|
+
type GetTokenBase = Variable | string | number | boolean | undefined | VariableValGeneric
|
|
7
|
+
|
|
8
|
+
// same-key token resolver: token in, Variable out. `true` and a named size
|
|
9
|
+
// read the size recipe (its control height, horizontal padding, or radius);
|
|
10
|
+
// numbers and unknown keys pass through unchanged.
|
|
11
|
+
const resolveToken = (
|
|
12
|
+
type: 'size' | 'space' | 'radius',
|
|
13
|
+
input: GetTokenBase
|
|
40
14
|
): Variable<number> => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
.map((k) => tokens[k])
|
|
51
|
-
.sort((a, b) => a.val - b.val)
|
|
52
|
-
|
|
53
|
-
for (const token of sorted) {
|
|
54
|
-
cacheKeys[type].push(token.key)
|
|
55
|
-
cacheVariables[type].push(token)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const sortedExcludingHalfSteps = sorted.filter((x) => !x.key.endsWith('.5'))
|
|
59
|
-
for (const token of sortedExcludingHalfSteps) {
|
|
60
|
-
cacheWholeKeys[type].push(token.key)
|
|
61
|
-
cacheWholeVariables[type].push(token)
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const isString = typeof current === 'string'
|
|
66
|
-
const cache = options.excludeHalfSteps
|
|
67
|
-
? isString
|
|
68
|
-
? cacheWholeKeys
|
|
69
|
-
: cacheWholeVariables
|
|
70
|
-
: isString
|
|
71
|
-
? cacheKeys
|
|
72
|
-
: cacheVariables
|
|
73
|
-
|
|
74
|
-
const tokensOrdered = cache[type]
|
|
75
|
-
|
|
76
|
-
const min = options.bounds?.[0] ?? 0
|
|
77
|
-
const max = options.bounds?.[1] ?? tokensOrdered.length - 1
|
|
78
|
-
const currentIndex = tokensOrdered.indexOf(current as any)
|
|
79
|
-
|
|
80
|
-
let shift = options.shift || 0
|
|
81
|
-
if (shift) {
|
|
82
|
-
if (current === '$true' || (isVariable(current) && current.name === 'true')) {
|
|
83
|
-
shift += shift > 0 ? 1 : -1
|
|
84
|
-
}
|
|
15
|
+
if (input == null || typeof input === 'number') return input as any
|
|
16
|
+
const tokens = getTokens()[type] as Record<string, Variable>
|
|
17
|
+
const key = typeof input === 'object' ? (input as Variable).key : String(input)
|
|
18
|
+
if (input === true || getConfig().sizes?.[key] != null) {
|
|
19
|
+
const resolved = resolveSize(input as any)
|
|
20
|
+
if (type === 'size') return resolved.controlHeight as any
|
|
21
|
+
return (
|
|
22
|
+
type === 'space' ? resolved.frame.paddingHorizontal : resolved.frame.borderRadius
|
|
23
|
+
) as any
|
|
85
24
|
}
|
|
25
|
+
return (tokens[key] ?? input) as any
|
|
26
|
+
}
|
|
86
27
|
|
|
87
|
-
|
|
88
|
-
const found = tokensOrdered[index]
|
|
89
|
-
|
|
90
|
-
const result = (typeof found === 'string' ? tokens[found] : found) || tokens['$true']
|
|
91
|
-
|
|
92
|
-
// console.log('found', { current, shift, index, found, result })
|
|
28
|
+
export const getSize = (size: GetTokenBase) => resolveToken('size', size)
|
|
93
29
|
|
|
94
|
-
|
|
95
|
-
return result
|
|
96
|
-
}
|
|
30
|
+
export const getSpace = (space: GetTokenBase) => resolveToken('space', space)
|
|
97
31
|
|
|
98
|
-
export const
|
|
32
|
+
export const getRadius = (radius: GetTokenBase) => resolveToken('radius', radius)
|
package/types/index.d.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import type { Variable, VariableValGeneric } from '@tamagui/web';
|
|
2
|
-
type GetTokenBase = Variable | string | number | undefined | VariableValGeneric;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
excludeHalfSteps?: boolean;
|
|
7
|
-
};
|
|
8
|
-
export declare const getSize: (size: GetTokenBase, options?: GetTokenOptions) => Variable<number>;
|
|
9
|
-
export declare const getSpace: (space: GetTokenBase, options?: GetTokenOptions) => Variable<number>;
|
|
10
|
-
export declare const getRadius: (radius: GetTokenBase, options?: GetTokenOptions) => Variable<number>;
|
|
11
|
-
/** @deprecated use getSize, getSpace, or getTokenRelative instead */
|
|
12
|
-
export declare const stepTokenUpOrDown: (type: "size" | "space" | "zIndex" | "radius", current: GetTokenBase, options?: GetTokenOptions) => Variable<number>;
|
|
13
|
-
export declare const getTokenRelative: (type: "size" | "space" | "zIndex" | "radius", current: GetTokenBase, options?: GetTokenOptions) => Variable<number>;
|
|
2
|
+
type GetTokenBase = Variable | string | number | boolean | undefined | VariableValGeneric;
|
|
3
|
+
export declare const getSize: (size: GetTokenBase) => Variable<number>;
|
|
4
|
+
export declare const getSpace: (space: GetTokenBase) => Variable<number>;
|
|
5
|
+
export declare const getRadius: (radius: GetTokenBase) => Variable<number>;
|
|
14
6
|
export {};
|
|
15
7
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAKhE,KAAK,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,kBAAkB,CAAA;AAsBzF,eAAO,MAAM,OAAO,SAAU,YAAY,qBAA+B,CAAA;AAEzE,eAAO,MAAM,QAAQ,UAAW,YAAY,qBAAiC,CAAA;AAE7E,eAAO,MAAM,SAAS,WAAY,YAAY,qBAAmC,CAAA"}
|