@hanzogui/get-token 2.0.0-rc.41-hanzoai.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/index.cjs +87 -0
- package/dist/cjs/index.native.js +138 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/esm/index.js +58 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +58 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +106 -0
- package/dist/esm/index.native.js.map +1 -0
- package/package.json +46 -0
- package/src/index.ts +98 -0
- package/types/index.d.ts +15 -0
- package/types/index.d.ts.map +1 -0
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,87 @@
|
|
|
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", {
|
|
21
|
+
value: true
|
|
22
|
+
}), mod);
|
|
23
|
+
var index_exports = {};
|
|
24
|
+
__export(index_exports, {
|
|
25
|
+
getRadius: () => getRadius,
|
|
26
|
+
getSize: () => getSize,
|
|
27
|
+
getSpace: () => getSpace,
|
|
28
|
+
getTokenRelative: () => getTokenRelative,
|
|
29
|
+
stepTokenUpOrDown: () => stepTokenUpOrDown
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
var import_web = require("@hanzogui/web");
|
|
33
|
+
const defaultOptions = {
|
|
34
|
+
shift: 0,
|
|
35
|
+
bounds: [0]
|
|
36
|
+
};
|
|
37
|
+
const getSize = (size, options) => {
|
|
38
|
+
return getTokenRelative("size", size, options);
|
|
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;
|
|
@@ -0,0 +1,138 @@
|
|
|
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", {
|
|
23
|
+
value: true
|
|
24
|
+
}), mod);
|
|
25
|
+
var index_exports = {};
|
|
26
|
+
__export(index_exports, {
|
|
27
|
+
getRadius: () => getRadius,
|
|
28
|
+
getSize: () => getSize,
|
|
29
|
+
getSpace: () => getSpace,
|
|
30
|
+
getTokenRelative: () => getTokenRelative,
|
|
31
|
+
stepTokenUpOrDown: () => stepTokenUpOrDown
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(index_exports);
|
|
34
|
+
var import_web = require("@hanzogui/web");
|
|
35
|
+
var defaultOptions = {
|
|
36
|
+
shift: 0,
|
|
37
|
+
bounds: [0]
|
|
38
|
+
};
|
|
39
|
+
var getSize = function (size, options) {
|
|
40
|
+
return getTokenRelative("size", size, options);
|
|
41
|
+
};
|
|
42
|
+
var getSpace = function (space, options) {
|
|
43
|
+
return getTokenRelative("space", space, options);
|
|
44
|
+
};
|
|
45
|
+
var getRadius = function (radius, options) {
|
|
46
|
+
return getTokenRelative("radius", radius, options);
|
|
47
|
+
};
|
|
48
|
+
var cacheVariables = {};
|
|
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;
|
|
138
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","__export","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","Object","keys","map","k","sort","a","b","val","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Symbol","iterator","_step","next","done","token","push","key","err","return"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA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e;IACjBJ,cAAA,CAAAI,IAAA;IAEAD,cAAM,CAAAC,IAAA;IACNH,mBAAW,CAASG,IAAA;IAClB,IAAAS,MAAA,GAAAC,MAAe,CAAAC,IAAM,CAAAL,MAAK,EAAAM,GAAM,CAAG,UAAAC,CAAA;MACnC,OAAAP,MAAA,CAAAO,CAAA;IACF,GAAAC,IAAA,WAAAC,CAAA,EAAAC,CAAA;MACF,OAAAD,CAAA,CAAAE,GAAA,GAAAD,CAAA,CAAAC,GAAA;IAEA;IACA,IAAMC,yBAAgB;MAAAC,iBAEhB;MAAAC,cACA;IAKN,IAAM;MAEN,KAAM,IAAMC,SAAQ,GAAAZ,MAAU,CAAAa,MAAK,CAAAC,QAAA,KAAAC,KAAA,IAAAN,yBAAA,IAAAM,KAAA,GAAAH,SAAA,CAAAI,IAAA,IAAAC,IAAA,GAAAR,yBAAA;QAC7B,IAAAS,KAAM,GAAAH,KAAQ,CAAA/C,KAAS;QACvBqB,SAAA,CAAAE,IAAA,CAAe,CAAA4B,IAAA,CAAAD,KAAA,CAAAE,GAAc;QAE/BjC,cAAgB,CAAAI,IAAA,EAAA4B,IAAS,CAAAD,KAAA;MACzB;IACF,SAAIG,GAAA;MACFX,iBAAiB,OAAI;MACvBC,cAAA,GAAAU,GAAA;IACF;MAEA,IAAM;QACA,KAAAZ,yBAA2B,IAAAG,SAAA,CAAAU,MAAA;UAE3BV,SAAU,CAAAU,MAAO;QAKvB;MACF;QAEa,IAAAZ,iBAAmB","ignoreList":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getTokens, isVariable } from "@hanzogui/web";
|
|
2
|
+
const defaultOptions = {
|
|
3
|
+
shift: 0,
|
|
4
|
+
bounds: [0]
|
|
5
|
+
};
|
|
6
|
+
const getSize = (size, options) => {
|
|
7
|
+
return getTokenRelative("size", size, options);
|
|
8
|
+
};
|
|
9
|
+
const getSpace = (space, options) => {
|
|
10
|
+
return getTokenRelative("space", space, options);
|
|
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 };
|
|
58
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getTokens","isVariable","defaultOptions","shift","bounds","getSize","size","options","getTokenRelative","getSpace","space","getRadius","radius","cacheVariables","cacheWholeVariables","cacheKeys","cacheWholeKeys","stepTokenUpOrDown","type","current","tokens","prefixed","sorted","Object","keys","map","k","sort","a","b","val","token","push","key","sortedExcludingHalfSteps","filter","x","endsWith","isString","cache","excludeHalfSteps","tokensOrdered","min","max","length","currentIndex","indexOf","name","index","Math","found","result"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,SAAA,EAAWC,UAAA,QAAkB;AAWtC,MAAMC,cAAA,GAAkC;EACtCC,KAAA,EAAO;EACPC,MAAA,EAAQ,CAAC,CAAC;AACZ;AAEO,MAAMC,OAAA,GAAUA,CAACC,IAAA,EAAoBC,OAAA,KAA8B;EACxE,OAAOC,gBAAA,CAAiB,QAAQF,IAAA,EAAMC,OAAO;AAC/C;AAEO,MAAME,QAAA,GAAWA,CAACC,KAAA,EAAqBH,OAAA,KAA8B;EAC1E,OAAOC,gBAAA,CAAiB,SAASE,KAAA,EAAOH,OAAO;AACjD;AAEO,MAAMI,SAAA,GAAYA,CAACC,MAAA,EAAsBL,OAAA,KAA8B;EAC5E,OAAOC,gBAAA,CAAiB,UAAUI,MAAA,EAAQL,OAAO;AACnD;AAEA,MAAMM,cAAA,GAA6C,CAAC;AACpD,MAAMC,mBAAA,GAAkD,CAAC;AACzD,MAAMC,SAAA,GAAsC,CAAC;AAC7C,MAAMC,cAAA,GAA2C,C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GACAF,cAAA;EAEN,MAAM4B,aAAA,GAAgBF,KAAA,CAAMrB,IAAI;EAEhC,MAAMwB,GAAA,GAAMnC,OAAA,CAAQH,MAAA,GAAS,CAAC,KAAK;EACnC,MAAMuC,GAAA,GAAMpC,OAAA,CAAQH,MAAA,GAAS,CAAC,KAAKqC,aAAA,CAAcG,MAAA,GAAS;EAC1D,MAAMC,YAAA,GAAeJ,aAAA,CAAcK,OAAA,CAAQ3B,OAAc;EAEzD,IAAIhB,KAAA,GAAQI,OAAA,CAAQJ,KAAA,IAAS;EAC7B,IAAIA,KAAA,EAAO;IACT,IAAIgB,OAAA,KAAY,WAAYlB,UAAA,CAAWkB,OAAO,KAAKA,OAAA,CAAQ4B,IAAA,KAAS,QAAS;MAC3E5C,KAAA,IAASA,KAAA,GAAQ,IAAI,IAAI;IAC3B;EACF;EAEA,MAAM6C,KAAA,GAAQC,IAAA,CAAKP,GAAA,CAAIC,GAAA,EAAKM,IAAA,CAAKN,GAAA,CAAID,GAAA,EAAKG,YAAA,GAAe1C,KAAK,CAAC;EAC/D,MAAM+C,KAAA,GAAQT,aAAA,CAAcO,KAAK;EAEjC,MAAMG,MAAA,IAAU,OAAOD,KAAA,KAAU,WAAW9B,MAAA,CAAO8B,KAAK,IAAIA,KAAA,KAAU9B,MAAA,CAAO,OAAO;EAKpF,OAAO+B,MAAA;AACT;AAEO,MAAM3C,gBAAA,GAAmBS,iBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getTokens, isVariable } from "@hanzogui/web";
|
|
2
|
+
const defaultOptions = {
|
|
3
|
+
shift: 0,
|
|
4
|
+
bounds: [0]
|
|
5
|
+
};
|
|
6
|
+
const getSize = (size, options) => {
|
|
7
|
+
return getTokenRelative("size", size, options);
|
|
8
|
+
};
|
|
9
|
+
const getSpace = (space, options) => {
|
|
10
|
+
return getTokenRelative("space", space, options);
|
|
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 };
|
|
58
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getTokens","isVariable","defaultOptions","shift","bounds","getSize","size","options","getTokenRelative","getSpace","space","getRadius","radius","cacheVariables","cacheWholeVariables","cacheKeys","cacheWholeKeys","stepTokenUpOrDown","type","current","tokens","prefixed","sorted","Object","keys","map","k","sort","a","b","val","token","push","key","sortedExcludingHalfSteps","filter","x","endsWith","isString","cache","excludeHalfSteps","tokensOrdered","min","max","length","currentIndex","indexOf","name","index","Math","found","result"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,SAAA,EAAWC,UAAA,QAAkB;AAWtC,MAAMC,cAAA,GAAkC;EACtCC,KAAA,EAAO;EACPC,MAAA,EAAQ,CAAC,CAAC;AACZ;AAEO,MAAMC,OAAA,GAAUA,CAACC,IAAA,EAAoBC,OAAA,KAA8B;EACxE,OAAOC,gBAAA,CAAiB,QAAQF,IAAA,EAAMC,OAAO;AAC/C;AAEO,MAAME,QAAA,GAAWA,CAACC,KAAA,EAAqBH,OAAA,KAA8B;EAC1E,OAAOC,gBAAA,CAAiB,SAASE,KAAA,EAAOH,OAAO;AACjD;AAEO,MAAMI,SAAA,GAAYA,CAACC,MAAA,EAAsBL,OAAA,KAA8B;EAC5E,OAAOC,gBAAA,CAAiB,UAAUI,MAAA,EAAQL,OAAO;AACnD;AAEA,MAAMM,cAAA,GAA6C,CAAC;AACpD,MAAMC,mBAAA,GAAkD,CAAC;AACzD,MAAMC,SAAA,GAAsC,CAAC;AAC7C,MAAMC,cAAA,GAA2C,CAAC;AAG3C,MAAMC,iBAAA,GAAoBA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AAgBF,KAAA,CAAMrB,IAAI;EAEhC,MAAMwB,GAAA,GAAMnC,OAAA,CAAQH,MAAA,GAAS,CAAC,KAAK;EACnC,MAAMuC,GAAA,GAAMpC,OAAA,CAAQH,MAAA,GAAS,CAAC,KAAKqC,aAAA,CAAcG,MAAA,GAAS;EAC1D,MAAMC,YAAA,GAAeJ,aAAA,CAAcK,OAAA,CAAQ3B,OAAc;EAEzD,IAAIhB,KAAA,GAAQI,OAAA,CAAQJ,KAAA,IAAS;EAC7B,IAAIA,KAAA,EAAO;IACT,IAAIgB,OAAA,KAAY,WAAYlB,UAAA,CAAWkB,OAAO,KAAKA,OAAA,CAAQ4B,IAAA,KAAS,QAAS;MAC3E5C,KAAA,IAASA,KAAA,GAAQ,IAAI,IAAI;IAC3B;EACF;EAEA,MAAM6C,KAAA,GAAQC,IAAA,CAAKP,GAAA,CAAIC,GAAA,EAAKM,IAAA,CAAKN,GAAA,CAAID,GAAA,EAAKG,YAAA,GAAe1C,KAAK,CAAC;EAC/D,MAAM+C,KAAA,GAAQT,aAAA,CAAcO,KAAK;EAEjC,MAAMG,MAAA,IAAU,OAAOD,KAAA,KAAU,WAAW9B,MAAA,CAAO8B,KAAK,IAAIA,KAAA,KAAU9B,MAAA,CAAO,OAAO;EAKpF,OAAO+B,MAAA;AACT;AAEO,MAAM3C,gBAAA,GAAmBS,iBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { getTokens, isVariable } from "@hanzogui/web";
|
|
2
|
+
var defaultOptions = {
|
|
3
|
+
shift: 0,
|
|
4
|
+
bounds: [0]
|
|
5
|
+
};
|
|
6
|
+
var getSize = function (size, options) {
|
|
7
|
+
return getTokenRelative("size", size, options);
|
|
8
|
+
};
|
|
9
|
+
var getSpace = function (space, options) {
|
|
10
|
+
return getTokenRelative("space", space, options);
|
|
11
|
+
};
|
|
12
|
+
var getRadius = function (radius, options) {
|
|
13
|
+
return getTokenRelative("radius", radius, options);
|
|
14
|
+
};
|
|
15
|
+
var cacheVariables = {};
|
|
16
|
+
var cacheWholeVariables = {};
|
|
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 };
|
|
106
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getTokens","isVariable","defaultOptions","shift","bounds","getSize","size","options","getTokenRelative","getSpace","space","getRadius","radius","cacheVariables","cacheWholeVariables","cacheKeys","cacheWholeKeys","stepTokenUpOrDown","type","current","arguments","length","_options_bounds","_options_bounds1","tokens","prefixed","sorted","Object","keys","map","k","sort","a","b","val","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Symbol","iterator","_step","next","done","token","value","push","key","err","return"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,SAAA,EAAWC,UAAA,QAAkB;AAWtC,IAAAC,cAAM;EACJC,KAAA,EAAO;EACPC,MAAA,EAAQ,CACV;AAGE;AACF,IAAAC,OAAA,YAAAA,CAAAC,IAAA,EAAAC,OAAA;EAEO,OAAMC,gBAAiC,SAAAF,IAA8B,EAAAC,OAAA;AAC1E;AACF,IAAAE,QAAA,YAAAA,CAAAC,KAAA,EAAAH,OAAA;EAEO,OAAMC,gBAAa,QAAsB,EAAAE,KAA8B,EAAAH,OAAA;AAC5E;AACF,IAAAI,SAAA,YAAAA,CAAAC,MAAA,EAAAL,OAAA;EAEA,OAAMC,gBAA8C,WAAAI,MAAA,EAAAL,OAAA;AACpD;AACA,IAAAM,cAA4C,GAAC;AAC7C,IAAAC,mBAAi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AA,IAAe,IAAM;UACzDX,SAAQ,CAAAW,MAAA;QAER;MAKN,UAAO;QACT,IAAAb,iBAAA;UAEa,MAAAC,cAAmB","ignoreList":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hanzogui/get-token",
|
|
3
|
+
"version": "2.0.0-rc.41-hanzoai.5",
|
|
4
|
+
"gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
|
|
5
|
+
"files": [
|
|
6
|
+
"src",
|
|
7
|
+
"types",
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"main": "dist/cjs",
|
|
13
|
+
"module": "dist/esm",
|
|
14
|
+
"types": "./types/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
"./package.json": "./package.json",
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./types/index.d.ts",
|
|
19
|
+
"react-native": "./dist/esm/index.native.js",
|
|
20
|
+
"browser": "./dist/esm/index.mjs",
|
|
21
|
+
"module": "./dist/esm/index.mjs",
|
|
22
|
+
"import": "./dist/esm/index.mjs",
|
|
23
|
+
"require": "./dist/cjs/index.cjs",
|
|
24
|
+
"default": "./dist/esm/index.mjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "hanzogui-build",
|
|
32
|
+
"watch": "hanzogui-build --watch",
|
|
33
|
+
"clean": "hanzogui-build clean",
|
|
34
|
+
"clean:build": "hanzogui-build clean:build"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@hanzogui/web": "2.0.0-rc.41-hanzoai.5"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@hanzogui/build": "2.0.0-rc.41-hanzoai.5",
|
|
41
|
+
"react": ">=19"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": ">=19"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Variable, VariableValGeneric } from '@hanzogui/web'
|
|
2
|
+
import { getTokens, isVariable } from '@hanzogui/web'
|
|
3
|
+
|
|
4
|
+
// technically number | undefined just for compat with the generic VariableVal
|
|
5
|
+
type GetTokenBase = Variable | string | number | undefined | VariableValGeneric
|
|
6
|
+
|
|
7
|
+
type GetTokenOptions = {
|
|
8
|
+
shift?: number
|
|
9
|
+
bounds?: [number] | [number, number]
|
|
10
|
+
excludeHalfSteps?: boolean
|
|
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
|
|
40
|
+
): Variable<number> => {
|
|
41
|
+
const tokens = getTokens({ prefixed: true })[type] as Record<string, Variable>
|
|
42
|
+
|
|
43
|
+
if (!(type in cacheVariables)) {
|
|
44
|
+
cacheKeys[type] = []
|
|
45
|
+
cacheVariables[type] = []
|
|
46
|
+
cacheWholeKeys[type] = []
|
|
47
|
+
cacheWholeVariables[type] = []
|
|
48
|
+
|
|
49
|
+
const sorted = Object.keys(tokens)
|
|
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
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const index = Math.min(max, Math.max(min, currentIndex + shift))
|
|
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 })
|
|
93
|
+
|
|
94
|
+
// @ts-ignore
|
|
95
|
+
return result
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export const getTokenRelative = stepTokenUpOrDown
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Variable, VariableValGeneric } from '@hanzogui/web';
|
|
2
|
+
type GetTokenBase = Variable | string | number | undefined | VariableValGeneric;
|
|
3
|
+
type GetTokenOptions = {
|
|
4
|
+
shift?: number;
|
|
5
|
+
bounds?: [number] | [number, number];
|
|
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>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAIjE,KAAK,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,kBAAkB,CAAA;AAE/E,KAAK,eAAe,GAAG;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAOD,eAAO,MAAM,OAAO,GAAI,MAAM,YAAY,EAAE,UAAU,eAAe,qBAEpE,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,OAAO,YAAY,EAAE,UAAU,eAAe,qBAEtE,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,QAAQ,YAAY,EAAE,UAAU,eAAe,qBAExE,CAAA;AAOD,qEAAqE;AACrE,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,EAC5C,SAAS,YAAY,EACrB,UAAS,eAAgC,KACxC,QAAQ,CAAC,MAAM,CAwDjB,CAAA;AAED,eAAO,MAAM,gBAAgB,SA7DrB,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,WACnC,YAAY,YACZ,eAAe,KACvB,QAAQ,CAAC,MAAM,CA0D+B,CAAA"}
|