@cutoff/audio-ui-core 1.0.0-preview.20260123.1125

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.
Files changed (48) hide show
  1. package/LICENSE.md +690 -0
  2. package/dist/constants/cssVars.d.ts +42 -0
  3. package/dist/constants/cssVars.d.ts.map +1 -0
  4. package/dist/constants/cursors.d.ts +2 -0
  5. package/dist/constants/cursors.d.ts.map +1 -0
  6. package/dist/constants/interaction.d.ts +24 -0
  7. package/dist/constants/interaction.d.ts.map +1 -0
  8. package/dist/constants/styles.d.ts +17 -0
  9. package/dist/constants/styles.d.ts.map +1 -0
  10. package/dist/constants/theme.d.ts +66 -0
  11. package/dist/constants/theme.d.ts.map +1 -0
  12. package/dist/constants/themeDefaults.d.ts +16 -0
  13. package/dist/constants/themeDefaults.d.ts.map +1 -0
  14. package/dist/controller/BooleanInteractionController.d.ts +141 -0
  15. package/dist/controller/BooleanInteractionController.d.ts.map +1 -0
  16. package/dist/controller/ContinuousInteractionController.d.ts +114 -0
  17. package/dist/controller/ContinuousInteractionController.d.ts.map +1 -0
  18. package/dist/controller/DiscreteInteractionController.d.ts +51 -0
  19. package/dist/controller/DiscreteInteractionController.d.ts.map +1 -0
  20. package/dist/controller/NoteInteractionController.d.ts +88 -0
  21. package/dist/controller/NoteInteractionController.d.ts.map +1 -0
  22. package/dist/index.d.ts +21 -0
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +1404 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/model/AudioParameter.d.ts +437 -0
  27. package/dist/model/AudioParameter.d.ts.map +1 -0
  28. package/dist/styles/styles.css +256 -0
  29. package/dist/styles/themes.css +193 -0
  30. package/dist/types.d.ts +18 -0
  31. package/dist/types.d.ts.map +1 -0
  32. package/dist/utils/colorUtils.d.ts +102 -0
  33. package/dist/utils/colorUtils.d.ts.map +1 -0
  34. package/dist/utils/math.d.ts +108 -0
  35. package/dist/utils/math.d.ts.map +1 -0
  36. package/dist/utils/normalizedProps.d.ts +22 -0
  37. package/dist/utils/normalizedProps.d.ts.map +1 -0
  38. package/dist/utils/noteUtils.d.ts +71 -0
  39. package/dist/utils/noteUtils.d.ts.map +1 -0
  40. package/dist/utils/propCompare.d.ts +22 -0
  41. package/dist/utils/propCompare.d.ts.map +1 -0
  42. package/dist/utils/sizing.d.ts +39 -0
  43. package/dist/utils/sizing.d.ts.map +1 -0
  44. package/dist/utils/svg.d.ts +27 -0
  45. package/dist/utils/svg.d.ts.map +1 -0
  46. package/dist/utils/valueFormatters.d.ts +167 -0
  47. package/dist/utils/valueFormatters.d.ts.map +1 -0
  48. package/package.json +48 -0
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Collection of reusable value formatters for control components
3
+ */
4
+ /**
5
+ * Calculates the center value for a range according to MIDI conventions.
6
+ *
7
+ * This is used for bipolar controls (pan, modulation depth) where the center point
8
+ * represents zero or neutral. The formula ensures proper centering for both even
9
+ * and odd ranges.
10
+ *
11
+ * @param min The minimum value
12
+ * @param max The maximum value
13
+ * @returns The center value according to MIDI conventions (floor((max - min + 1) / 2) + min)
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * calculateCenterValue(-64, 63); // 0 (bipolar 7-bit MIDI)
18
+ * calculateCenterValue(0, 100); // 50
19
+ * ```
20
+ */
21
+ export declare const calculateCenterValue: (min: number, max: number) => number;
22
+ /**
23
+ * Formats a value with a bipolar display (adds + sign for positive values).
24
+ *
25
+ * This is useful for displaying values that can be positive or negative, such as
26
+ * pan controls or modulation depth. Zero and negative values are displayed as-is,
27
+ * while positive values get a "+" prefix.
28
+ *
29
+ * @param value The value to format
30
+ * @returns Formatted string with + prefix for positive values
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * bipolarFormatter(50); // "+50"
35
+ * bipolarFormatter(-50); // "-50"
36
+ * bipolarFormatter(0); // "0"
37
+ * ```
38
+ */
39
+ export declare const bipolarFormatter: (value: number) => string;
40
+ /**
41
+ * Formats a value with MIDI bipolar convention (shifts value by center value).
42
+ *
43
+ * This formatter is designed for MIDI-style bipolar parameters where the raw value
44
+ * is in the range [min, max], but you want to display it as an offset from center.
45
+ * For example, a pan control with range [0, 127] centered at 64 would display as
46
+ * "+3" when the value is 67.
47
+ *
48
+ * @param value The value to format
49
+ * @param min The minimum value
50
+ * @param max The maximum value
51
+ * @returns Formatted string with the value shifted by center value
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * midiBipolarFormatter(67, 0, 127); // "+3" (67 - 64 = 3)
56
+ * midiBipolarFormatter(60, 0, 127); // "-4" (60 - 64 = -4)
57
+ * ```
58
+ */
59
+ export declare const midiBipolarFormatter: (value: number, min: number, max: number) => string;
60
+ /**
61
+ * Creates a formatter function that appends a unit suffix to values.
62
+ *
63
+ * This is a higher-order function that returns a formatter. Useful for creating
64
+ * reusable formatters for parameters with units (dB, Hz, ms, etc.).
65
+ *
66
+ * @param unit The unit to append (e.g., "dB", "Hz", "ms")
67
+ * @returns A formatter function that appends the unit
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * const dbFormatter = withUnit("dB");
72
+ * dbFormatter(-6.0); // "-6.0dB"
73
+ *
74
+ * // Can be combined with other formatters
75
+ * const formatter = combineFormatters(withPrecision(1), withUnit("Hz"));
76
+ * formatter(440.5); // "440.5Hz"
77
+ * ```
78
+ */
79
+ export declare const withUnit: (unit: string) => (value: number) => string;
80
+ /**
81
+ * Creates a formatter function that formats values with fixed decimal precision.
82
+ *
83
+ * This is a higher-order function that returns a formatter. Useful for ensuring
84
+ * consistent decimal display across your application.
85
+ *
86
+ * @param precision Number of decimal places (0-20)
87
+ * @returns A formatter function that formats with the specified precision
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * const twoDecimals = withPrecision(2);
92
+ * twoDecimals(3.14159); // "3.14"
93
+ *
94
+ * // Can be combined with other formatters
95
+ * const formatter = combineFormatters(withPrecision(1), withUnit("dB"));
96
+ * formatter(-6.02); // "-6.0dB"
97
+ * ```
98
+ */
99
+ export declare const withPrecision: (precision: number) => (value: number) => string;
100
+ /**
101
+ * Combines multiple formatters into a single formatter function.
102
+ *
103
+ * Formatters are applied in sequence, with each formatter receiving the output
104
+ * of the previous one (after parsing back to a number if needed). This allows
105
+ * you to compose complex formatting pipelines.
106
+ *
107
+ * @param formatters Array of formatter functions to apply in sequence
108
+ * @returns A formatter function that applies all formatters in sequence
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * // Combine precision and unit formatting
113
+ * const formatter = combineFormatters(
114
+ * withPrecision(1),
115
+ * withUnit("dB")
116
+ * );
117
+ * formatter(-6.02); // "-6.0dB"
118
+ *
119
+ * // Combine multiple transformations
120
+ * const complexFormatter = combineFormatters(
121
+ * (v) => (v * 100).toString(), // Convert to percentage
122
+ * withUnit("%")
123
+ * );
124
+ * complexFormatter(0.5); // "50%"
125
+ * ```
126
+ */
127
+ export declare const combineFormatters: (...formatters: ((value: number, min?: number, max?: number) => string)[]) => (value: number, min?: number, max?: number) => string;
128
+ /**
129
+ * Formats a value as a percentage based on its position in the min-max range.
130
+ *
131
+ * The percentage is calculated as: ((value - min) / (max - min)) * 100
132
+ * and rounded to the nearest integer.
133
+ *
134
+ * @param value The value to format
135
+ * @param min The minimum value (corresponds to 0%)
136
+ * @param max The maximum value (corresponds to 100%)
137
+ * @returns Formatted percentage string (e.g., "50%")
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * percentageFormatter(50, 0, 100); // "50%"
142
+ * percentageFormatter(25, 0, 100); // "25%"
143
+ * percentageFormatter(75, 0, 200); // "38%" (75/200 = 37.5%, rounded to 38%)
144
+ * ```
145
+ */
146
+ export declare const percentageFormatter: (value: number, min: number, max: number) => string;
147
+ /**
148
+ * Formats a frequency value with appropriate units (Hz or kHz).
149
+ *
150
+ * Values >= 1000 Hz are displayed in kHz with one decimal place.
151
+ * Values < 1000 Hz are displayed in Hz as integers.
152
+ *
153
+ * This is optimized for audio frequency display where values can range from
154
+ * sub-audio (20 Hz) to ultrasonic (20 kHz+).
155
+ *
156
+ * @param value The frequency value in Hz
157
+ * @returns Formatted string with appropriate units (Hz, kHz)
158
+ *
159
+ * @example
160
+ * ```ts
161
+ * frequencyFormatter(440); // "440Hz"
162
+ * frequencyFormatter(1000); // "1.0kHz"
163
+ * frequencyFormatter(15000); // "15.0kHz"
164
+ * ```
165
+ */
166
+ export declare const frequencyFormatter: (value: number) => string;
167
+ //# sourceMappingURL=valueFormatters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valueFormatters.d.ts","sourceRoot":"","sources":["../../src/utils/valueFormatters.ts"],"names":[],"mappings":"AAMA;;GAEG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,MAE/D,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,KAAG,MAEhD,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,oBAAoB,GAAI,OAAO,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,MAI9E,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,MACzB,OAAO,MAAM,KAAG,MAC3B,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,GAAI,WAAW,MAAM,MACnC,OAAO,MAAM,KAAG,MAC3B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,iBAAiB,GAAI,GAAG,YAAY,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC,EAAE,MAC9F,OAAO,MAAM,EAAE,MAAM,MAAM,EAAE,MAAM,MAAM,KAAG,MAgBvD,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,MAAM,EAAE,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,MAG7E,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,MAKlD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@cutoff/audio-ui-core",
3
+ "version": "1.0.0-preview.20260123.1125",
4
+ "description": "Core logic and models for AudioUI by Cutoff",
5
+ "private": false,
6
+ "author": "Renaud Denis <mail@renauddenis.com> (https://renauddenis.com)",
7
+ "license": "GPL-3.0-only",
8
+ "type": "module",
9
+ "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "sideEffects": [
12
+ "**/*.css"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/index.js",
17
+ "types": "./dist/index.d.ts"
18
+ },
19
+ "./styles.css": "./dist/styles/styles.css",
20
+ "./themes.css": "./dist/styles/themes.css"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "dependencies": {
29
+ "fast-deep-equal": "^3.1.3"
30
+ },
31
+ "devDependencies": {
32
+ "jsdom": "^24.1.3",
33
+ "typescript": "^5.9.3",
34
+ "vite": "^5.4.21",
35
+ "vite-plugin-dts": "^3.9.1",
36
+ "vitest": "^1.6.1"
37
+ },
38
+ "scripts": {
39
+ "build": "pnpm exec vite build",
40
+ "typecheck": "tsc --noEmit",
41
+ "test": "vitest run",
42
+ "test:watch": "vitest",
43
+ "test:coverage": "vitest run --coverage",
44
+ "lint": "eslint \"src/**/*.ts\"",
45
+ "lint:fix": "eslint \"src/**/*.ts\" --fix || true",
46
+ "clean": "rm -rf node_modules dist .turbo"
47
+ }
48
+ }