@fxhash/params 0.0.5 → 0.0.8
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-4OV7OX5A.js +37 -0
- package/dist/chunk-4OV7OX5A.js.map +1 -0
- package/dist/chunk-57UENWLF.js +110 -0
- package/dist/chunk-57UENWLF.js.map +1 -0
- package/dist/chunk-6VMIOQSE.js +34 -0
- package/dist/chunk-6VMIOQSE.js.map +1 -0
- package/dist/chunk-C6GTVBY6.cjs +46 -0
- package/dist/chunk-C6GTVBY6.cjs.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-EACKNC6C.cjs +103 -0
- package/dist/chunk-EACKNC6C.cjs.map +1 -0
- package/dist/chunk-FZWZHHQ2.js +398 -0
- package/dist/chunk-FZWZHHQ2.js.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-KZMSUHQX.cjs +120 -0
- package/dist/chunk-KZMSUHQX.cjs.map +1 -0
- package/dist/chunk-LX23UR4X.cjs +115 -0
- package/dist/chunk-LX23UR4X.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-P77D7XSP.js +46 -0
- package/dist/chunk-P77D7XSP.js.map +1 -0
- package/dist/chunk-PTXBICTZ.js +67 -0
- package/dist/chunk-PTXBICTZ.js.map +1 -0
- package/dist/chunk-QDLMFMLL.cjs +398 -0
- package/dist/chunk-QDLMFMLL.cjs.map +1 -0
- package/dist/chunk-QM6EKPI6.cjs +67 -0
- package/dist/chunk-QM6EKPI6.cjs.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-X4O42D2P.cjs +37 -0
- package/dist/chunk-X4O42D2P.cjs.map +1 -0
- package/dist/chunk-YOS2HCIS.js +23 -0
- package/dist/chunk-YOS2HCIS.js.map +1 -0
- package/dist/chunk-YXDLGCFJ.cjs +110 -0
- package/dist/chunk-YXDLGCFJ.cjs.map +1 -0
- package/dist/chunk-YYEIYDDF.js +24 -0
- package/dist/chunk-YYEIYDDF.js.map +1 -0
- package/dist/chunk-Z7K2LNS2.js +115 -0
- package/dist/chunk-Z7K2LNS2.js.map +1 -0
- package/dist/chunk-ZG3OT7LF.js +120 -0
- package/dist/chunk-ZG3OT7LF.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,135 @@
|
|
1
|
+
import {
|
2
|
+
BaseInput
|
3
|
+
} from "./chunk-2BHABOFI.js";
|
4
|
+
|
5
|
+
// src/Controller/Controller.module.scss
|
6
|
+
var Controller_module_default = {
|
7
|
+
"controller": "_controller_1rjbl_1",
|
8
|
+
"inputContainer": "_inputContainer_1rjbl_12",
|
9
|
+
"default": "_default_1rjbl_18",
|
10
|
+
"invert": "_invert_1rjbl_31",
|
11
|
+
"box": "_box_1rjbl_44",
|
12
|
+
"numberInput": "_numberInput_1rjbl_58"
|
13
|
+
};
|
14
|
+
|
15
|
+
// src/Controller/Controller.tsx
|
16
|
+
import cx from "classnames";
|
17
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
18
|
+
function BaseParamsInput(props) {
|
19
|
+
const { id } = props;
|
20
|
+
return /* @__PURE__ */ jsx(BaseInput, { name: `${id}-params-search`, autoComplete: "off", ...props });
|
21
|
+
}
|
22
|
+
function Controller(props) {
|
23
|
+
const {
|
24
|
+
id,
|
25
|
+
label,
|
26
|
+
layout = "default",
|
27
|
+
className,
|
28
|
+
inputContainerProps,
|
29
|
+
isCodeDriven
|
30
|
+
} = props;
|
31
|
+
return /* @__PURE__ */ jsxs(
|
32
|
+
"div",
|
33
|
+
{
|
34
|
+
className: cx(Controller_module_default.controller, Controller_module_default[layout], className),
|
35
|
+
title: isCodeDriven ? "This parameter is solely code-driven. Controller is just shown for debugging purposes." : "",
|
36
|
+
children: [
|
37
|
+
id && /* @__PURE__ */ jsx("label", { htmlFor: id, children: label || id }),
|
38
|
+
/* @__PURE__ */ jsx("div", { className: Controller_module_default.inputContainer, ...inputContainerProps, children: props.children })
|
39
|
+
]
|
40
|
+
}
|
41
|
+
);
|
42
|
+
}
|
43
|
+
function HTMLInputController(props) {
|
44
|
+
const {
|
45
|
+
label,
|
46
|
+
id,
|
47
|
+
onChange,
|
48
|
+
value,
|
49
|
+
type,
|
50
|
+
className,
|
51
|
+
inputProps,
|
52
|
+
layout = "default",
|
53
|
+
isCodeDriven
|
54
|
+
} = props;
|
55
|
+
return /* @__PURE__ */ jsx(
|
56
|
+
Controller,
|
57
|
+
{
|
58
|
+
id,
|
59
|
+
label,
|
60
|
+
layout,
|
61
|
+
isCodeDriven,
|
62
|
+
children: /* @__PURE__ */ jsx(
|
63
|
+
BaseParamsInput,
|
64
|
+
{
|
65
|
+
className,
|
66
|
+
type,
|
67
|
+
id,
|
68
|
+
onChange,
|
69
|
+
value,
|
70
|
+
disabled: isCodeDriven,
|
71
|
+
...inputProps
|
72
|
+
}
|
73
|
+
)
|
74
|
+
}
|
75
|
+
);
|
76
|
+
}
|
77
|
+
function HTMLInputControllerWithTextInput(props) {
|
78
|
+
const {
|
79
|
+
label,
|
80
|
+
id,
|
81
|
+
onChange,
|
82
|
+
value,
|
83
|
+
type,
|
84
|
+
className,
|
85
|
+
inputProps = {},
|
86
|
+
layout = "default",
|
87
|
+
textInputProps,
|
88
|
+
isCodeDriven
|
89
|
+
} = props;
|
90
|
+
return /* @__PURE__ */ jsxs(
|
91
|
+
Controller,
|
92
|
+
{
|
93
|
+
id,
|
94
|
+
label,
|
95
|
+
layout,
|
96
|
+
isCodeDriven,
|
97
|
+
children: [
|
98
|
+
/* @__PURE__ */ jsx(
|
99
|
+
BaseParamsInput,
|
100
|
+
{
|
101
|
+
className,
|
102
|
+
type,
|
103
|
+
id,
|
104
|
+
onChange,
|
105
|
+
value,
|
106
|
+
autoComplete: "off",
|
107
|
+
disabled: isCodeDriven,
|
108
|
+
...inputProps
|
109
|
+
}
|
110
|
+
),
|
111
|
+
/* @__PURE__ */ jsx(
|
112
|
+
BaseParamsInput,
|
113
|
+
{
|
114
|
+
type: "text",
|
115
|
+
id: `text-${id}`,
|
116
|
+
onChange,
|
117
|
+
value,
|
118
|
+
autoComplete: "off",
|
119
|
+
disabled: isCodeDriven,
|
120
|
+
...textInputProps
|
121
|
+
}
|
122
|
+
)
|
123
|
+
]
|
124
|
+
}
|
125
|
+
);
|
126
|
+
}
|
127
|
+
|
128
|
+
export {
|
129
|
+
Controller_module_default,
|
130
|
+
BaseParamsInput,
|
131
|
+
Controller,
|
132
|
+
HTMLInputController,
|
133
|
+
HTMLInputControllerWithTextInput
|
134
|
+
};
|
135
|
+
//# sourceMappingURL=chunk-CE3TPOSO.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/Controller/Controller.module.scss","../src/Controller/Controller.tsx"],"sourcesContent":["import 'css-chunk:src/Controller/Controller.module.scss';export default {\n \"controller\": \"_controller_1rjbl_1\",\n \"inputContainer\": \"_inputContainer_1rjbl_12\",\n \"default\": \"_default_1rjbl_18\",\n \"invert\": \"_invert_1rjbl_31\",\n \"box\": \"_box_1rjbl_44\",\n \"numberInput\": \"_numberInput_1rjbl_58\"\n};","import {\n HTMLInputTypeAttribute,\n InputHTMLAttributes,\n ReactNode,\n RefObject,\n} from \"react\"\nimport { FxParamOptionsMap, FxParamType } from \"../types\"\nimport classes from \"./Controller.module.scss\"\nimport cx from \"classnames\"\nimport { BaseInput } from \"../BaseInput\"\n\n/*\n * Providing a name starting or ending with `search` prevents\n * 1Password extension to appear in the input fields\n * https://1password.community/discussion/comment/606453/#Comment_606453\n */\nexport function BaseParamsInput(props: InputHTMLAttributes<HTMLInputElement>) {\n const { id } = props\n return (\n <BaseInput name={`${id}-params-search`} autoComplete=\"off\" {...props} />\n )\n}\n\nexport type FxParamInputChangeHandler = (e: any) => void\n\nexport interface ControllerProps {\n label?: string\n id?: string\n children: ReactNode\n layout?: \"default\" | \"invert\" | \"box\"\n className?: string\n inputContainerProps?: {\n ref: RefObject<HTMLDivElement>\n }\n isCodeDriven?: boolean\n}\n\nexport function Controller(props: ControllerProps) {\n const {\n id,\n label,\n layout = \"default\",\n className,\n inputContainerProps,\n isCodeDriven,\n } = props\n return (\n <div\n className={cx(classes.controller, classes[layout], className)}\n title={\n isCodeDriven\n ? \"This parameter is solely code-driven. Controller is just shown for debugging purposes.\"\n : \"\"\n }\n >\n {id && <label htmlFor={id}>{label || id}</label>}\n <div className={classes.inputContainer} {...inputContainerProps}>\n {props.children}\n </div>\n </div>\n )\n}\n\nexport interface HTMLInputControllerProps {\n id: string\n value: string\n onChange: FxParamInputChangeHandler\n type: HTMLInputTypeAttribute\n inputProps?: InputHTMLAttributes<HTMLInputElement | HTMLSelectElement>\n className?: string\n label?: string\n layout?: \"default\" | \"invert\" | \"box\"\n isCodeDriven?: boolean\n}\n\nexport type FxParamControllerProps<Type extends FxParamType> = Omit<\n HTMLInputControllerProps,\n \"type\"\n> & {\n value: any\n options?: FxParamOptionsMap[Type]\n onChange: FxParamInputChangeHandler\n}\n\nexport function HTMLInputController(props: HTMLInputControllerProps) {\n const {\n label,\n id,\n onChange,\n value,\n type,\n className,\n inputProps,\n layout = \"default\",\n isCodeDriven,\n } = props\n return (\n <Controller\n id={id}\n label={label}\n layout={layout}\n isCodeDriven={isCodeDriven}\n >\n <BaseParamsInput\n className={className}\n type={type}\n id={id}\n onChange={onChange}\n value={value}\n disabled={isCodeDriven}\n {...inputProps}\n />\n </Controller>\n )\n}\n\nexport interface HTMLInputControllerWithTextInputProps\n extends HTMLInputControllerProps {\n textInputProps?: InputHTMLAttributes<HTMLInputElement>\n}\n\nexport function HTMLInputControllerWithTextInput(\n props: HTMLInputControllerWithTextInputProps\n) {\n const {\n label,\n id,\n onChange,\n value,\n type,\n className,\n inputProps = {},\n layout = \"default\",\n textInputProps,\n isCodeDriven,\n } = props\n return (\n <Controller\n id={id}\n label={label}\n layout={layout}\n isCodeDriven={isCodeDriven}\n >\n <BaseParamsInput\n className={className}\n type={type}\n id={id}\n onChange={onChange}\n value={value}\n autoComplete=\"off\"\n disabled={isCodeDriven}\n {...inputProps}\n />\n <BaseParamsInput\n type=\"text\"\n id={`text-${id}`}\n onChange={onChange}\n value={value}\n autoComplete=\"off\"\n disabled={isCodeDriven}\n {...textInputProps}\n />\n </Controller>\n )\n}\n"],"mappings":";;;;;AAAyD,IAAO,4BAAQ;AAAA,EACtE,cAAc;AAAA,EACd,kBAAkB;AAAA,EAClB,WAAW;AAAA,EACX,UAAU;AAAA,EACV,OAAO;AAAA,EACP,eAAe;AACjB;;;ACCA,OAAO,QAAQ;AAWX,cA4BA,YA5BA;AAHG,SAAS,gBAAgB,OAA8C;AAC5E,QAAM,EAAE,GAAG,IAAI;AACf,SACE,oBAAC,aAAU,MAAM,GAAG,oBAAoB,cAAa,OAAO,GAAG,OAAO;AAE1E;AAgBO,SAAS,WAAW,OAAwB;AACjD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI;AACJ,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,GAAG,0BAAQ,YAAY,0BAAQ,MAAM,GAAG,SAAS;AAAA,MAC5D,OACE,eACI,2FACA;AAAA,MAGL;AAAA,cAAM,oBAAC,WAAM,SAAS,IAAK,mBAAS,IAAG;AAAA,QACxC,oBAAC,SAAI,WAAW,0BAAQ,gBAAiB,GAAG,qBACzC,gBAAM,UACT;AAAA;AAAA;AAAA,EACF;AAEJ;AAuBO,SAAS,oBAAoB,OAAiC;AACnE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF,IAAI;AACJ,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,UAAU;AAAA,UACT,GAAG;AAAA;AAAA,MACN;AAAA;AAAA,EACF;AAEJ;AAOO,SAAS,iCACd,OACA;AACA,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa,CAAC;AAAA,IACd,SAAS;AAAA,IACT;AAAA,IACA;AAAA,EACF,IAAI;AACJ,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MAEA;AAAA;AAAA,UAAC;AAAA;AAAA,YACC;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA,cAAa;AAAA,YACb,UAAU;AAAA,YACT,GAAG;AAAA;AAAA,QACN;AAAA,QACA;AAAA,UAAC;AAAA;AAAA,YACC,MAAK;AAAA,YACL,IAAI,QAAQ;AAAA,YACZ;AAAA,YACA;AAAA,YACA,cAAa;AAAA,YACb,UAAU;AAAA,YACT,GAAG;AAAA;AAAA,QACN;AAAA;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
2
|
+
|
3
|
+
var _chunkHJBHIE5Tcjs = require('./chunk-HJBHIE5T.cjs');
|
4
|
+
|
5
|
+
// src/Controller/Boolean.tsx
|
6
|
+
var _jsxruntime = require('react/jsx-runtime');
|
7
|
+
function BooleanController(props) {
|
8
|
+
const { ...rest } = props;
|
9
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
10
|
+
_chunkHJBHIE5Tcjs.HTMLInputController,
|
11
|
+
{
|
12
|
+
type: "checkbox",
|
13
|
+
layout: "box",
|
14
|
+
inputProps: { checked: props.value },
|
15
|
+
...rest
|
16
|
+
}
|
17
|
+
);
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
exports.BooleanController = BooleanController;
|
23
|
+
//# sourceMappingURL=chunk-D4RVVQC7.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/Controller/Boolean.tsx"],"names":[],"mappings":";;;;;AAMI;AAHG,SAAS,kBAAkB,OAA0C;AAC1E,QAAM,EAAE,GAAG,KAAK,IAAI;AACpB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL,QAAO;AAAA,MACP,YAAY,EAAE,SAAS,MAAM,MAAM;AAAA,MAClC,GAAG;AAAA;AAAA,EACN;AAEJ","sourcesContent":["import { FxParamControllerProps, HTMLInputController } from \"./Controller\"\nimport classes from \"./Controller.module.scss\"\n\nexport function BooleanController(props: FxParamControllerProps<\"boolean\">) {\n const { ...rest } = props\n return (\n <HTMLInputController\n type=\"checkbox\"\n layout=\"box\"\n inputProps={{ checked: props.value }}\n {...rest}\n />\n )\n}\n"]}
|
@@ -0,0 +1,103 @@
|
|
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/validation.ts
|
2
|
+
var _zod = require('zod');
|
3
|
+
var ControllerTypeSchema = _zod.z.enum([
|
4
|
+
"number",
|
5
|
+
"bigint",
|
6
|
+
"color",
|
7
|
+
"string",
|
8
|
+
"bytes",
|
9
|
+
"boolean",
|
10
|
+
"select"
|
11
|
+
]);
|
12
|
+
var FxParamOptions_bigintSchema = _zod.z.object({
|
13
|
+
min: _zod.z.number().or(_zod.z.bigint()).optional(),
|
14
|
+
max: _zod.z.number().or(_zod.z.bigint()).optional()
|
15
|
+
});
|
16
|
+
var FxParamOptions_numberSchema = _zod.z.object({
|
17
|
+
min: _zod.z.number().gte(Number.MIN_SAFE_INTEGER).optional(),
|
18
|
+
max: _zod.z.number().lte(Number.MAX_SAFE_INTEGER).optional(),
|
19
|
+
step: _zod.z.number().optional()
|
20
|
+
});
|
21
|
+
var FxParamOptions_stringSchema = _zod.z.object({
|
22
|
+
minLength: _zod.z.number().gte(0).optional(),
|
23
|
+
maxLength: _zod.z.number().optional()
|
24
|
+
});
|
25
|
+
var FxParamOptions_bytesSchema = _zod.z.object({
|
26
|
+
length: _zod.z.number().gt(0)
|
27
|
+
});
|
28
|
+
var FxParamOptions_selectSchema = _zod.z.object({
|
29
|
+
options: _zod.z.string().array().nonempty()
|
30
|
+
});
|
31
|
+
var BaseControllerDefinitionSchema = _zod.z.object({
|
32
|
+
id: _zod.z.string(),
|
33
|
+
name: _zod.z.string().optional(),
|
34
|
+
exposedAsFeature: _zod.z.boolean().optional()
|
35
|
+
});
|
36
|
+
var StringControllerSchema = BaseControllerDefinitionSchema.extend({
|
37
|
+
type: _zod.z.literal(ControllerTypeSchema.enum.string),
|
38
|
+
options: FxParamOptions_stringSchema.optional(),
|
39
|
+
default: _zod.z.string().optional()
|
40
|
+
});
|
41
|
+
var BytesControllerSchema = BaseControllerDefinitionSchema.extend({
|
42
|
+
type: _zod.z.literal(ControllerTypeSchema.enum.bytes),
|
43
|
+
options: FxParamOptions_bytesSchema,
|
44
|
+
default: _zod.z.any().optional(),
|
45
|
+
update: _zod.z.literal("code-driven", {
|
46
|
+
invalid_type_error: "Bytes parameters must be code-driven",
|
47
|
+
required_error: "Bytes parameters must be code-driven"
|
48
|
+
})
|
49
|
+
});
|
50
|
+
var NumberControllerSchema = BaseControllerDefinitionSchema.extend({
|
51
|
+
type: _zod.z.literal(ControllerTypeSchema.enum.number),
|
52
|
+
options: FxParamOptions_numberSchema.optional(),
|
53
|
+
default: _zod.z.number().gte(Number.MIN_SAFE_INTEGER).lte(Number.MAX_SAFE_INTEGER).optional()
|
54
|
+
});
|
55
|
+
var BigIntControllerSchema = BaseControllerDefinitionSchema.extend({
|
56
|
+
type: _zod.z.literal(ControllerTypeSchema.enum.bigint),
|
57
|
+
options: FxParamOptions_bigintSchema.optional(),
|
58
|
+
default: _zod.z.bigint().optional()
|
59
|
+
});
|
60
|
+
var SelectControllerSchema = BaseControllerDefinitionSchema.extend({
|
61
|
+
type: _zod.z.literal(ControllerTypeSchema.enum.select),
|
62
|
+
options: FxParamOptions_selectSchema,
|
63
|
+
default: _zod.z.string().optional()
|
64
|
+
});
|
65
|
+
var BooleanControllerSchema = BaseControllerDefinitionSchema.extend({
|
66
|
+
type: _zod.z.literal(ControllerTypeSchema.enum.boolean),
|
67
|
+
options: _zod.z.undefined(),
|
68
|
+
default: _zod.z.boolean().optional()
|
69
|
+
});
|
70
|
+
var ColorControllerSchema = BaseControllerDefinitionSchema.extend({
|
71
|
+
type: _zod.z.literal(ControllerTypeSchema.enum.color),
|
72
|
+
options: _zod.z.undefined(),
|
73
|
+
default: _zod.z.string().optional()
|
74
|
+
});
|
75
|
+
var ControllerDefinitionSchema = _zod.z.union([
|
76
|
+
StringControllerSchema,
|
77
|
+
NumberControllerSchema,
|
78
|
+
BigIntControllerSchema,
|
79
|
+
SelectControllerSchema,
|
80
|
+
BytesControllerSchema,
|
81
|
+
BooleanControllerSchema,
|
82
|
+
ColorControllerSchema
|
83
|
+
]);
|
84
|
+
var controllerSchema = {
|
85
|
+
number: NumberControllerSchema,
|
86
|
+
bigint: BigIntControllerSchema,
|
87
|
+
color: ColorControllerSchema,
|
88
|
+
string: StringControllerSchema,
|
89
|
+
bytes: BytesControllerSchema,
|
90
|
+
boolean: BooleanControllerSchema,
|
91
|
+
select: SelectControllerSchema
|
92
|
+
};
|
93
|
+
function validateParameterDefinition(parameterDefinition) {
|
94
|
+
return _optionalChain([controllerSchema, 'access', _ => _[parameterDefinition.type], 'optionalAccess', _2 => _2.safeParse, 'call', _3 => _3(
|
95
|
+
parameterDefinition
|
96
|
+
)]);
|
97
|
+
}
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
exports.BaseControllerDefinitionSchema = BaseControllerDefinitionSchema; exports.validateParameterDefinition = validateParameterDefinition;
|
103
|
+
//# sourceMappingURL=chunk-EACKNC6C.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/validation.ts"],"names":[],"mappings":"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","sourcesContent":["import { SafeParseError, SafeParseSuccess, z } from \"zod\"\nimport { FxParamDefinition, FxParamType } from \"./types\"\n\nconst ControllerTypeSchema = z.enum([\n \"number\",\n \"bigint\",\n \"color\",\n \"string\",\n \"bytes\",\n \"boolean\",\n \"select\",\n])\n\nconst FxParamOptions_bigintSchema = z.object({\n min: z.number().or(z.bigint()).optional(),\n max: z.number().or(z.bigint()).optional(),\n})\n\nconst FxParamOptions_numberSchema = z.object({\n min: z.number().gte(Number.MIN_SAFE_INTEGER).optional(),\n max: z.number().lte(Number.MAX_SAFE_INTEGER).optional(),\n step: z.number().optional(),\n})\n\nconst FxParamOptions_stringSchema = z.object({\n minLength: z.number().gte(0).optional(),\n maxLength: z.number().optional(),\n})\n\nconst FxParamOptions_bytesSchema = z.object({\n length: z.number().gt(0),\n})\n\nconst FxParamOptions_selectSchema = z.object({\n options: z.string().array().nonempty(),\n})\n\nexport const BaseControllerDefinitionSchema = z.object({\n id: z.string(),\n name: z.string().optional(),\n exposedAsFeature: z.boolean().optional(),\n})\n\nconst StringControllerSchema = BaseControllerDefinitionSchema.extend({\n type: z.literal(ControllerTypeSchema.enum.string),\n options: FxParamOptions_stringSchema.optional(),\n default: z.string().optional(),\n})\n\nconst BytesControllerSchema = BaseControllerDefinitionSchema.extend({\n type: z.literal(ControllerTypeSchema.enum.bytes),\n options: FxParamOptions_bytesSchema,\n default: z.any().optional(),\n update: z.literal(\"code-driven\", {\n invalid_type_error: \"Bytes parameters must be code-driven\",\n required_error: \"Bytes parameters must be code-driven\",\n }),\n})\n\nconst NumberControllerSchema = BaseControllerDefinitionSchema.extend({\n type: z.literal(ControllerTypeSchema.enum.number),\n options: FxParamOptions_numberSchema.optional(),\n default: z\n .number()\n .gte(Number.MIN_SAFE_INTEGER)\n .lte(Number.MAX_SAFE_INTEGER)\n .optional(),\n})\n\nconst BigIntControllerSchema = BaseControllerDefinitionSchema.extend({\n type: z.literal(ControllerTypeSchema.enum.bigint),\n options: FxParamOptions_bigintSchema.optional(),\n default: z.bigint().optional(),\n})\n\nconst SelectControllerSchema = BaseControllerDefinitionSchema.extend({\n type: z.literal(ControllerTypeSchema.enum.select),\n options: FxParamOptions_selectSchema,\n default: z.string().optional(),\n})\n\nconst BooleanControllerSchema = BaseControllerDefinitionSchema.extend({\n type: z.literal(ControllerTypeSchema.enum.boolean),\n options: z.undefined(),\n default: z.boolean().optional(),\n})\n\nconst ColorControllerSchema = BaseControllerDefinitionSchema.extend({\n type: z.literal(ControllerTypeSchema.enum.color),\n options: z.undefined(),\n default: z.string().optional(),\n})\n\nconst ControllerDefinitionSchema = z.union([\n StringControllerSchema,\n NumberControllerSchema,\n BigIntControllerSchema,\n SelectControllerSchema,\n BytesControllerSchema,\n BooleanControllerSchema,\n ColorControllerSchema,\n])\n\nexport type ControllerDefinitionSchemaType = z.infer<\n typeof ControllerDefinitionSchema\n>\n\nconst controllerSchema = {\n number: NumberControllerSchema,\n bigint: BigIntControllerSchema,\n color: ColorControllerSchema,\n string: StringControllerSchema,\n bytes: BytesControllerSchema,\n boolean: BooleanControllerSchema,\n select: SelectControllerSchema,\n}\n\nexport function validateParameterDefinition(\n parameterDefinition: FxParamDefinition<FxParamType>\n):\n | SafeParseError<ControllerDefinitionSchemaType>\n | SafeParseSuccess<ControllerDefinitionSchemaType>\n | undefined {\n return controllerSchema[parameterDefinition.type]?.safeParse(\n parameterDefinition\n )\n}\n"]}
|
@@ -0,0 +1,398 @@
|
|
1
|
+
// 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 definition.options?.min !== "undefined")
|
74
|
+
min = Number(definition.options.min);
|
75
|
+
let max = Number.MAX_SAFE_INTEGER;
|
76
|
+
if (typeof definition.options?.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 (definition?.options?.step) {
|
82
|
+
const t = 1 / definition?.options?.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 definition.options?.min !== "undefined")
|
90
|
+
min = Number(definition.options.min);
|
91
|
+
let max = Number.MAX_SAFE_INTEGER;
|
92
|
+
if (typeof definition.options?.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 (definition?.options?.step) {
|
98
|
+
const t = 1 / definition?.options?.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 definition.options?.min !== "undefined")
|
122
|
+
min = BigInt(definition.options.min);
|
123
|
+
if (typeof definition.options?.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 def.options?.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 def.options?.maxLength !== "undefined")
|
205
|
+
return Number(def.options.maxLength) * 2;
|
206
|
+
return 64 * 2;
|
207
|
+
},
|
208
|
+
random: (definition) => {
|
209
|
+
let min = 0;
|
210
|
+
if (typeof definition.options?.minLength !== "undefined")
|
211
|
+
min = definition.options.minLength;
|
212
|
+
let max = 64;
|
213
|
+
if (typeof definition.options?.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 definition.options?.minLength !== "undefined")
|
221
|
+
min = definition.options.minLength;
|
222
|
+
let max = 64;
|
223
|
+
if (typeof definition.options?.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 = def.options?.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, def.options?.options?.indexOf(input) || 0).toString(16).padStart(2, "0");
|
259
|
+
},
|
260
|
+
deserialize: (input, def) => {
|
261
|
+
const idx = parseInt(input, 16);
|
262
|
+
return def.options?.options?.[idx] || def.options?.options?.[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 definition?.options?.options[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
|
+
for (const def of definition) {
|
297
|
+
const processor = ParameterProcessors[def.type];
|
298
|
+
const transformer = options.withTransform && processor[options.transformType || "transform"];
|
299
|
+
if (!bytes) {
|
300
|
+
let v;
|
301
|
+
if (typeof def.default === "undefined")
|
302
|
+
v = processor.random(def);
|
303
|
+
else
|
304
|
+
v = def.default;
|
305
|
+
params[def.id] = transformer ? transformer(v, def) : v;
|
306
|
+
continue;
|
307
|
+
}
|
308
|
+
const bytesLen = processor.bytesLength(def);
|
309
|
+
const valueBytes = bytes.substring(0, bytesLen * 2);
|
310
|
+
bytes = bytes.substring(bytesLen * 2);
|
311
|
+
const val = processor.deserialize(valueBytes, def);
|
312
|
+
params[def.id] = transformer ? transformer(val, def) : val;
|
313
|
+
}
|
314
|
+
return params;
|
315
|
+
}
|
316
|
+
function consolidateParams(params, data) {
|
317
|
+
if (!params)
|
318
|
+
return [];
|
319
|
+
const rtn = [...params];
|
320
|
+
for (const p in rtn) {
|
321
|
+
const definition = rtn[p];
|
322
|
+
const { id, type, default: def } = definition;
|
323
|
+
if (data && data.hasOwnProperty(id)) {
|
324
|
+
rtn[p].value = data[id];
|
325
|
+
} else {
|
326
|
+
const processor = ParameterProcessors[type];
|
327
|
+
let v;
|
328
|
+
if (typeof def === "undefined")
|
329
|
+
v = processor.random(definition);
|
330
|
+
else
|
331
|
+
v = def;
|
332
|
+
rtn[p].value = processor.transform?.(v) || v;
|
333
|
+
}
|
334
|
+
}
|
335
|
+
return rtn;
|
336
|
+
}
|
337
|
+
function getRandomParamValues(params, options) {
|
338
|
+
return params.reduce((acc, definition) => {
|
339
|
+
const processor = ParameterProcessors[definition.type];
|
340
|
+
const v = processor.random(definition);
|
341
|
+
acc[definition.id] = options?.noTransform ? v : processor.transform?.(v) || v;
|
342
|
+
return acc;
|
343
|
+
}, {});
|
344
|
+
}
|
345
|
+
function sumBytesParams(definitions) {
|
346
|
+
return definitions?.reduce(
|
347
|
+
(acc, def) => acc + ParameterProcessors[def.type].bytesLength(def),
|
348
|
+
0
|
349
|
+
) || 0;
|
350
|
+
}
|
351
|
+
function stringifyParamsData(data) {
|
352
|
+
return JSON.stringify(data, (key, value) => {
|
353
|
+
if (typeof value === "bigint")
|
354
|
+
return value.toString();
|
355
|
+
return value;
|
356
|
+
});
|
357
|
+
}
|
358
|
+
function jsonStringifyBigint(data) {
|
359
|
+
return JSON.stringify(data, (key, value) => {
|
360
|
+
if (typeof value === "bigint")
|
361
|
+
return value.toString();
|
362
|
+
return value;
|
363
|
+
});
|
364
|
+
}
|
365
|
+
var processParam = (paramId, value, definitions, transformType) => {
|
366
|
+
const definition = definitions.find((d) => d.id === paramId);
|
367
|
+
const processor = ParameterProcessors[definition.type];
|
368
|
+
const transformer = processor[transformType];
|
369
|
+
return transformer?.(value, definition) || value;
|
370
|
+
};
|
371
|
+
var processParams = (values, definitions, transformType) => {
|
372
|
+
const paramValues = {};
|
373
|
+
for (const definition of definitions) {
|
374
|
+
const processor = ParameterProcessors[definition.type];
|
375
|
+
const value = values[definition.id];
|
376
|
+
const transformer = processor[transformType];
|
377
|
+
paramValues[definition.id] = transformer?.(value, definition) || value;
|
378
|
+
}
|
379
|
+
return paramValues;
|
380
|
+
};
|
381
|
+
|
382
|
+
export {
|
383
|
+
rgbaToHex,
|
384
|
+
hexToRgba,
|
385
|
+
MIN_SAFE_INT64,
|
386
|
+
MAX_SAFE_INT64,
|
387
|
+
ParameterProcessors,
|
388
|
+
serializeParams,
|
389
|
+
deserializeParams,
|
390
|
+
consolidateParams,
|
391
|
+
getRandomParamValues,
|
392
|
+
sumBytesParams,
|
393
|
+
stringifyParamsData,
|
394
|
+
jsonStringifyBigint,
|
395
|
+
processParam,
|
396
|
+
processParams
|
397
|
+
};
|
398
|
+
//# sourceMappingURL=chunk-FZWZHHQ2.js.map
|