@tremolo-ui/functions 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tremolo-ui/functions",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "functions used in @tremolo-ui/react",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -41,32 +41,12 @@
41
41
  "exports": {
42
42
  ".": {
43
43
  "require": {
44
- "default": "./dist/index.cjs",
45
- "types": "./dist/index.d.cts"
44
+ "types": "./dist/index.d.cts",
45
+ "default": "./dist/index.cjs"
46
46
  },
47
47
  "import": {
48
- "default": "./dist/index.js",
49
- "types": "./dist/index.d.ts"
50
- }
51
- },
52
- "./NumberInput": {
53
- "require": {
54
- "default": "./dist/NumberInput/type.cjs",
55
- "types": "./dist/types/NumberInput/type.d.cts"
56
- },
57
- "import": {
58
- "default": "./dist/NumberInput/type.js",
59
- "types": "./dist/types/NumberInput/type.d.ts"
60
- }
61
- },
62
- "./Slider": {
63
- "require": {
64
- "default": "./dist/Slider/type.cjs",
65
- "types": "./dist/types/Slider/type.d.cts"
66
- },
67
- "import": {
68
- "default": "./dist/Slider/type.js",
69
- "types": "./dist/types/Slider/type.d.ts"
48
+ "types": "./dist/index.d.ts",
49
+ "default": "./dist/index.js"
70
50
  }
71
51
  }
72
52
  }
