@fxhash/params 0.0.4 → 0.0.7
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/BaseInput.cjs +13 -0
- package/dist/BaseInput.cjs.map +1 -0
- package/dist/BaseInput.css +112 -0
- package/dist/BaseInput.css.map +1 -0
- package/dist/BaseInput.d.ts +12 -0
- package/dist/BaseInput.js +13 -0
- package/dist/BaseInput.js.map +1 -0
- package/dist/Context.cjs +49 -0
- package/dist/Context.cjs.map +1 -0
- package/dist/Context.d.ts +19 -0
- package/dist/Context.js +49 -0
- package/dist/Context.js.map +1 -0
- package/dist/Controller/BigInt.cjs +10 -0
- package/dist/Controller/BigInt.cjs.map +1 -0
- package/dist/Controller/BigInt.css +183 -0
- package/dist/Controller/BigInt.css.map +1 -0
- package/dist/Controller/BigInt.d.ts +8 -0
- package/dist/Controller/BigInt.js +10 -0
- package/dist/Controller/BigInt.js.map +1 -0
- package/dist/Controller/Boolean.cjs +9 -0
- package/dist/Controller/Boolean.cjs.map +1 -0
- package/dist/Controller/Boolean.css +183 -0
- package/dist/Controller/Boolean.css.map +1 -0
- package/dist/Controller/Boolean.d.ts +8 -0
- package/dist/Controller/Boolean.js +9 -0
- package/dist/Controller/Boolean.js.map +1 -0
- package/dist/Controller/Bytes.cjs +9 -0
- package/dist/Controller/Bytes.cjs.map +1 -0
- package/dist/Controller/Bytes.css +191 -0
- package/dist/Controller/Bytes.css.map +1 -0
- package/dist/Controller/Bytes.d.ts +8 -0
- package/dist/Controller/Bytes.js +9 -0
- package/dist/Controller/Bytes.js.map +1 -0
- package/dist/Controller/Color.cjs +10 -0
- package/dist/Controller/Color.cjs.map +1 -0
- package/dist/Controller/Color.css +227 -0
- package/dist/Controller/Color.css.map +1 -0
- package/dist/Controller/Color.d.ts +8 -0
- package/dist/Controller/Color.js +10 -0
- package/dist/Controller/Color.js.map +1 -0
- package/dist/Controller/Controller.cjs +14 -0
- package/dist/Controller/Controller.cjs.map +1 -0
- package/dist/Controller/Controller.css +183 -0
- package/dist/Controller/Controller.css.map +1 -0
- package/dist/Controller/Controller.d.ts +41 -0
- package/dist/Controller/Controller.js +14 -0
- package/dist/Controller/Controller.js.map +1 -0
- package/dist/Controller/Invalid.cjs +7 -0
- package/dist/Controller/Invalid.cjs.map +1 -0
- package/dist/Controller/Invalid.css +48 -0
- package/dist/Controller/Invalid.css.map +1 -0
- package/dist/Controller/Invalid.d.ts +11 -0
- package/dist/Controller/Invalid.js +7 -0
- package/dist/Controller/Invalid.js.map +1 -0
- package/dist/Controller/Number.cjs +9 -0
- package/dist/Controller/Number.cjs.map +1 -0
- package/dist/Controller/Number.css +183 -0
- package/dist/Controller/Number.css.map +1 -0
- package/dist/Controller/Number.d.ts +8 -0
- package/dist/Controller/Number.js +9 -0
- package/dist/Controller/Number.js.map +1 -0
- package/dist/Controller/Param.cjs +21 -0
- package/dist/Controller/Param.cjs.map +1 -0
- package/dist/Controller/Param.css +283 -0
- package/dist/Controller/Param.css.map +1 -0
- package/dist/Controller/Param.d.ts +25 -0
- package/dist/Controller/Param.js +21 -0
- package/dist/Controller/Param.js.map +1 -0
- package/dist/Controller/Select.cjs +9 -0
- package/dist/Controller/Select.cjs.map +1 -0
- package/dist/Controller/Select.css +183 -0
- package/dist/Controller/Select.css.map +1 -0
- package/dist/Controller/Select.d.ts +8 -0
- package/dist/Controller/Select.js +9 -0
- package/dist/Controller/Select.js.map +1 -0
- package/dist/Controller/String.cjs +9 -0
- package/dist/Controller/String.cjs.map +1 -0
- package/dist/Controller/String.css +183 -0
- package/dist/Controller/String.css.map +1 -0
- package/dist/Controller/String.d.ts +8 -0
- package/dist/Controller/String.js +9 -0
- package/dist/Controller/String.js.map +1 -0
- package/dist/Controls.cjs +102 -0
- package/dist/Controls.cjs.map +1 -0
- package/dist/Controls.css +304 -0
- package/dist/Controls.css.map +1 -0
- package/dist/Controls.d.ts +17 -0
- package/dist/Controls.js +102 -0
- package/dist/Controls.js.map +1 -0
- package/dist/LockButton/LockButton.cjs +8 -0
- package/dist/LockButton/LockButton.cjs.map +1 -0
- package/dist/LockButton/LockButton.css +117 -0
- package/dist/LockButton/LockButton.css.map +1 -0
- package/dist/LockButton/LockButton.d.ts +11 -0
- package/dist/LockButton/LockButton.js +8 -0
- package/dist/LockButton/LockButton.js.map +1 -0
- package/dist/ParamsHistory.cjs +89 -0
- package/dist/ParamsHistory.cjs.map +1 -0
- package/dist/ParamsHistory.d.ts +22 -0
- package/dist/ParamsHistory.js +89 -0
- package/dist/ParamsHistory.js.map +1 -0
- package/dist/RuntimeContext.cjs +10 -0
- package/dist/RuntimeContext.cjs.map +1 -0
- package/dist/RuntimeContext.d.ts +44 -0
- package/dist/RuntimeContext.js +10 -0
- package/dist/RuntimeContext.js.map +1 -0
- package/dist/chunk-2BHABOFI.js +43 -0
- package/dist/chunk-2BHABOFI.js.map +1 -0
- package/dist/chunk-2QIAF3U7.js +39 -0
- package/dist/chunk-2QIAF3U7.js.map +1 -0
- package/dist/chunk-2QU65L2O.cjs +399 -0
- package/dist/chunk-2QU65L2O.cjs.map +1 -0
- package/dist/chunk-4FX3ATAX.js +110 -0
- package/dist/chunk-4FX3ATAX.js.map +1 -0
- package/dist/chunk-4OV7OX5A.js +37 -0
- package/dist/chunk-4OV7OX5A.js.map +1 -0
- package/dist/chunk-6VMIOQSE.js +34 -0
- package/dist/chunk-6VMIOQSE.js.map +1 -0
- package/dist/chunk-7NOMBXLG.js +120 -0
- package/dist/chunk-7NOMBXLG.js.map +1 -0
- package/dist/chunk-CE3TPOSO.js +135 -0
- package/dist/chunk-CE3TPOSO.js.map +1 -0
- package/dist/chunk-D4RVVQC7.cjs +23 -0
- package/dist/chunk-D4RVVQC7.cjs.map +1 -0
- package/dist/chunk-DP5CBORY.cjs +46 -0
- package/dist/chunk-DP5CBORY.cjs.map +1 -0
- package/dist/chunk-EACKNC6C.cjs +103 -0
- package/dist/chunk-EACKNC6C.cjs.map +1 -0
- package/dist/chunk-EIQHQNZJ.js +115 -0
- package/dist/chunk-EIQHQNZJ.js.map +1 -0
- package/dist/chunk-FDUCXROE.cjs +120 -0
- package/dist/chunk-FDUCXROE.cjs.map +1 -0
- package/dist/chunk-H5IMTNFG.js +44 -0
- package/dist/chunk-H5IMTNFG.js.map +1 -0
- package/dist/chunk-HJBHIE5T.cjs +135 -0
- package/dist/chunk-HJBHIE5T.cjs.map +1 -0
- package/dist/chunk-JAU4ONF2.cjs +24 -0
- package/dist/chunk-JAU4ONF2.cjs.map +1 -0
- package/dist/chunk-K4EW6YY3.cjs +34 -0
- package/dist/chunk-K4EW6YY3.cjs.map +1 -0
- package/dist/chunk-MWP7SJWC.js +103 -0
- package/dist/chunk-MWP7SJWC.js.map +1 -0
- package/dist/chunk-OFUKQ2TB.cjs +43 -0
- package/dist/chunk-OFUKQ2TB.cjs.map +1 -0
- package/dist/chunk-PTXBICTZ.js +67 -0
- package/dist/chunk-PTXBICTZ.js.map +1 -0
- package/dist/chunk-QM6EKPI6.cjs +67 -0
- package/dist/chunk-QM6EKPI6.cjs.map +1 -0
- package/dist/chunk-SDPENM2L.js +399 -0
- package/dist/chunk-SDPENM2L.js.map +1 -0
- package/dist/chunk-TKKYM77A.cjs +44 -0
- package/dist/chunk-TKKYM77A.cjs.map +1 -0
- package/dist/chunk-VED7SCYX.cjs +39 -0
- package/dist/chunk-VED7SCYX.cjs.map +1 -0
- package/dist/chunk-WQVPKBSN.cjs +110 -0
- package/dist/chunk-WQVPKBSN.cjs.map +1 -0
- package/dist/chunk-X4O42D2P.cjs +37 -0
- package/dist/chunk-X4O42D2P.cjs.map +1 -0
- package/dist/chunk-YBV33YPC.cjs +115 -0
- package/dist/chunk-YBV33YPC.cjs.map +1 -0
- package/dist/chunk-YOS2HCIS.js +23 -0
- package/dist/chunk-YOS2HCIS.js.map +1 -0
- package/dist/chunk-YYEIYDDF.js +24 -0
- package/dist/chunk-YYEIYDDF.js.map +1 -0
- package/dist/chunk-ZUITF5XX.js +46 -0
- package/dist/chunk-ZUITF5XX.js.map +1 -0
- package/dist/hooks.cjs +29 -0
- package/dist/hooks.cjs.map +1 -0
- package/dist/hooks.d.ts +6 -0
- package/dist/hooks.js +29 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.cjs +7 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +112 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/types.cjs +1 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.ts +100 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.cjs +33 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.ts +50 -0
- package/dist/utils.js +33 -0
- package/dist/utils.js.map +1 -0
- package/dist/validation.cjs +9 -0
- package/dist/validation.cjs.map +1 -0
- package/dist/validation.d.ts +241 -0
- package/dist/validation.js +9 -0
- package/dist/validation.js.map +1 -0
- package/package.json +1 -1
@@ -0,0 +1,399 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/utils.ts
|
2
|
+
function rgbaToHex(r, g, b, a) {
|
3
|
+
const outParts = [
|
4
|
+
r.toString(16),
|
5
|
+
g.toString(16),
|
6
|
+
b.toString(16),
|
7
|
+
Math.round(a * 255).toString(16).substring(0, 2)
|
8
|
+
];
|
9
|
+
outParts.forEach(function(part, i) {
|
10
|
+
if (part.length === 1) {
|
11
|
+
outParts[i] = "0" + part;
|
12
|
+
}
|
13
|
+
});
|
14
|
+
return "#" + outParts.join("");
|
15
|
+
}
|
16
|
+
function completeHexColor(hexCode) {
|
17
|
+
let hex = hexCode.replace("#", "");
|
18
|
+
if (hex.length === 6) {
|
19
|
+
hex = `${hex}ff`;
|
20
|
+
}
|
21
|
+
if (hex.length === 3) {
|
22
|
+
hex = `${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}ff`;
|
23
|
+
}
|
24
|
+
return hex;
|
25
|
+
}
|
26
|
+
function hexToRgba(hexCode) {
|
27
|
+
const hex = completeHexColor(hexCode);
|
28
|
+
const r = parseInt(hex.substring(0, 2), 16);
|
29
|
+
const g = parseInt(hex.substring(2, 4), 16);
|
30
|
+
const b = parseInt(hex.substring(4, 6), 16);
|
31
|
+
const a = Math.round(
|
32
|
+
(parseInt(hex.substring(6, 8), 16) / 255 + Number.EPSILON) * 100
|
33
|
+
) / 100;
|
34
|
+
return { r, g, b, a };
|
35
|
+
}
|
36
|
+
var stringToHex = function(s) {
|
37
|
+
let rtn = "";
|
38
|
+
for (let i = 0; i < s.length; i++) {
|
39
|
+
rtn += s.charCodeAt(i).toString(16).padStart(4, "0");
|
40
|
+
}
|
41
|
+
return rtn;
|
42
|
+
};
|
43
|
+
var hexToString = function(h) {
|
44
|
+
const hx = h.match(/.{1,4}/g) || [];
|
45
|
+
let rtn = "";
|
46
|
+
for (let i = 0; i < hx.length; i++) {
|
47
|
+
const int = parseInt(hx[i], 16);
|
48
|
+
if (int === 0)
|
49
|
+
break;
|
50
|
+
rtn += String.fromCharCode(int);
|
51
|
+
}
|
52
|
+
return rtn;
|
53
|
+
};
|
54
|
+
var MIN_SAFE_INT64 = BigInt("-9223372036854775808");
|
55
|
+
var MAX_SAFE_INT64 = BigInt("9223372036854775807");
|
56
|
+
var ParameterProcessors = {
|
57
|
+
number: {
|
58
|
+
serialize: (input) => {
|
59
|
+
const view = new DataView(new ArrayBuffer(8));
|
60
|
+
view.setFloat64(0, input);
|
61
|
+
return view.getBigUint64(0).toString(16).padStart(16, "0");
|
62
|
+
},
|
63
|
+
deserialize: (input) => {
|
64
|
+
const view = new DataView(new ArrayBuffer(8));
|
65
|
+
for (let i = 0; i < 8; i++) {
|
66
|
+
view.setUint8(i, parseInt(input.substring(i * 2, i * 2 + 2), 16));
|
67
|
+
}
|
68
|
+
return view.getFloat64(0);
|
69
|
+
},
|
70
|
+
bytesLength: () => 8,
|
71
|
+
constrain: (value, definition) => {
|
72
|
+
let min = Number.MIN_SAFE_INTEGER;
|
73
|
+
if (typeof _optionalChain([definition, 'access', _ => _.options, 'optionalAccess', _2 => _2.min]) !== "undefined")
|
74
|
+
min = Number(definition.options.min);
|
75
|
+
let max = Number.MAX_SAFE_INTEGER;
|
76
|
+
if (typeof _optionalChain([definition, 'access', _3 => _3.options, 'optionalAccess', _4 => _4.max]) !== "undefined")
|
77
|
+
max = Number(definition.options.max);
|
78
|
+
max = Math.min(max, Number.MAX_SAFE_INTEGER);
|
79
|
+
min = Math.max(min, Number.MIN_SAFE_INTEGER);
|
80
|
+
const v = Math.min(Math.max(value, min), max);
|
81
|
+
if (_optionalChain([definition, 'optionalAccess', _5 => _5.options, 'optionalAccess', _6 => _6.step])) {
|
82
|
+
const t = 1 / _optionalChain([definition, 'optionalAccess', _7 => _7.options, 'optionalAccess', _8 => _8.step]);
|
83
|
+
return Math.round(v * t) / t;
|
84
|
+
}
|
85
|
+
return v;
|
86
|
+
},
|
87
|
+
random: (definition) => {
|
88
|
+
let min = Number.MIN_SAFE_INTEGER;
|
89
|
+
if (typeof _optionalChain([definition, 'access', _9 => _9.options, 'optionalAccess', _10 => _10.min]) !== "undefined")
|
90
|
+
min = Number(definition.options.min);
|
91
|
+
let max = Number.MAX_SAFE_INTEGER;
|
92
|
+
if (typeof _optionalChain([definition, 'access', _11 => _11.options, 'optionalAccess', _12 => _12.max]) !== "undefined")
|
93
|
+
max = Number(definition.options.max);
|
94
|
+
max = Math.min(max, Number.MAX_SAFE_INTEGER);
|
95
|
+
min = Math.max(min, Number.MIN_SAFE_INTEGER);
|
96
|
+
const v = Math.random() * (max - min) + min;
|
97
|
+
if (_optionalChain([definition, 'optionalAccess', _13 => _13.options, 'optionalAccess', _14 => _14.step])) {
|
98
|
+
const t = 1 / _optionalChain([definition, 'optionalAccess', _15 => _15.options, 'optionalAccess', _16 => _16.step]);
|
99
|
+
return Math.round(v * t) / t;
|
100
|
+
}
|
101
|
+
return v;
|
102
|
+
}
|
103
|
+
},
|
104
|
+
bigint: {
|
105
|
+
serialize: (input) => {
|
106
|
+
const view = new DataView(new ArrayBuffer(8));
|
107
|
+
view.setBigInt64(0, BigInt(input));
|
108
|
+
return view.getBigUint64(0).toString(16).padStart(16, "0");
|
109
|
+
},
|
110
|
+
deserialize: (input) => {
|
111
|
+
const view = new DataView(new ArrayBuffer(8));
|
112
|
+
for (let i = 0; i < 8; i++) {
|
113
|
+
view.setUint8(i, parseInt(input.substring(i * 2, i * 2 + 2), 16));
|
114
|
+
}
|
115
|
+
return view.getBigInt64(0);
|
116
|
+
},
|
117
|
+
bytesLength: () => 8,
|
118
|
+
random: (definition) => {
|
119
|
+
let min = MIN_SAFE_INT64;
|
120
|
+
let max = MAX_SAFE_INT64;
|
121
|
+
if (typeof _optionalChain([definition, 'access', _17 => _17.options, 'optionalAccess', _18 => _18.min]) !== "undefined")
|
122
|
+
min = BigInt(definition.options.min);
|
123
|
+
if (typeof _optionalChain([definition, 'access', _19 => _19.options, 'optionalAccess', _20 => _20.max]) !== "undefined")
|
124
|
+
max = BigInt(definition.options.max);
|
125
|
+
const range = max - min;
|
126
|
+
const bits = range.toString(2).length;
|
127
|
+
let random;
|
128
|
+
do {
|
129
|
+
random = BigInt(
|
130
|
+
"0b" + Array.from(
|
131
|
+
crypto.getRandomValues(new Uint8Array(Math.ceil(bits / 8)))
|
132
|
+
).map((b) => b.toString(2).padStart(8, "0")).join("")
|
133
|
+
);
|
134
|
+
} while (random > range);
|
135
|
+
return random + min;
|
136
|
+
}
|
137
|
+
},
|
138
|
+
boolean: {
|
139
|
+
serialize: (input) => {
|
140
|
+
return typeof input === "boolean" ? input ? "01" : "00" : typeof input === "string" ? input === "true" ? "01" : "00" : "00";
|
141
|
+
},
|
142
|
+
deserialize: (input) => {
|
143
|
+
return input === "00" ? false : true;
|
144
|
+
},
|
145
|
+
bytesLength: () => 1,
|
146
|
+
random: () => Math.random() < 0.5
|
147
|
+
},
|
148
|
+
color: {
|
149
|
+
serialize: (input) => {
|
150
|
+
return completeHexColor(input);
|
151
|
+
},
|
152
|
+
deserialize: (input) => {
|
153
|
+
return input;
|
154
|
+
},
|
155
|
+
bytesLength: () => 4,
|
156
|
+
transform: (input) => {
|
157
|
+
const color = completeHexColor(input);
|
158
|
+
const r = parseInt(color.slice(0, 2), 16);
|
159
|
+
const g = parseInt(color.slice(2, 4), 16);
|
160
|
+
const b = parseInt(color.slice(4, 6), 16);
|
161
|
+
const a = parseInt(color.slice(6, 8), 16);
|
162
|
+
return {
|
163
|
+
hex: {
|
164
|
+
rgb: "#" + input.slice(0, 6),
|
165
|
+
rgba: "#" + input
|
166
|
+
},
|
167
|
+
obj: {
|
168
|
+
rgb: { r, g, b },
|
169
|
+
rgba: { r, g, b, a }
|
170
|
+
},
|
171
|
+
arr: {
|
172
|
+
rgb: [r, g, b],
|
173
|
+
rgba: [r, g, b, a]
|
174
|
+
}
|
175
|
+
};
|
176
|
+
},
|
177
|
+
constrain: (value) => {
|
178
|
+
const hex = value.replace("#", "");
|
179
|
+
return hex.slice(0, 8).padEnd(8, "f");
|
180
|
+
},
|
181
|
+
random: () => `${[...Array(8)].map(() => Math.floor(Math.random() * 16).toString(16)).join("")}`
|
182
|
+
},
|
183
|
+
string: {
|
184
|
+
serialize: (input, def) => {
|
185
|
+
if (!def.version) {
|
186
|
+
let hex2 = stringToHex(input.substring(0, 64));
|
187
|
+
hex2 = hex2.padEnd(64 * 4, "0");
|
188
|
+
return hex2;
|
189
|
+
}
|
190
|
+
let max = 64;
|
191
|
+
if (typeof _optionalChain([def, 'access', _21 => _21.options, 'optionalAccess', _22 => _22.maxLength]) !== "undefined")
|
192
|
+
max = Number(def.options.maxLength);
|
193
|
+
let hex = stringToHex(input.substring(0, max));
|
194
|
+
hex = hex.padEnd(max * 4, "0");
|
195
|
+
return hex;
|
196
|
+
},
|
197
|
+
deserialize: (input) => {
|
198
|
+
return hexToString(input);
|
199
|
+
},
|
200
|
+
bytesLength: (def) => {
|
201
|
+
if (!def.version) {
|
202
|
+
return 64 * 2;
|
203
|
+
}
|
204
|
+
if (typeof _optionalChain([def, 'access', _23 => _23.options, 'optionalAccess', _24 => _24.maxLength]) !== "undefined")
|
205
|
+
return Number(def.options.maxLength) * 2;
|
206
|
+
return 64 * 2;
|
207
|
+
},
|
208
|
+
random: (definition) => {
|
209
|
+
let min = 0;
|
210
|
+
if (typeof _optionalChain([definition, 'access', _25 => _25.options, 'optionalAccess', _26 => _26.minLength]) !== "undefined")
|
211
|
+
min = definition.options.minLength;
|
212
|
+
let max = 64;
|
213
|
+
if (typeof _optionalChain([definition, 'access', _27 => _27.options, 'optionalAccess', _28 => _28.maxLength]) !== "undefined")
|
214
|
+
max = definition.options.maxLength;
|
215
|
+
const length = Math.round(Math.random() * (max - min) + min);
|
216
|
+
return [...Array(length)].map((i) => (~~(Math.random() * 36)).toString(36)).join("");
|
217
|
+
},
|
218
|
+
constrain: (value, definition) => {
|
219
|
+
let min = 0;
|
220
|
+
if (typeof _optionalChain([definition, 'access', _29 => _29.options, 'optionalAccess', _30 => _30.minLength]) !== "undefined")
|
221
|
+
min = definition.options.minLength;
|
222
|
+
let max = 64;
|
223
|
+
if (typeof _optionalChain([definition, 'access', _31 => _31.options, 'optionalAccess', _32 => _32.maxLength]) !== "undefined")
|
224
|
+
max = definition.options.maxLength;
|
225
|
+
const v = value.slice(0, max);
|
226
|
+
if (v.length < min) {
|
227
|
+
return v.padEnd(min);
|
228
|
+
}
|
229
|
+
return v;
|
230
|
+
}
|
231
|
+
},
|
232
|
+
bytes: {
|
233
|
+
serialize: (input, def) => {
|
234
|
+
return Array.from(input).map((i) => i.toString(16).padStart(2, "0")).join("");
|
235
|
+
},
|
236
|
+
deserialize: (input, def) => {
|
237
|
+
const len = input.length / 2;
|
238
|
+
const uint8 = new Uint8Array(len);
|
239
|
+
let idx;
|
240
|
+
for (let i = 0; i < len; i++) {
|
241
|
+
idx = i * 2;
|
242
|
+
uint8[i] = parseInt(`${input[idx]}${input[idx + 1]}`, 16);
|
243
|
+
}
|
244
|
+
return uint8;
|
245
|
+
},
|
246
|
+
bytesLength: (def) => def.options.length,
|
247
|
+
random: (def) => {
|
248
|
+
const len = _optionalChain([def, 'access', _33 => _33.options, 'optionalAccess', _34 => _34.length]) || 0;
|
249
|
+
const uint8 = new Uint8Array(len);
|
250
|
+
for (let i = 0; i < len; i++) {
|
251
|
+
uint8[i] = Math.random() * 255 | 0;
|
252
|
+
}
|
253
|
+
return uint8;
|
254
|
+
}
|
255
|
+
},
|
256
|
+
select: {
|
257
|
+
serialize: (input, def) => {
|
258
|
+
return Math.min(255, _optionalChain([def, 'access', _35 => _35.options, 'optionalAccess', _36 => _36.options, 'optionalAccess', _37 => _37.indexOf, 'call', _38 => _38(input)]) || 0).toString(16).padStart(2, "0");
|
259
|
+
},
|
260
|
+
deserialize: (input, def) => {
|
261
|
+
const idx = parseInt(input, 16);
|
262
|
+
return _optionalChain([def, 'access', _39 => _39.options, 'optionalAccess', _40 => _40.options, 'optionalAccess', _41 => _41[idx]]) || _optionalChain([def, 'access', _42 => _42.options, 'optionalAccess', _43 => _43.options, 'optionalAccess', _44 => _44[0]]) || "";
|
263
|
+
},
|
264
|
+
bytesLength: () => 1,
|
265
|
+
// index between 0 and 255
|
266
|
+
constrain: (value, definition) => {
|
267
|
+
if (definition.options.options.includes(value)) {
|
268
|
+
return value;
|
269
|
+
}
|
270
|
+
return definition.options.options[0];
|
271
|
+
},
|
272
|
+
random: (definition) => {
|
273
|
+
const index = Math.round(
|
274
|
+
Math.random() * (definition.options.options.length - 1) + 0
|
275
|
+
);
|
276
|
+
return _optionalChain([definition, 'optionalAccess', _45 => _45.options, 'optionalAccess', _46 => _46.options, 'access', _47 => _47[index]]);
|
277
|
+
}
|
278
|
+
}
|
279
|
+
};
|
280
|
+
function serializeParams(params, definition) {
|
281
|
+
let bytes = "";
|
282
|
+
if (!definition)
|
283
|
+
return bytes;
|
284
|
+
for (const def of definition) {
|
285
|
+
const { id, type } = def;
|
286
|
+
const processor = ParameterProcessors[type];
|
287
|
+
const v = params[id];
|
288
|
+
const val = typeof v !== "undefined" ? v : typeof def.default !== "undefined" ? def.default : processor.random(def);
|
289
|
+
const serialized = processor.serialize(val, def);
|
290
|
+
bytes += serialized;
|
291
|
+
}
|
292
|
+
return bytes;
|
293
|
+
}
|
294
|
+
function deserializeParams(bytes, definition, options) {
|
295
|
+
const params = {};
|
296
|
+
console.log(bytes, definition, options);
|
297
|
+
for (const def of definition) {
|
298
|
+
const processor = ParameterProcessors[def.type];
|
299
|
+
const transformer = options.withTransform && processor[options.transformType || "transform"];
|
300
|
+
if (!bytes) {
|
301
|
+
let v;
|
302
|
+
if (typeof def.default === "undefined")
|
303
|
+
v = processor.random(def);
|
304
|
+
else
|
305
|
+
v = def.default;
|
306
|
+
params[def.id] = transformer ? transformer(v, def) : v;
|
307
|
+
continue;
|
308
|
+
}
|
309
|
+
const bytesLen = processor.bytesLength(def);
|
310
|
+
const valueBytes = bytes.substring(0, bytesLen * 2);
|
311
|
+
bytes = bytes.substring(bytesLen * 2);
|
312
|
+
const val = processor.deserialize(valueBytes, def);
|
313
|
+
params[def.id] = transformer ? transformer(val, def) : val;
|
314
|
+
}
|
315
|
+
return params;
|
316
|
+
}
|
317
|
+
function consolidateParams(params, data) {
|
318
|
+
if (!params)
|
319
|
+
return [];
|
320
|
+
const rtn = [...params];
|
321
|
+
for (const p in rtn) {
|
322
|
+
const definition = rtn[p];
|
323
|
+
const { id, type, default: def } = definition;
|
324
|
+
if (data && data.hasOwnProperty(id)) {
|
325
|
+
rtn[p].value = data[id];
|
326
|
+
} else {
|
327
|
+
const processor = ParameterProcessors[type];
|
328
|
+
let v;
|
329
|
+
if (typeof def === "undefined")
|
330
|
+
v = processor.random(definition);
|
331
|
+
else
|
332
|
+
v = def;
|
333
|
+
rtn[p].value = _optionalChain([processor, 'access', _48 => _48.transform, 'optionalCall', _49 => _49(v)]) || v;
|
334
|
+
}
|
335
|
+
}
|
336
|
+
return rtn;
|
337
|
+
}
|
338
|
+
function getRandomParamValues(params, options) {
|
339
|
+
return params.reduce((acc, definition) => {
|
340
|
+
const processor = ParameterProcessors[definition.type];
|
341
|
+
const v = processor.random(definition);
|
342
|
+
acc[definition.id] = _optionalChain([options, 'optionalAccess', _50 => _50.noTransform]) ? v : _optionalChain([processor, 'access', _51 => _51.transform, 'optionalCall', _52 => _52(v)]) || v;
|
343
|
+
return acc;
|
344
|
+
}, {});
|
345
|
+
}
|
346
|
+
function sumBytesParams(definitions) {
|
347
|
+
return _optionalChain([definitions, 'optionalAccess', _53 => _53.reduce, 'call', _54 => _54(
|
348
|
+
(acc, def) => acc + ParameterProcessors[def.type].bytesLength(def),
|
349
|
+
0
|
350
|
+
)]) || 0;
|
351
|
+
}
|
352
|
+
function stringifyParamsData(data) {
|
353
|
+
return JSON.stringify(data, (key, value) => {
|
354
|
+
if (typeof value === "bigint")
|
355
|
+
return value.toString();
|
356
|
+
return value;
|
357
|
+
});
|
358
|
+
}
|
359
|
+
function jsonStringifyBigint(data) {
|
360
|
+
return JSON.stringify(data, (key, value) => {
|
361
|
+
if (typeof value === "bigint")
|
362
|
+
return value.toString();
|
363
|
+
return value;
|
364
|
+
});
|
365
|
+
}
|
366
|
+
var processParam = (paramId, value, definitions, transformType) => {
|
367
|
+
const definition = definitions.find((d) => d.id === paramId);
|
368
|
+
const processor = ParameterProcessors[definition.type];
|
369
|
+
const transformer = processor[transformType];
|
370
|
+
return _optionalChain([transformer, 'optionalCall', _55 => _55(value, definition)]) || value;
|
371
|
+
};
|
372
|
+
var processParams = (values, definitions, transformType) => {
|
373
|
+
const paramValues = {};
|
374
|
+
for (const definition of definitions) {
|
375
|
+
const processor = ParameterProcessors[definition.type];
|
376
|
+
const value = values[definition.id];
|
377
|
+
const transformer = processor[transformType];
|
378
|
+
paramValues[definition.id] = _optionalChain([transformer, 'optionalCall', _56 => _56(value, definition)]) || value;
|
379
|
+
}
|
380
|
+
return paramValues;
|
381
|
+
};
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
exports.rgbaToHex = rgbaToHex; exports.hexToRgba = hexToRgba; exports.MIN_SAFE_INT64 = MIN_SAFE_INT64; exports.MAX_SAFE_INT64 = MAX_SAFE_INT64; exports.ParameterProcessors = ParameterProcessors; exports.serializeParams = serializeParams; exports.deserializeParams = deserializeParams; exports.consolidateParams = consolidateParams; exports.getRandomParamValues = getRandomParamValues; exports.sumBytesParams = sumBytesParams; exports.stringifyParamsData = stringifyParamsData; exports.jsonStringifyBigint = jsonStringifyBigint; exports.processParam = processParam; exports.processParams = processParams;
|
399
|
+
//# sourceMappingURL=chunk-2QU65L2O.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"names":["hex"],"mappings":";AAcO,SAAS,UAAU,GAAW,GAAW,GAAW,GAAmB;AAC5E,QAAM,WAAW;AAAA,IACf,EAAE,SAAS,EAAE;AAAA,IACb,EAAE,SAAS,EAAE;AAAA,IACb,EAAE,SAAS,EAAE;AAAA,IACb,KAAK,MAAM,IAAI,GAAG,EACf,SAAS,EAAE,EACX,UAAU,GAAG,CAAC;AAAA,EACnB;AAGA,WAAS,QAAQ,SAAU,MAAM,GAAG;AAClC,QAAI,KAAK,WAAW,GAAG;AACrB,eAAS,CAAC,IAAI,MAAM;AAAA,IACtB;AAAA,EACF,CAAC;AAED,SAAO,MAAM,S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AAY,WAAW,EAAE,IAAI,cAAc,OAAO,UAAU,KAAK;AAAA,EAEnE;AACA,SAAO;AACT","sourcesContent":["import {\n hexString,\n FxParamDefinition,\n FxParamProcessor,\n FxParamProcessors,\n FxParamTypeMap,\n FxParamType,\n FxParamsData,\n FxParamValue,\n FxParamTranformType,\n FxParamTransformationTypeMap,\n FxParamProcessorTransformer,\n} from \"./types\"\n\nexport function rgbaToHex(r: number, g: number, b: number, a: number): string {\n const outParts = [\n r.toString(16),\n g.toString(16),\n b.toString(16),\n Math.round(a * 255)\n .toString(16)\n .substring(0, 2),\n ]\n\n // Pad single-digit output values\n outParts.forEach(function (part, i) {\n if (part.length === 1) {\n outParts[i] = \"0\" + part\n }\n })\n\n return \"#\" + outParts.join(\"\")\n}\n\nfunction completeHexColor(hexCode: hexString | string): string {\n let hex = hexCode.replace(\"#\", \"\")\n if (hex.length === 6) {\n hex = `${hex}ff`\n }\n if (hex.length === 3) {\n hex = `${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}ff`\n }\n return hex\n}\n\nexport function hexToRgba(hexCode: hexString) {\n const hex = completeHexColor(hexCode)\n\n const r = parseInt(hex.substring(0, 2), 16)\n const g = parseInt(hex.substring(2, 4), 16)\n const b = parseInt(hex.substring(4, 6), 16)\n const a =\n Math.round(\n (parseInt(hex.substring(6, 8), 16) / 255 + Number.EPSILON) * 100\n ) / 100\n\n return { r, g, b, a }\n}\n\nconst stringToHex = function (s: string) {\n let rtn = \"\"\n for (let i = 0; i < s.length; i++) {\n rtn += s.charCodeAt(i).toString(16).padStart(4, \"0\")\n }\n return rtn\n}\nconst hexToString = function (h: string) {\n const hx = h.match(/.{1,4}/g) || []\n let rtn = \"\"\n for (let i = 0; i < hx.length; i++) {\n const int = parseInt(hx[i], 16)\n if (int === 0) break\n rtn += String.fromCharCode(int)\n }\n return rtn\n}\n\nexport const MIN_SAFE_INT64 = BigInt(\"-9223372036854775808\")\nexport const MAX_SAFE_INT64 = BigInt(\"9223372036854775807\")\n\nexport const ParameterProcessors: FxParamProcessors = {\n number: {\n serialize: input => {\n const view = new DataView(new ArrayBuffer(8))\n view.setFloat64(0, input)\n return view.getBigUint64(0).toString(16).padStart(16, \"0\")\n },\n deserialize: input => {\n const view = new DataView(new ArrayBuffer(8))\n for (let i = 0; i < 8; i++) {\n view.setUint8(i, parseInt(input.substring(i * 2, i * 2 + 2), 16))\n }\n return view.getFloat64(0)\n },\n bytesLength: () => 8,\n constrain: (value, definition) => {\n let min = Number.MIN_SAFE_INTEGER\n if (typeof definition.options?.min !== \"undefined\")\n min = Number(definition.options.min)\n let max = Number.MAX_SAFE_INTEGER\n if (typeof definition.options?.max !== \"undefined\")\n max = Number(definition.options.max)\n max = Math.min(max, Number.MAX_SAFE_INTEGER)\n min = Math.max(min, Number.MIN_SAFE_INTEGER)\n const v = Math.min(Math.max(value, min), max)\n if (definition?.options?.step) {\n const t = 1.0 / definition?.options?.step\n return Math.round(v * t) / t\n }\n return v\n },\n random: definition => {\n let min = Number.MIN_SAFE_INTEGER\n if (typeof definition.options?.min !== \"undefined\")\n min = Number(definition.options.min)\n let max = Number.MAX_SAFE_INTEGER\n if (typeof definition.options?.max !== \"undefined\")\n max = Number(definition.options.max)\n max = Math.min(max, Number.MAX_SAFE_INTEGER)\n min = Math.max(min, Number.MIN_SAFE_INTEGER)\n const v = Math.random() * (max - min) + min\n if (definition?.options?.step) {\n const t = 1.0 / definition?.options?.step\n return Math.round(v * t) / t\n }\n return v\n },\n },\n bigint: {\n serialize: (input: any) => {\n const view = new DataView(new ArrayBuffer(8))\n view.setBigInt64(0, BigInt(input))\n return view.getBigUint64(0).toString(16).padStart(16, \"0\")\n },\n deserialize: (input: any) => {\n const view = new DataView(new ArrayBuffer(8))\n for (let i = 0; i < 8; i++) {\n view.setUint8(i, parseInt(input.substring(i * 2, i * 2 + 2), 16))\n }\n return view.getBigInt64(0)\n },\n bytesLength: () => 8,\n random: (definition) => {\n let min = MIN_SAFE_INT64\n let max = MAX_SAFE_INT64\n if (typeof definition.options?.min !== \"undefined\")\n min = BigInt(definition.options.min)\n if (typeof definition.options?.max !== \"undefined\")\n max = BigInt(definition.options.max)\n const range = max - min\n const bits = range.toString(2).length\n let random\n do {\n random = BigInt(\n \"0b\" +\n Array.from(\n crypto.getRandomValues(new Uint8Array(Math.ceil(bits / 8)))\n )\n .map((b) => b.toString(2).padStart(8, \"0\"))\n .join(\"\")\n )\n } while (random > range)\n return random + min\n },\n },\n boolean: {\n serialize: (input) => {\n return typeof input === \"boolean\"\n ? input\n ? \"01\"\n : \"00\"\n : typeof input === \"string\"\n ? input === \"true\"\n ? \"01\"\n : \"00\"\n : \"00\"\n },\n deserialize: (input) => {\n return input === \"00\" ? false : true\n },\n bytesLength: () => 1,\n random: () => Math.random() < 0.5,\n },\n\n color: {\n serialize: (input: string) => {\n return completeHexColor(input)\n },\n\n deserialize: (input): hexString => {\n return input as hexString\n },\n bytesLength: () => 4,\n transform: (input: string) => {\n const color = completeHexColor(input)\n const r = parseInt(color.slice(0, 2), 16)\n const g = parseInt(color.slice(2, 4), 16)\n const b = parseInt(color.slice(4, 6), 16)\n const a = parseInt(color.slice(6, 8), 16)\n return {\n hex: {\n rgb: \"#\" + input.slice(0, 6),\n rgba: \"#\" + input,\n },\n obj: {\n rgb: { r, g, b },\n rgba: { r, g, b, a },\n },\n arr: {\n rgb: [r, g, b],\n rgba: [r, g, b, a],\n },\n }\n },\n constrain: (value) => {\n const hex = value.replace(\"#\", \"\")\n return hex.slice(0, 8).padEnd(8, \"f\")\n },\n random: () =>\n `${[...Array(8)]\n .map(() => Math.floor(Math.random() * 16).toString(16))\n .join(\"\")}`,\n },\n\n string: {\n serialize: (input, def) => {\n if (!def.version) {\n let hex = stringToHex(input.substring(0, 64))\n hex = hex.padEnd(64 * 4, \"0\")\n return hex\n }\n let max = 64\n if (typeof def.options?.maxLength !== \"undefined\")\n max = Number(def.options.maxLength)\n let hex = stringToHex(input.substring(0, max))\n hex = hex.padEnd(max * 4, \"0\")\n return hex\n },\n deserialize: (input) => {\n return hexToString(input)\n },\n\n bytesLength: (def) => {\n if (!def.version) {\n return 64 * 2\n }\n if (typeof def.options?.maxLength !== \"undefined\")\n return Number(def.options.maxLength) * 2\n return 64 * 2\n },\n random: (definition) => {\n let min = 0\n if (typeof definition.options?.minLength !== \"undefined\")\n min = definition.options.minLength\n let max = 64\n if (typeof definition.options?.maxLength !== \"undefined\")\n max = definition.options.maxLength\n const length = Math.round(Math.random() * (max - min) + min)\n return [...Array(length)]\n .map((i) => (~~(Math.random() * 36)).toString(36))\n .join(\"\")\n },\n constrain: (value, definition) => {\n let min = 0\n if (typeof definition.options?.minLength !== \"undefined\")\n min = definition.options.minLength\n let max = 64\n if (typeof definition.options?.maxLength !== \"undefined\")\n max = definition.options.maxLength\n const v = value.slice(0, max)\n if (v.length < min) {\n return v.padEnd(min)\n }\n return v\n },\n },\n\n bytes: {\n serialize: (input, def) => {\n return Array.from(input)\n .map((i) => i.toString(16).padStart(2, \"0\"))\n .join(\"\")\n },\n deserialize: (input, def) => {\n const len = input.length / 2\n const uint8 = new Uint8Array(len)\n let idx\n for (let i = 0; i < len; i++) {\n idx = i * 2\n uint8[i] = parseInt(`${input[idx]}${input[idx + 1]}`, 16)\n }\n return uint8\n },\n bytesLength: (def) => def.options.length,\n random: (def) => {\n const len = def.options?.length || 0\n const uint8 = new Uint8Array(len)\n for (let i = 0; i < len; i++) {\n uint8[i] = (Math.random() * 255) | 0\n }\n return uint8\n },\n },\n\n select: {\n serialize: (input, def) => {\n // find the index of the input in the array of options\n return Math.min(255, def.options?.options?.indexOf(input) || 0)\n .toString(16)\n .padStart(2, \"0\")\n },\n\n deserialize: (input, def) => {\n // get the index, which is the input\n const idx = parseInt(input, 16)\n return def.options?.options?.[idx] || def.options?.options?.[0] || \"\"\n },\n\n bytesLength: () => 1, // index between 0 and 255\n constrain: (value, definition) => {\n if (definition.options.options.includes(value)) {\n return value\n }\n return definition.options.options[0]\n },\n random: (definition) => {\n const index = Math.round(\n Math.random() * (definition.options.options.length - 1) + 0\n )\n return definition?.options?.options[index]\n },\n },\n}\n\n// params are injected into the piece using the binary representation of the\n// numbers, to keep precision\nexport function serializeParams(\n params: any,\n definition: FxParamDefinition<any>[]\n) {\n // a single hex string will be used for all the params\n let bytes = \"\"\n if (!definition) return bytes\n // loop through each parameter from the definition to find the associated\n // parameter as set on the UI\n for (const def of definition) {\n const { id, type } = def\n const processor = ParameterProcessors[\n type as FxParamType\n ] as FxParamProcessor<any>\n // if the param is definined in the object\n\n const v = params[id] as FxParamTypeMap[]\n const val =\n typeof v !== \"undefined\"\n ? v\n : typeof def.default !== \"undefined\"\n ? def.default\n : processor.random(def)\n const serialized = processor.serialize(val, def)\n bytes += serialized\n }\n\n return bytes\n}\n\n// takes an array of bytes, in hexadecimal format, and a parametric space\n// definition and outputs an array of parameters, mapping the definition and\n// validating input based on the definition constraints\nexport function deserializeParams(\n bytes: string,\n definition: FxParamDefinition<FxParamType>[],\n options: { withTransform?: boolean, transformType?: FxParamTranformType }\n) {\n const params: Record<string, FxParamValue<FxParamType> | FxParamTransformationTypeMap[FxParamType]> = {}\n console.log(bytes, definition, options)\n for (const def of definition) {\n const processor = ParameterProcessors[\n def.type as FxParamType\n ] as FxParamProcessor<FxParamType>\n const transformer = options.withTransform && processor[options.transformType || \"transform\"] as FxParamProcessorTransformer<FxParamType>\n if (!bytes) {\n let v\n if (typeof def.default === \"undefined\") v = processor.random(def)\n else v = def.default\n params[def.id] = transformer ? transformer(v, def) : v\n continue\n }\n // extract the length from the bytes & shift the initial bytes string\n const bytesLen = processor.bytesLength(def)\n const valueBytes = bytes.substring(0, bytesLen * 2)\n bytes = bytes.substring(bytesLen * 2)\n // deserialize the bytes into the params\n const val = processor.deserialize(valueBytes, def) as FxParamValue<FxParamType>\n params[def.id] = transformer ? transformer(val, def) : val\n }\n return params\n}\n\n\n// Consolidates parameters from both a params object provided by the token\n// and the dat object of params, which is stored by the controls component.\nexport function consolidateParams(params: any, data: any) {\n if (!params) return []\n\n const rtn = [...params]\n\n for (const p in rtn) {\n const definition = rtn[p]\n const { id, type, default: def } = definition\n if (data && data.hasOwnProperty(id)) {\n rtn[p].value = data[id]\n } else {\n const processor = ParameterProcessors[\n type as FxParamType\n ] as FxParamProcessor<any>\n let v\n if (typeof def === \"undefined\") v = processor.random(definition)\n else v = def\n rtn[p].value = processor.transform?.(v) || v\n }\n }\n\n return rtn\n}\n\nexport function getRandomParamValues(\n params: FxParamDefinition<FxParamType>[],\n options?: { noTransform: boolean }\n): any {\n return params.reduce((acc, definition) => {\n const processor = ParameterProcessors[\n definition.type as FxParamType\n ] as FxParamProcessor<FxParamType>\n const v = processor.random(definition) as FxParamType\n acc[definition.id] = options?.noTransform\n ? v\n : processor.transform?.(v) || v\n return acc\n }, {} as Record<string, any>)\n}\n\nexport function sumBytesParams(\n definitions: FxParamDefinition<FxParamType>[]\n): number {\n return (\n definitions?.reduce(\n (acc, def) =>\n acc +\n (\n ParameterProcessors[\n def.type as FxParamType\n ] as FxParamProcessor<FxParamType>\n ).bytesLength(def),\n 0\n ) || 0\n )\n}\n\nexport function stringifyParamsData(data: FxParamsData) {\n return JSON.stringify(data, (key, value) => {\n if (typeof value === \"bigint\") return value.toString()\n return value\n })\n}\n\nexport function jsonStringifyBigint(data: any): string {\n return JSON.stringify(data, (key, value) => {\n if (typeof value === \"bigint\") return value.toString()\n return value\n })\n}\n\n\nexport const processParam = (paramId: string, value: FxParamValue<FxParamType>, definitions: FxParamDefinition<FxParamType>[], transformType: FxParamTranformType): FxParamValue<FxParamType> | FxParamTransformationTypeMap[FxParamType] => {\n const definition = definitions.find(d => d.id === paramId)\n const processor = ParameterProcessors[definition.type]\n const transformer = (processor[transformType] as FxParamProcessorTransformer<FxParamType>)\n return transformer?.(value, definition) || value\n }\n\nexport const processParams = (values: FxParamsData, definitions: FxParamDefinition<FxParamType>[], transformType: FxParamTranformType) => {\n const paramValues = {}\n for (const definition of definitions) {\n const processor = ParameterProcessors[definition.type]\n const value = values[definition.id]\n // deserialize the bytes into the params\n const transformer = (processor[transformType] as FxParamProcessorTransformer<FxParamType>)\n paramValues[definition.id] = transformer?.(value, definition) || value\n\n }\n return paramValues\n }\n\n"]}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
import {
|
2
|
+
NumberController
|
3
|
+
} from "./chunk-H5IMTNFG.js";
|
4
|
+
import {
|
5
|
+
SelectController
|
6
|
+
} from "./chunk-6VMIOQSE.js";
|
7
|
+
import {
|
8
|
+
StringController
|
9
|
+
} from "./chunk-YYEIYDDF.js";
|
10
|
+
import {
|
11
|
+
validateParameterDefinition
|
12
|
+
} from "./chunk-MWP7SJWC.js";
|
13
|
+
import {
|
14
|
+
BigIntController
|
15
|
+
} from "./chunk-ZUITF5XX.js";
|
16
|
+
import {
|
17
|
+
BooleanController
|
18
|
+
} from "./chunk-YOS2HCIS.js";
|
19
|
+
import {
|
20
|
+
BytesController
|
21
|
+
} from "./chunk-2QIAF3U7.js";
|
22
|
+
import {
|
23
|
+
ColorController
|
24
|
+
} from "./chunk-7NOMBXLG.js";
|
25
|
+
import {
|
26
|
+
ControllerInvalid
|
27
|
+
} from "./chunk-PTXBICTZ.js";
|
28
|
+
|
29
|
+
// src/Controller/Param.tsx
|
30
|
+
import { useMemo } from "react";
|
31
|
+
import { jsx } from "react/jsx-runtime";
|
32
|
+
var controllerDefinitions = {
|
33
|
+
number: {
|
34
|
+
type: "number",
|
35
|
+
controller: NumberController,
|
36
|
+
handler: (e) => Number(e.target.value)
|
37
|
+
},
|
38
|
+
bigint: {
|
39
|
+
type: "bigint",
|
40
|
+
controller: BigIntController,
|
41
|
+
handler: (e) => BigInt(e.target.value)
|
42
|
+
},
|
43
|
+
string: {
|
44
|
+
type: "string",
|
45
|
+
controller: StringController,
|
46
|
+
handler: (e) => e.target.value
|
47
|
+
},
|
48
|
+
bytes: {
|
49
|
+
type: "bytes",
|
50
|
+
controller: BytesController,
|
51
|
+
handler: (e) => e.target.value
|
52
|
+
},
|
53
|
+
boolean: {
|
54
|
+
type: "boolean",
|
55
|
+
controller: BooleanController,
|
56
|
+
handler: (e) => e.target.checked
|
57
|
+
},
|
58
|
+
color: {
|
59
|
+
type: "color",
|
60
|
+
controller: ColorController,
|
61
|
+
handler: (v) => v
|
62
|
+
},
|
63
|
+
select: {
|
64
|
+
type: "select",
|
65
|
+
controller: SelectController,
|
66
|
+
handler: (e) => e.target.value
|
67
|
+
}
|
68
|
+
};
|
69
|
+
function ParameterController(props) {
|
70
|
+
const { parameter, onChange, parsed } = props;
|
71
|
+
const parsedDefinition = useMemo(
|
72
|
+
() => parsed || validateParameterDefinition(parameter),
|
73
|
+
[parameter, parsed]
|
74
|
+
);
|
75
|
+
const { controller: Controller, handler } = useMemo(
|
76
|
+
() => controllerDefinitions[parameter.type],
|
77
|
+
[parameter.type]
|
78
|
+
);
|
79
|
+
const handleChangeParam = (e) => {
|
80
|
+
const value = handler(e);
|
81
|
+
onChange(parameter.id, value);
|
82
|
+
};
|
83
|
+
if (parsedDefinition && parsedDefinition.success === false) {
|
84
|
+
return /* @__PURE__ */ jsx(
|
85
|
+
ControllerInvalid,
|
86
|
+
{
|
87
|
+
definition: parameter,
|
88
|
+
error: parsedDefinition.error
|
89
|
+
}
|
90
|
+
);
|
91
|
+
}
|
92
|
+
const isCodeDriven = parameter.update === "code-driven";
|
93
|
+
return /* @__PURE__ */ jsx(
|
94
|
+
Controller,
|
95
|
+
{
|
96
|
+
id: parameter.id,
|
97
|
+
label: parameter.name,
|
98
|
+
value: props.value,
|
99
|
+
onChange: handleChangeParam,
|
100
|
+
options: parameter.options,
|
101
|
+
isCodeDriven
|
102
|
+
}
|
103
|
+
);
|
104
|
+
}
|
105
|
+
|
106
|
+
export {
|
107
|
+
controllerDefinitions,
|
108
|
+
ParameterController
|
109
|
+
};
|
110
|
+
//# sourceMappingURL=chunk-4FX3ATAX.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/Controller/Param.tsx"],"sourcesContent":["import { useMemo, ReactElement } from \"react\"\nimport { FxParamDefinition, FxParamType } from \"../types\"\nimport { FxParamInputChangeHandler, FxParamControllerProps } from \"./Controller\"\nimport { BooleanController } from \"./Boolean\"\nimport { ColorController } from \"./Color\"\nimport { NumberController } from \"./Number\"\nimport { BigIntController } from \"./BigInt\"\nimport { SelectController } from \"./Select\"\nimport { StringController } from \"./String\"\nimport {\n validateParameterDefinition,\n ControllerDefinitionSchemaType,\n} from \"../validation\"\nimport { SafeParseError, SafeParseSuccess, z } from \"zod\"\nimport { ControllerInvalid } from \"./Invalid\"\nimport { BytesController } from \"./Bytes\"\n\ninterface FxParamControllerDefiniton<Type extends FxParamType> {\n type: Type\n controller: (props: FxParamControllerProps<Type>) => ReactElement\n handler: FxParamInputChangeHandler\n}\n\nexport type FxParamControllerDefinitions = {\n [T in FxParamType]: FxParamControllerDefiniton<T>\n}\n\nexport const controllerDefinitions: FxParamControllerDefinitions = {\n number: {\n type: \"number\",\n controller: NumberController,\n handler: (e) => Number(e.target.value),\n },\n bigint: {\n type: \"bigint\",\n controller: BigIntController,\n handler: (e) => BigInt(e.target.value),\n },\n string: {\n type: \"string\",\n controller: StringController,\n handler: (e) => e.target.value,\n },\n bytes: {\n type: \"bytes\",\n controller: BytesController,\n handler: (e) => e.target.value,\n },\n boolean: {\n type: \"boolean\",\n controller: BooleanController,\n handler: (e) => (e as React.ChangeEvent<HTMLInputElement>).target.checked,\n },\n color: {\n type: \"color\",\n controller: ColorController,\n handler: (v) => v,\n },\n select: {\n type: \"select\",\n controller: SelectController,\n handler: (e) => e.target.value,\n },\n}\n\nexport interface ParameterControllerProps {\n parameter: FxParamDefinition<FxParamType>\n value: any\n onChange: (id: string, value: any) => void\n parsed?:\n | SafeParseError<ControllerDefinitionSchemaType>\n | SafeParseSuccess<ControllerDefinitionSchemaType>\n}\n\nexport function ParameterController(props: ParameterControllerProps) {\n const { parameter, onChange, parsed } = props\n\n const parsedDefinition = useMemo(\n () => parsed || validateParameterDefinition(parameter),\n [parameter, parsed]\n )\n const { controller: Controller, handler } = useMemo(\n () => controllerDefinitions[parameter.type],\n [parameter.type]\n )\n\n const handleChangeParam = (e: any) => {\n const value = handler(e)\n onChange(parameter.id, value)\n }\n\n if (parsedDefinition && parsedDefinition.success === false) {\n return (\n <ControllerInvalid\n definition={parameter}\n error={parsedDefinition.error}\n />\n )\n }\n\n const isCodeDriven = parameter.update === \"code-driven\"\n\n return (\n <Controller\n id={parameter.id}\n label={parameter.name}\n value={props.value}\n onChange={handleChangeParam}\n // TODO: This should be properly casted\n options={parameter.options as any}\n isCodeDriven={isCodeDriven}\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,eAA6B;AA6FhC;AAlEC,IAAM,wBAAsD;AAAA,EACjE,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,SAAS,CAAC,MAAM,OAAO,EAAE,OAAO,KAAK;AAAA,EACvC;AAAA,EACA,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,SAAS,CAAC,MAAM,OAAO,EAAE,OAAO,KAAK;AAAA,EACvC;AAAA,EACA,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,SAAS,CAAC,MAAM,EAAE,OAAO;AAAA,EAC3B;AAAA,EACA,OAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,SAAS,CAAC,MAAM,EAAE,OAAO;AAAA,EAC3B;AAAA,EACA,SAAS;AAAA,IACP,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,SAAS,CAAC,MAAO,EAA0C,OAAO;AAAA,EACpE;AAAA,EACA,OAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,SAAS,CAAC,MAAM;AAAA,EAClB;AAAA,EACA,QAAQ;AAAA,IACN,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,SAAS,CAAC,MAAM,EAAE,OAAO;AAAA,EAC3B;AACF;AAWO,SAAS,oBAAoB,OAAiC;AACnE,QAAM,EAAE,WAAW,UAAU,OAAO,IAAI;AAExC,QAAM,mBAAmB;AAAA,IACvB,MAAM,UAAU,4BAA4B,SAAS;AAAA,IACrD,CAAC,WAAW,MAAM;AAAA,EACpB;AACA,QAAM,EAAE,YAAY,YAAY,QAAQ,IAAI;AAAA,IAC1C,MAAM,sBAAsB,UAAU,IAAI;AAAA,IAC1C,CAAC,UAAU,IAAI;AAAA,EACjB;AAEA,QAAM,oBAAoB,CAAC,MAAW;AACpC,UAAM,QAAQ,QAAQ,CAAC;AACvB,aAAS,UAAU,IAAI,KAAK;AAAA,EAC9B;AAEA,MAAI,oBAAoB,iBAAiB,YAAY,OAAO;AAC1D,WACE;AAAA,MAAC;AAAA;AAAA,QACC,YAAY;AAAA,QACZ,OAAO,iBAAiB;AAAA;AAAA,IAC1B;AAAA,EAEJ;AAEA,QAAM,eAAe,UAAU,WAAW;AAE1C,SACE;AAAA,IAAC;AAAA;AAAA,MACC,IAAI,UAAU;AAAA,MACd,OAAO,UAAU;AAAA,MACjB,OAAO,MAAM;AAAA,MACb,UAAU;AAAA,MAEV,SAAS,UAAU;AAAA,MACnB;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import {
|
2
|
+
IconButton
|
3
|
+
} from "./chunk-2BHABOFI.js";
|
4
|
+
|
5
|
+
// src/LockButton/LockButton.tsx
|
6
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
7
|
+
|
8
|
+
// src/LockButton/LockButton.module.scss
|
9
|
+
var LockButton_module_default = {
|
10
|
+
"lockButton": "_lockButton_1bbiz_1"
|
11
|
+
};
|
12
|
+
|
13
|
+
// src/LockButton/LockButton.tsx
|
14
|
+
import { faLock, faLockOpen } from "@fortawesome/free-solid-svg-icons";
|
15
|
+
import cx from "classnames";
|
16
|
+
import { jsx } from "react/jsx-runtime";
|
17
|
+
function LockButton(props) {
|
18
|
+
const { isLocked, className, ...rest } = props;
|
19
|
+
return /* @__PURE__ */ jsx(
|
20
|
+
IconButton,
|
21
|
+
{
|
22
|
+
color: "secondary",
|
23
|
+
className: cx(
|
24
|
+
LockButton_module_default.lockButton,
|
25
|
+
{ [LockButton_module_default.isOpen]: !isLocked },
|
26
|
+
className
|
27
|
+
),
|
28
|
+
...rest,
|
29
|
+
children: /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: isLocked ? faLock : faLockOpen })
|
30
|
+
}
|
31
|
+
);
|
32
|
+
}
|
33
|
+
|
34
|
+
export {
|
35
|
+
LockButton
|
36
|
+
};
|
37
|
+
//# sourceMappingURL=chunk-4OV7OX5A.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/LockButton/LockButton.tsx","../src/LockButton/LockButton.module.scss"],"sourcesContent":["import { FontAwesomeIcon } from \"@fortawesome/react-fontawesome\"\nimport { BaseButtonProps, IconButton } from \"../BaseInput\"\nimport classes from \"./LockButton.module.scss\"\nimport { faLock, faLockOpen } from \"@fortawesome/free-solid-svg-icons\"\nimport cx from \"classnames\"\ninterface LockButtonProps extends BaseButtonProps {\n isLocked?: boolean\n className?: string\n}\n\nexport function LockButton(props: LockButtonProps) {\n const { isLocked, className, ...rest } = props\n return (\n <IconButton\n color=\"secondary\"\n className={cx(\n classes.lockButton,\n { [classes.isOpen]: !isLocked },\n className\n )}\n {...rest}\n >\n <FontAwesomeIcon icon={isLocked ? faLock : faLockOpen} />\n </IconButton>\n )\n}\n","import 'css-chunk:src/LockButton/LockButton.module.scss';export default {\n \"lockButton\": \"_lockButton_1bbiz_1\"\n};"],"mappings":";;;;;AAAA,SAAS,uBAAuB;;;ACAyB,IAAO,4BAAQ;AAAA,EACtE,cAAc;AAChB;;;ADCA,SAAS,QAAQ,kBAAkB;AACnC,OAAO,QAAQ;AAkBT;AAZC,SAAS,WAAW,OAAwB;AACjD,QAAM,EAAE,UAAU,WAAW,GAAG,KAAK,IAAI;AACzC,SACE;AAAA,IAAC;AAAA;AAAA,MACC,OAAM;AAAA,MACN,WAAW;AAAA,QACT,0BAAQ;AAAA,QACR,EAAE,CAAC,0BAAQ,MAAM,GAAG,CAAC,SAAS;AAAA,QAC9B;AAAA,MACF;AAAA,MACC,GAAG;AAAA,MAEJ,8BAAC,mBAAgB,MAAM,WAAW,SAAS,YAAY;AAAA;AAAA,EACzD;AAEJ;","names":[]}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import {
|
2
|
+
Controller
|
3
|
+
} from "./chunk-CE3TPOSO.js";
|
4
|
+
import {
|
5
|
+
BaseSelect
|
6
|
+
} from "./chunk-2BHABOFI.js";
|
7
|
+
|
8
|
+
// src/Controller/Select.tsx
|
9
|
+
import { jsx } from "react/jsx-runtime";
|
10
|
+
function SelectController({
|
11
|
+
id,
|
12
|
+
label,
|
13
|
+
value,
|
14
|
+
onChange,
|
15
|
+
options,
|
16
|
+
isCodeDriven
|
17
|
+
}) {
|
18
|
+
return /* @__PURE__ */ jsx(Controller, { id, label, isCodeDriven, children: /* @__PURE__ */ jsx(
|
19
|
+
BaseSelect,
|
20
|
+
{
|
21
|
+
name: id,
|
22
|
+
id,
|
23
|
+
onChange,
|
24
|
+
value,
|
25
|
+
disabled: isCodeDriven,
|
26
|
+
children: options?.options.map((o) => /* @__PURE__ */ jsx("option", { value: o, children: o }, o))
|
27
|
+
}
|
28
|
+
) });
|
29
|
+
}
|
30
|
+
|
31
|
+
export {
|
32
|
+
SelectController
|
33
|
+
};
|
34
|
+
//# sourceMappingURL=chunk-6VMIOQSE.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/Controller/Select.tsx"],"sourcesContent":["import { Controller, FxParamControllerProps } from \"./Controller\"\nimport { BaseSelect } from \"../BaseInput\"\n\nexport function SelectController({\n id,\n label,\n value,\n onChange,\n options,\n isCodeDriven,\n}: FxParamControllerProps<\"select\">) {\n return (\n <Controller id={id} label={label} isCodeDriven={isCodeDriven}>\n <BaseSelect\n name={id}\n id={id}\n onChange={onChange}\n value={value}\n disabled={isCodeDriven}\n >\n {options?.options.map((o) => (\n <option key={o} value={o}>\n {o}\n </option>\n ))}\n </BaseSelect>\n </Controller>\n )\n}\n"],"mappings":";;;;;;;;AAqBU;AAlBH,SAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAqC;AACnC,SACE,oBAAC,cAAW,IAAQ,OAAc,cAChC;AAAA,IAAC;AAAA;AAAA,MACC,MAAM;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MAET,mBAAS,QAAQ,IAAI,CAAC,MACrB,oBAAC,YAAe,OAAO,GACpB,eADU,CAEb,CACD;AAAA;AAAA,EACH,GACF;AAEJ;","names":[]}
|