previewFooterFoundation.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import BaseFoundation, { DefaultAdapter } from "../base/foundation";
  2. export interface PreviewFooterAdapter<P = Record<string, any>, S = Record<string, any>> extends DefaultAdapter<P, S> {
  3. setStartMouseOffset: (time: number) => void
  4. }
  5. export default class PreviewFooterFoundation<P = Record<string, any>, S = Record<string, any>> extends BaseFoundation<PreviewFooterAdapter<P, S>, P, S> {
  6. changeSliderValue = (type: string): void => {
  7. const { zoom, step, min, max } = this.getProps();
  8. let newValue = type === "plus" ? zoom + step : zoom - step;
  9. if (newValue > max) {
  10. newValue = max;
  11. } else if (newValue < min) {
  12. newValue = min;
  13. }
  14. this.handleValueChange(newValue);
  15. };
  16. handleValueChange = (value: number): void => {
  17. const { onZoomIn, onZoomOut, zoom } = this.getProps();
  18. if (value > zoom) {
  19. onZoomIn(value / 100);
  20. } else {
  21. onZoomOut(value / 100);
  22. }
  23. this._adapter.setStartMouseOffset(value);
  24. };
  25. handleRatioClick = (): void => {
  26. const { ratio, onAdjustRatio } = this.getProps();
  27. const type = ratio === "adaptation" ? "realSize" : "adaptation";
  28. onAdjustRatio(type);
  29. }
  30. handleRotate = (direction: string): void => {
  31. const { onRotate } = this.getProps();
  32. onRotate && onRotate(direction);
  33. }
  34. }