@@ -1,45 +0,0 @@
1
-
2
- //#region src/components/NumberInput/type.ts
3
- function selectUnit(units, value) {
4
- let i = 0;
5
- for (; i < units.length; i++) if (Math.abs(units[i][1]) > Math.abs(value)) break;
6
- return units[Math.max(0, i - 1)];
7
- }
8
- function parseValue(inputString, units, digit) {
9
- const str = inputString.trim();
10
- if (!units || typeof units == "string") {
11
- const m$1 = str.match(/-?\d+(\.\d+)?/);
12
- let v = Number(m$1?.[0] ?? "0");
13
- v = isNaN(v) ? 0 : v;
14
- return {
15
- rawValue: v,
16
- formatValue: (digit != void 0 ? v.toFixed(digit) : v) + (units ?? ""),
17
- unit: units ?? ""
18
- };
19
- }
20
- const unitList = units.map(([u, _s]) => u);
21
- const scaleList = units.map(([_u, s]) => s);
22
- let rawValue = 0;
23
- let unit = unitList[0];
24
- let formatValue = (digit != void 0 ? rawValue.toFixed(digit) : rawValue) + unit;
25
- const m = str.match(/^(-?\d+(\.\d+)?)\s*(\w*)$/);
26
- if (m) {
27
- rawValue = Number(m[1]) || 0;
28
- const uIndex = unitList.indexOf(m[3]);
29
- rawValue *= uIndex != -1 ? scaleList[uIndex] : 1;
30
- const [u, scale] = selectUnit(units, rawValue);
31
- const v = rawValue / scale;
32
- formatValue = (digit != void 0 ? v.toFixed(digit) : v) + u;
33
- unit = u;
34
- }
35
- return {
36
- rawValue,
37
- formatValue,
38
- unit
39
- };
40
- }
41
-
42
- //#endregion
43
- exports.parseValue = parseValue;
44
- exports.selectUnit = selectUnit;
45
- //# sourceMappingURL=type.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.cjs","names":["units: Units","value: number","inputString: string","units?: string | Units","digit?: number","m"],"sources":["../../src/components/NumberInput/type.ts"],"sourcesContent":["/**\n * @module NumberInput\n */\n\n/**\n * [unit, scale][]\n * @example\n * [['Hz', 1], ['kHz', 1000]]\n */\nexport type Units = [string, number][]\n\nexport function selectUnit(units: Units, value: number): [string, number] {\n let i = 0\n for (; i < units.length; i++) {\n if (Math.abs(units[i][1]) > Math.abs(value)) break\n }\n return units[Math.max(0, i - 1)]\n}\n\nexport function parseValue(\n inputString: string,\n units?: string | Units,\n digit?: number,\n): {\n rawValue: number\n formatValue: string\n unit: string\n} {\n const str = inputString.trim()\n if (!units || typeof units == 'string') {\n const m = str.match(/-?\\d+(\\.\\d+)?/)\n let v = Number(m?.[0] ?? '0')\n v = isNaN(v) ? 0 : v\n return {\n rawValue: v,\n formatValue: (digit != undefined ? v.toFixed(digit) : v) + (units ?? ''),\n unit: units ?? '',\n }\n }\n\n const unitList = units.map(([u, _s]) => u)\n const scaleList = units.map(([_u, s]) => s)\n let rawValue = 0\n let unit = unitList[0]\n let formatValue =\n (digit != undefined ? rawValue.toFixed(digit) : rawValue) + unit\n const m = str.match(/^(-?\\d+(\\.\\d+)?)\\s*(\\w*)$/)\n if (m) {\n rawValue = Number(m[1]) || 0\n const uIndex = unitList.indexOf(m[3])\n rawValue *= uIndex != -1 ? scaleList[uIndex] : 1\n const [u, scale] = selectUnit(units, rawValue)\n const v = rawValue / scale\n formatValue = (digit != undefined ? v.toFixed(digit) : v) + u\n unit = u\n }\n return {\n rawValue: rawValue,\n formatValue: formatValue,\n unit: unit,\n }\n}\n"],"mappings":";;AAWA,SAAgB,WAAWA,OAAcC,OAAiC;CACxE,IAAI,IAAI;AACR,QAAO,IAAI,MAAM,QAAQ,IACvB,KAAI,KAAK,IAAI,MAAM,GAAG,GAAG,GAAG,KAAK,IAAI,MAAM,CAAE;AAE/C,QAAO,MAAM,KAAK,IAAI,GAAG,IAAI,EAAE;AAChC;AAED,SAAgB,WACdC,aACAC,OACAC,OAKA;CACA,MAAM,MAAM,YAAY,MAAM;AAC9B,MAAK,gBAAgB,SAAS,UAAU;EACtC,MAAMC,MAAI,IAAI,MAAM,gBAAgB;EACpC,IAAI,IAAI,OAAOA,MAAI,MAAM,IAAI;AAC7B,MAAI,MAAM,EAAE,GAAG,IAAI;AACnB,SAAO;GACL,UAAU;GACV,cAAc,kBAAqB,EAAE,QAAQ,MAAM,GAAG,MAAM,SAAS;GACrE,MAAM,SAAS;EAChB;CACF;CAED,MAAM,WAAW,MAAM,IAAI,CAAC,CAAC,GAAG,GAAG,KAAK,EAAE;CAC1C,MAAM,YAAY,MAAM,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE;CAC3C,IAAI,WAAW;CACf,IAAI,OAAO,SAAS;CACpB,IAAI,eACD,kBAAqB,SAAS,QAAQ,MAAM,GAAG,YAAY;CAC9D,MAAM,IAAI,IAAI,MAAM,4BAA4B;AAChD,KAAI,GAAG;AACL,aAAW,OAAO,EAAE,GAAG,IAAI;EAC3B,MAAM,SAAS,SAAS,QAAQ,EAAE,GAAG;AACrC,cAAY,UAAU,KAAK,UAAU,UAAU;EAC/C,MAAM,CAAC,GAAG,MAAM,GAAG,WAAW,OAAO,SAAS;EAC9C,MAAM,IAAI,WAAW;AACrB,iBAAe,kBAAqB,EAAE,QAAQ,MAAM,GAAG,KAAK;AAC5D,SAAO;CACR;AACD,QAAO;EACK;EACG;EACP;CACP;AACF"}
@@ -1,20 +0,0 @@
1
- //#region src/components/NumberInput/type.d.ts
2
- /**
3
- * @module NumberInput
4
- */
5
- /**
6
- * [unit, scale][]
7
- * @example
8
- * [['Hz', 1], ['kHz', 1000]]
9
- */
10
- type Units = [string, number][];
11
- declare function selectUnit(units: Units, value: number): [string, number];
12
- declare function parseValue(inputString: string, units?: string | Units, digit?: number): {
13
- rawValue: number;
14
- formatValue: string;
15
- unit: string;
16
- };
17
- //# sourceMappingURL=type.d.ts.map
18
- //#endregion
19
- export { Units, parseValue, selectUnit };
20
- //# sourceMappingURL=type.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.d.cts","names":[],"sources":["../../../src/components/NumberInput/type.ts"],"sourcesContent":[],"mappings":";;AASA;AAEA;AAQA;;;;;KAVY,KAAA;iBAEI,UAAA,QAAkB;iBAQlB,UAAA,uCAEG"}
@@ -1,20 +0,0 @@
1
- //#region src/components/NumberInput/type.d.ts
2
- /**
3
- * @module NumberInput
4
- */
5
- /**
6
- * [unit, scale][]
7
- * @example
8
- * [['Hz', 1], ['kHz', 1000]]
9
- */
10
- type Units = [string, number][];
11
- declare function selectUnit(units: Units, value: number): [string, number];
12
- declare function parseValue(inputString: string, units?: string | Units, digit?: number): {
13
- rawValue: number;
14
- formatValue: string;
15
- unit: string;
16
- };
17
- //# sourceMappingURL=type.d.ts.map
18
- //#endregion
19
- export { Units, parseValue, selectUnit };
20
- //# sourceMappingURL=type.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.d.ts","names":[],"sources":["../../../src/components/NumberInput/type.ts"],"sourcesContent":[],"mappings":";;AASA;AAEA;AAQA;;;;;KAVY,KAAA;iBAEI,UAAA,QAAkB;iBAQlB,UAAA,uCAEG"}
@@ -1,43 +0,0 @@
1
- //#region src/components/NumberInput/type.ts
2
- function selectUnit(units, value) {
3
- let i = 0;
4
- for (; i < units.length; i++) if (Math.abs(units[i][1]) > Math.abs(value)) break;
5
- return units[Math.max(0, i - 1)];
6
- }
7
- function parseValue(inputString, units, digit) {
8
- const str = inputString.trim();
9
- if (!units || typeof units == "string") {
10
- const m$1 = str.match(/-?\d+(\.\d+)?/);
11
- let v = Number(m$1?.[0] ?? "0");
12
- v = isNaN(v) ? 0 : v;
13
- return {
14
- rawValue: v,
15
- formatValue: (digit != void 0 ? v.toFixed(digit) : v) + (units ?? ""),
16
- unit: units ?? ""
17
- };
18
- }
19
- const unitList = units.map(([u, _s]) => u);
20
- const scaleList = units.map(([_u, s]) => s);
21
- let rawValue = 0;
22
- let unit = unitList[0];
23
- let formatValue = (digit != void 0 ? rawValue.toFixed(digit) : rawValue) + unit;
24
- const m = str.match(/^(-?\d+(\.\d+)?)\s*(\w*)$/);
25
- if (m) {
26
- rawValue = Number(m[1]) || 0;
27
- const uIndex = unitList.indexOf(m[3]);
28
- rawValue *= uIndex != -1 ? scaleList[uIndex] : 1;
29
- const [u, scale] = selectUnit(units, rawValue);
30
- const v = rawValue / scale;
31
- formatValue = (digit != void 0 ? v.toFixed(digit) : v) + u;
32
- unit = u;
33
- }
34
- return {
35
- rawValue,
36
- formatValue,
37
- unit
38
- };
39
- }
40
-
41
- //#endregion
42
- export { parseValue, selectUnit };
43
- //# sourceMappingURL=type.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.js","names":["units: Units","value: number","inputString: string","units?: string | Units","digit?: number","m"],"sources":["../../src/components/NumberInput/type.ts"],"sourcesContent":["/**\n * @module NumberInput\n */\n\n/**\n * [unit, scale][]\n * @example\n * [['Hz', 1], ['kHz', 1000]]\n */\nexport type Units = [string, number][]\n\nexport function selectUnit(units: Units, value: number): [string, number] {\n let i = 0\n for (; i < units.length; i++) {\n if (Math.abs(units[i][1]) > Math.abs(value)) break\n }\n return units[Math.max(0, i - 1)]\n}\n\nexport function parseValue(\n inputString: string,\n units?: string | Units,\n digit?: number,\n): {\n rawValue: number\n formatValue: string\n unit: string\n} {\n const str = inputString.trim()\n if (!units || typeof units == 'string') {\n const m = str.match(/-?\\d+(\\.\\d+)?/)\n let v = Number(m?.[0] ?? '0')\n v = isNaN(v) ? 0 : v\n return {\n rawValue: v,\n formatValue: (digit != undefined ? v.toFixed(digit) : v) + (units ?? ''),\n unit: units ?? '',\n }\n }\n\n const unitList = units.map(([u, _s]) => u)\n const scaleList = units.map(([_u, s]) => s)\n let rawValue = 0\n let unit = unitList[0]\n let formatValue =\n (digit != undefined ? rawValue.toFixed(digit) : rawValue) + unit\n const m = str.match(/^(-?\\d+(\\.\\d+)?)\\s*(\\w*)$/)\n if (m) {\n rawValue = Number(m[1]) || 0\n const uIndex = unitList.indexOf(m[3])\n rawValue *= uIndex != -1 ? scaleList[uIndex] : 1\n const [u, scale] = selectUnit(units, rawValue)\n const v = rawValue / scale\n formatValue = (digit != undefined ? v.toFixed(digit) : v) + u\n unit = u\n }\n return {\n rawValue: rawValue,\n formatValue: formatValue,\n unit: unit,\n }\n}\n"],"mappings":";AAWA,SAAgB,WAAWA,OAAcC,OAAiC;CACxE,IAAI,IAAI;AACR,QAAO,IAAI,MAAM,QAAQ,IACvB,KAAI,KAAK,IAAI,MAAM,GAAG,GAAG,GAAG,KAAK,IAAI,MAAM,CAAE;AAE/C,QAAO,MAAM,KAAK,IAAI,GAAG,IAAI,EAAE;AAChC;AAED,SAAgB,WACdC,aACAC,OACAC,OAKA;CACA,MAAM,MAAM,YAAY,MAAM;AAC9B,MAAK,gBAAgB,SAAS,UAAU;EACtC,MAAMC,MAAI,IAAI,MAAM,gBAAgB;EACpC,IAAI,IAAI,OAAOA,MAAI,MAAM,IAAI;AAC7B,MAAI,MAAM,EAAE,GAAG,IAAI;AACnB,SAAO;GACL,UAAU;GACV,cAAc,kBAAqB,EAAE,QAAQ,MAAM,GAAG,MAAM,SAAS;GACrE,MAAM,SAAS;EAChB;CACF;CAED,MAAM,WAAW,MAAM,IAAI,CAAC,CAAC,GAAG,GAAG,KAAK,EAAE;CAC1C,MAAM,YAAY,MAAM,IAAI,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE;CAC3C,IAAI,WAAW;CACf,IAAI,OAAO,SAAS;CACpB,IAAI,eACD,kBAAqB,SAAS,QAAQ,MAAM,GAAG,YAAY;CAC9D,MAAM,IAAI,IAAI,MAAM,4BAA4B;AAChD,KAAI,GAAG;AACL,aAAW,OAAO,EAAE,GAAG,IAAI;EAC3B,MAAM,SAAS,SAAS,QAAQ,EAAE,GAAG;AACrC,cAAY,UAAU,KAAK,UAAU,UAAU;EAC/C,MAAM,CAAC,GAAG,MAAM,GAAG,WAAW,OAAO,SAAS;EAC9C,MAAM,IAAI,WAAW;AACrB,iBAAe,kBAAqB,EAAE,QAAQ,MAAM,GAAG,KAAK;AAC5D,SAAO;CACR;AACD,QAAO;EACK;EACG;EACP;CACP;AACF"}
@@ -1,36 +0,0 @@
1
-
2
- //#region src/math.ts
3
- /**
4
- *
5
- * @category Math
6
- */
7
- function toFixed(x, fractionDigits) {
8
- return Number(x.toFixed(fractionDigits));
9
- }
10
- /**
11
- *
12
- * @category Math
13
- */
14
- function decimalPart(x) {
15
- return String(x).split(".")[1];
16
- }
17
-
18
- //#endregion
19
- //#region src/components/Slider/type.ts
20
- function generateOptionsList(options, min, max, step) {
21
- const optionsList = [];
22
- const per = options[0] == "step" ? step : options[0];
23
- const count = Math.floor(max / per) - Math.ceil(min / per) + 1;
24
- for (let i = 0; i < count; i++) {
25
- const value = toFixed(per * (Math.ceil(min / per) + i), decimalPart(per)?.length);
26
- optionsList.push({
27
- value,
28
- type: options[1]
29
- });
30
- }
31
- return optionsList;
32
- }
33
-
34
- //#endregion
35
- exports.generateOptionsList = generateOptionsList;
36
- //# sourceMappingURL=type.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.cjs","names":["x: number","fractionDigits?: number","x: number | string","options: ScaleOptions","min: number","max: number","step: number","optionsList: {\n value: number\n type: ScaleType\n }[]"],"sources":["../../src/math.ts","../../src/components/Slider/type.ts"],"sourcesContent":["/**\n * clamp value between min and max\n * @category Math\n */\nexport function clamp(value: number, min: number, max: number) {\n return Math.max(min, Math.min(value, max))\n}\n\n/**\n * Normalize the value from 0 to 1\n * @category Math\n */\nexport function normalizeValue(\n rawValue: number,\n min: number,\n max: number,\n skew = 1,\n) {\n if (min >= max) throw new RangeError('requirements: min < max')\n const v = clamp((rawValue - min) / (max - min), 0, 1)\n return Math.pow(v, skew)\n}\n\n/**\n * Convert normalized values back to raw values.\n * @category Math\n */\nexport function rawValue(\n normalizedValue: number,\n min: number,\n max: number,\n skew = 1,\n) {\n if (min >= max) throw new RangeError('requirements: min < max')\n const v =\n skew == 1\n ? clamp(normalizedValue, 0, 1)\n : Math.exp(Math.log(clamp(normalizedValue, 0, 1)) / skew)\n return min + v * (max - min)\n}\n\n/**\n *\n * @category Math\n */\nexport function skewWithCenterValue(\n centerValue: number,\n min: number,\n max: number,\n) {\n if (!(min <= centerValue && centerValue <= max))\n throw new RangeError('requirements: min <= centerValue <= max')\n return Math.log(0.5) / Math.log((centerValue - min) / (max - min))\n}\n\n/**\n *\n * @category Math\n */\nexport function stepValue(value: number, step: number) {\n if (step <= 0) throw new RangeError('requirements: step > 0')\n const quotient = Math.floor(value / step)\n const decimalDigits = decimalPart(step)?.length\n const v = toFixed(quotient * step, decimalDigits)\n const next = toFixed((quotient + 1) * step, decimalDigits)\n return Math.abs(value - v) < Math.abs(value - next) ? v : next\n}\n\n/**\n *\n * @category Math\n */\nexport function toFixed(x: number, fractionDigits?: number) {\n return Number(x.toFixed(fractionDigits))\n}\n\n/**\n *\n * @category Math\n */\nexport function integerPart(x: number | string): string | undefined {\n if (Number.isNaN(x)) {\n return undefined\n }\n return String(x).split('.')[0]\n}\n\n/**\n *\n * @category Math\n */\nexport function decimalPart(x: number | string): string | undefined {\n return String(x).split('.')[1]\n}\n\n/**\n *\n * @category Math\n */\nexport function radian(degree: number) {\n return (Math.PI * degree) / 180\n}\n\n/**\n *\n * @category Math\n */\nexport function degree(radian: number) {\n return (180 * radian) / Math.PI\n}\n\n/**\n *\n * @category Math\n */\nexport function mapValue(\n value: number,\n inMin: number,\n inMax: number,\n outMin: number,\n outMax: number,\n) {\n return ((value - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin\n}\n\n/**\n *\n * @category Math\n */\nexport function dbToGain(db: number) {\n return Math.pow(10, db / 20)\n}\n\n/**\n *\n * @category Math\n */\nexport function gainToDb(gain: number) {\n return 20 * (Math.log(gain) / Math.LN10)\n}\n","/**\n * @module Slider\n */\n\nimport { decimalPart, toFixed } from '../../math'\n\nexport type ScaleType = 'mark' | 'mark-number' | 'number'\nexport type ScaleOptions = ['step', ScaleType] | [number, ScaleType]\n\nexport function generateOptionsList(\n options: ScaleOptions,\n min: number,\n max: number,\n step: number,\n) {\n const optionsList: {\n value: number\n type: ScaleType\n }[] = []\n const per = options[0] == 'step' ? step : options[0]\n const count = Math.floor(max / per) - Math.ceil(min / per) + 1\n for (let i = 0; i < count; i++) {\n const value = toFixed(\n per * (Math.ceil(min / per) + i),\n decimalPart(per)?.length,\n )\n optionsList.push({ value: value, type: options[1] })\n }\n return optionsList\n}\n"],"mappings":";;;;;;AAwEA,SAAgB,QAAQA,GAAWC,gBAAyB;AAC1D,QAAO,OAAO,EAAE,QAAQ,eAAe,CAAC;AACzC;;;;;AAiBD,SAAgB,YAAYC,GAAwC;AAClE,QAAO,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC;AAC7B;;;;ACpFD,SAAgB,oBACdC,SACAC,KACAC,KACAC,MACA;CACA,MAAMC,cAGA,CAAE;CACR,MAAM,MAAM,QAAQ,MAAM,SAAS,OAAO,QAAQ;CAClD,MAAM,QAAQ,KAAK,MAAM,MAAM,IAAI,GAAG,KAAK,KAAK,MAAM,IAAI,GAAG;AAC7D,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;EAC9B,MAAM,QAAQ,QACZ,OAAO,KAAK,KAAK,MAAM,IAAI,GAAG,IAC9B,YAAY,IAAI,EAAE,OACnB;AACD,cAAY,KAAK;GAAS;GAAO,MAAM,QAAQ;EAAI,EAAC;CACrD;AACD,QAAO;AACR"}
@@ -1,15 +0,0 @@
1
- //#region src/components/Slider/type.d.ts
2
- /**
3
- * @module Slider
4
- */
5
- type ScaleType = 'mark' | 'mark-number' | 'number';
6
- type ScaleOptions = ['step', ScaleType] | [number, ScaleType];
7
- declare function generateOptionsList(options: ScaleOptions, min: number, max: number, step: number): {
8
- value: number;
9
- type: ScaleType;
10
- }[];
11
- //# sourceMappingURL=type.d.ts.map
12
-
13
- //#endregion
14
- export { ScaleOptions, ScaleType, generateOptionsList };
15
- //# sourceMappingURL=type.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.d.cts","names":[],"sources":["../../../src/components/Slider/type.ts"],"sourcesContent":[],"mappings":";;AAMA;AACA;AAAwB,KADZ,SAAA,GACY,MAAA,GAAA,aAAA,GAAA,QAAA;AAAY,KAAxB,YAAA,GAAwB,CAAA,MAAA,EAAA,SAAA,CAAA,GAAA,CAAA,MAAA,EAAsB,SAAtB,CAAA;AAAsB,iBAE1C,mBAAA,CAF0C,OAAA,EAG/C,YAH+C,EAAA,GAAA,EAAA,MAAA,EAAA,GAAA,EAAA,MAAA,EAAA,IAAA,EAAA,MAAA,CAAA,EAAA;EAAS,KAAA,EAAA,MAAA;EAEnD,IAAA,EAQN,SARM;CAAmB,EAAA"}
@@ -1,15 +0,0 @@
1
- //#region src/components/Slider/type.d.ts
2
- /**
3
- * @module Slider
4
- */
5
- type ScaleType = 'mark' | 'mark-number' | 'number';
6
- type ScaleOptions = ['step', ScaleType] | [number, ScaleType];
7
- declare function generateOptionsList(options: ScaleOptions, min: number, max: number, step: number): {
8
- value: number;
9
- type: ScaleType;
10
- }[];
11
- //# sourceMappingURL=type.d.ts.map
12
-
13
- //#endregion
14
- export { ScaleOptions, ScaleType, generateOptionsList };
15
- //# sourceMappingURL=type.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.d.ts","names":[],"sources":["../../../src/components/Slider/type.ts"],"sourcesContent":[],"mappings":";;AAMA;AACA;AAAwB,KADZ,SAAA,GACY,MAAA,GAAA,aAAA,GAAA,QAAA;AAAY,KAAxB,YAAA,GAAwB,CAAA,MAAA,EAAA,SAAA,CAAA,GAAA,CAAA,MAAA,EAAsB,SAAtB,CAAA;AAAsB,iBAE1C,mBAAA,CAF0C,OAAA,EAG/C,YAH+C,EAAA,GAAA,EAAA,MAAA,EAAA,GAAA,EAAA,MAAA,EAAA,IAAA,EAAA,MAAA,CAAA,EAAA;EAAS,KAAA,EAAA,MAAA;EAEnD,IAAA,EAQN,SARM;CAAmB,EAAA"}
@@ -1,35 +0,0 @@
1
- //#region src/math.ts
2
- /**
3
- *
4
- * @category Math
5
- */
6
- function toFixed(x, fractionDigits) {
7
- return Number(x.toFixed(fractionDigits));
8
- }
9
- /**
10
- *
11
- * @category Math
12
- */
13
- function decimalPart(x) {
14
- return String(x).split(".")[1];
15
- }
16
-
17
- //#endregion
18
- //#region src/components/Slider/type.ts
19
- function generateOptionsList(options, min, max, step) {
20
- const optionsList = [];
21
- const per = options[0] == "step" ? step : options[0];
22
- const count = Math.floor(max / per) - Math.ceil(min / per) + 1;
23
- for (let i = 0; i < count; i++) {
24
- const value = toFixed(per * (Math.ceil(min / per) + i), decimalPart(per)?.length);
25
- optionsList.push({
26
- value,
27
- type: options[1]
28
- });
29
- }
30
- return optionsList;
31
- }
32
-
33
- //#endregion
34
- export { generateOptionsList };
35
- //# sourceMappingURL=type.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"type.js","names":["x: number","fractionDigits?: number","x: number | string","options: ScaleOptions","min: number","max: number","step: number","optionsList: {\n value: number\n type: ScaleType\n }[]"],"sources":["../../src/math.ts","../../src/components/Slider/type.ts"],"sourcesContent":["/**\n * clamp value between min and max\n * @category Math\n */\nexport function clamp(value: number, min: number, max: number) {\n return Math.max(min, Math.min(value, max))\n}\n\n/**\n * Normalize the value from 0 to 1\n * @category Math\n */\nexport function normalizeValue(\n rawValue: number,\n min: number,\n max: number,\n skew = 1,\n) {\n if (min >= max) throw new RangeError('requirements: min < max')\n const v = clamp((rawValue - min) / (max - min), 0, 1)\n return Math.pow(v, skew)\n}\n\n/**\n * Convert normalized values back to raw values.\n * @category Math\n */\nexport function rawValue(\n normalizedValue: number,\n min: number,\n max: number,\n skew = 1,\n) {\n if (min >= max) throw new RangeError('requirements: min < max')\n const v =\n skew == 1\n ? clamp(normalizedValue, 0, 1)\n : Math.exp(Math.log(clamp(normalizedValue, 0, 1)) / skew)\n return min + v * (max - min)\n}\n\n/**\n *\n * @category Math\n */\nexport function skewWithCenterValue(\n centerValue: number,\n min: number,\n max: number,\n) {\n if (!(min <= centerValue && centerValue <= max))\n throw new RangeError('requirements: min <= centerValue <= max')\n return Math.log(0.5) / Math.log((centerValue - min) / (max - min))\n}\n\n/**\n *\n * @category Math\n */\nexport function stepValue(value: number, step: number) {\n if (step <= 0) throw new RangeError('requirements: step > 0')\n const quotient = Math.floor(value / step)\n const decimalDigits = decimalPart(step)?.length\n const v = toFixed(quotient * step, decimalDigits)\n const next = toFixed((quotient + 1) * step, decimalDigits)\n return Math.abs(value - v) < Math.abs(value - next) ? v : next\n}\n\n/**\n *\n * @category Math\n */\nexport function toFixed(x: number, fractionDigits?: number) {\n return Number(x.toFixed(fractionDigits))\n}\n\n/**\n *\n * @category Math\n */\nexport function integerPart(x: number | string): string | undefined {\n if (Number.isNaN(x)) {\n return undefined\n }\n return String(x).split('.')[0]\n}\n\n/**\n *\n * @category Math\n */\nexport function decimalPart(x: number | string): string | undefined {\n return String(x).split('.')[1]\n}\n\n/**\n *\n * @category Math\n */\nexport function radian(degree: number) {\n return (Math.PI * degree) / 180\n}\n\n/**\n *\n * @category Math\n */\nexport function degree(radian: number) {\n return (180 * radian) / Math.PI\n}\n\n/**\n *\n * @category Math\n */\nexport function mapValue(\n value: number,\n inMin: number,\n inMax: number,\n outMin: number,\n outMax: number,\n) {\n return ((value - inMin) / (inMax - inMin)) * (outMax - outMin) + outMin\n}\n\n/**\n *\n * @category Math\n */\nexport function dbToGain(db: number) {\n return Math.pow(10, db / 20)\n}\n\n/**\n *\n * @category Math\n */\nexport function gainToDb(gain: number) {\n return 20 * (Math.log(gain) / Math.LN10)\n}\n","/**\n * @module Slider\n */\n\nimport { decimalPart, toFixed } from '../../math'\n\nexport type ScaleType = 'mark' | 'mark-number' | 'number'\nexport type ScaleOptions = ['step', ScaleType] | [number, ScaleType]\n\nexport function generateOptionsList(\n options: ScaleOptions,\n min: number,\n max: number,\n step: number,\n) {\n const optionsList: {\n value: number\n type: ScaleType\n }[] = []\n const per = options[0] == 'step' ? step : options[0]\n const count = Math.floor(max / per) - Math.ceil(min / per) + 1\n for (let i = 0; i < count; i++) {\n const value = toFixed(\n per * (Math.ceil(min / per) + i),\n decimalPart(per)?.length,\n )\n optionsList.push({ value: value, type: options[1] })\n }\n return optionsList\n}\n"],"mappings":";;;;;AAwEA,SAAgB,QAAQA,GAAWC,gBAAyB;AAC1D,QAAO,OAAO,EAAE,QAAQ,eAAe,CAAC;AACzC;;;;;AAiBD,SAAgB,YAAYC,GAAwC;AAClE,QAAO,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC;AAC7B;;;;ACpFD,SAAgB,oBACdC,SACAC,KACAC,KACAC,MACA;CACA,MAAMC,cAGA,CAAE;CACR,MAAM,MAAM,QAAQ,MAAM,SAAS,OAAO,QAAQ;CAClD,MAAM,QAAQ,KAAK,MAAM,MAAM,IAAI,GAAG,KAAK,KAAK,MAAM,IAAI,GAAG;AAC7D,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KAAK;EAC9B,MAAM,QAAQ,QACZ,OAAO,KAAK,KAAK,MAAM,IAAI,GAAG,IAC9B,YAAY,IAAI,EAAE,OACnB;AACD,cAAY,KAAK;GAAS;GAAO,MAAM,QAAQ;EAAI,EAAC;CACrD;AACD,QAAO;AACR"}
@@ -1,62 +0,0 @@
1
- /**
2
- * @module NumberInput
3
- */
4
-
5
- /**
6
- * [unit, scale][]
7
- * @example
8
- * [['Hz', 1], ['kHz', 1000]]
9
- */
10
- export type Units = [string, number][]
11
-
12
- export function selectUnit(units: Units, value: number): [string, number] {
13
- let i = 0
14
- for (; i < units.length; i++) {
15
- if (Math.abs(units[i][1]) > Math.abs(value)) break
16
- }
17
- return units[Math.max(0, i - 1)]
18
- }
19
-
20
- export function parseValue(
21
- inputString: string,
22
- units?: string | Units,
23
- digit?: number,
24
- ): {
25
- rawValue: number
26
- formatValue: string
27
- unit: string
28
- } {
29
- const str = inputString.trim()
30
- if (!units || typeof units == 'string') {
31
- const m = str.match(/-?\d+(\.\d+)?/)
32
- let v = Number(m?.[0] ?? '0')
33
- v = isNaN(v) ? 0 : v
34
- return {
35
- rawValue: v,
36
- formatValue: (digit != undefined ? v.toFixed(digit) : v) + (units ?? ''),
37
- unit: units ?? '',
38
- }
39
- }
40
-
41
- const unitList = units.map(([u, _s]) => u)
42
- const scaleList = units.map(([_u, s]) => s)
43
- let rawValue = 0
44
- let unit = unitList[0]
45
- let formatValue =
46
- (digit != undefined ? rawValue.toFixed(digit) : rawValue) + unit
47
- const m = str.match(/^(-?\d+(\.\d+)?)\s*(\w*)$/)
48
- if (m) {
49
- rawValue = Number(m[1]) || 0
50
- const uIndex = unitList.indexOf(m[3])
51
- rawValue *= uIndex != -1 ? scaleList[uIndex] : 1
52
- const [u, scale] = selectUnit(units, rawValue)
53
- const v = rawValue / scale
54
- formatValue = (digit != undefined ? v.toFixed(digit) : v) + u
55
- unit = u
56
- }
57
- return {
58
- rawValue: rawValue,
59
- formatValue: formatValue,
60
- unit: unit,
61
- }
62
- }
@@ -1,30 +0,0 @@
1
- /**
2
- * @module Slider
3
- */
4
-
5
- import { decimalPart, toFixed } from '../../math'
6
-
7
- export type ScaleType = 'mark' | 'mark-number' | 'number'
8
- export type ScaleOptions = ['step', ScaleType] | [number, ScaleType]
9
-
10
- export function generateOptionsList(
11
- options: ScaleOptions,
12
- min: number,
13
- max: number,
14
- step: number,
15
- ) {
16
- const optionsList: {
17
- value: number
18
- type: ScaleType
19
- }[] = []
20
- const per = options[0] == 'step' ? step : options[0]
21
- const count = Math.floor(max / per) - Math.ceil(min / per) + 1
22
- for (let i = 0; i < count; i++) {
23
- const value = toFixed(
24
- per * (Math.ceil(min / per) + i),
25
- decimalPart(per)?.length,
26
- )
27
- optionsList.push({ value: value, type: options[1] })
28
- }
29
- return optionsList
30
- }