@hanzogui/get-token 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,64 @@
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: !0
9
+ });
10
+ },
11
+ __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
13
+ get: () => from[key],
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ return to;
17
+ };
18
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
+ value: !0
20
+ }), mod);
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ getRadius: () => getRadius,
24
+ getSize: () => getSize,
25
+ getSpace: () => getSpace,
26
+ getTokenRelative: () => getTokenRelative,
27
+ stepTokenUpOrDown: () => stepTokenUpOrDown
28
+ });
29
+ module.exports = __toCommonJS(index_exports);
30
+ var import_web = require("@hanzogui/web");
31
+ const defaultOptions = {
32
+ shift: 0,
33
+ bounds: [0]
34
+ },
35
+ getSize = (size, options) => getTokenRelative("size", size, options),
36
+ getSpace = (space, options) => getTokenRelative("space", space, options),
37
+ getRadius = (radius, options) => getTokenRelative("radius", radius, options),
38
+ cacheVariables = {},
39
+ cacheWholeVariables = {},
40
+ cacheKeys = {},
41
+ cacheWholeKeys = {},
42
+ stepTokenUpOrDown = (type, current, options = defaultOptions) => {
43
+ const tokens = (0, import_web.getTokens)({
44
+ prefixed: !0
45
+ })[type];
46
+ if (!(type in cacheVariables)) {
47
+ cacheKeys[type] = [], cacheVariables[type] = [], cacheWholeKeys[type] = [], cacheWholeVariables[type] = [];
48
+ const sorted = Object.keys(tokens).map(k => tokens[k]).sort((a, b) => a.val - b.val);
49
+ for (const token of sorted) cacheKeys[type].push(token.key), cacheVariables[type].push(token);
50
+ const sortedExcludingHalfSteps = sorted.filter(x => !x.key.endsWith(".5"));
51
+ for (const token of sortedExcludingHalfSteps) cacheWholeKeys[type].push(token.key), cacheWholeVariables[type].push(token);
52
+ }
53
+ const isString = typeof current == "string",
54
+ tokensOrdered = (options.excludeHalfSteps ? isString ? cacheWholeKeys : cacheWholeVariables : isString ? cacheKeys : cacheVariables)[type],
55
+ min = options.bounds?.[0] ?? 0,
56
+ max = options.bounds?.[1] ?? tokensOrdered.length - 1,
57
+ currentIndex = tokensOrdered.indexOf(current);
58
+ let shift = options.shift || 0;
59
+ shift && (current === "$true" || (0, import_web.isVariable)(current) && current.name === "true") && (shift += shift > 0 ? 1 : -1);
60
+ const index = Math.min(max, Math.max(min, currentIndex + shift)),
61
+ found = tokensOrdered[index];
62
+ return (typeof found == "string" ? tokens[found] : found) || tokens.$true;
63
+ },
64
+ getTokenRelative = stepTokenUpOrDown;
@@ -0,0 +1,118 @@
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: !0
11
+ });
12
+ },
13
+ __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
+ get: () => from[key],
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: !0
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
+ defaultOptions = {
34
+ shift: 0,
35
+ bounds: [0]
36
+ },
37
+ getSize = function (size, options) {
38
+ return getTokenRelative("size", size, options);
39
+ },
40
+ getSpace = function (space, options) {
41
+ return getTokenRelative("space", space, options);
42
+ },
43
+ getRadius = function (radius, options) {
44
+ return getTokenRelative("radius", radius, options);
45
+ },
46
+ cacheVariables = {},
47
+ cacheWholeVariables = {},
48
+ cacheKeys = {},
49
+ cacheWholeKeys = {},
50
+ stepTokenUpOrDown = function (type, current) {
51
+ var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOptions,
52
+ _options_bounds,
53
+ _options_bounds1,
54
+ tokens = (0, import_web.getTokens)({
55
+ prefixed: !0
56
+ })[type];
57
+ if (!(type in cacheVariables)) {
58
+ cacheKeys[type] = [], cacheVariables[type] = [], cacheWholeKeys[type] = [], cacheWholeVariables[type] = [];
59
+ var sorted = Object.keys(tokens).map(function (k) {
60
+ return tokens[k];
61
+ }).sort(function (a, b) {
62
+ return a.val - b.val;
63
+ }),
64
+ _iteratorNormalCompletion = !0,
65
+ _didIteratorError = !1,
66
+ _iteratorError = void 0;
67
+ try {
68
+ for (var _iterator = sorted[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
69
+ var token = _step.value;
70
+ cacheKeys[type].push(token.key), cacheVariables[type].push(token);
71
+ }
72
+ } catch (err) {
73
+ _didIteratorError = !0, _iteratorError = err;
74
+ } finally {
75
+ try {
76
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
77
+ } finally {
78
+ if (_didIteratorError) throw _iteratorError;
79
+ }
80
+ }
81
+ var sortedExcludingHalfSteps = sorted.filter(function (x) {
82
+ return !x.key.endsWith(".5");
83
+ }),
84
+ _iteratorNormalCompletion1 = !0,
85
+ _didIteratorError1 = !1,
86
+ _iteratorError1 = void 0;
87
+ try {
88
+ for (var _iterator1 = sortedExcludingHalfSteps[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0) {
89
+ var token1 = _step1.value;
90
+ cacheWholeKeys[type].push(token1.key), cacheWholeVariables[type].push(token1);
91
+ }
92
+ } catch (err) {
93
+ _didIteratorError1 = !0, _iteratorError1 = err;
94
+ } finally {
95
+ try {
96
+ !_iteratorNormalCompletion1 && _iterator1.return != null && _iterator1.return();
97
+ } finally {
98
+ if (_didIteratorError1) throw _iteratorError1;
99
+ }
100
+ }
101
+ }
102
+ var isString = typeof current == "string",
103
+ cache = options.excludeHalfSteps ? isString ? cacheWholeKeys : cacheWholeVariables : isString ? cacheKeys : cacheVariables,
104
+ tokensOrdered = cache[type],
105
+ _options_bounds_,
106
+ 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,
107
+ _options_bounds_1,
108
+ 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,
109
+ currentIndex = tokensOrdered.indexOf(current),
110
+ shift = options.shift || 0;
111
+ shift && (current === "$true" || (0, import_web.isVariable)(current) && current.name === "true") && (shift += shift > 0 ? 1 : -1);
112
+ var index = Math.min(max, Math.max(min, currentIndex + shift)),
113
+ found = tokensOrdered[index],
114
+ result = (typeof found == "string" ? tokens[found] : found) || tokens.$true;
115
+ return result;
116
+ },
117
+ getTokenRelative = stepTokenUpOrDown;
118
+ //# 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"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,SAAA,EAAAA,CAAA,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AAA;QAQZ,GAAAC,IAAA,WAAAC,CAAmB,EAAAC,CAAA","ignoreList":[]}
@@ -0,0 +1,37 @@
1
+ import { getTokens, isVariable } from "@hanzogui/web";
2
+ const defaultOptions = {
3
+ shift: 0,
4
+ bounds: [0]
5
+ },
6
+ getSize = (size, options) => getTokenRelative("size", size, options),
7
+ getSpace = (space, options) => getTokenRelative("space", space, options),
8
+ getRadius = (radius, options) => getTokenRelative("radius", radius, options),
9
+ cacheVariables = {},
10
+ cacheWholeVariables = {},
11
+ cacheKeys = {},
12
+ cacheWholeKeys = {},
13
+ stepTokenUpOrDown = (type, current, options = defaultOptions) => {
14
+ const tokens = getTokens({
15
+ prefixed: !0
16
+ })[type];
17
+ if (!(type in cacheVariables)) {
18
+ cacheKeys[type] = [], cacheVariables[type] = [], cacheWholeKeys[type] = [], cacheWholeVariables[type] = [];
19
+ const sorted = Object.keys(tokens).map(k => tokens[k]).sort((a, b) => a.val - b.val);
20
+ for (const token of sorted) cacheKeys[type].push(token.key), cacheVariables[type].push(token);
21
+ const sortedExcludingHalfSteps = sorted.filter(x => !x.key.endsWith(".5"));
22
+ for (const token of sortedExcludingHalfSteps) cacheWholeKeys[type].push(token.key), cacheWholeVariables[type].push(token);
23
+ }
24
+ const isString = typeof current == "string",
25
+ tokensOrdered = (options.excludeHalfSteps ? isString ? cacheWholeKeys : cacheWholeVariables : isString ? cacheKeys : cacheVariables)[type],
26
+ min = options.bounds?.[0] ?? 0,
27
+ max = options.bounds?.[1] ?? tokensOrdered.length - 1,
28
+ currentIndex = tokensOrdered.indexOf(current);
29
+ let shift = options.shift || 0;
30
+ shift && (current === "$true" || isVariable(current) && current.name === "true") && (shift += shift > 0 ? 1 : -1);
31
+ const index = Math.min(max, Math.max(min, currentIndex + shift)),
32
+ found = tokensOrdered[index];
33
+ return (typeof found == "string" ? tokens[found] : found) || tokens.$true;
34
+ },
35
+ getTokenRelative = stepTokenUpOrDown;
36
+ export { getRadius, getSize, getSpace, getTokenRelative, stepTokenUpOrDown };
37
+ //# 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","tokensOrdered","excludeHalfSteps","min","max","length","currentIndex","indexOf","name","index","Math","found","$true"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,SAAA,EAAWC,UAAA,QAAkB;AAWtC,MAAMC,cAAA,GAAkC;IACtCC,KAAA,EAAO;IACPC,MAAA,EAAQ,CAAC,CAAC;EACZ;EAEaC,OAAA,GAAUA,CAACC,IAAA,EAAoBC,OAAA,KACnCC,gBAAA,CAAiB,QAAQF,IAAA,EAAMC,OAAO;EAGlCE,QAAA,GAAWA,CAACC,KAAA,EAAqBH,OAAA,KACrCC,gBAAA,CAAiB,SAASE,KAAA,EAAOH,OAAO;EAGpCI,SAAA,GAAYA,CAACC,MAAA,EAAsBL,OAAA,KACvCC,gBAAA,CAAiB,UAAUI,MAAA,EAAQL,OAAO;EAG7CM,cAAA,GAA6C,CAAC;EAC9CC,mBAAA,GAAkD,CAAC;EACnDC,SAAA,GAAsC,CAAC;EACvCC,cAAA,GAA2C,CAAC;EAGrCC,iBAAA,GAAoBA,CAC/BC,IAAA,EACAC,OAAA,EACAZ,OAAA,GAA2BL,cAAA,KACN;IACrB,MAAMkB,MAAA,GAASpB,SAAA,CAAU;MAAEqB,QAAA,EAAU;IAAK,CAAC,EAAEH,IAAI;IAEjD,IAAI,EAAEA,IAAA,IAAQL,cAAA,GAAiB;MAC7BE,SAAA,CAAUG,IAAI,IAAI,EAAC,EACnBL,cAAA,CAAeK,IAAI,IAAI,EAAC,EACxBF,cAAA,CAAeE,IAAI,IAAI,EAAC,EACxBJ,mBA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E3C,KAAA,IAASA,KAAA,GAAQ,IAAI,IAAI;IAI7B,MAAM4C,KAAA,GAAQC,IAAA,CAAKP,GAAA,CAAIC,GAAA,EAAKM,IAAA,CAAKN,GAAA,CAAID,GAAA,EAAKG,YAAA,GAAezC,KAAK,CAAC;MACzD8C,KAAA,GAAQV,aAAA,CAAcQ,KAAK;IAOjC,QALgB,OAAOE,KAAA,IAAU,WAAW7B,MAAA,CAAO6B,KAAK,IAAIA,KAAA,KAAU7B,MAAA,CAAO8B,KAAA;EAM/E;EAEa1C,gBAAA,GAAmBS,iBAAA","ignoreList":[]}
@@ -0,0 +1,37 @@
1
+ import { getTokens, isVariable } from "@hanzogui/web";
2
+ const defaultOptions = {
3
+ shift: 0,
4
+ bounds: [0]
5
+ },
6
+ getSize = (size, options) => getTokenRelative("size", size, options),
7
+ getSpace = (space, options) => getTokenRelative("space", space, options),
8
+ getRadius = (radius, options) => getTokenRelative("radius", radius, options),
9
+ cacheVariables = {},
10
+ cacheWholeVariables = {},
11
+ cacheKeys = {},
12
+ cacheWholeKeys = {},
13
+ stepTokenUpOrDown = (type, current, options = defaultOptions) => {
14
+ const tokens = getTokens({
15
+ prefixed: !0
16
+ })[type];
17
+ if (!(type in cacheVariables)) {
18
+ cacheKeys[type] = [], cacheVariables[type] = [], cacheWholeKeys[type] = [], cacheWholeVariables[type] = [];
19
+ const sorted = Object.keys(tokens).map(k => tokens[k]).sort((a, b) => a.val - b.val);
20
+ for (const token of sorted) cacheKeys[type].push(token.key), cacheVariables[type].push(token);
21
+ const sortedExcludingHalfSteps = sorted.filter(x => !x.key.endsWith(".5"));
22
+ for (const token of sortedExcludingHalfSteps) cacheWholeKeys[type].push(token.key), cacheWholeVariables[type].push(token);
23
+ }
24
+ const isString = typeof current == "string",
25
+ tokensOrdered = (options.excludeHalfSteps ? isString ? cacheWholeKeys : cacheWholeVariables : isString ? cacheKeys : cacheVariables)[type],
26
+ min = options.bounds?.[0] ?? 0,
27
+ max = options.bounds?.[1] ?? tokensOrdered.length - 1,
28
+ currentIndex = tokensOrdered.indexOf(current);
29
+ let shift = options.shift || 0;
30
+ shift && (current === "$true" || isVariable(current) && current.name === "true") && (shift += shift > 0 ? 1 : -1);
31
+ const index = Math.min(max, Math.max(min, currentIndex + shift)),
32
+ found = tokensOrdered[index];
33
+ return (typeof found == "string" ? tokens[found] : found) || tokens.$true;
34
+ },
35
+ getTokenRelative = stepTokenUpOrDown;
36
+ export { getRadius, getSize, getSpace, getTokenRelative, stepTokenUpOrDown };
37
+ //# 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","tokensOrdered","excludeHalfSteps","min","max","length","currentIndex","indexOf","name","index","Math","found","$true"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,SAAA,EAAWC,UAAA,QAAkB;AAWtC,MAAMC,cAAA,GAAkC;IACtCC,KAAA,EAAO;IACPC,MAAA,EAAQ,CAAC,CAAC;EACZ;EAEaC,OAAA,GAAUA,CAACC,IAAA,EAAoBC,OAAA,KACnCC,gBAAA,CAAiB,QAAQF,IAAA,EAAMC,OAAO;EAGlCE,QAAA,GAAWA,CAACC,KAAA,EAAqBH,OAAA,KACrCC,gBAAA,CAAiB,SAASE,KAAA,EAAOH,OAAO;EAGpCI,SAAA,GAAYA,CAACC,MAAA,EAAsBL,OAAA,KACvCC,gBAAA,CAAiB,UAAUI,MAAA,EAAQL,OAAO;EAG7CM,cAAA,GAA6C,CAAC;EAC9CC,mBAAA,GAAkD,CAAC;EACnDC,SAAA,GAAsC,CAAC;EACvCC,cAAA,GAA2C,CAAC;EAGrCC,iBAAA,GAAoBA,CAC/BC,IAA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C,KAAK;MAC7BsC,GAAA,GAAMnC,OAAA,CAAQH,MAAA,GAAS,CAAC,KAAKmC,aAAA,CAAcI,MAAA,GAAS;MACpDC,YAAA,GAAeL,aAAA,CAAcM,OAAA,CAAQ1B,OAAc;IAEzD,IAAIhB,KAAA,GAAQI,OAAA,CAAQJ,KAAA,IAAS;IACzBA,KAAA,KACEgB,OAAA,KAAY,WAAYlB,UAAA,CAAWkB,OAAO,KAAKA,OAAA,CAAQ2B,IAAA,KAAS,YAClE3C,KAAA,IAASA,KAAA,GAAQ,IAAI,IAAI;IAI7B,MAAM4C,KAAA,GAAQC,IAAA,CAAKP,GAAA,CAAIC,GAAA,EAAKM,IAAA,CAAKN,GAAA,CAAID,GAAA,EAAKG,YAAA,GAAezC,KAAK,CAAC;MACzD8C,KAAA,GAAQV,aAAA,CAAcQ,KAAK;IAOjC,QALgB,OAAOE,KAAA,IAAU,WAAW7B,MAAA,CAAO6B,KAAK,IAAIA,KAAA,KAAU7B,MAAA,CAAO8B,KAAA;EAM/E;EAEa1C,gBAAA,GAAmBS,iBAAA","ignoreList":[]}
@@ -0,0 +1,88 @@
1
+ import { getTokens, isVariable } from "@hanzogui/web";
2
+ var defaultOptions = {
3
+ shift: 0,
4
+ bounds: [0]
5
+ },
6
+ getSize = function (size, options) {
7
+ return getTokenRelative("size", size, options);
8
+ },
9
+ getSpace = function (space, options) {
10
+ return getTokenRelative("space", space, options);
11
+ },
12
+ getRadius = function (radius, options) {
13
+ return getTokenRelative("radius", radius, options);
14
+ },
15
+ cacheVariables = {},
16
+ cacheWholeVariables = {},
17
+ cacheKeys = {},
18
+ cacheWholeKeys = {},
19
+ stepTokenUpOrDown = function (type, current) {
20
+ var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : defaultOptions,
21
+ _options_bounds,
22
+ _options_bounds1,
23
+ tokens = getTokens({
24
+ prefixed: !0
25
+ })[type];
26
+ if (!(type in cacheVariables)) {
27
+ cacheKeys[type] = [], cacheVariables[type] = [], cacheWholeKeys[type] = [], cacheWholeVariables[type] = [];
28
+ var sorted = Object.keys(tokens).map(function (k) {
29
+ return tokens[k];
30
+ }).sort(function (a, b) {
31
+ return a.val - b.val;
32
+ }),
33
+ _iteratorNormalCompletion = !0,
34
+ _didIteratorError = !1,
35
+ _iteratorError = void 0;
36
+ try {
37
+ for (var _iterator = sorted[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
38
+ var token = _step.value;
39
+ cacheKeys[type].push(token.key), cacheVariables[type].push(token);
40
+ }
41
+ } catch (err) {
42
+ _didIteratorError = !0, _iteratorError = err;
43
+ } finally {
44
+ try {
45
+ !_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
46
+ } finally {
47
+ if (_didIteratorError) throw _iteratorError;
48
+ }
49
+ }
50
+ var sortedExcludingHalfSteps = sorted.filter(function (x) {
51
+ return !x.key.endsWith(".5");
52
+ }),
53
+ _iteratorNormalCompletion1 = !0,
54
+ _didIteratorError1 = !1,
55
+ _iteratorError1 = void 0;
56
+ try {
57
+ for (var _iterator1 = sortedExcludingHalfSteps[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = !0) {
58
+ var token1 = _step1.value;
59
+ cacheWholeKeys[type].push(token1.key), cacheWholeVariables[type].push(token1);
60
+ }
61
+ } catch (err) {
62
+ _didIteratorError1 = !0, _iteratorError1 = err;
63
+ } finally {
64
+ try {
65
+ !_iteratorNormalCompletion1 && _iterator1.return != null && _iterator1.return();
66
+ } finally {
67
+ if (_didIteratorError1) throw _iteratorError1;
68
+ }
69
+ }
70
+ }
71
+ var isString = typeof current == "string",
72
+ cache = options.excludeHalfSteps ? isString ? cacheWholeKeys : cacheWholeVariables : isString ? cacheKeys : cacheVariables,
73
+ tokensOrdered = cache[type],
74
+ _options_bounds_,
75
+ 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,
76
+ _options_bounds_1,
77
+ 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,
78
+ currentIndex = tokensOrdered.indexOf(current),
79
+ shift = options.shift || 0;
80
+ shift && (current === "$true" || isVariable(current) && current.name === "true") && (shift += shift > 0 ? 1 : -1);
81
+ var index = Math.min(max, Math.max(min, currentIndex + shift)),
82
+ found = tokensOrdered[index],
83
+ result = (typeof found == "string" ? tokens[found] : found) || tokens.$true;
84
+ return result;
85
+ },
86
+ getTokenRelative = stepTokenUpOrDown;
87
+ export { getRadius, getSize, getSpace, getTokenRelative, stepTokenUpOrDown };
88
+ //# 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"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,SAAA,EAAWC,UAAA,QAAkB;AAWtC,IAAAC,cAAM;IACJC,KAAA,EAAO;IACPC,MAAA,EAAQ,CAGG;EAyBX;EAAAC,OAAM,YAAAA,CAAQC,IAAA,EAAAC,OAAiB;IAC7B,OAAAC,gBAAmB,CACnB,QAAAF,IAAA,EAAAC,OAAmB;EAInB;EAAAE,QAAM,YAAAA,CAASC,KAAO,EAAAH,OAAW,EAC9B;IAGH,OAAAC,gBAAoB,UAAAE,KAAA,EAAAH,OAAA;EAClB;EAAAI,SAAA,YAAAA,CAAgBC,MAAK,EAAAL,OACrB;IAGF,OAAAC,gBAAM,WAAAI,MAA2B,EAAOL,OAAO,CAAC;EAChD;EAAAM,cAAW;EAASC,mBAAA;EAAAC,SAAA;EAAAC,cAAA;EAAAC,iBAAA,YAAAA,CAAAC,IAAA,EAAAC,OAAA;IAClB,IAAAZ,OAAA,GAAAa,SAAmB,CAAAC,MAAO,QAAMD,SAChC,iBAAoBA,SAAW,MAAKlB,cAAA;MAAAoB,eAAA;MAAAC,gBAAA;MAAAC,MAAA,GAAAxB,SAAA;QAExCyB,QAAA;MAEA,GAAAP,IAAM;IAeN,IAAI,EAAAA,IAAA,IAAQL,cAAQ,CAAS;MACzBE,SACE,CAAAG,IAAA,MAAY,EAAAL,cAAY,CAAAK,IAAA,CAAW,OAAOF,cAAa,CAAAE,IAAA,IAAS,IAAAJ,mBACzD,CAAAI,IAAQ,IAAI;MAIzB,IAAMQ,MAAA,GAAQC,MAAK,CAAAC,IAAI,CAAAJ,MAAU,EAAAK,GAAI,WAAKC,CAAA;UAQ1C,OALgBN,MAAO,CAAAM,CAAA;QAQZ,GAAAC,IAAA,WAAAC,CAAmB,EAAAC,CAAA","ignoreList":[]}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@hanzogui/get-token",
3
+ "version": "2.0.0",
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": "hanzo-gui-build",
32
+ "watch": "hanzo-gui-build --watch",
33
+ "clean": "hanzo-gui-build clean",
34
+ "clean:build": "hanzo-gui-build clean:build"
35
+ },
36
+ "dependencies": {
37
+ "@hanzogui/web": "workspace:*"
38
+ },
39
+ "devDependencies": {
40
+ "@hanzogui/build": "workspace:*",
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
@@ -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"}