zds-pickers 4.0.5 → 4.0.6

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 (74) hide show
  1. package/.editorconfig +19 -0
  2. package/.github/workflows/codeql-analysis.yml +67 -0
  3. package/.nvmrc +1 -0
  4. package/.prettierignore +0 -0
  5. package/.prettierrc +13 -0
  6. package/.storybook/main.ts +42 -0
  7. package/.storybook/manager.ts +12 -0
  8. package/.storybook/preview.tsx +26 -0
  9. package/.vscode/extensions.json +32 -0
  10. package/.vscode/javascript.code-snippets +229 -0
  11. package/.vscode/settings.json +358 -0
  12. package/biome.jsonc +158 -0
  13. package/dist/index.es.js +3 -1
  14. package/dist/types/index.d.ts +266 -2
  15. package/dist/types/pickers/CCPicker.d.ts +2 -1
  16. package/dist/types/pickers/ChannelMappingPicker.d.ts +2 -1
  17. package/dist/types/pickers/ChannelPicker.d.ts +5 -3
  18. package/dist/types/pickers/LatchPicker.d.ts +5 -3
  19. package/dist/types/pickers/MappingPicker.d.ts +2 -1
  20. package/dist/types/pickers/NotePicker.d.ts +2 -1
  21. package/dist/types/pickers/PolarityPicker.d.ts +6 -4
  22. package/dist/types/pickers/ResponseCurve.d.ts +14 -5
  23. package/dist/types/pickers/ResponseCurvePicker.d.ts +6 -4
  24. package/dist/types/pickers/StatusPicker.d.ts +2 -1
  25. package/dist/types/pickers/ValuePicker.d.ts +2 -1
  26. package/lib/@types/nebiru-react-rotary-knob.d.ts +20 -0
  27. package/lib/@types/react-svgmt.d.ts +74 -0
  28. package/lib/@types/zds-mappings.d.ts +55 -0
  29. package/lib/@types/zds-react-piano.d.ts +17 -0
  30. package/lib/hooks/useComponentSize.ts +52 -0
  31. package/lib/hooks/useStateWithDynamicDefault.ts +13 -0
  32. package/lib/main.ts +34 -0
  33. package/lib/midi/ccValues.ts +139 -0
  34. package/lib/midi/export.ts +54 -0
  35. package/lib/other/DefaultTooltip.ts +14 -0
  36. package/lib/other/OctavePlayer.tsx +141 -0
  37. package/lib/other/SVGText.tsx +221 -0
  38. package/lib/other/SoundFontProvider.tsx +130 -0
  39. package/lib/pickers/CCPicker.tsx +28 -0
  40. package/lib/pickers/ChannelMappingPicker.tsx +135 -0
  41. package/lib/pickers/ChannelPicker.tsx +76 -0
  42. package/lib/pickers/Knob.tsx +93 -0
  43. package/lib/pickers/KnobPicker.tsx +93 -0
  44. package/lib/pickers/LatchPicker.tsx +33 -0
  45. package/lib/pickers/MappingPicker.tsx +68 -0
  46. package/lib/pickers/NotePicker.tsx +95 -0
  47. package/lib/pickers/PianoPicker.tsx +77 -0
  48. package/lib/pickers/PolarityPicker.tsx +39 -0
  49. package/lib/pickers/ResponseCurve.tsx +304 -0
  50. package/lib/pickers/ResponseCurvePicker.tsx +74 -0
  51. package/lib/pickers/Select.tsx +248 -0
  52. package/lib/pickers/StatusPicker.tsx +28 -0
  53. package/lib/pickers/ValuePicker.tsx +67 -0
  54. package/lib/pickers/knobSkin10.tsx +94 -0
  55. package/lib/rotaryKnob/InternalInput.tsx +43 -0
  56. package/lib/rotaryKnob/Types.ts +6 -0
  57. package/lib/rotaryKnob/helpers/DrawCircle.tsx +41 -0
  58. package/lib/rotaryKnob/helpers/DrawLine.tsx +32 -0
  59. package/lib/rotaryKnob/helpers/HelpersOverlay.tsx +43 -0
  60. package/lib/rotaryKnob/helpers/KnobVisualHelpers.tsx +138 -0
  61. package/lib/rotaryKnob/index.tsx +417 -0
  62. package/lib/rotaryKnob/knobdefaultskin.ts +56 -0
  63. package/lib/rotaryKnob/utils.ts +112 -0
  64. package/lib/temp/acoustic_grand_piano-mp3.js +94 -0
  65. package/lib/utils.ts +41 -0
  66. package/package.json +2 -6
  67. package/stories/assets/sampleStyles.css +349 -0
  68. package/stories/assets/utils.js +7 -0
  69. package/stories/picker.stories.tsx +313 -0
  70. package/tsconfig.app.json +26 -0
  71. package/tsconfig.json +34 -0
  72. package/tsconfig.node.json +24 -0
  73. package/vite.config.ts +45 -0
  74. package/dist/index.d.ts +0 -244
