@tremolo-ui/functions 0.0.4
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/README.md +11 -0
- package/dist/cjs/components/NumberInput/type.js +82 -0
- package/dist/cjs/components/NumberInput/type.js.map +1 -0
- package/dist/cjs/components/NumberInput/types/components/NumberInput/type.d.ts +14 -0
- package/dist/cjs/components/NumberInput/types/components/NumberInput/type.d.ts.map +1 -0
- package/dist/cjs/components/NumberInput/types/components/Slider/type.d.ts +32 -0
- package/dist/cjs/components/NumberInput/types/components/Slider/type.d.ts.map +1 -0
- package/dist/cjs/components/NumberInput/types/index.d.ts +4 -0
- package/dist/cjs/components/NumberInput/types/index.d.ts.map +1 -0
- package/dist/cjs/components/NumberInput/types/math.d.ts +12 -0
- package/dist/cjs/components/NumberInput/types/math.d.ts.map +1 -0
- package/dist/cjs/components/NumberInput/types/types.d.ts +2 -0
- package/dist/cjs/components/NumberInput/types/types.d.ts.map +1 -0
- package/dist/cjs/components/NumberInput/types/util.d.ts +6 -0
- package/dist/cjs/components/NumberInput/types/util.d.ts.map +1 -0
- package/dist/cjs/components/Slider/type.js +50 -0
- package/dist/cjs/components/Slider/type.js.map +1 -0
- package/dist/cjs/components/Slider/types/components/NumberInput/type.d.ts +14 -0
- package/dist/cjs/components/Slider/types/components/NumberInput/type.d.ts.map +1 -0
- package/dist/cjs/components/Slider/types/components/Slider/type.d.ts +32 -0
- package/dist/cjs/components/Slider/types/components/Slider/type.d.ts.map +1 -0
- package/dist/cjs/components/Slider/types/index.d.ts +4 -0
- package/dist/cjs/components/Slider/types/index.d.ts.map +1 -0
- package/dist/cjs/components/Slider/types/math.d.ts +12 -0
- package/dist/cjs/components/Slider/types/math.d.ts.map +1 -0
- package/dist/cjs/components/Slider/types/types.d.ts +2 -0
- package/dist/cjs/components/Slider/types/types.d.ts.map +1 -0
- package/dist/cjs/components/Slider/types/util.d.ts +6 -0
- package/dist/cjs/components/Slider/types/util.d.ts.map +1 -0
- package/dist/cjs/index.js +96 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types/components/NumberInput/type.d.ts +14 -0
- package/dist/cjs/types/components/NumberInput/type.d.ts.map +1 -0
- package/dist/cjs/types/components/Slider/type.d.ts +32 -0
- package/dist/cjs/types/components/Slider/type.d.ts.map +1 -0
- package/dist/cjs/types/index.d.ts +4 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/math.d.ts +12 -0
- package/dist/cjs/types/math.d.ts.map +1 -0
- package/dist/cjs/types/types.d.ts +2 -0
- package/dist/cjs/types/types.d.ts.map +1 -0
- package/dist/cjs/types/util.d.ts +6 -0
- package/dist/cjs/types/util.d.ts.map +1 -0
- package/dist/esm/components/NumberInput/type.js +78 -0
- package/dist/esm/components/NumberInput/type.js.map +1 -0
- package/dist/esm/components/NumberInput/types/components/NumberInput/type.d.ts +14 -0
- package/dist/esm/components/NumberInput/types/components/NumberInput/type.d.ts.map +1 -0
- package/dist/esm/components/NumberInput/types/components/Slider/type.d.ts +32 -0
- package/dist/esm/components/NumberInput/types/components/Slider/type.d.ts.map +1 -0
- package/dist/esm/components/NumberInput/types/index.d.ts +4 -0
- package/dist/esm/components/NumberInput/types/index.d.ts.map +1 -0
- package/dist/esm/components/NumberInput/types/math.d.ts +12 -0
- package/dist/esm/components/NumberInput/types/math.d.ts.map +1 -0
- package/dist/esm/components/NumberInput/types/types.d.ts +2 -0
- package/dist/esm/components/NumberInput/types/types.d.ts.map +1 -0
- package/dist/esm/components/NumberInput/types/util.d.ts +6 -0
- package/dist/esm/components/NumberInput/types/util.d.ts.map +1 -0
- package/dist/esm/components/Slider/type.js +44 -0
- package/dist/esm/components/Slider/type.js.map +1 -0
- package/dist/esm/components/Slider/types/components/NumberInput/type.d.ts +14 -0
- package/dist/esm/components/Slider/types/components/NumberInput/type.d.ts.map +1 -0
- package/dist/esm/components/Slider/types/components/Slider/type.d.ts +32 -0
- package/dist/esm/components/Slider/types/components/Slider/type.d.ts.map +1 -0
- package/dist/esm/components/Slider/types/index.d.ts +4 -0
- package/dist/esm/components/Slider/types/index.d.ts.map +1 -0
- package/dist/esm/components/Slider/types/math.d.ts +12 -0
- package/dist/esm/components/Slider/types/math.d.ts.map +1 -0
- package/dist/esm/components/Slider/types/types.d.ts +2 -0
- package/dist/esm/components/Slider/types/types.d.ts.map +1 -0
- package/dist/esm/components/Slider/types/util.d.ts +6 -0
- package/dist/esm/components/Slider/types/util.d.ts.map +1 -0
- package/dist/esm/components/tsconfig.tsbuildinfo +1 -0
- package/dist/esm/index.js +82 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types/components/NumberInput/type.d.ts +14 -0
- package/dist/esm/types/components/NumberInput/type.d.ts.map +1 -0
- package/dist/esm/types/components/Slider/type.d.ts +32 -0
- package/dist/esm/types/components/Slider/type.d.ts.map +1 -0
- package/dist/esm/types/index.d.ts +4 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/math.d.ts +12 -0
- package/dist/esm/types/math.d.ts.map +1 -0
- package/dist/esm/types/types.d.ts +2 -0
- package/dist/esm/types/types.d.ts.map +1 -0
- package/dist/esm/types/util.d.ts +6 -0
- package/dist/esm/types/util.d.ts.map +1 -0
- package/package.json +68 -0
- package/src/components/NumberInput/type.ts +82 -0
- package/src/components/Slider/type.ts +82 -0
- package/src/index.ts +3 -0
- package/src/math.ts +71 -0
- package/src/types.ts +1 -0
- package/src/util.ts +34 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/math.ts","../../../src/util.ts"],"sourcesContent":[null,null],"names":[],"mappings":"SAAgB,KAAK,CAAC,KAAa,EAAE,GAAW,EAAE,GAAW,EAAA;AAC3D,IAAA,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC5C;AAEM,SAAU,cAAc,CAC5B,QAAgB,EAChB,GA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CAAC;AAC1C;;SC9DgB,WAAW,CACzB,KAAsB,EACtB,EAAa,EACb,UAAmB,EAAA;AAEnB,IAAA,IAAI,EAAE,IAAI,UAAU,EAAE;AACpB,QAAA,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE;YAC5B,IAAI,EAAE,IAAI,GAAG;AAAE,gBAAA,OAAO,CAAG,EAAA,KAAK,GAAG,UAAU,IAAI;YAC/C,IAAI,EAAE,IAAI,GAAG;AAAE,gBAAA,OAAO,CAAG,EAAA,KAAK,GAAG,UAAU,IAAI;YAC/C,IAAI,EAAE,IAAI,GAAG;AAAE,gBAAA,OAAO,CAAG,EAAA,KAAK,GAAG,UAAU,IAAI;YAC/C,IAAI,EAAE,IAAI,GAAG;AAAE,gBAAA,OAAO,CAAG,EAAA,KAAK,GAAG,UAAU,IAAI;;aAC1C;AACL,YAAA,OAAO,QAAQ,KAAK,CAAA,GAAA,EAAM,EAAE,CAAI,CAAA,EAAA,UAAU,GAAG;;;SAE1C;AACL,QAAA,IAAI,OAAO,KAAK,IAAI,QAAQ,EAAE;YAC5B,OAAO,CAAA,EAAG,KAAK,CAAA,EAAA,CAAI;;aACd;AACL,YAAA,OAAO,KAAK;;;AAGlB;AAEM,SAAU,OAAO,CAAC,GAAW,EAAA;IACjC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC;AACrC;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* [unit, scale][]
|
|
3
|
+
* @example
|
|
4
|
+
* [['Hz', 1], ['kHz', 1000]]
|
|
5
|
+
*/
|
|
6
|
+
export type Units = [string, number][];
|
|
7
|
+
export declare function selectUnit(units: Units, value: number): [string, number];
|
|
8
|
+
export declare function parseValue(inputString: string, units?: string | Units, digit?: number, defaultValue?: number): {
|
|
9
|
+
rawValue: number;
|
|
10
|
+
formatValue: string;
|
|
11
|
+
unit: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function formatValue(value: number, units?: string | Units): string;
|
|
14
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../../../src/components/NumberInput/type.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAA;AAEtC,wBAAgB,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAQxE;AAED,wBAAgB,UAAU,CACxB,WAAW,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,EACtB,KAAK,CAAC,EAAE,MAAM,EACd,YAAY,SAAI;;;;EA6CjB;AAID,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,UAShE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type Horizontal = 'right' | 'left';
|
|
2
|
+
export type Vertical = 'up' | 'down';
|
|
3
|
+
export type Direction = Horizontal | Vertical;
|
|
4
|
+
export declare function isHorizontal(d: Direction): d is "right" | "left";
|
|
5
|
+
export declare function isVertical(d: Direction): d is "up" | "down";
|
|
6
|
+
export declare function isReversed(d: Direction): d is "left" | "up";
|
|
7
|
+
export declare function gradientDirection(d: Direction): "right" | "left" | "top" | "bottom" | undefined;
|
|
8
|
+
export type ScaleType = 'mark' | 'mark-number' | 'number';
|
|
9
|
+
export type ScaleOrderList = {
|
|
10
|
+
at: number;
|
|
11
|
+
type?: ScaleType;
|
|
12
|
+
text?: string;
|
|
13
|
+
style?: {
|
|
14
|
+
markColor?: string;
|
|
15
|
+
labelColor?: string;
|
|
16
|
+
length?: number | string;
|
|
17
|
+
thickness?: number | string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export declare function parseScaleOrderList(scale: ['step', ScaleType] | [number, ScaleType] | ScaleOrderList[] | undefined, min: number, max: number, step: number): ScaleOrderList[];
|
|
21
|
+
export type ScaleOption = {
|
|
22
|
+
/**
|
|
23
|
+
* @default 'mark-number'
|
|
24
|
+
*/
|
|
25
|
+
defaultType?: ScaleType;
|
|
26
|
+
markColor?: string;
|
|
27
|
+
labelColor?: string;
|
|
28
|
+
gap?: number | string;
|
|
29
|
+
labelWidth?: number | string;
|
|
30
|
+
style?: unknown;
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../../../src/components/Slider/type.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,CAAA;AACzC,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,MAAM,CAAA;AACpC,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAA;AAE7C,wBAAgB,YAAY,CAAC,CAAC,EAAE,SAAS,yBAExC;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,SAAS,sBAEtC;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,SAAS,sBAEtC;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,SAAS,mDAI7C;AAID,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,aAAa,GAAG,QAAQ,CAAA;AACzD,MAAM,MAAM,cAAc,GAAG;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE;QACN,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,UAAU,CAAC,EAAE,MAAM,CAAA;QACnB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;QACxB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAC5B,CAAA;CACF,CAAA;AAED,wBAAgB,mBAAmB,CACjC,KAAK,EACD,CAAC,MAAM,EAAE,SAAS,CAAC,GACnB,CAAC,MAAM,EAAE,SAAS,CAAC,GACnB,cAAc,EAAE,GAChB,SAAS,EACb,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,oBAmBb;AAKD,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAA;AACtB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
2
|
+
export declare function normalizeValue(rawValue: number, min: number, max: number, skew?: number): number;
|
|
3
|
+
export declare function rawValue(normalizedValue: number, min: number, max: number, skew?: number): number;
|
|
4
|
+
export declare function skewWithCenterValue(centerValue: number, min: number, max: number): number;
|
|
5
|
+
export declare function stepValue(value: number, step: number): number;
|
|
6
|
+
export declare function toFixed(x: number, fractionDigits?: number): number;
|
|
7
|
+
export declare function decimalPart(x: number | string): string | undefined;
|
|
8
|
+
export declare function radian(degree: number): number;
|
|
9
|
+
export declare function degree(radian: number): number;
|
|
10
|
+
export declare function dbToGain(db: number): number;
|
|
11
|
+
export declare function gainToDb(gain: number): number;
|
|
12
|
+
//# sourceMappingURL=math.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.ts","sourceRoot":"","sources":["../../../src/math.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,UAE5D;AAED,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,IAAI,SAAI,UAKT;AAED,wBAAgB,QAAQ,CACtB,eAAe,EAAE,MAAM,EACvB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,IAAI,SAAI,UAQT;AAED,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EACnB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,UAKZ;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAOpD;AAED,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM,UAEzD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAElE;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,UAEpC;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,MAAM,UAEpC;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,UAElC;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,UAEpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,CAAC,YAAY,GAAG,KAAK,EAAE,MAAM,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
type Operator = '+' | '-' | '*' | '/';
|
|
2
|
+
export declare function styleHelper(value: string | number): string;
|
|
3
|
+
export declare function styleHelper(value: string | number, op: Operator, influencer?: number): string;
|
|
4
|
+
export declare function isEmpty(obj: object): boolean;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/util.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;AAErC,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;AAC3D,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,GAAG,MAAM,EACtB,EAAE,EAAE,QAAQ,EACZ,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAAA;AAwBT,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,WAElC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tremolo-ui/functions",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "functions used in @tremolo-ui/react",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest",
|
|
8
|
+
"build:package": "rollup -c",
|
|
9
|
+
"clean": "npm run clean:build",
|
|
10
|
+
"clean:build": "rimraf ./dist .rollup.cache",
|
|
11
|
+
"lint": "eslint --fix --ext .ts,.tsx .",
|
|
12
|
+
"format": "prettier --write ."
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"require": {
|
|
17
|
+
"default": "./dist/cjs/index.js",
|
|
18
|
+
"types": "./dist/cjs/types/index.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"import": {
|
|
21
|
+
"default": "./dist/esm/index.js",
|
|
22
|
+
"types": "./dist/esm/types/index.d.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"./NumberInput": {
|
|
26
|
+
"require": {
|
|
27
|
+
"default": "./dist/cjs/components/NumberInput/type.js",
|
|
28
|
+
"types": "./dist/cjs/types/components/NumberInput/type.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"import": {
|
|
31
|
+
"default": "./dist/esm/components/NumberInput/type.js",
|
|
32
|
+
"types": "./dist/esm/types/components/NumberInput/type.d.ts"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"./Slider": {
|
|
36
|
+
"require": {
|
|
37
|
+
"default": "./dist/cjs/components/Slider/type.js",
|
|
38
|
+
"types": "./dist/cjs/types/components/Slider/type.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"import": {
|
|
41
|
+
"default": "./dist/esm/components/Slider/type.js",
|
|
42
|
+
"types": "./dist/esm/types/components/Slider/type.d.ts"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"src"
|
|
49
|
+
],
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"author": {
|
|
54
|
+
"name": "mimoz",
|
|
55
|
+
"email": "contact.m1m0zzz@gmail.com"
|
|
56
|
+
},
|
|
57
|
+
"license": "MIT",
|
|
58
|
+
"homepage": "https://github.com/m1m0zzz/tremolo-ui",
|
|
59
|
+
"repository": {
|
|
60
|
+
"type": "git",
|
|
61
|
+
"url": "https://github.com/m1m0zzz/tremolo-ui",
|
|
62
|
+
"directory": "packages/functions"
|
|
63
|
+
},
|
|
64
|
+
"keywords": [
|
|
65
|
+
"web-audio",
|
|
66
|
+
"math"
|
|
67
|
+
]
|
|
68
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { toFixed } from '../../math'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* [unit, scale][]
|
|
5
|
+
* @example
|
|
6
|
+
* [['Hz', 1], ['kHz', 1000]]
|
|
7
|
+
*/
|
|
8
|
+
export type Units = [string, number][]
|
|
9
|
+
|
|
10
|
+
export function selectUnit(units: Units, value: number): [string, number] {
|
|
11
|
+
if (typeof units == 'string') return [units, 1]
|
|
12
|
+
|
|
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
|
+
defaultValue = 0,
|
|
25
|
+
) {
|
|
26
|
+
let str = inputString.trim()
|
|
27
|
+
if (str == '') str = String(defaultValue)
|
|
28
|
+
if (!units) {
|
|
29
|
+
return {
|
|
30
|
+
rawValue: Number(str) || defaultValue,
|
|
31
|
+
formatValue: str,
|
|
32
|
+
unit: '',
|
|
33
|
+
}
|
|
34
|
+
} else if (typeof units == 'string') {
|
|
35
|
+
return {
|
|
36
|
+
rawValue: Number(str) || defaultValue,
|
|
37
|
+
formatValue: `${str}${units}`,
|
|
38
|
+
unit: units,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const unitList = units.map(([u, _s]) => u)
|
|
43
|
+
const scaleList = units.map(([_u, s]) => s)
|
|
44
|
+
let rawValue = defaultValue
|
|
45
|
+
let formatValue = `${scaleList[0]}`
|
|
46
|
+
let unit = unitList[0]
|
|
47
|
+
const m = str.match(/^(-?\d+(\.\d+)?)\s*(\w*)$/)
|
|
48
|
+
if (m) {
|
|
49
|
+
rawValue = Number(m[1]) || 0
|
|
50
|
+
const inputUnit = m[3]
|
|
51
|
+
if (inputUnit != '' && unitList.indexOf(inputUnit) != -1) {
|
|
52
|
+
rawValue *= scaleList[unitList.indexOf(inputUnit)]
|
|
53
|
+
const s = selectUnit(units, rawValue)
|
|
54
|
+
const v = rawValue / s[1]
|
|
55
|
+
formatValue = `${digit != undefined ? toFixed(v, digit) : v}${s[0]}`
|
|
56
|
+
unit = s[0]
|
|
57
|
+
} else {
|
|
58
|
+
const [u, scale] = selectUnit(units, rawValue)
|
|
59
|
+
const v = rawValue / scale
|
|
60
|
+
formatValue = `${digit != undefined ? toFixed(v, digit) : v}${u}`
|
|
61
|
+
unit = u
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
rawValue: rawValue,
|
|
66
|
+
formatValue: formatValue,
|
|
67
|
+
unit: unit,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// TODO: toFixed 以外のフォーマット手法
|
|
72
|
+
// e.g. 小数点第n位
|
|
73
|
+
export function formatValue(value: number, units?: string | Units) {
|
|
74
|
+
if (!units) {
|
|
75
|
+
return `${value}`
|
|
76
|
+
} else if (typeof units == 'string') {
|
|
77
|
+
return `${value}${units}`
|
|
78
|
+
} else {
|
|
79
|
+
const [unit, scale] = selectUnit(units, value)
|
|
80
|
+
return `${toFixed(value / scale)}${unit}`
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { decimalPart, toFixed } from '../../math'
|
|
2
|
+
|
|
3
|
+
export type Horizontal = 'right' | 'left'
|
|
4
|
+
export type Vertical = 'up' | 'down'
|
|
5
|
+
export type Direction = Horizontal | Vertical
|
|
6
|
+
|
|
7
|
+
export function isHorizontal(d: Direction) {
|
|
8
|
+
return d == 'right' || d == 'left'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isVertical(d: Direction) {
|
|
12
|
+
return d == 'up' || d == 'down'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isReversed(d: Direction) {
|
|
16
|
+
return d == 'left' || d == 'up'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function gradientDirection(d: Direction) {
|
|
20
|
+
if (d == 'left' || d == 'right') return d
|
|
21
|
+
if (d == 'up') return 'top'
|
|
22
|
+
if (d == 'down') return 'bottom'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// export type SkewFunction = (x: number) => number
|
|
26
|
+
|
|
27
|
+
export type ScaleType = 'mark' | 'mark-number' | 'number'
|
|
28
|
+
export type ScaleOrderList = {
|
|
29
|
+
at: number
|
|
30
|
+
type?: ScaleType
|
|
31
|
+
text?: string
|
|
32
|
+
style?: {
|
|
33
|
+
markColor?: string
|
|
34
|
+
labelColor?: string
|
|
35
|
+
length?: number | string
|
|
36
|
+
thickness?: number | string
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function parseScaleOrderList(
|
|
41
|
+
scale:
|
|
42
|
+
| ['step', ScaleType]
|
|
43
|
+
| [number, ScaleType]
|
|
44
|
+
| ScaleOrderList[]
|
|
45
|
+
| undefined,
|
|
46
|
+
min: number,
|
|
47
|
+
max: number,
|
|
48
|
+
step: number,
|
|
49
|
+
) {
|
|
50
|
+
let scalesList: ScaleOrderList[] = []
|
|
51
|
+
if (!scale) {
|
|
52
|
+
// return empty array
|
|
53
|
+
} else if (typeof scale[0] == 'object') {
|
|
54
|
+
scalesList = scale
|
|
55
|
+
} else {
|
|
56
|
+
const per = scale[0] == 'step' ? step : scale[0]
|
|
57
|
+
const count = Math.floor(max / per) - Math.ceil(min / per) + 1
|
|
58
|
+
for (let i = 0; i < count; i++) {
|
|
59
|
+
const at = toFixed(
|
|
60
|
+
per * (Math.ceil(min / per) + i),
|
|
61
|
+
decimalPart(per)?.length,
|
|
62
|
+
)
|
|
63
|
+
scalesList.push({ at: at, type: scale[1] })
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return scalesList
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// TODO: anyにして、それぞれのプロジェクトにあった方法にオーバーライドする
|
|
70
|
+
// style
|
|
71
|
+
|
|
72
|
+
export type ScaleOption = {
|
|
73
|
+
/**
|
|
74
|
+
* @default 'mark-number'
|
|
75
|
+
*/
|
|
76
|
+
defaultType?: ScaleType
|
|
77
|
+
markColor?: string
|
|
78
|
+
labelColor?: string
|
|
79
|
+
gap?: number | string
|
|
80
|
+
labelWidth?: number | string
|
|
81
|
+
style?: unknown
|
|
82
|
+
}
|
package/src/index.ts
ADDED
package/src/math.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export function clamp(value: number, min: number, max: number) {
|
|
2
|
+
return Math.max(min, Math.min(value, max))
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function normalizeValue(
|
|
6
|
+
rawValue: number,
|
|
7
|
+
min: number,
|
|
8
|
+
max: number,
|
|
9
|
+
skew = 1,
|
|
10
|
+
) {
|
|
11
|
+
if (min >= max) throw new RangeError('requirements: min < max')
|
|
12
|
+
const v = clamp((rawValue - min) / (max - min), 0, 1)
|
|
13
|
+
return Math.pow(v, skew)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function rawValue(
|
|
17
|
+
normalizedValue: number,
|
|
18
|
+
min: number,
|
|
19
|
+
max: number,
|
|
20
|
+
skew = 1,
|
|
21
|
+
) {
|
|
22
|
+
if (min >= max) throw new RangeError('requirements: min < max')
|
|
23
|
+
const v =
|
|
24
|
+
skew == 1
|
|
25
|
+
? clamp(normalizedValue, 0, 1)
|
|
26
|
+
: Math.exp(Math.log(clamp(normalizedValue, 0, 1)) / skew)
|
|
27
|
+
return min + v * (max - min)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function skewWithCenterValue(
|
|
31
|
+
centerValue: number,
|
|
32
|
+
min: number,
|
|
33
|
+
max: number,
|
|
34
|
+
) {
|
|
35
|
+
if (!(min <= centerValue && centerValue <= max))
|
|
36
|
+
throw new RangeError('requirements: min <= centerValue <= max')
|
|
37
|
+
return Math.log(0.5) / Math.log((centerValue - min) / (max - min))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function stepValue(value: number, step: number) {
|
|
41
|
+
if (step <= 0) throw new RangeError('requirements: step > 0')
|
|
42
|
+
const quotient = Math.floor(value / step)
|
|
43
|
+
const decimalDigits = decimalPart(step)?.length
|
|
44
|
+
const v = toFixed(quotient * step, decimalDigits)
|
|
45
|
+
const next = toFixed((quotient + 1) * step, decimalDigits)
|
|
46
|
+
return Math.abs(value - v) < Math.abs(value - next) ? v : next
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function toFixed(x: number, fractionDigits?: number) {
|
|
50
|
+
return Number(x.toFixed(fractionDigits))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function decimalPart(x: number | string): string | undefined {
|
|
54
|
+
return String(x).split('.')[1]
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function radian(degree: number) {
|
|
58
|
+
return (Math.PI * degree) / 180
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function degree(radian: number) {
|
|
62
|
+
return (180 * radian) / Math.PI
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function dbToGain(db: number) {
|
|
66
|
+
return Math.pow(10, db / 20)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function gainToDb(gain: number) {
|
|
70
|
+
return 20 * (Math.log(gain) / Math.LN10)
|
|
71
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type WheelOption = ['normalized' | 'raw', number]
|
package/src/util.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
type Operator = '+' | '-' | '*' | '/'
|
|
2
|
+
|
|
3
|
+
export function styleHelper(value: string | number): string
|
|
4
|
+
export function styleHelper(
|
|
5
|
+
value: string | number,
|
|
6
|
+
op: Operator,
|
|
7
|
+
influencer?: number,
|
|
8
|
+
): string
|
|
9
|
+
export function styleHelper(
|
|
10
|
+
value: string | number,
|
|
11
|
+
op?: Operator,
|
|
12
|
+
influencer?: number,
|
|
13
|
+
) {
|
|
14
|
+
if (op && influencer) {
|
|
15
|
+
if (typeof value == 'number') {
|
|
16
|
+
if (op == '+') return `${value + influencer}px`
|
|
17
|
+
if (op == '-') return `${value - influencer}px`
|
|
18
|
+
if (op == '*') return `${value * influencer}px`
|
|
19
|
+
if (op == '/') return `${value / influencer}px`
|
|
20
|
+
} else {
|
|
21
|
+
return `calc(${value}px ${op} ${influencer})`
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
if (typeof value == 'number') {
|
|
25
|
+
return `${value}px`
|
|
26
|
+
} else {
|
|
27
|
+
return value
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isEmpty(obj: object) {
|
|
33
|
+
return Object.keys(obj).length == 0
|
|
34
|
+
}
|