@tremolo-ui/react 0.1.0-alpha.2 → 0.1.1

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.
@@ -1,13 +1,33 @@
1
- import { ComponentPropsWithoutRef, ReactElement, RefObject } from 'react';
1
+ import { ComponentPropsWithoutRef, ReactElement } from 'react';
2
2
  /** @category AnimationCanvas */
3
- export type DrawFunction = (context: CanvasRenderingContext2D, width: RefObject<number>, height: RefObject<number>, count: number) => void;
3
+ export type InitFunction = (context: CanvasRenderingContext2D, option: {
4
+ /** current canvas width */
5
+ width: number;
6
+ /** current canvas height */
7
+ height: number;
8
+ }) => void;
9
+ /** @category AnimationCanvas */
10
+ export type DrawFunction = (context: CanvasRenderingContext2D, option: {
11
+ /** current canvas width */
12
+ width: number;
13
+ /** current canvas height */
14
+ height: number;
15
+ /** frame count */
16
+ count: number;
17
+ /** delta time (ms) */
18
+ deltaTime: number;
19
+ /** elapsed time (ms) */
20
+ elapsedTime: number;
21
+ /** frame per second */
22
+ fps: number;
23
+ }) => void;
4
24
  /** @category AnimationCanvas */
5
25
  export interface CommonProps {
6
26
  /**
7
27
  * @see https://developer.mozilla.org/docs/Web/API/HTMLCanvasElement/getContext#contextattributes
8
28
  */
9
29
  options?: CanvasRenderingContext2DSettings;
10
- init?: DrawFunction;
30
+ init?: InitFunction;
11
31
  draw: DrawFunction;
12
32
  }
13
33
  /** @category AnimationCanvas */
@@ -21,11 +41,11 @@ export interface RelativeSizingProps {
21
41
  reduceFlickering?: boolean;
22
42
  }
23
43
  /** @category AnimationCanvas */
24
- export type AnimationCanvasProps = AbsoluteSizingProps & RelativeSizingProps & CommonProps;
44
+ export type AnimationCanvasProps = CommonProps & AbsoluteSizingProps & RelativeSizingProps;
25
45
  /**
26
46
  * A simple animatable canvas with requestAnimationFrame()
27
47
  * @category AnimationCanvas
28
48
  */
