# ease()

## 용도 <a href="#use" id="use"></a>

CSS를 사용해 물리 움직임을 부드럽게 표현하려면 [cubic-bezier()](https://cubic-bezier.com) 함수를 사용해야 합니다. 이 함수는 P0(`x1`, `y1`)과 P1(`x2`, `y2`) 사이의 움직임을 그래프로 표현하며 사이 움직임을 부드럽게 그려내므로 '[이징 함수](https://developer.mozilla.org/en-US/docs/Web/CSS/easing-function)'라 불립니다.

하지만 물리 곡선 값을 그리기 위한 P1, P2 값을 연상해 설정하기도, 암기해 작성하기도 쉽지 않아 상대적으로 기억하기 용이한 이징(easing) 키워드를 전달해 매칭되는 `cubic-bezier(x1, y1, x2, y2)` 함수를 반환하면 편리합니다.

<div align="left"><img src="/files/-MPKGqB6_VUJ3RaucB74" alt="cubic-bezier(0.075, 0.75, 0.875, 0.36)"></div>

#### 이징 함수 키워드

이징 함수 별 움직임은 [easings.net](https://easings.net/ko)에서 확인할 수 있습니다.

| 키워드          | 이징 함수                                   |
| ------------ | --------------------------------------- |
| in-**sine**  | cubic-bezier(0.47, 0, 0.745, 0.715)     |
| out-sine     | cubic-bezier(0.39, 0.575, 0.565, 1)     |
| inout-sine   | cubic-bezier(0.39, 0.575, 0.565, 1)     |
| in-**quad**  | cubic-bezier(0.55, 0.085, 0.68, 0.53)   |
| out-quad     | cubic-bezier(0.25, 0.46, 0.45, 0.94)    |
| inout-quad   | cubic-bezier(0.25, 0.46, 0.45, 0.94)    |
| in-**cubic** | cubic-bezier(0.55, 0.055, 0.675, 0.19)  |
| out-cubic    | cubic-bezier(0.215, 0.61, 0.355, 1)     |
| inout-cubic  | cubic-bezier(0.215, 0.61, 0.355, 1)     |
| in-**quart** | cubic-bezier(0.895, 0.03, 0.685, 0.22)  |
| out-quart    | cubic-bezier(0.165, 0.84, 0.44, 1)      |
| inout-quart  | cubic-bezier(0.165, 0.84, 0.44, 1)      |
| in-**quint** | cubic-bezier(0.755, 0.05, 0.855, 0.06)  |
| out-quint    | cubic-bezier(0.23, 1, 0.32, 1)          |
| inout-quint  | cubic-bezier(0.23, 1, 0.32, 1)          |
| in-**expo**  | cubic-bezier(0.95, 0.05, 0.795, 0.035)  |
| out-expo     | cubic-bezier(0.19, 1, 0.22, 1)          |
| inout-expo   | cubic-bezier(0.19, 1, 0.22, 1)          |
| in-**circ**  | cubic-bezier(0.6, 0.04, 0.98, 0.335)    |
| out-circ     | cubic-bezier(0.075, 0.82, 0.165, 1)     |
| inout-circ   | cubic-bezier(0.075, 0.82, 0.165, 1)     |
| in-**back**  | cubic-bezier(0.6, -0.28, 0.735, 0.045)  |
| out-back     | cubic-bezier(0.175, 0.885, 0.32, 1.275) |
| inout-back   | cubic-bezier(0.68, -0.55, 0.265, 1.55)  |

## 사용법 <a href="#usage" id="usage"></a>

`ease()` 함수에 이징 키워드를 전달합니다.

> ease($keyword:**string**) → **string**

```javascript
@debug ease(out-expo); // cubic-bezier(0.19, 1, 0.22, 1) 반환
```

| 매개변수(parameter) | 유형(type) | 필수(required) | 기본 값(default) |
| :-------------: | :------: | :----------: | :-----------: |
|     $keyword    |  string  |      ✔︎      |               |

CSS 트랜지션 코드의 이징 함수 값을 손쉽게 사용하기 위해 `ease()` 유틸리티 함수를 사용한 예시

```javascript
.usage {
  transition: opacity 0.32s ease(out-expo);
}
```

## 로직 <a href="#logic" id="logic"></a>

`ease()` 유틸리티는 다음의 로직에 의해 작성되었습니다.&#x20;

```javascript
@function ease($keyword) {
  @if map-has-key($easings, $keyword) {
    @return map-get($easings, $keyword);
  } @else {
    @error 'ease() 함수에 전달 가능한 값은 다음 중 하나입니다 → #{map-keys($easings)}';
  }
}
```

1. 전달 받은 키워드와 일치하는 키(`key`)를 $easings 맵 변수에 포함되어 있는지 검토
2. 키가 존재할 경우, 키에 연결된 값 반환
3. 키가 존재하지 않을 경우, 오류 메시지 출력

{% hint style="info" %}
**이징 함수 맵(Map)**

`ease()` 유틸리티 함수 내에서 사용되는 `$easings` 변수는 앞서 소개한 자주 사용되는 이징 함수 별 키워드 및 함수 값을 키(key):값(value) 형식으로 관리합니다.

```css
$easings: (
  in-sine: cubic-bezier(0.47, 0, 0.745, 0.715),
  out-sine: cubic-bezier(0.39, 0.575, 0.565, 1),
  inout-sine: cubic-bezier(0.39, 0.575, 0.565, 1),
  in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53),
  out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94),
  inout-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94),
  in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19),
  out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1),
  inout-cubic: cubic-bezier(0.215, 0.61, 0.355, 1),
  in-quart: cubic-bezier(0.895, 0.03, 0.685, 0.22),
  out-quart: cubic-bezier(0.165, 0.84, 0.44, 1),
  inout-quart: cubic-bezier(0.165, 0.84, 0.44, 1),
  in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06),
  out-quint: cubic-bezier(0.23, 1, 0.32, 1),
  inout-quint: cubic-bezier(0.23, 1, 0.32, 1),
  in-expo: cubic-bezier(0.95, 0.05, 0.795, 0.035),
  out-expo: cubic-bezier(0.19, 1, 0.22, 1),
  inout-expo: cubic-bezier(0.19, 1, 0.22, 1),
  in-circ: cubic-bezier(0.6, 0.04, 0.98, 0.335),
  out-circ: cubic-bezier(0.075, 0.82, 0.165, 1),
  inout-circ: cubic-bezier(0.075, 0.82, 0.165, 1),
  in-back: cubic-bezier(0.6, -0.28, 0.735, 0.045),
  out-back: cubic-bezier(0.175, 0.885, 0.32, 1.275),
  inout-back: cubic-bezier(0.68, -0.55, 0.265, 1.55),
) !default;
```

{% endhint %}

## 참고 <a href="#reference" id="reference"></a>

유틸리티 함수 로직에 사용된 Sass의 흐름 제어(Flow Control) 문은 다음과 같습니다.

* [@if / @else](https://sass-lang.com/documentation/at-rules/control/if)

유틸리티 함수 로직에 사용된 Sass:map 함수는 다음과 같습니다.

* [map-has-key()](https://sass-lang.com/documentation/modules/map#has-key)
* [map-get()](https://sass-lang.com/documentation/modules/map#get)

{% hint style="info" %}
Sass의 Map 자료형(Data Type)은 JavaScript의 Object와 유사합니다.
{% endhint %}

{% embed url="<https://sass-lang.com/documentation/modules/map>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yamoo9.gitbook.io/scss-mixins/utilities/easing/ease.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