@@ -0,0 +1,112 @@
1
+ /** Note on viewbox/width
2
+ * This methods only work when the pixels match the svg units.
3
+ * when the viewbox is changed, or width is set they won't return
4
+ * the correct results
5
+ */
6
+ /**
7
+ * Returns the global coordinates of a position given
8
+ * for a specific coordinate system
9
+ * @param {*} svgdoc
10
+ * @param {*} elem
11
+ * @param {*} x
12
+ * @param {*} y
13
+ */
14
+ // function toGlobalCoordinates(svgdoc: any, elem: any, x: number, y: number) {
15
+ // var offset = svgdoc.getBoundingClientRect()
16
+ // var matrix = elem.getScreenCTM()
17
+ // return {
18
+ // x: matrix.a * x + matrix.c * y + matrix.e - offset.left,
19
+ // y: matrix.b * x + matrix.d * y + matrix.f - offset.top,
20
+ // }
21
+ // }
22
+
23
+ /**
24
+ * Converts a global position to a local one
25
+ * @param {*} svgdoc
26
+ * @param {*} elem
27
+ * @param {*} x
28
+ * @param {*} y
29
+ */
30
+ // function toLocalCoordinates(svgdoc: any, elem: any, x: number, y: number) {
31
+ // const offset = svgdoc.getBoundingClientRect()
32
+ // const matrix = elem.getScreenCTM().inverse()
33
+ // return {
34
+ // x: matrix.a * x + matrix.c * y + matrix.e - offset.left,
35
+ // y: matrix.b * x + matrix.d * y + matrix.f - offset.top,
36
+ // }
37
+ // }
38
+
39
+ function toRadians(angle: number) {
40
+ return (angle * Math.PI) / 180
41
+ }
42
+
43
+ function getQuadrant(x: number, y: number) {
44
+ if (x >= 0 && y >= 0) return 1
45
+ if (x <= 0 && y >= 0) return 2
46
+ if (x <= 0 && y <= 0) return 3
47
+ if (x >= 0 && y <= 0) return 4
48
+ return 1
49
+ }
50
+
51
+ /**
52
+ * Returns the angle (degrees) given a point.
53
+ * Assumes 0,0 as the center of the circle
54
+ * @param {number} x
55
+ * @param {number} y
56
+ */
57
+ function getAngleForPoint(x: number, y: number) {
58
+ if (x === 0 && y === 0) return 0
59
+
60
+ const angle = Math.atan(x / y)
61
+ let angleDeg = (angle * 180) / Math.PI
62
+ //The final value depends on the quadrant
63
+ const quadrant = getQuadrant(x, y)
64
+
65
+ if (quadrant === 1) {
66
+ angleDeg = 90 - angleDeg
67
+ }
68
+ if (quadrant === 2) {
69
+ angleDeg = 90 - angleDeg
70
+ }
71
+ if (quadrant === 3) {
72
+ angleDeg = 270 - angleDeg
73
+ }
74
+ if (quadrant === 4) {
75
+ angleDeg = 270 - angleDeg
76
+ }
77
+ return angleDeg
78
+ }
79
+
80
+ /**
81
+ * Transforms the top/left variables of the rectangle
82
+ * returned by getBoundingClientRect to document based coordinates
83
+ * without the scroll.
84
+ * UPDATE
85
+ * @param {Rect} box
86
+ */
87
+ function transformBoundingClientRectToDocument(box: DOMRect) {
88
+ let t: HTMLElement
89
+ t = document.documentElement || document.body.parentNode
90
+ const scrollX = (typeof t.scrollLeft === 'number' ? t : document.body)
91
+ .scrollLeft
92
+
93
+ t = document.documentElement || document.body.parentNode
94
+ const scrollY = (typeof t.scrollTop === 'number' ? t : document.body)
95
+ .scrollTop
96
+
97
+ //This assumes width == height
98
+ const ttop = box.top - scrollY
99
+ const tleft = box.left - scrollX
100
+ //info needed to draw line from center to mousepos
101
+
102
+ return { top: ttop, left: tleft, width: box.width, height: box.height }
103
+ }
104
+
105
+ export default {
106
+ // toGlobalCoordinates,
107
+ // toLocalCoordinates,
108
+ toRadians,
109
+ getQuadrant,
110
+ getAngleForPoint,
111
+ transformBoundingClientRectToDocument,
112
+ }