29
- export declare function AnimationCanvas(props: AbsoluteSizingProps & CommonProps & Omit<ComponentPropsWithoutRef<'canvas'>, keyof AnimationCanvasProps>): ReactElement;
30
- export declare function AnimationCanvas(props: RelativeSizingProps & CommonProps & Omit<ComponentPropsWithoutRef<'canvas'>, keyof AnimationCanvasProps>): ReactElement;
49
+ export declare function AnimationCanvas(props: CommonProps & AbsoluteSizingProps & Omit<ComponentPropsWithoutRef<'canvas'>, keyof AnimationCanvasProps>): ReactElement;
50
+ export declare function AnimationCanvas(pros: CommonProps & RelativeSizingProps & Omit<ComponentPropsWithoutRef<'canvas'>, keyof AnimationCanvasProps>): ReactElement;
31
51
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/AnimationCanvas/index.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,wBAAwB,EACxB,YAAY,EACZ,SAAS,EAIV,MAAM,OAAO,CAAA;AAkBd,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG,CAGzB,OAAO,EAAE,wBAAwB,EACjC,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,EACxB,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EACzB,KAAK,EAAE,MAAM,KACV,IAAI,CAAA;AAET,gCAAgC;AAChC,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,OAAO,CAAC,EAAE,gCAAgC,CAAA;IAC1C,IAAI,CAAC,EAAE,YAAY,CAAA;IACnB,IAAI,EAAE,YAAY,CAAA;CACnB;AAED,gCAAgC;AAChC,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,gCAAgC;AAChC,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,gCAAgC;AAChC,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,GACpD,mBAAmB,GACnB,WAAW,CAAA;AAEb;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,mBAAmB,GACxB,WAAW,GACX,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,EAAE,MAAM,oBAAoB,CAAC,GACrE,YAAY,CAAA;AACf,wBAAgB,eAAe,CAC7B,KAAK,EAAE,mBAAmB,GACxB,WAAW,GACX,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,EAAE,MAAM,oBAAoB,CAAC,GACrE,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/AnimationCanvas/index.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,wBAAwB,EACxB,YAAY,EAKb,MAAM,OAAO,CAAA;AA2Bd,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG,CACzB,OAAO,EAAE,wBAAwB,EACjC,MAAM,EAAE;IACN,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAA;CACf,KACE,IAAI,CAAA;AAET,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG,CAGzB,OAAO,EAAE,wBAAwB,EACjC,MAAM,EAAE;IACN,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,4BAA4B;IAC5B,MAAM,EAAE,MAAM,CAAA;IACd,kBAAkB;IAClB,KAAK,EAAE,MAAM,CAAA;IACb,sBAAsB;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,wBAAwB;IACxB,WAAW,EAAE,MAAM,CAAA;IACnB,uBAAuB;IACvB,GAAG,EAAE,MAAM,CAAA;CACZ,KACE,IAAI,CAAA;AAET,gCAAgC;AAChC,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,OAAO,CAAC,EAAE,gCAAgC,CAAA;IAC1C,IAAI,CAAC,EAAE,YAAY,CAAA;IACnB,IAAI,EAAE,YAAY,CAAA;CACnB;AAED,gCAAgC;AAChC,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,gCAAgC;AAChC,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED,gCAAgC;AAChC,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAC5C,mBAAmB,GACnB,mBAAmB,CAAA;AAErB;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,WAAW,GAChB,mBAAmB,GACnB,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,EAAE,MAAM,oBAAoB,CAAC,GACrE,YAAY,CAAA;AACf,wBAAgB,eAAe,CAC7B,IAAI,EAAE,WAAW,GACf,mBAAmB,GACnB,IAAI,CAAC,wBAAwB,CAAC,QAAQ,CAAC,EAAE,MAAM,oBAAoB,CAAC,GACrE,YAAY,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/AnimationKnob/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAEZ,aAAa,EAKd,MAAM,OAAO,CAAA;AAEd,OAAO,EAML,gBAAgB,EACjB,MAAM,uBAAuB,CAAA;AAK9B,OAAO,EAAmB,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAElE,8BAA8B;AAC9B,MAAM,MAAM,kBAAkB,GAAG;IAE/B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IAGX,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,oCAAoC;IACpC,IAAI,CAAC,EAAE,MAAM,GAAG,GAAG,MAAM,GAAG,CAA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GAGG;AACH,eAAO,MAAM,aAAa,8NA0NzB,CAAA"}
@@ -16,7 +16,7 @@ type State = {
16
16
  type Action = {
17
17
  notePosition: (note: number) => number;
18
18
  };
19
- type PianoProviderProps = React.PropsWithChildren<Partial<State>>;
19
+ type PianoProviderProps = React.PropsWithChildren<Partial<State> & Action>;
20
20
  export declare function PianoProvider({ children, ...props }: PianoProviderProps): import("react/jsx-runtime").JSX.Element;
21
21
  /** @category Piano */
22
22
  export declare function usePianoContext<T>(selector: (state: State & Action) => T): T;
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../../src/components/Piano/context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAiC,MAAM,OAAO,CAAA;AAO/E,sBAAsB;AACtB,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,KAAK,KAAK,GAAG;IACX,SAAS,EAAE,SAAS,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,OAAO,CAAA;IACb,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;IACxC,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;IACxC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAA;CAClD,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CACvC,CAAA;AAsDD,KAAK,kBAAkB,GAAG,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAA;AAEjE,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,kBAAkB,2CAmBvE;AAED,sBAAsB;AACtB,wBAAgB,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAI5E"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../../src/components/Piano/context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAiC,MAAM,OAAO,CAAA;AAG/E,sBAAsB;AACtB,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED,KAAK,KAAK,GAAG;IACX,SAAS,EAAE,SAAS,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,OAAO,CAAA;IACb,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;IACxC,UAAU,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;IACxC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAA;CAClD,CAAA;AAED,KAAK,MAAM,GAAG;IACZ,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CACvC,CAAA;AAyBD,KAAK,kBAAkB,GAAG,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,CAAA;AAE1E,wBAAgB,aAAa,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,kBAAkB,2CAmBvE;AAED,sBAAsB;AACtB,wBAAgB,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAI5E"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/Piano/index.tsx"],"names":[],"mappings":"AACA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G,YAAY,EAAE,CAAA;CACzC;AAID;;;GAGG;AACH,wBAAgB,KAAK,CAAC,EACpB,SAAS,EACT,SAAgB,EAChB,OAAa,EACb,iBAAiB,EACjB,IAAY,EACZ,MAA4B,EAC5B,cAAc,EAAE,eAAsC,EACtD,KAAK,EACL,SAAS,EACT,UAAU,EACV,UAAU,EACV,KAAK,EACL,QAAQ,EACR,aAAa,EACb,GAAG,KAAK,EACT,EAAE,UAAU,GAAG,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,EAAE,MAAM,UAAU,CAAC,2CAiNtE;AAED,cAAc,qBAAqB,CAAA;AAEnC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,OAAO,CAAA;AAC1E,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAA"}
package/dist/esm/index.js CHANGED
@@ -59,23 +59,52 @@ const drawingState = [
59
59
  'imageSmoothingEnabled',
60
60
  ];
61
61
 
62
+ /*
63
+ TODO
64
+ AbsoluteSizingProps, RelativeSizingPropsの型付けを強くする
65
+ AbsoluteSizingPropsの場合、width, heightは必須
66
+ RelativeSizingPropsのの場合、relativeSizeは必須、reduceFlickeringはオプショナル
67
+ */
62
68
  function setDprConfig(canvas, context, width, height, dpr) {
63
69
  canvas.width = width * dpr;
64
70
  canvas.height = height * dpr;
71
+ // Reset current transformation matrix to the identity matrix
72
+ context.setTransform(1, 0, 0, 1, 0, 0);
65
73
  context.scale(dpr, dpr);
66
74
  canvas.style.width = `${width}px`;
67
75
  canvas.style.height = `${height}px`;
68
76
  }
69
77
  function AnimationCanvas(_a) {
70
- var { width = 100, height = 100, relativeSize = false, reduceFlickering = true, options, init, draw, className, onContextMenu = (event) => event.preventDefault() } = _a, props = __rest(_a, ["width", "height", "relativeSize", "reduceFlickering", "options", "init", "draw", "className", "onContextMenu"]);
78
+ var {
79
+ // common
80
+ options, init, draw,
81
+ // absolute
82
+ width = 100, height = 100,
83
+ // relative
84
+ relativeSize, reduceFlickering = true,
85
+ // canvas props
86
+ className, onContextMenu = (event) => event.preventDefault() } = _a, props = __rest(_a, ["options", "init", "draw", "width", "height", "relativeSize", "reduceFlickering", "className", "onContextMenu"]);
71
87
  const canvasRef = useRef(null);
72
88
  const memoCanvasRef = useRef(null);
73
89
  const reqIdRef = useRef(-1);
74
90
  const widthRef = useRef(0);
75
91
  const heightRef = useRef(0);
92
+ const deltaMemoRef = useRef(-1);
93
+ const startTimeRef = useRef(-1);
76
94
  const loop = useCallback((context, width, height, count) => {
95
+ const now = performance.now();
96
+ const deltaTime = now - deltaMemoRef.current;
97
+ const elapsedTime = now - startTimeRef.current;
98
+ deltaMemoRef.current = now;
77
99
  reqIdRef.current = requestAnimationFrame(() => loop(context, width, height, count + 1));
78
- draw(context, width, height, count + 1);
100
+ draw(context, {
101
+ width: width.current,
102
+ height: height.current,
103
+ count: count + 1,
104
+ deltaTime,
105
+ elapsedTime,
106
+ fps: 1000 / deltaTime,
107
+ });
79
108
  }, [draw]);
80
109
  useEffect(() => {
81
110
  if (!canvasRef.current)
@@ -84,26 +113,22 @@ function AnimationCanvas(_a) {
84
113
  const context = canvas.getContext('2d', options);
85
114
  if (!context)
86
115
  throw new Error('Cannot get canvas context.');
87
- const dpr = globalThis.window.devicePixelRatio;
116
+ const dpr = globalThis.devicePixelRatio;
88
117
  if (relativeSize) {
89
118
  const parent = canvas.parentElement;
90
119
  if (!parent)
91
120
  throw new Error("Canvas doesn't have a parent element.");
92
121
  const memoCanvas = memoCanvasRef.current;
93
122
  const memoContext = memoCanvas === null || memoCanvas === void 0 ? void 0 : memoCanvas.getContext('2d', options);
94
- const resizeObserver = new ResizeObserver((entries) => {
95
- // TODO: If the parent element has no absolute height, the height increases infinitely.
96
- // : 親要素に絶対的な高さを持たない場合、高さは無限に増加します。
97
- // https://zenn.dev/megeton/articles/be1c677e174c84#%E6%A0%B9%E6%9C%AC%E7%9A%84%E3%81%AB-resizeobserver-loop-limit-exceeded-%E3%81%8C%E5%87%BA%E3%82%8B%E5%95%8F%E9%A1%8C%E3%81%AB%E5%90%91%E3%81%8D%E5%90%88%E3%81%86
123
+ const ro = new ResizeObserver((entries) => {
98
124
  for (const entry of entries) {
99
125
  // Prevents loss of some context when the canvas is resized
100
- // TODO: saving scale and translate
101
126
  const contextMemo = {};
102
127
  for (const prop of drawingState) {
103
128
  contextMemo[prop] = context[prop];
104
129
  }
105
- const w = Math.floor(entry.contentRect.width);
106
- const h = Math.floor(entry.contentRect.height);
130
+ const w = entry.contentRect.width;
131
+ const h = entry.contentRect.height;
107
132
  if (reduceFlickering && memoCanvas && memoContext) {
108
133
  memoCanvas.width = w * dpr;
109
134
  memoCanvas.height = h * dpr;
@@ -127,17 +152,20 @@ function AnimationCanvas(_a) {
127
152
  }
128
153
  }
129
154
  });
130
- resizeObserver.observe(parent);
131
- const w = Math.floor(parent.clientWidth);
132
- const h = Math.floor(parent.clientHeight);
155
+ ro.observe(parent);
156
+ const w = parent.clientWidth;
157
+ const h = parent.clientHeight;
133
158
  setDprConfig(canvas, context, w, h, dpr);
134
159
  if (init)
135
- init(context, widthRef, heightRef, 0);
136
- loop(context, widthRef, heightRef, 0);
160
+ init(context, { width: widthRef.current, height: heightRef.current });
161
+ const now = performance.now();
162
+ deltaMemoRef.current = now;
163
+ startTimeRef.current = now;
164
+ loop(context, widthRef, heightRef, -1);
137
165
  return () => {
138
166
  if (reqIdRef.current)
139
167
  cancelAnimationFrame(reqIdRef.current);
140
- resizeObserver.unobserve(parent);
168
+ ro.disconnect();
141
169
  };
142
170
  }
143
171
  else {
@@ -146,8 +174,11 @@ function AnimationCanvas(_a) {
146
174
  widthRef.current = rect.width;
147
175
  heightRef.current = rect.height;
148
176
  if (init)
149
- init(context, widthRef, heightRef, 0);
150
- loop(context, widthRef, heightRef, 0);
177
+ init(context, { width: widthRef.current, height: heightRef.current });
178
+ const now = performance.now();
179
+ deltaMemoRef.current = now;
180
+ startTimeRef.current = now;
181
+ loop(context, widthRef, heightRef, -1);
151
182
  return () => {
152
183
  if (reqIdRef.current)
153
184
  cancelAnimationFrame(reqIdRef.current);
@@ -525,16 +556,16 @@ const AnimationKnob = forwardRef((_a, ref) => {
525
556
  height: size !== null && size !== void 0 ? size : height,
526
557
  }), { draw: draw
527
558
  ? draw
528
- : (ctx, width, height) => {
559
+ : (ctx, { width, height }) => {
529
560
  const p = normalizeValue(value, min, max, skew);
530
561
  const startP = normalizeValue(startValue, min, max, skew);
531
- const w = width.current, cx = w / 2;
532
- const h = height.current, cy = h / 2;
562
+ const cx = width / 2;
563
+ const cy = height / 2;
533
564
  const r = Math.min(cx, cy);
534
565
  if (r <= 0)
535
566
  return;
536
567
  // reset
537
- ctx.clearRect(0, 0, w, h);
568
+ ctx.clearRect(0, 0, width, height);
538
569
  ctx.lineCap = 'butt';
539
570
  // bg
540
571
  ctx.beginPath();
@@ -717,14 +748,14 @@ const createStoreImpl = (createState) => {
717
748
  const initialState = state = createState(setState, getState, api);
718
749
  return api;
719
750
  };
720
- const createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
751
+ const createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
721
752
 
722
753
  const identity = (arg) => arg;
723
754
  function useStore(api, selector = identity) {
724
755
  const slice = React.useSyncExternalStore(
725
756
  api.subscribe,
726
- () => selector(api.getState()),
727
- () => selector(api.getInitialState())
757
+ React.useCallback(() => selector(api.getState()), [api, selector]),
758
+ React.useCallback(() => selector(api.getInitialState()), [api, selector])
728
759
  );
729
760
  React.useDebugValue(slice);
730
761
  return slice;
@@ -904,7 +935,7 @@ const InternalInput = forwardRef((_a, ref) => {
904
935
  event.preventDefault();
905
936
  const x = key == 'ArrowUp' ? keyboard[1] : -keyboard[1];
906
937
  const parsed = parseValue(String(updateValueByEvent(keyboard[0], x)));
907
- console.log('key control');
938
+ // console.log('key control')
908
939
  onChange === null || onChange === void 0 ? void 0 : onChange(parsed.rawValue, parsed.formatValue);
909
940
  }, [keyboard, readonly, onChange, updateValueByEvent]);
910
941
  const wheelRefCallback = useRefCallbackEvent('wheel', (event) => {
@@ -915,7 +946,7 @@ const InternalInput = forwardRef((_a, ref) => {
915
946
  return;
916
947
  const x = Math.sign(event.deltaY) * -wheel[1];
917
948
  const parsed = parseValue(String(updateValueByEvent(wheel[0], x)));
918
- console.log('wheel control');
949
+ // console.log('wheel control')
919
950
  onChange === null || onChange === void 0 ? void 0 : onChange(parsed.rawValue, parsed.formatValue);
920
951
  }, { passive: false }, [wheel, readonly, onChange, updateValueByEvent]);
921
952
  useImperativeHandle(ref, () => {
@@ -1104,6 +1135,44 @@ function useDragWithElement({ baseElementRef, onDrag, onDragStart, onDragEnd, })
1104
1135
  return [refHandler, pointerDownHandler];
1105
1136
  }
1106
1137
 
1138
+ const createPianoStore = (initProps) => {
1139
+ // const noteRange = initProps.noteRange || { first: 0, last: 127 }
1140
+ const DEFAULT_PROPS = {
1141
+ noteRange: { first: 0, last: 127 },
1142
+ glissando: true,
1143
+ midiMax: 127,
1144
+ fill: false,
1145
+ label: () => undefined,
1146
+ onPlayNote: () => { },
1147
+ onStopNote: () => { },
1148
+ };
1149
+ return createStore()(() => (Object.assign(Object.assign(Object.assign({}, DEFAULT_PROPS), initProps), { notePosition: initProps.notePosition })));
1150
+ };
1151
+ const PianoContext = createContext(null);
1152
+ function PianoProvider(_a) {
1153
+ var { children } = _a, props = __rest(_a, ["children"]);
1154
+ const storeRef = useRef(null);
1155
+ if (!storeRef.current) {
1156
+ storeRef.current = createPianoStore(props);
1157
+ }
1158
+ useEffect(() => {
1159
+ if (storeRef.current) {
1160
+ storeRef.current.setState(props);
1161
+ }
1162
+ else {
1163
+ storeRef.current = createPianoStore(props);
1164
+ }
1165
+ }, [props]);
1166
+ return (jsx(PianoContext.Provider, { value: storeRef.current, children: children }));
1167
+ }
1168
+ /** @category Piano */
1169
+ function usePianoContext(selector) {
1170
+ const store = useContext(PianoContext);
1171
+ if (!store)
1172
+ throw new Error('Missing PianoContext.Provider in the tree');
1173
+ return useStore(store, selector);
1174
+ }
1175
+
1107
1176
  /** @category Piano */
1108
1177
  function KeyLabel(_a) {
1109
1178
  var { label, className, wrapperClassName, wrapperStyle, __note, __label } = _a, props = __rest(_a, ["label", "className", "wrapperClassName", "wrapperStyle", "__note", "__label"]);
@@ -1186,70 +1255,6 @@ const BlackKey = forwardRef((_a, ref) => {
1186
1255
  return (jsx(KeyImpl, Object.assign({ ref: ref, keyType: "black", width: width, height: height, onContextMenu: onContextMenu }, props)));
1187
1256
  });
1188
1257
 
1189
- const createPianoStore = (initProps) => {
1190
- const noteRange = (initProps === null || initProps === void 0 ? void 0 : initProps.noteRange) || { first: 0};
1191
- const DEFAULT_PROPS = {
1192
- noteRange: { first: 0, last: 127 },
1193
- glissando: true,
1194
- midiMax: 127,
1195
- fill: false,
1196
- label: () => undefined,
1197
- onPlayNote: () => { },
1198
- onStopNote: () => { },
1199
- };
1200
- return createStore()(() => (Object.assign(Object.assign(Object.assign({}, DEFAULT_PROPS), initProps), { notePosition: (note) => {
1201
- const pitchPositions = {
1202
- C: 0,
1203
- 'C#': 1,
1204
- D: 1,
1205
- 'D#': 2,
1206
- E: 2,
1207
- F: 3,
1208
- 'F#': 4,
1209
- G: 4,
1210
- 'G#': 5,
1211
- A: 5,
1212
- 'A#': 6,
1213
- B: 6,
1214
- };
1215
- const whiteNoteWidth = defaultWhiteKeyWidth;
1216
- const blackNoteWidth = defaultBlackKeyWidth;
1217
- const padding = 1;
1218
- const targetNoteKey = noteKey(note);
1219
- const firstNoteKey = noteKey(noteRange.first);
1220
- const octave = Math.floor((note - noteRange.first) / 12);
1221
- const octaveOffset = noteKeys.indexOf(firstNoteKey) > noteKeys.indexOf(targetNoteKey) ? 1 : 0;
1222
- const w = whiteNoteWidth + padding;
1223
- const pos = pitchPositions[targetNoteKey] - pitchPositions[firstNoteKey];
1224
- const blackKeyOffset = isBlackKey(note) ? blackNoteWidth / 2 : 0;
1225
- return pos * w + (octave + octaveOffset) * 7 * w - blackKeyOffset;
1226
- } })));
1227
- };
1228
- const PianoContext = createContext(null);
1229
- function PianoProvider(_a) {
1230
- var { children } = _a, props = __rest(_a, ["children"]);
1231
- const storeRef = useRef(null);
1232
- if (!storeRef.current) {
1233
- storeRef.current = createPianoStore(props);
1234
- }
1235
- useEffect(() => {
1236
- if (storeRef.current) {
1237
- storeRef.current.setState(props);
1238
- }
1239
- else {
1240
- storeRef.current = createPianoStore(props);
1241
- }
1242
- }, [props]);
1243
- return (jsx(PianoContext.Provider, { value: storeRef.current, children: children }));
1244
- }
1245
- /** @category Piano */
1246
- function usePianoContext(selector) {
1247
- const store = useContext(PianoContext);
1248
- if (!store)
1249
- throw new Error('Missing PianoContext.Provider in the tree');
1250
- return useStore(store, selector);
1251
- }
1252
-
1253
1258
  /** @category Piano */
1254
1259
  const SHORTCUTS = {
1255
1260
  HOME_ROW: {
@@ -1285,6 +1290,7 @@ const SHORTCUTS = {
1285
1290
  function getNoteRangeArray(noteRange) {
1286
1291
  return Array.from({ length: noteRange.last - noteRange.first + 1 }, (_, i) => i + noteRange.first);
1287
1292
  }
1293
+ const blackPerWhiteWidth = defaultBlackKeyWidth / defaultWhiteKeyWidth; // 0.65
1288
1294
  /**
1289
1295
  * Customizable piano component.
1290
1296
  * @category Piano
@@ -1307,19 +1313,17 @@ function Piano(_a) {
1307
1313
  const padding = 1;
1308
1314
  const staticWidth = (whiteNoteWidth + padding) * whiteNoteCount;
1309
1315
  // const blackNoteShiftPercent = 0.3
1310
- // TODO: if fill setWhiteNoteWidth
1311
- // useMemo
1312
- // __width
1313
1316
  const childrenWithProps = useMemo(() => {
1314
1317
  return (children &&
1315
1318
  React.Children.map(children, (child, index) => {
1316
1319
  if (React.isValidElement(child)) {
1317
- const props = { ref: keyRefs.current[index] };
1320
+ const __width = child.type == WhiteKey ? whiteNoteWidth : whiteNoteWidth * 0.65;
1321
+ const props = { ref: keyRefs.current[index], __width };
1318
1322
  return React.cloneElement(child, props);
1319
1323
  }
1320
1324
  return child;
1321
1325
  }));
1322
- }, [children]);
1326
+ }, [children, whiteNoteWidth]);
1323
1327
  // --- internal functions ---
1324
1328
  const notePosition = useCallback((note) => {
1325
1329
  const pitchPositions = {
@@ -1336,8 +1340,7 @@ function Piano(_a) {
1336
1340
  'A#': 6,
1337
1341
  B: 6,
1338
1342
  };
1339
- const whiteNoteWidth = defaultWhiteKeyWidth;
1340
- const blackNoteWidth = defaultBlackKeyWidth;
1343
+ const blackNoteWidth = whiteNoteWidth * blackPerWhiteWidth;
1341
1344
  const padding = 1;
1342
1345
  const targetNoteKey = noteKey(note);
1343
1346
  const firstNoteKey = noteKey(noteRange.first);
@@ -1347,7 +1350,7 @@ function Piano(_a) {
1347
1350
  const pos = pitchPositions[targetNoteKey] - pitchPositions[firstNoteKey];
1348
1351
  const blackKeyOffset = isBlackKey(note) ? blackNoteWidth / 2 : 0;
1349
1352
  return pos * w + (octave + octaveOffset) * 7 * w - blackKeyOffset;
1350
- }, [noteRange.first]);
1353
+ }, [noteRange.first, whiteNoteWidth]);
1351
1354
  const getHitKeyIndex = useCallback((x, y) => {
1352
1355
  if (!pianoRef.current)
1353
1356
  return -1;
@@ -1356,14 +1359,16 @@ function Piano(_a) {
1356
1359
  for (let i = 0; i < notes.length; i++) {
1357
1360
  const note = notes[i];
1358
1361
  const pos = notePosition(note);
1359
- const w = isWhiteKey(note) ? defaultWhiteKeyWidth : defaultBlackKeyWidth;
1362
+ const w = isWhiteKey(note)
1363
+ ? whiteNoteWidth
1364
+ : whiteNoteWidth * blackPerWhiteWidth;
1360
1365
  const h = isWhiteKey(note) ? containerHeight : containerHeight * 0.6;
1361
1366
  if (pos <= x && x < pos + w && 0 <= y && y < h) {
1362
1367
  return note;
1363
1368
  }
1364
1369
  }
1365
1370
  return -1;
1366
- }, [blackNotes, notePosition, whiteNotes]);
1371
+ }, [blackNotes, notePosition, whiteNoteWidth, whiteNotes]);
1367
1372
  // TODO: 単一のポインターに対しては、useDragで対応可能だが、
1368
1373
  // マルチタッチに対しては、TouchEventを使う必要がありそう
1369
1374
  // 取り敢えず、シングルタッチだけ対応
@@ -1438,14 +1443,14 @@ function Piano(_a) {
1438
1443
  (_b = (_a = keyRefs.current[index]) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.stop();
1439
1444
  }
1440
1445
  });
1441
- return (jsx(PianoProvider, { noteRange: noteRange, glissando: glissando, midiMax: midiMax, fill: fill, onPlayNote: onPlayNote, onStopNote: onStopNote, label: label, children: jsx("div", Object.assign({ ref: (div) => {
1446
+ return (jsx(PianoProvider, { notePosition: notePosition, noteRange: noteRange, glissando: glissando, midiMax: midiMax, fill: fill, onPlayNote: onPlayNote, onStopNote: onStopNote, label: label, children: jsx("div", Object.assign({ ref: (div) => {
1442
1447
  pianoRef.current = div;
1443
1448
  touchMoveRefCallback(div);
1444
1449
  }, className: clsx('tremolo-piano', className), style: Object.assign({ width: fill ? '100%' : staticWidth, height: height }, style), onPointerDown: (event) => {
1445
1450
  pointerDownHandler(event);
1446
1451
  onPointerDown === null || onPointerDown === void 0 ? void 0 : onPointerDown(event);
1447
1452
  } }, props, { children: childrenWithProps ||
1448
- getNoteRangeArray(noteRange).map((note, index) => isWhiteKey(note) ? (jsx(WhiteKey, { ref: keyRefs.current[index], noteNumber: note }, note)) : (jsx(BlackKey, { ref: keyRefs.current[index], noteNumber: note }, note))) })) }));
1453
+ noteRangeArray.map((note, index) => isWhiteKey(note) ? (jsx(WhiteKey, { ref: keyRefs.current[index], noteNumber: note, __width: whiteNoteWidth }, note)) : (jsx(BlackKey, { ref: keyRefs.current[index], noteNumber: note, __width: whiteNoteWidth * blackPerWhiteWidth }, note))) })) }));
1449
1454
  }
1450
1455
 
1451
1456
  const createSliderStore = (initProps) => {