@1337exp/taoux 0.17.0 → 0.18.0
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.
- package/CHANGELOG.md +8 -0
- package/README.md +2 -0
- package/README.ru.md +2 -0
- package/dist/chunks/{curveeditor-B1mAStQs.js → curveeditor-C9SsYXjQ.js} +4 -166
- package/dist/chunks/curveeditor-C9SsYXjQ.js.map +1 -0
- package/dist/commands.d.ts +7 -0
- package/dist/commands.js +6 -3
- package/dist/commands.js.map +1 -1
- package/dist/commandsvue.d.ts +47 -0
- package/dist/commandsvue.js +51 -0
- package/dist/commandsvue.js.map +1 -0
- package/dist/curveeditor/ops.d.ts +1 -63
- package/dist/curveeditor.js +3 -1
- package/dist/curvefield.css +10 -10
- package/dist/curvefield.js +6 -5
- package/dist/curvefield.js.map +1 -1
- package/dist/curveops.d.ts +63 -0
- package/dist/curveops.js +167 -0
- package/dist/curveops.js.map +1 -0
- package/package.json +12 -4
- package/skills/taoux/SKILL.md +2 -0
- package/dist/chunks/curveeditor-B1mAStQs.js.map +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { computed, getCurrentInstance, getCurrentScope, onActivated, onDeactivated, onMounted, onScopeDispose, ref } from "vue";
|
|
2
|
+
//#region src/commandsvue.ts
|
|
3
|
+
function useCommands(registry, options = {}) {
|
|
4
|
+
const version = ref(0);
|
|
5
|
+
let remove;
|
|
6
|
+
let unbind;
|
|
7
|
+
const attach = () => {
|
|
8
|
+
if (options.add?.length && !remove) {
|
|
9
|
+
remove = registry.add(options.add);
|
|
10
|
+
version.value += 1;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const listen = () => {
|
|
14
|
+
if (options.target === false || typeof window === "undefined" || unbind) return;
|
|
15
|
+
unbind = registry.bind(options.target ?? window);
|
|
16
|
+
};
|
|
17
|
+
const detach = () => {
|
|
18
|
+
unbind?.();
|
|
19
|
+
unbind = void 0;
|
|
20
|
+
if (remove) {
|
|
21
|
+
remove();
|
|
22
|
+
remove = void 0;
|
|
23
|
+
version.value += 1;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
attach();
|
|
27
|
+
if (getCurrentInstance()) {
|
|
28
|
+
onMounted(listen);
|
|
29
|
+
onDeactivated(detach);
|
|
30
|
+
onActivated(() => {
|
|
31
|
+
attach();
|
|
32
|
+
listen();
|
|
33
|
+
});
|
|
34
|
+
} else listen();
|
|
35
|
+
if (getCurrentScope()) onScopeDispose(detach);
|
|
36
|
+
return {
|
|
37
|
+
menu: (layout) => computed(() => {
|
|
38
|
+
version.value;
|
|
39
|
+
return registry.toMenu(layout);
|
|
40
|
+
}),
|
|
41
|
+
onSelect: (item) => {
|
|
42
|
+
const id = typeof item === "string" ? item : item.id;
|
|
43
|
+
return id === void 0 ? false : registry.run(id);
|
|
44
|
+
},
|
|
45
|
+
run: (id) => registry.run(id)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { useCommands };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=commandsvue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commandsvue.js","names":[],"sources":["../src/commandsvue.ts"],"sourcesContent":["import { computed, getCurrentInstance, getCurrentScope, onActivated, onDeactivated, onMounted, onScopeDispose, ref, type ComputedRef } from 'vue';\n\n/**\n * The registry of commands (`createCommands`) in a Vue app: the commands live as long as the component does, the keys are\n * listened to while it is mounted, a menu is a `computed` that follows the state, and the `select` of a menu runs the command.\n * It takes the registry by its shape, not by import, so a composite module stays independent of another one.\n * Реестр команд (`createCommands`) в приложении на Vue: команды живут, пока жив компонент, клавиши слушаются, пока он\n * смонтирован, меню это `computed`, который следует за состоянием, а `select` меню выполняет команду. Реестр берётся по\n * форме, а не импортом, чтобы составной модуль не зависел от другого.\n *\n * ```ts\n * const commands = createCommands() // once, in a module of the app\n * // in the root component:\n * const { menu, onSelect } = useCommands(commands, { add: [...appCommands] })\n * const bar = menu(layout) // a ComputedRef of menu items\n * ```\n * ```vue\n * <TaoMenubar :items=\"bar\" @select=\"onSelect\" />\n * ```\n */\n\n/** What `useCommands` needs from a registry: `createCommands()` fits as it is. / Что `useCommands` нужно от реестра: `createCommands()` подходит как есть. */\nexport interface CommandRegistry<C, L, I> {\n add(command: C | readonly C[]): () => void;\n bind(target: EventTarget): () => void;\n toMenu(layout: L): I[];\n run(id: string): boolean;\n}\n\nexport interface UseCommandsOptions<C> {\n /** Commands of this component: added now, removed when it goes. / Команды этого компонента: добавляются сразу, убираются вместе с ним. */\n add?: readonly C[];\n /** Where the shortcuts are listened to. Default: `window`. `false`: do not listen (the menu only). / Где слушать сочетания. По умолчанию `window`. `false`: не слушать (только меню). */\n target?: EventTarget | false;\n}\n\nexport interface UseCommands<L, I> {\n /** A menu from a layout, as a `computed`: it is made again when a state that a label, `enabled` or `checked` reads changes. / Меню по раскладке как `computed`: пересобирается, когда меняется состояние, которое читают подпись, `enabled` или `checked`. */\n menu(layout: L): ComputedRef<I[]>;\n /**\n * For `@select` of a menu: runs the command named by the item. It takes the item that TaoUI 6 emits (not a bare id); returns whether\n * it ran (a disabled command does not).\n * Для `@select` меню: выполняет команду, названную пунктом. Берёт пункт, который отдаёт TaoUI 6 (не голый id); возвращает,\n * выполнилась ли команда (недоступная — нет).\n */\n onSelect(item: { id?: string } | string): boolean;\n run(id: string): boolean;\n}\n\nexport function useCommands<C, L, I>(registry: CommandRegistry<C, L, I>, options: UseCommandsOptions<C> = {}): UseCommands<L, I> {\n // the registry is not reactive: this one number is what a menu waits for when commands come or go\n // реестр не реактивен: это число и ждёт меню, когда команды приходят или уходят\n const version = ref(0);\n let remove: (() => void) | undefined;\n let unbind: (() => void) | undefined;\n\n const attach = () => {\n if (options.add?.length && !remove) {\n remove = registry.add(options.add);\n version.value += 1;\n }\n };\n const listen = () => {\n if (options.target === false || typeof window === 'undefined' || unbind) {\n return;\n }\n unbind = registry.bind(options.target ?? window);\n };\n const detach = () => {\n unbind?.();\n unbind = undefined;\n if (remove) {\n remove();\n remove = undefined;\n version.value += 1;\n }\n };\n\n attach();\n if (getCurrentInstance()) {\n onMounted(listen);\n // a component kept alive (`<KeepAlive>`) is not disposed when it is hidden: it must not hold its keys and its ids, or the page\n // that replaced it would throw on the same ids and the hidden one would still answer the keyboard\n // кэшированный компонент (`<KeepAlive>`) при скрытии не уничтожается: он не должен держать клавиши и id, иначе сменившая его\n // страница упала бы на тех же id, а скрытая всё ещё отвечала бы на клавиатуру\n onDeactivated(detach);\n onActivated(() => {\n attach();\n listen();\n });\n } else {\n listen();\n }\n if (getCurrentScope()) {\n onScopeDispose(detach);\n }\n\n return {\n menu: (layout) =>\n computed(() => {\n void version.value;\n return registry.toMenu(layout);\n }),\n onSelect: (item) => {\n const id = typeof item === 'string' ? item : item.id;\n return id === undefined ? false : registry.run(id);\n },\n run: (id) => registry.run(id),\n };\n}\n"],"mappings":";;AAiDA,SAAgB,YAAqB,UAAoC,UAAiC,CAAC,GAAsB;CAG7H,MAAM,UAAU,IAAI,CAAC;CACrB,IAAI;CACJ,IAAI;CAEJ,MAAM,eAAe;EACjB,IAAI,QAAQ,KAAK,UAAU,CAAC,QAAQ;GAChC,SAAS,SAAS,IAAI,QAAQ,GAAG;GACjC,QAAQ,SAAS;EACrB;CACJ;CACA,MAAM,eAAe;EACjB,IAAI,QAAQ,WAAW,SAAS,OAAO,WAAW,eAAe,QAC7D;EAEJ,SAAS,SAAS,KAAK,QAAQ,UAAU,MAAM;CACnD;CACA,MAAM,eAAe;EACjB,SAAS;EACT,SAAS,KAAA;EACT,IAAI,QAAQ;GACR,OAAO;GACP,SAAS,KAAA;GACT,QAAQ,SAAS;EACrB;CACJ;CAEA,OAAO;CACP,IAAI,mBAAmB,GAAG;EACtB,UAAU,MAAM;EAKhB,cAAc,MAAM;EACpB,kBAAkB;GACd,OAAO;GACP,OAAO;EACX,CAAC;CACL,OACI,OAAO;CAEX,IAAI,gBAAgB,GAChB,eAAe,MAAM;CAGzB,OAAO;EACH,OAAO,WACH,eAAe;GACX,QAAa;GACb,OAAO,SAAS,OAAO,MAAM;EACjC,CAAC;EACL,WAAW,SAAS;GAChB,MAAM,KAAK,OAAO,SAAS,WAAW,OAAO,KAAK;GAClD,OAAO,OAAO,KAAA,IAAY,QAAQ,SAAS,IAAI,EAAE;EACrD;EACA,MAAM,OAAO,SAAS,IAAI,EAAE;CAChC;AACJ"}
|
|
@@ -1,63 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* A curve point: t in 0…1, v is the value. `ease` sets how to go from this point to the next (linear by default);
|
|
4
|
-
* on the last point it has no effect.
|
|
5
|
-
* Точка кривой: t в 0…1, v значение. `ease` задаёт, как идти от этой точки к следующей (по умолчанию линейно);
|
|
6
|
-
* у последней точки он ни на что не влияет.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Guides from the selected point to the axes: none, lines only, lines and values.
|
|
10
|
-
* Направляющие от выбранной точки к осям: нет, только линии, линии и значения.
|
|
11
|
-
*/
|
|
12
|
-
export type CurveGuides = 'off' | 'lines' | 'values';
|
|
13
|
-
export interface CurvePoint {
|
|
14
|
-
t: number;
|
|
15
|
-
v: number;
|
|
16
|
-
ease?: Ease;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* The curve value at t: beyond the end points it equals the end point, between them it follows the `ease` of the left point (linear without it).
|
|
20
|
-
* Значение кривой в t: вне крайних точек равно крайней, между ними по переходу `ease` левой точки (без него линейно).
|
|
21
|
-
*/
|
|
22
|
-
export declare function sampleCurve(points: readonly CurvePoint[], t: number): number;
|
|
23
|
-
/**
|
|
24
|
-
* Moves point `i`: along t it stays between its neighbours (the order is kept), along v it is free.
|
|
25
|
-
* Двигает точку `i`: по t она остаётся между соседями (порядок не нарушается), по v свободна.
|
|
26
|
-
*/
|
|
27
|
-
export declare function movePoint(points: readonly CurvePoint[], i: number, t: number, v: number): CurvePoint[];
|
|
28
|
-
/**
|
|
29
|
-
* Adds a point at `t` with value `v` (the curve value at that point by default); returns the new list and the point index.
|
|
30
|
-
* Добавляет точку в `t` со значением `v` (по умолчанию значение кривой в этой точке); возвращает новый список и индекс точки.
|
|
31
|
-
*/
|
|
32
|
-
export declare function addPoint(points: readonly CurvePoint[], t: number, v?: number): {
|
|
33
|
-
points: CurvePoint[];
|
|
34
|
-
index: number;
|
|
35
|
-
};
|
|
36
|
-
/**
|
|
37
|
-
* Removes a point; never leaves fewer than two (a curve of one point is just a number).
|
|
38
|
-
* Убирает точку; меньше двух точек не оставляет (кривая из одной точки это просто число).
|
|
39
|
-
*/
|
|
40
|
-
export declare function removePoint(points: readonly CurvePoint[], i: number): CurvePoint[];
|
|
41
|
-
/**
|
|
42
|
-
* The polyline of segment a→b for drawing: a straight one has two ends, other transitions `steps` pieces (a step: a corner).
|
|
43
|
-
* Ломаная участка a→b для рисования: у прямой два конца, у остальных переходов `steps` отрезков (ступенька: угол).
|
|
44
|
-
*/
|
|
45
|
-
export declare function sampleSegment(a: CurvePoint, b: CurvePoint, steps?: number): {
|
|
46
|
-
t: number;
|
|
47
|
-
v: number;
|
|
48
|
-
}[];
|
|
49
|
-
/**
|
|
50
|
-
* A copy of the list with the transition of point `i` (`undefined` and `linear` remove the field: the file stays short).
|
|
51
|
-
* Копия списка с переходом точки `i` (`undefined` и `linear` убирают поле: файл остаётся коротким).
|
|
52
|
-
*/
|
|
53
|
-
export declare function setEase(points: readonly CurvePoint[], i: number, ease: Ease | undefined): CurvePoint[];
|
|
54
|
-
/**
|
|
55
|
-
* Value limits for drawing: from 0 (or below the minimum) to the maximum with some headroom, no narrower than 0…1.
|
|
56
|
-
* The given `min`/`max` (the field bounds) fix the view: the plot neither drifts nor leaves the allowed range.
|
|
57
|
-
* Пределы значений для отрисовки: от 0 (или ниже минимума) до максимума с запасом, не уже чем 0…1.
|
|
58
|
-
* Заданные `min`/`max` (границы поля) фиксируют вид: график не плывёт и не выходит за допустимое.
|
|
59
|
-
*/
|
|
60
|
-
export declare function valueBounds(points: readonly CurvePoint[], min?: number, max?: number): {
|
|
61
|
-
min: number;
|
|
62
|
-
max: number;
|
|
63
|
-
};
|
|
1
|
+
export * from '../curveops';
|
package/dist/curveeditor.js
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { addPoint, movePoint, removePoint, sampleCurve, sampleSegment, setEase, valueBounds } from "./curveops.js";
|
|
2
|
+
import { t as TaoxCurveEditor_default } from "./chunks/curveeditor-C9SsYXjQ.js";
|
|
3
|
+
export { TaoxCurveEditor_default as TaoxCurveEditor, addPoint, movePoint, removePoint, sampleCurve, sampleSegment, setEase, valueBounds };
|
package/dist/curvefield.css
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
1
|
|
|
2
|
-
.tx-curve-field[data-v-
|
|
2
|
+
.tx-curve-field[data-v-c2165b9d] {
|
|
3
3
|
display: flex;
|
|
4
4
|
flex-direction: column;
|
|
5
5
|
gap: 8px;
|
|
6
6
|
}
|
|
7
|
-
.tx-curve-field__fields[data-v-
|
|
7
|
+
.tx-curve-field__fields[data-v-c2165b9d] {
|
|
8
8
|
display: grid;
|
|
9
9
|
grid-template-columns: 1fr 1fr;
|
|
10
10
|
gap: 8px;
|
|
11
11
|
}
|
|
12
|
-
.tx-curve-field__fields > label[data-v-
|
|
12
|
+
.tx-curve-field__fields > label[data-v-c2165b9d] {
|
|
13
13
|
display: flex;
|
|
14
14
|
flex-direction: column;
|
|
15
15
|
gap: 2px;
|
|
16
16
|
color: var(--tx-curve-label, #8b929c);
|
|
17
17
|
font-size: 11px;
|
|
18
18
|
}
|
|
19
|
-
.tx-curve-field__ease[data-v-
|
|
19
|
+
.tx-curve-field__ease[data-v-c2165b9d] {
|
|
20
20
|
display: flex;
|
|
21
21
|
flex-direction: column;
|
|
22
22
|
gap: 2px;
|
|
23
23
|
}
|
|
24
|
-
.tx-curve-field__title[data-v-
|
|
24
|
+
.tx-curve-field__title[data-v-c2165b9d] {
|
|
25
25
|
color: var(--tx-curve-label, #8b929c);
|
|
26
26
|
font-size: 11px;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
/* The list and the direction in one row: the list takes the rest, the switch keeps its own width / Список и направление в одну строку: список забирает остаток, переключатель держит свою ширину */
|
|
30
|
-
.tx-curve-field__ease-row[data-v-
|
|
30
|
+
.tx-curve-field__ease-row[data-v-c2165b9d] {
|
|
31
31
|
display: flex;
|
|
32
32
|
align-items: center;
|
|
33
33
|
gap: 6px;
|
|
34
34
|
}
|
|
35
|
-
.tx-curve-field__kind[data-v-
|
|
35
|
+
.tx-curve-field__kind[data-v-c2165b9d] {
|
|
36
36
|
flex: 1;
|
|
37
37
|
min-width: 0;
|
|
38
38
|
}
|
|
39
|
-
.tx-curve-field__ease-row[data-v-
|
|
39
|
+
.tx-curve-field__ease-row[data-v-c2165b9d] > :last-child {
|
|
40
40
|
flex: none;
|
|
41
41
|
}
|
|
42
|
-
.tx-curve-field__bar[data-v-
|
|
42
|
+
.tx-curve-field__bar[data-v-c2165b9d] {
|
|
43
43
|
display: flex;
|
|
44
44
|
align-items: center;
|
|
45
45
|
gap: 4px;
|
|
46
46
|
font-size: 12px;
|
|
47
47
|
}
|
|
48
|
-
.tx-curve-field__spacer[data-v-
|
|
48
|
+
.tx-curve-field__spacer[data-v-c2165b9d] {
|
|
49
49
|
flex: 1;
|
|
50
50
|
}
|
package/dist/curvefield.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { clampTo, niceStep, roundTo } from "./num.js";
|
|
2
2
|
import { DEFAULT_BEZIER, EASE_DIRECTIONS, EASE_FAMILIES, easeName, easeParts } from "./ease.js";
|
|
3
|
-
import {
|
|
3
|
+
import { movePoint, removePoint, setEase, valueBounds } from "./curveops.js";
|
|
4
|
+
import { t as TaoxCurveEditor_default } from "./chunks/curveeditor-C9SsYXjQ.js";
|
|
4
5
|
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, openBlock, ref, renderList, toDisplayString, unref, withCtx } from "vue";
|
|
5
6
|
import { TaoButton, TaoInputNumber, TaoSegmented, TaoSegmentedOption, TaoSelect, TaoSwitch } from "@1337exp/taoui";
|
|
6
7
|
//#region src/curvefield/TaoxCurveField.vue?vue&type=script&setup=true&lang.ts
|
|
@@ -98,7 +99,7 @@ var TaoxCurveField_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
|
|
|
98
99
|
...EASE_FAMILIES,
|
|
99
100
|
"bezier"
|
|
100
101
|
].map((v) => ({
|
|
101
|
-
|
|
102
|
+
id: v,
|
|
102
103
|
label: v
|
|
103
104
|
}));
|
|
104
105
|
function applyEase(next) {
|
|
@@ -185,12 +186,12 @@ var TaoxCurveField_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ d
|
|
|
185
186
|
class: "tx-curve-field__kind",
|
|
186
187
|
size: "small",
|
|
187
188
|
clearable: false,
|
|
188
|
-
|
|
189
|
+
items: unref(kindOptions),
|
|
189
190
|
disabled: isLast.value,
|
|
190
191
|
"model-value": kind.value,
|
|
191
192
|
"onUpdate:modelValue": setKind
|
|
192
193
|
}, null, 8, [
|
|
193
|
-
"
|
|
194
|
+
"items",
|
|
194
195
|
"disabled",
|
|
195
196
|
"model-value"
|
|
196
197
|
]), createVNode(unref(TaoSegmented), {
|
|
@@ -248,7 +249,7 @@ var _plugin_vue_export_helper_default = (sfc, props) => {
|
|
|
248
249
|
};
|
|
249
250
|
//#endregion
|
|
250
251
|
//#region src/curvefield/TaoxCurveField.vue
|
|
251
|
-
var TaoxCurveField_default = /*#__PURE__*/ _plugin_vue_export_helper_default(TaoxCurveField_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-
|
|
252
|
+
var TaoxCurveField_default = /*#__PURE__*/ _plugin_vue_export_helper_default(TaoxCurveField_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-c2165b9d"]]);
|
|
252
253
|
//#endregion
|
|
253
254
|
export { TaoxCurveField_default as TaoxCurveField };
|
|
254
255
|
|
package/dist/curvefield.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curvefield.js","names":["_openBlock","_createElementBlock","_createVNode","_unref","TaoxCurveEditor","_createElementVNode","_createTextVNode","_toDisplayString","_withCtx","_Fragment","_renderList","_createBlock","_createCommentVNode","_sfc_main"],"sources":["../src/curvefield/TaoxCurveField.vue","../src/curvefield/TaoxCurveField.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { TaoButton, TaoInputNumber, TaoSegmented, TaoSegmentedOption, TaoSelect, TaoSwitch } from '@1337exp/taoui';\nimport { computed, ref } from 'vue';\nimport { movePoint, removePoint, setEase, TaoxCurveEditor, valueBounds, type CurveGuides, type CurvePoint } from '../curveeditor';\nimport { DEFAULT_BEZIER, EASE_DIRECTIONS, EASE_FAMILIES, easeName, easeParts, type Ease, type EaseDirection, type EaseFamily } from '../ease';\nimport { clampTo, niceStep, roundTo } from '../num';\nimport type { CurveFieldLabels } from './labels';\n\n// A curve with fields: the plot (TaoxCurveEditor), the fields of the selected point, the transition to the next point, the grid step, remove and reset.\n// The first taoux module on top of TaoUI: the plot and the logic stay in taoux, the fields and buttons are TaoUI components.\n// Кривая с полями: график (TaoxCurveEditor), поля выбранной точки, переход к следующей точке, шаг сетки, удаление и сброс.\n// Первый модуль taoux поверх TaoUI: график и логика остаются в taoux, поля и кнопки это компоненты TaoUI.\nconst props = withDefaults(\n defineProps<{\n /**\n * Curve points.\n * Точки кривой.\n */\n modelValue: readonly CurvePoint[];\n /**\n * Allowed values: they fix the plot view and do not let a point be dragged past the bound.\n * Допустимые значения: фиксируют вид графика и не дают утащить точку за границу.\n */\n min?: number;\n max?: number;\n /**\n * The \"default\" curve: without it there is no reset button.\n * Кривая «по умолчанию»: без неё кнопки сброса нет.\n */\n defaultValue?: readonly CurvePoint[];\n /**\n * How many decimals to keep in time and value; not set means do not round.\n * Сколько знаков после запятой оставлять у времени и значения; не задано — не обрезать.\n */\n precision?: number;\n /**\n * The time step of the grid and of the time field.\n * Шаг по времени у сетки и у поля времени.\n */\n stepT?: number;\n /**\n * Snapping to the grid at start.\n * Прилипание к сетке при старте.\n */\n snap?: boolean;\n /**\n * Labels in the app language; missing ones fall back to English.\n * Надписи на языке приложения; недостающие берутся английские.\n */\n labels?: Partial<CurveFieldLabels>;\n /**\n * Guides from the selected point to the axes: `off`, `lines` (default) or `values`.\n * Направляющие от выбранной точки к осям: `off`, `lines` (по умолчанию) или `values`.\n */\n guides?: CurveGuides;\n /**\n * Labels for screen readers: see TaoxCurveEditor.\n * Подписи для скринридеров: см. TaoxCurveEditor.\n */\n pointLabel?: (index: number, point: CurvePoint) => string;\n handleLabel?: (n: number, index: number) => string;\n /**\n * How the plot writes time (its axis and the tag of the selected point): see TaoxCurveEditor.\n * Как график записывает время (ось и метка выбранной точки): см. TaoxCurveEditor.\n */\n formatT?: (t: number) => string;\n }>(),\n { stepT: 0.05, snap: true, guides: 'lines' },\n);\nconst emit = defineEmits<{ 'update:modelValue': [value: CurvePoint[]]; commit: [] }>();\n\nconst DEFAULT_LABELS: CurveFieldLabels = {\n time: 'Time',\n value: 'Value',\n transition: 'Transition to the next point',\n snap: 'Snap to grid',\n remove: 'Remove',\n reset: 'Reset',\n hint: 'Double-click adds a point, Alt+click or Delete removes it, Shift disables snapping',\n};\nconst text = computed(() => ({ ...DEFAULT_LABELS, ...props.labels }));\n\nconst selected = ref(0);\nconst snapOn = ref(props.snap);\n\nconst points = computed(() => props.modelValue.map((p) => ({ ...p })));\nconst current = computed(() => points.value[Math.min(selected.value, points.value.length - 1)]!);\nconst stepV = computed(() => {\n const b = valueBounds(points.value, props.min, props.max);\n return niceStep(b.max - b.min, 20);\n});\nconst canReset = computed(() => props.defaultValue !== undefined && JSON.stringify(points.value) !== JSON.stringify(props.defaultValue));\n\nfunction change(next: CurvePoint[]) {\n emit('update:modelValue', next);\n}\n\nfunction removeSelected() {\n change(removePoint(points.value, selected.value));\n selected.value = 0;\n emit('commit');\n}\n\nfunction setField(field: 't' | 'v', value: number | null) {\n if (value === null || !Number.isFinite(value)) return;\n const p = current.value;\n const tt = field === 't' ? roundTo(value, props.precision) : p.t;\n const v = field === 'v' ? clampTo(roundTo(value, props.precision), props.min, props.max) : p.v;\n change(movePoint(points.value, selected.value, tt, v));\n emit('commit');\n}\n\nfunction reset() {\n if (props.defaultValue === undefined) return;\n selected.value = 0;\n change(props.defaultValue.map((p) => ({ ...p })));\n emit('commit');\n}\n\n//--------------------------------------------------\n// The transition from the selected point to the next: the kind (linear, step, a family or bezier) and the direction.\n// Function names are not translated: they are known from CSS and animation libraries and would not be found by a translation.\n// Переход от выбранной точки к следующей: вид (linear, step, семейство или bezier) и направление.\n// Названия функций не переводятся: их знают по CSS и библиотекам анимации, по переводу не найдут.\n\nconst isLast = computed(() => selected.value >= points.value.length - 1);\nconst kind = computed(() => {\n const e = current.value.ease;\n if (e === undefined || e === 'linear') return 'linear';\n if (typeof e === 'object') return 'bezier';\n return easeParts(e)?.family ?? e;\n});\nconst direction = computed<EaseDirection>(() => {\n const e = current.value.ease;\n return typeof e === 'string' ? (easeParts(e)?.direction ?? 'in-out') : 'in-out';\n});\n// linear, step and Bezier have no direction: the switch stays in place, inactive, so that it is visible how this works\n// У linear, step и Безье направления нет: переключатель остаётся на месте неактивным, чтобы было видно, как это устроено\nconst hasDirection = computed(() => !isLast.value && typeof current.value.ease === 'string' && easeParts(current.value.ease) !== null);\nconst kindOptions = ['linear', 'step', ...EASE_FAMILIES, 'bezier'].map((v) => ({ value: v, label: v }));\n\nfunction applyEase(next: Ease) {\n change(setEase(points.value, selected.value, next));\n emit('commit');\n}\n\nfunction setKind(v: string | number | null) {\n if (typeof v !== 'string') return;\n if (v === 'linear' || v === 'step') applyEase(v);\n else if (v === 'bezier') applyEase({ bezier: DEFAULT_BEZIER });\n else applyEase(easeName(v as EaseFamily, direction.value));\n}\n\nfunction setDirection(v: unknown) {\n const e = current.value.ease;\n const parts = typeof e === 'string' ? easeParts(e) : null;\n if (parts && typeof v === 'string' && (EASE_DIRECTIONS as readonly string[]).includes(v)) applyEase(easeName(parts.family, v as EaseDirection));\n}\n</script>\n\n<template>\n <div class=\"tx-curve-field\">\n <TaoxCurveEditor\n :model-value=\"points\"\n v-model:selected=\"selected\"\n :min=\"min\"\n :max=\"max\"\n :precision=\"precision\"\n :snap=\"snapOn\"\n :step-t=\"stepT\"\n :hint=\"text.hint\"\n :guides=\"guides\"\n :point-label=\"pointLabel\"\n :handle-label=\"handleLabel\"\n :format-t=\"formatT\"\n @update:model-value=\"change\"\n @commit=\"emit('commit')\"\n />\n\n <div class=\"tx-curve-field__fields\">\n <label>{{ text.time }}<TaoInputNumber size=\"small\" :min=\"0\" :max=\"1\" :step=\"stepT\" :precision=\"precision\" :controls=\"false\" :model-value=\"current.t\" @update:model-value=\"(x) => setField('t', x)\" /></label>\n <label>{{ text.value }}<TaoInputNumber size=\"small\" :min=\"min\" :max=\"max\" :step=\"stepV\" :precision=\"precision\" :controls=\"false\" :model-value=\"current.v\" @update:model-value=\"(x) => setField('v', x)\" /></label>\n </div>\n\n <div class=\"tx-curve-field__ease\">\n <span class=\"tx-curve-field__title\" aria-hidden=\"true\">{{ text.transition }}</span>\n <div class=\"tx-curve-field__ease-row\" role=\"group\" :aria-label=\"text.transition\">\n <TaoSelect class=\"tx-curve-field__kind\" size=\"small\" :clearable=\"false\" :options=\"kindOptions\" :disabled=\"isLast\" :model-value=\"kind\" @update:model-value=\"setKind\" />\n <TaoSegmented size=\"small\" :disabled=\"!hasDirection\" :model-value=\"hasDirection ? direction : undefined\" @update:model-value=\"setDirection\">\n <TaoSegmentedOption v-for=\"d in EASE_DIRECTIONS\" :key=\"d\" :value=\"d\" :label=\"d\" />\n </TaoSegmented>\n </div>\n </div>\n\n <div class=\"tx-curve-field__bar\">\n <TaoSwitch v-model=\"snapOn\" :label=\"text.snap\" />\n <span class=\"tx-curve-field__spacer\" />\n <TaoButton size=\"small\" variant=\"ghost\" :disabled=\"points.length <= 2\" @click=\"removeSelected\">{{ text.remove }}</TaoButton>\n <TaoButton v-if=\"defaultValue !== undefined\" size=\"small\" variant=\"ghost\" :disabled=\"!canReset\" @click=\"reset\">{{ text.reset }}</TaoButton>\n </div>\n </div>\n</template>\n\n<style scoped>\n.tx-curve-field {\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.tx-curve-field__fields {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 8px;\n}\n\n.tx-curve-field__fields > label {\n display: flex;\n flex-direction: column;\n gap: 2px;\n color: var(--tx-curve-label, #8b929c);\n font-size: 11px;\n}\n\n.tx-curve-field__ease {\n display: flex;\n flex-direction: column;\n gap: 2px;\n}\n\n.tx-curve-field__title {\n color: var(--tx-curve-label, #8b929c);\n font-size: 11px;\n}\n\n/* The list and the direction in one row: the list takes the rest, the switch keeps its own width / Список и направление в одну строку: список забирает остаток, переключатель держит свою ширину */\n.tx-curve-field__ease-row {\n display: flex;\n align-items: center;\n gap: 6px;\n}\n\n.tx-curve-field__kind {\n flex: 1;\n min-width: 0;\n}\n\n.tx-curve-field__ease-row > :last-child {\n flex: none;\n}\n\n.tx-curve-field__bar {\n display: flex;\n align-items: center;\n gap: 4px;\n font-size: 12px;\n}\n\n.tx-curve-field__spacer {\n flex: 1;\n}\n</style>\n","<script lang=\"ts\" setup>\nimport { TaoButton, TaoInputNumber, TaoSegmented, TaoSegmentedOption, TaoSelect, TaoSwitch } from '@1337exp/taoui';\nimport { computed, ref } from 'vue';\nimport { movePoint, removePoint, setEase, TaoxCurveEditor, valueBounds, type CurveGuides, type CurvePoint } from '../curveeditor';\nimport { DEFAULT_BEZIER, EASE_DIRECTIONS, EASE_FAMILIES, easeName, easeParts, type Ease, type EaseDirection, type EaseFamily } from '../ease';\nimport { clampTo, niceStep, roundTo } from '../num';\nimport type { CurveFieldLabels } from './labels';\n\n// A curve with fields: the plot (TaoxCurveEditor), the fields of the selected point, the transition to the next point, the grid step, remove and reset.\n// The first taoux module on top of TaoUI: the plot and the logic stay in taoux, the fields and buttons are TaoUI components.\n// Кривая с полями: график (TaoxCurveEditor), поля выбранной точки, переход к следующей точке, шаг сетки, удаление и сброс.\n// Первый модуль taoux поверх TaoUI: график и логика остаются в taoux, поля и кнопки это компоненты TaoUI.\nconst props = withDefaults(\n defineProps<{\n /**\n * Curve points.\n * Точки кривой.\n */\n modelValue: readonly CurvePoint[];\n /**\n * Allowed values: they fix the plot view and do not let a point be dragged past the bound.\n * Допустимые значения: фиксируют вид графика и не дают утащить точку за границу.\n */\n min?: number;\n max?: number;\n /**\n * The \"default\" curve: without it there is no reset button.\n * Кривая «по умолчанию»: без неё кнопки сброса нет.\n */\n defaultValue?: readonly CurvePoint[];\n /**\n * How many decimals to keep in time and value; not set means do not round.\n * Сколько знаков после запятой оставлять у времени и значения; не задано — не обрезать.\n */\n precision?: number;\n /**\n * The time step of the grid and of the time field.\n * Шаг по времени у сетки и у поля времени.\n */\n stepT?: number;\n /**\n * Snapping to the grid at start.\n * Прилипание к сетке при старте.\n */\n snap?: boolean;\n /**\n * Labels in the app language; missing ones fall back to English.\n * Надписи на языке приложения; недостающие берутся английские.\n */\n labels?: Partial<CurveFieldLabels>;\n /**\n * Guides from the selected point to the axes: `off`, `lines` (default) or `values`.\n * Направляющие от выбранной точки к осям: `off`, `lines` (по умолчанию) или `values`.\n */\n guides?: CurveGuides;\n /**\n * Labels for screen readers: see TaoxCurveEditor.\n * Подписи для скринридеров: см. TaoxCurveEditor.\n */\n pointLabel?: (index: number, point: CurvePoint) => string;\n handleLabel?: (n: number, index: number) => string;\n /**\n * How the plot writes time (its axis and the tag of the selected point): see TaoxCurveEditor.\n * Как график записывает время (ось и метка выбранной точки): см. TaoxCurveEditor.\n */\n formatT?: (t: number) => string;\n }>(),\n { stepT: 0.05, snap: true, guides: 'lines' },\n);\nconst emit = defineEmits<{ 'update:modelValue': [value: CurvePoint[]]; commit: [] }>();\n\nconst DEFAULT_LABELS: CurveFieldLabels = {\n time: 'Time',\n value: 'Value',\n transition: 'Transition to the next point',\n snap: 'Snap to grid',\n remove: 'Remove',\n reset: 'Reset',\n hint: 'Double-click adds a point, Alt+click or Delete removes it, Shift disables snapping',\n};\nconst text = computed(() => ({ ...DEFAULT_LABELS, ...props.labels }));\n\nconst selected = ref(0);\nconst snapOn = ref(props.snap);\n\nconst points = computed(() => props.modelValue.map((p) => ({ ...p })));\nconst current = computed(() => points.value[Math.min(selected.value, points.value.length - 1)]!);\nconst stepV = computed(() => {\n const b = valueBounds(points.value, props.min, props.max);\n return niceStep(b.max - b.min, 20);\n});\nconst canReset = computed(() => props.defaultValue !== undefined && JSON.stringify(points.value) !== JSON.stringify(props.defaultValue));\n\nfunction change(next: CurvePoint[]) {\n emit('update:modelValue', next);\n}\n\nfunction removeSelected() {\n change(removePoint(points.value, selected.value));\n selected.value = 0;\n emit('commit');\n}\n\nfunction setField(field: 't' | 'v', value: number | null) {\n if (value === null || !Number.isFinite(value)) return;\n const p = current.value;\n const tt = field === 't' ? roundTo(value, props.precision) : p.t;\n const v = field === 'v' ? clampTo(roundTo(value, props.precision), props.min, props.max) : p.v;\n change(movePoint(points.value, selected.value, tt, v));\n emit('commit');\n}\n\nfunction reset() {\n if (props.defaultValue === undefined) return;\n selected.value = 0;\n change(props.defaultValue.map((p) => ({ ...p })));\n emit('commit');\n}\n\n//--------------------------------------------------\n// The transition from the selected point to the next: the kind (linear, step, a family or bezier) and the direction.\n// Function names are not translated: they are known from CSS and animation libraries and would not be found by a translation.\n// Переход от выбранной точки к следующей: вид (linear, step, семейство или bezier) и направление.\n// Названия функций не переводятся: их знают по CSS и библиотекам анимации, по переводу не найдут.\n\nconst isLast = computed(() => selected.value >= points.value.length - 1);\nconst kind = computed(() => {\n const e = current.value.ease;\n if (e === undefined || e === 'linear') return 'linear';\n if (typeof e === 'object') return 'bezier';\n return easeParts(e)?.family ?? e;\n});\nconst direction = computed<EaseDirection>(() => {\n const e = current.value.ease;\n return typeof e === 'string' ? (easeParts(e)?.direction ?? 'in-out') : 'in-out';\n});\n// linear, step and Bezier have no direction: the switch stays in place, inactive, so that it is visible how this works\n// У linear, step и Безье направления нет: переключатель остаётся на месте неактивным, чтобы было видно, как это устроено\nconst hasDirection = computed(() => !isLast.value && typeof current.value.ease === 'string' && easeParts(current.value.ease) !== null);\nconst kindOptions = ['linear', 'step', ...EASE_FAMILIES, 'bezier'].map((v) => ({ value: v, label: v }));\n\nfunction applyEase(next: Ease) {\n change(setEase(points.value, selected.value, next));\n emit('commit');\n}\n\nfunction setKind(v: string | number | null) {\n if (typeof v !== 'string') return;\n if (v === 'linear' || v === 'step') applyEase(v);\n else if (v === 'bezier') applyEase({ bezier: DEFAULT_BEZIER });\n else applyEase(easeName(v as EaseFamily, direction.value));\n}\n\nfunction setDirection(v: unknown) {\n const e = current.value.ease;\n const parts = typeof e === 'string' ? easeParts(e) : null;\n if (parts && typeof v === 'string' && (EASE_DIRECTIONS as readonly string[]).includes(v)) applyEase(easeName(parts.family, v as EaseDirection));\n}\n</script>\n\n<template>\n <div class=\"tx-curve-field\">\n <TaoxCurveEditor\n :model-value=\"points\"\n v-model:selected=\"selected\"\n :min=\"min\"\n :max=\"max\"\n :precision=\"precision\"\n :snap=\"snapOn\"\n :step-t=\"stepT\"\n :hint=\"text.hint\"\n :guides=\"guides\"\n :point-label=\"pointLabel\"\n :handle-label=\"handleLabel\"\n :format-t=\"formatT\"\n @update:model-value=\"change\"\n @commit=\"emit('commit')\"\n />\n\n <div class=\"tx-curve-field__fields\">\n <label>{{ text.time }}<TaoInputNumber size=\"small\" :min=\"0\" :max=\"1\" :step=\"stepT\" :precision=\"precision\" :controls=\"false\" :model-value=\"current.t\" @update:model-value=\"(x) => setField('t', x)\" /></label>\n <label>{{ text.value }}<TaoInputNumber size=\"small\" :min=\"min\" :max=\"max\" :step=\"stepV\" :precision=\"precision\" :controls=\"false\" :model-value=\"current.v\" @update:model-value=\"(x) => setField('v', x)\" /></label>\n </div>\n\n <div class=\"tx-curve-field__ease\">\n <span class=\"tx-curve-field__title\" aria-hidden=\"true\">{{ text.transition }}</span>\n <div class=\"tx-curve-field__ease-row\" role=\"group\" :aria-label=\"text.transition\">\n <TaoSelect class=\"tx-curve-field__kind\" size=\"small\" :clearable=\"false\" :options=\"kindOptions\" :disabled=\"isLast\" :model-value=\"kind\" @update:model-value=\"setKind\" />\n <TaoSegmented size=\"small\" :disabled=\"!hasDirection\" :model-value=\"hasDirection ? direction : undefined\" @update:model-value=\"setDirection\">\n <TaoSegmentedOption v-for=\"d in EASE_DIRECTIONS\" :key=\"d\" :value=\"d\" :label=\"d\" />\n </TaoSegmented>\n </div>\n </div>\n\n <div class=\"tx-curve-field__bar\">\n <TaoSwitch v-model=\"snapOn\" :label=\"text.snap\" />\n <span class=\"tx-curve-field__spacer\" />\n <TaoButton size=\"small\" variant=\"ghost\" :disabled=\"points.length <= 2\" @click=\"removeSelected\">{{ text.remove }}</TaoButton>\n <TaoButton v-if=\"defaultValue !== undefined\" size=\"small\" variant=\"ghost\" :disabled=\"!canReset\" @click=\"reset\">{{ text.reset }}</TaoButton>\n </div>\n </div>\n</template>\n\n<style scoped>\n.tx-curve-field {\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.tx-curve-field__fields {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 8px;\n}\n\n.tx-curve-field__fields > label {\n display: flex;\n flex-direction: column;\n gap: 2px;\n color: var(--tx-curve-label, #8b929c);\n font-size: 11px;\n}\n\n.tx-curve-field__ease {\n display: flex;\n flex-direction: column;\n gap: 2px;\n}\n\n.tx-curve-field__title {\n color: var(--tx-curve-label, #8b929c);\n font-size: 11px;\n}\n\n/* The list and the direction in one row: the list takes the rest, the switch keeps its own width / Список и направление в одну строку: список забирает остаток, переключатель держит свою ширину */\n.tx-curve-field__ease-row {\n display: flex;\n align-items: center;\n gap: 6px;\n}\n\n.tx-curve-field__kind {\n flex: 1;\n min-width: 0;\n}\n\n.tx-curve-field__ease-row > :last-child {\n flex: none;\n}\n\n.t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AAA,GAAAW,YAA2IR,MAAA,SAAA,GAAA;;MAA9F,MAAK;MAAQ,SAAQ;MAAS,UAAQ,CAAG,SAAA;MAAW,SAAO;;MAAO,SAAAK,cAAgB,CAAbF,gBAAAC,gBAAA,KAAA,MAAK,KAAK,GAAA,CAAA,C"}
|
|
1
|
+
{"version":3,"file":"curvefield.js","names":["_openBlock","_createElementBlock","_createVNode","_unref","TaoxCurveEditor","_createElementVNode","_createTextVNode","_toDisplayString","_withCtx","_Fragment","_renderList","_createBlock","_createCommentVNode","_sfc_main"],"sources":["../src/curvefield/TaoxCurveField.vue","../src/curvefield/TaoxCurveField.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { TaoButton, TaoInputNumber, TaoSegmented, TaoSegmentedOption, TaoSelect, TaoSwitch } from '@1337exp/taoui';\nimport { computed, ref } from 'vue';\nimport { movePoint, removePoint, setEase, TaoxCurveEditor, valueBounds, type CurveGuides, type CurvePoint } from '../curveeditor';\nimport { DEFAULT_BEZIER, EASE_DIRECTIONS, EASE_FAMILIES, easeName, easeParts, type Ease, type EaseDirection, type EaseFamily } from '../ease';\nimport { clampTo, niceStep, roundTo } from '../num';\nimport type { CurveFieldLabels } from './labels';\n\n// A curve with fields: the plot (TaoxCurveEditor), the fields of the selected point, the transition to the next point, the grid step, remove and reset.\n// The first taoux module on top of TaoUI: the plot and the logic stay in taoux, the fields and buttons are TaoUI components.\n// Кривая с полями: график (TaoxCurveEditor), поля выбранной точки, переход к следующей точке, шаг сетки, удаление и сброс.\n// Первый модуль taoux поверх TaoUI: график и логика остаются в taoux, поля и кнопки это компоненты TaoUI.\nconst props = withDefaults(\n defineProps<{\n /**\n * Curve points.\n * Точки кривой.\n */\n modelValue: readonly CurvePoint[];\n /**\n * Allowed values: they fix the plot view and do not let a point be dragged past the bound.\n * Допустимые значения: фиксируют вид графика и не дают утащить точку за границу.\n */\n min?: number;\n max?: number;\n /**\n * The \"default\" curve: without it there is no reset button.\n * Кривая «по умолчанию»: без неё кнопки сброса нет.\n */\n defaultValue?: readonly CurvePoint[];\n /**\n * How many decimals to keep in time and value; not set means do not round.\n * Сколько знаков после запятой оставлять у времени и значения; не задано — не обрезать.\n */\n precision?: number;\n /**\n * The time step of the grid and of the time field.\n * Шаг по времени у сетки и у поля времени.\n */\n stepT?: number;\n /**\n * Snapping to the grid at start.\n * Прилипание к сетке при старте.\n */\n snap?: boolean;\n /**\n * Labels in the app language; missing ones fall back to English.\n * Надписи на языке приложения; недостающие берутся английские.\n */\n labels?: Partial<CurveFieldLabels>;\n /**\n * Guides from the selected point to the axes: `off`, `lines` (default) or `values`.\n * Направляющие от выбранной точки к осям: `off`, `lines` (по умолчанию) или `values`.\n */\n guides?: CurveGuides;\n /**\n * Labels for screen readers: see TaoxCurveEditor.\n * Подписи для скринридеров: см. TaoxCurveEditor.\n */\n pointLabel?: (index: number, point: CurvePoint) => string;\n handleLabel?: (n: number, index: number) => string;\n /**\n * How the plot writes time (its axis and the tag of the selected point): see TaoxCurveEditor.\n * Как график записывает время (ось и метка выбранной точки): см. TaoxCurveEditor.\n */\n formatT?: (t: number) => string;\n }>(),\n { stepT: 0.05, snap: true, guides: 'lines' },\n);\nconst emit = defineEmits<{ 'update:modelValue': [value: CurvePoint[]]; commit: [] }>();\n\nconst DEFAULT_LABELS: CurveFieldLabels = {\n time: 'Time',\n value: 'Value',\n transition: 'Transition to the next point',\n snap: 'Snap to grid',\n remove: 'Remove',\n reset: 'Reset',\n hint: 'Double-click adds a point, Alt+click or Delete removes it, Shift disables snapping',\n};\nconst text = computed(() => ({ ...DEFAULT_LABELS, ...props.labels }));\n\nconst selected = ref(0);\nconst snapOn = ref(props.snap);\n\nconst points = computed(() => props.modelValue.map((p) => ({ ...p })));\nconst current = computed(() => points.value[Math.min(selected.value, points.value.length - 1)]!);\nconst stepV = computed(() => {\n const b = valueBounds(points.value, props.min, props.max);\n return niceStep(b.max - b.min, 20);\n});\nconst canReset = computed(() => props.defaultValue !== undefined && JSON.stringify(points.value) !== JSON.stringify(props.defaultValue));\n\nfunction change(next: CurvePoint[]) {\n emit('update:modelValue', next);\n}\n\nfunction removeSelected() {\n change(removePoint(points.value, selected.value));\n selected.value = 0;\n emit('commit');\n}\n\nfunction setField(field: 't' | 'v', value: number | null) {\n if (value === null || !Number.isFinite(value)) return;\n const p = current.value;\n const tt = field === 't' ? roundTo(value, props.precision) : p.t;\n const v = field === 'v' ? clampTo(roundTo(value, props.precision), props.min, props.max) : p.v;\n change(movePoint(points.value, selected.value, tt, v));\n emit('commit');\n}\n\nfunction reset() {\n if (props.defaultValue === undefined) return;\n selected.value = 0;\n change(props.defaultValue.map((p) => ({ ...p })));\n emit('commit');\n}\n\n//--------------------------------------------------\n// The transition from the selected point to the next: the kind (linear, step, a family or bezier) and the direction.\n// Function names are not translated: they are known from CSS and animation libraries and would not be found by a translation.\n// Переход от выбранной точки к следующей: вид (linear, step, семейство или bezier) и направление.\n// Названия функций не переводятся: их знают по CSS и библиотекам анимации, по переводу не найдут.\n\nconst isLast = computed(() => selected.value >= points.value.length - 1);\nconst kind = computed(() => {\n const e = current.value.ease;\n if (e === undefined || e === 'linear') return 'linear';\n if (typeof e === 'object') return 'bezier';\n return easeParts(e)?.family ?? e;\n});\nconst direction = computed<EaseDirection>(() => {\n const e = current.value.ease;\n return typeof e === 'string' ? (easeParts(e)?.direction ?? 'in-out') : 'in-out';\n});\n// linear, step and Bezier have no direction: the switch stays in place, inactive, so that it is visible how this works\n// У linear, step и Безье направления нет: переключатель остаётся на месте неактивным, чтобы было видно, как это устроено\nconst hasDirection = computed(() => !isLast.value && typeof current.value.ease === 'string' && easeParts(current.value.ease) !== null);\nconst kindOptions = ['linear', 'step', ...EASE_FAMILIES, 'bezier'].map((v) => ({ id: v, label: v }));\n\nfunction applyEase(next: Ease) {\n change(setEase(points.value, selected.value, next));\n emit('commit');\n}\n\nfunction setKind(v: string | number | null) {\n if (typeof v !== 'string') return;\n if (v === 'linear' || v === 'step') applyEase(v);\n else if (v === 'bezier') applyEase({ bezier: DEFAULT_BEZIER });\n else applyEase(easeName(v as EaseFamily, direction.value));\n}\n\nfunction setDirection(v: unknown) {\n const e = current.value.ease;\n const parts = typeof e === 'string' ? easeParts(e) : null;\n if (parts && typeof v === 'string' && (EASE_DIRECTIONS as readonly string[]).includes(v)) applyEase(easeName(parts.family, v as EaseDirection));\n}\n</script>\n\n<template>\n <div class=\"tx-curve-field\">\n <TaoxCurveEditor\n :model-value=\"points\"\n v-model:selected=\"selected\"\n :min=\"min\"\n :max=\"max\"\n :precision=\"precision\"\n :snap=\"snapOn\"\n :step-t=\"stepT\"\n :hint=\"text.hint\"\n :guides=\"guides\"\n :point-label=\"pointLabel\"\n :handle-label=\"handleLabel\"\n :format-t=\"formatT\"\n @update:model-value=\"change\"\n @commit=\"emit('commit')\"\n />\n\n <div class=\"tx-curve-field__fields\">\n <label>{{ text.time }}<TaoInputNumber size=\"small\" :min=\"0\" :max=\"1\" :step=\"stepT\" :precision=\"precision\" :controls=\"false\" :model-value=\"current.t\" @update:model-value=\"(x) => setField('t', x)\" /></label>\n <label>{{ text.value }}<TaoInputNumber size=\"small\" :min=\"min\" :max=\"max\" :step=\"stepV\" :precision=\"precision\" :controls=\"false\" :model-value=\"current.v\" @update:model-value=\"(x) => setField('v', x)\" /></label>\n </div>\n\n <div class=\"tx-curve-field__ease\">\n <span class=\"tx-curve-field__title\" aria-hidden=\"true\">{{ text.transition }}</span>\n <div class=\"tx-curve-field__ease-row\" role=\"group\" :aria-label=\"text.transition\">\n <TaoSelect class=\"tx-curve-field__kind\" size=\"small\" :clearable=\"false\" :items=\"kindOptions\" :disabled=\"isLast\" :model-value=\"kind\" @update:model-value=\"setKind\" />\n <TaoSegmented size=\"small\" :disabled=\"!hasDirection\" :model-value=\"hasDirection ? direction : undefined\" @update:model-value=\"setDirection\">\n <TaoSegmentedOption v-for=\"d in EASE_DIRECTIONS\" :key=\"d\" :value=\"d\" :label=\"d\" />\n </TaoSegmented>\n </div>\n </div>\n\n <div class=\"tx-curve-field__bar\">\n <TaoSwitch v-model=\"snapOn\" :label=\"text.snap\" />\n <span class=\"tx-curve-field__spacer\" />\n <TaoButton size=\"small\" variant=\"ghost\" :disabled=\"points.length <= 2\" @click=\"removeSelected\">{{ text.remove }}</TaoButton>\n <TaoButton v-if=\"defaultValue !== undefined\" size=\"small\" variant=\"ghost\" :disabled=\"!canReset\" @click=\"reset\">{{ text.reset }}</TaoButton>\n </div>\n </div>\n</template>\n\n<style scoped>\n.tx-curve-field {\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.tx-curve-field__fields {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 8px;\n}\n\n.tx-curve-field__fields > label {\n display: flex;\n flex-direction: column;\n gap: 2px;\n color: var(--tx-curve-label, #8b929c);\n font-size: 11px;\n}\n\n.tx-curve-field__ease {\n display: flex;\n flex-direction: column;\n gap: 2px;\n}\n\n.tx-curve-field__title {\n color: var(--tx-curve-label, #8b929c);\n font-size: 11px;\n}\n\n/* The list and the direction in one row: the list takes the rest, the switch keeps its own width / Список и направление в одну строку: список забирает остаток, переключатель держит свою ширину */\n.tx-curve-field__ease-row {\n display: flex;\n align-items: center;\n gap: 6px;\n}\n\n.tx-curve-field__kind {\n flex: 1;\n min-width: 0;\n}\n\n.tx-curve-field__ease-row > :last-child {\n flex: none;\n}\n\n.tx-curve-field__bar {\n display: flex;\n align-items: center;\n gap: 4px;\n font-size: 12px;\n}\n\n.tx-curve-field__spacer {\n flex: 1;\n}\n</style>\n","<script lang=\"ts\" setup>\nimport { TaoButton, TaoInputNumber, TaoSegmented, TaoSegmentedOption, TaoSelect, TaoSwitch } from '@1337exp/taoui';\nimport { computed, ref } from 'vue';\nimport { movePoint, removePoint, setEase, TaoxCurveEditor, valueBounds, type CurveGuides, type CurvePoint } from '../curveeditor';\nimport { DEFAULT_BEZIER, EASE_DIRECTIONS, EASE_FAMILIES, easeName, easeParts, type Ease, type EaseDirection, type EaseFamily } from '../ease';\nimport { clampTo, niceStep, roundTo } from '../num';\nimport type { CurveFieldLabels } from './labels';\n\n// A curve with fields: the plot (TaoxCurveEditor), the fields of the selected point, the transition to the next point, the grid step, remove and reset.\n// The first taoux module on top of TaoUI: the plot and the logic stay in taoux, the fields and buttons are TaoUI components.\n// Кривая с полями: график (TaoxCurveEditor), поля выбранной точки, переход к следующей точке, шаг сетки, удаление и сброс.\n// Первый модуль taoux поверх TaoUI: график и логика остаются в taoux, поля и кнопки это компоненты TaoUI.\nconst props = withDefaults(\n defineProps<{\n /**\n * Curve points.\n * Точки кривой.\n */\n modelValue: readonly CurvePoint[];\n /**\n * Allowed values: they fix the plot view and do not let a point be dragged past the bound.\n * Допустимые значения: фиксируют вид графика и не дают утащить точку за границу.\n */\n min?: number;\n max?: number;\n /**\n * The \"default\" curve: without it there is no reset button.\n * Кривая «по умолчанию»: без неё кнопки сброса нет.\n */\n defaultValue?: readonly CurvePoint[];\n /**\n * How many decimals to keep in time and value; not set means do not round.\n * Сколько знаков после запятой оставлять у времени и значения; не задано — не обрезать.\n */\n precision?: number;\n /**\n * The time step of the grid and of the time field.\n * Шаг по времени у сетки и у поля времени.\n */\n stepT?: number;\n /**\n * Snapping to the grid at start.\n * Прилипание к сетке при старте.\n */\n snap?: boolean;\n /**\n * Labels in the app language; missing ones fall back to English.\n * Надписи на языке приложения; недостающие берутся английские.\n */\n labels?: Partial<CurveFieldLabels>;\n /**\n * Guides from the selected point to the axes: `off`, `lines` (default) or `values`.\n * Направляющие от выбранной точки к осям: `off`, `lines` (по умолчанию) или `values`.\n */\n guides?: CurveGuides;\n /**\n * Labels for screen readers: see TaoxCurveEditor.\n * Подписи для скринридеров: см. TaoxCurveEditor.\n */\n pointLabel?: (index: number, point: CurvePoint) => string;\n handleLabel?: (n: number, index: number) => string;\n /**\n * How the plot writes time (its axis and the tag of the selected point): see TaoxCurveEditor.\n * Как график записывает время (ось и метка выбранной точки): см. TaoxCurveEditor.\n */\n formatT?: (t: number) => string;\n }>(),\n { stepT: 0.05, snap: true, guides: 'lines' },\n);\nconst emit = defineEmits<{ 'update:modelValue': [value: CurvePoint[]]; commit: [] }>();\n\nconst DEFAULT_LABELS: CurveFieldLabels = {\n time: 'Time',\n value: 'Value',\n transition: 'Transition to the next point',\n snap: 'Snap to grid',\n remove: 'Remove',\n reset: 'Reset',\n hint: 'Double-click adds a point, Alt+click or Delete removes it, Shift disables snapping',\n};\nconst text = computed(() => ({ ...DEFAULT_LABELS, ...props.labels }));\n\nconst selected = ref(0);\nconst snapOn = ref(props.snap);\n\nconst points = computed(() => props.modelValue.map((p) => ({ ...p })));\nconst current = computed(() => points.value[Math.min(selected.value, points.value.length - 1)]!);\nconst stepV = computed(() => {\n const b = valueBounds(points.value, props.min, props.max);\n return niceStep(b.max - b.min, 20);\n});\nconst canReset = computed(() => props.defaultValue !== undefined && JSON.stringify(points.value) !== JSON.stringify(props.defaultValue));\n\nfunction change(next: CurvePoint[]) {\n emit('update:modelValue', next);\n}\n\nfunction removeSelected() {\n change(removePoint(points.value, selected.value));\n selected.value = 0;\n emit('commit');\n}\n\nfunction setField(field: 't' | 'v', value: number | null) {\n if (value === null || !Number.isFinite(value)) return;\n const p = current.value;\n const tt = field === 't' ? roundTo(value, props.precision) : p.t;\n const v = field === 'v' ? clampTo(roundTo(value, props.precision), props.min, props.max) : p.v;\n change(movePoint(points.value, selected.value, tt, v));\n emit('commit');\n}\n\nfunction reset() {\n if (props.defaultValue === undefined) return;\n selected.value = 0;\n change(props.defaultValue.map((p) => ({ ...p })));\n emit('commit');\n}\n\n//--------------------------------------------------\n// The transition from the selected point to the next: the kind (linear, step, a family or bezier) and the direction.\n// Function names are not translated: they are known from CSS and animation libraries and would not be found by a translation.\n// Переход от выбранной точки к следующей: вид (linear, step, семейство или bezier) и направление.\n// Названия функций не переводятся: их знают по CSS и библиотекам анимации, по переводу не найдут.\n\nconst isLast = computed(() => selected.value >= points.value.length - 1);\nconst kind = computed(() => {\n const e = current.value.ease;\n if (e === undefined || e === 'linear') return 'linear';\n if (typeof e === 'object') return 'bezier';\n return easeParts(e)?.family ?? e;\n});\nconst direction = computed<EaseDirection>(() => {\n const e = current.value.ease;\n return typeof e === 'string' ? (easeParts(e)?.direction ?? 'in-out') : 'in-out';\n});\n// linear, step and Bezier have no direction: the switch stays in place, inactive, so that it is visible how this works\n// У linear, step и Безье направления нет: переключатель остаётся на месте неактивным, чтобы было видно, как это устроено\nconst hasDirection = computed(() => !isLast.value && typeof current.value.ease === 'string' && easeParts(current.value.ease) !== null);\nconst kindOptions = ['linear', 'step', ...EASE_FAMILIES, 'bezier'].map((v) => ({ id: v, label: v }));\n\nfunction applyEase(next: Ease) {\n change(setEase(points.value, selected.value, next));\n emit('commit');\n}\n\nfunction setKind(v: string | number | null) {\n if (typeof v !== 'string') return;\n if (v === 'linear' || v === 'step') applyEase(v);\n else if (v === 'bezier') applyEase({ bezier: DEFAULT_BEZIER });\n else applyEase(easeName(v as EaseFamily, direction.value));\n}\n\nfunction setDirection(v: unknown) {\n const e = current.value.ease;\n const parts = typeof e === 'string' ? easeParts(e) : null;\n if (parts && typeof v === 'string' && (EASE_DIRECTIONS as readonly string[]).includes(v)) applyEase(easeName(parts.family, v as EaseDirection));\n}\n</script>\n\n<template>\n <div class=\"tx-curve-field\">\n <TaoxCurveEditor\n :model-value=\"points\"\n v-model:selected=\"selected\"\n :min=\"min\"\n :max=\"max\"\n :precision=\"precision\"\n :snap=\"snapOn\"\n :step-t=\"stepT\"\n :hint=\"text.hint\"\n :guides=\"guides\"\n :point-label=\"pointLabel\"\n :handle-label=\"handleLabel\"\n :format-t=\"formatT\"\n @update:model-value=\"change\"\n @commit=\"emit('commit')\"\n />\n\n <div class=\"tx-curve-field__fields\">\n <label>{{ text.time }}<TaoInputNumber size=\"small\" :min=\"0\" :max=\"1\" :step=\"stepT\" :precision=\"precision\" :controls=\"false\" :model-value=\"current.t\" @update:model-value=\"(x) => setField('t', x)\" /></label>\n <label>{{ text.value }}<TaoInputNumber size=\"small\" :min=\"min\" :max=\"max\" :step=\"stepV\" :precision=\"precision\" :controls=\"false\" :model-value=\"current.v\" @update:model-value=\"(x) => setField('v', x)\" /></label>\n </div>\n\n <div class=\"tx-curve-field__ease\">\n <span class=\"tx-curve-field__title\" aria-hidden=\"true\">{{ text.transition }}</span>\n <div class=\"tx-curve-field__ease-row\" role=\"group\" :aria-label=\"text.transition\">\n <TaoSelect class=\"tx-curve-field__kind\" size=\"small\" :clearable=\"false\" :items=\"kindOptions\" :disabled=\"isLast\" :model-value=\"kind\" @update:model-value=\"setKind\" />\n <TaoSegmented size=\"small\" :disabled=\"!hasDirection\" :model-value=\"hasDirection ? direction : undefined\" @update:model-value=\"setDirection\">\n <TaoSegmentedOption v-for=\"d in EASE_DIRECTIONS\" :key=\"d\" :value=\"d\" :label=\"d\" />\n </TaoSegmented>\n </div>\n </div>\n\n <div class=\"tx-curve-field__bar\">\n <TaoSwitch v-model=\"snapOn\" :label=\"text.snap\" />\n <span class=\"tx-curve-field__spacer\" />\n <TaoButton size=\"small\" variant=\"ghost\" :disabled=\"points.length <= 2\" @click=\"removeSelected\">{{ text.remove }}</TaoButton>\n <TaoButton v-if=\"defaultValue !== undefined\" size=\"small\" variant=\"ghost\" :disabled=\"!canReset\" @click=\"reset\">{{ text.reset }}</TaoButton>\n </div>\n </div>\n</template>\n\n<style scoped>\n.tx-curve-field {\n display: flex;\n flex-direction: column;\n gap: 8px;\n}\n\n.tx-curve-field__fields {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 8px;\n}\n\n.tx-curve-field__fields > label {\n display: flex;\n flex-direction: column;\n gap: 2px;\n color: var(--tx-curve-label, #8b929c);\n font-size: 11px;\n}\n\n.tx-curve-field__ease {\n display: flex;\n flex-direction: column;\n gap: 2px;\n}\n\n.tx-curve-field__title {\n color: var(--tx-curve-label, #8b929c);\n font-size: 11px;\n}\n\n/* The list and the direction in one row: the list takes the rest, the switch keeps its own width / Список и направление в одну строку: список забирает остаток, переключатель держит свою ширину */\n.tx-curve-field__ease-row {\n display: flex;\n align-items: center;\n gap: 6px;\n}\n\n.tx-curve-field__kind {\n flex: 1;\n min-width: 0;\n}\n\n.tx-curve-field__ease-row > :last-child {\n flex: none;\n}\n\n.tx-curve-field__bar {\n display: flex;\n align-items: center;\n gap: 4px;\n font-size: 12px;\n}\n\n.tx-curve-field__spacer {\n flex: 1;\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYA,MAAM,QAAQ;EAyDd,MAAM,OAAO;EAEb,MAAM,iBAAmC;GACrC,MAAM;GACN,OAAO;GACP,YAAY;GACZ,MAAM;GACN,QAAQ;GACR,OAAO;GACP,MAAM;EACV;EACA,MAAM,OAAO,gBAAgB;GAAE,GAAG;GAAgB,GAAG,MAAM;EAAO,EAAE;EAEpE,MAAM,WAAW,IAAI,CAAC;EACtB,MAAM,SAAS,IAAI,MAAM,IAAI;EAE7B,MAAM,SAAS,eAAe,MAAM,WAAW,KAAK,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC;EACrE,MAAM,UAAU,eAAe,OAAO,MAAM,KAAK,IAAI,SAAS,OAAO,OAAO,MAAM,SAAS,CAAC,EAAG;EAC/F,MAAM,QAAQ,eAAe;GACzB,MAAM,IAAI,YAAY,OAAO,OAAO,MAAM,KAAK,MAAM,GAAG;GACxD,OAAO,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE;EACrC,CAAC;EACD,MAAM,WAAW,eAAe,MAAM,iBAAiB,KAAA,KAAa,KAAK,UAAU,OAAO,KAAK,MAAM,KAAK,UAAU,MAAM,YAAY,CAAC;EAEvI,SAAS,OAAO,MAAoB;GAChC,KAAK,qBAAqB,IAAI;EAClC;EAEA,SAAS,iBAAiB;GACtB,OAAO,YAAY,OAAO,OAAO,SAAS,KAAK,CAAC;GAChD,SAAS,QAAQ;GACjB,KAAK,QAAQ;EACjB;EAEA,SAAS,SAAS,OAAkB,OAAsB;GACtD,IAAI,UAAU,QAAQ,CAAC,OAAO,SAAS,KAAK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,SAAO;;MAAgB,SAAAK,cAAiB,CAAdF,gBAAAC,gBAAA,KAAA,MAAK,MAAM,GAAA,CAAA,C;;;KAC5F,QAAA,iBAAiB,KAAA,KAAlCP,UAAA,GAAAW,YAA2IR,MAAA,SAAA,GAAA;;MAA9F,MAAK;MAAQ,SAAQ;MAAS,UAAQ,CAAG,SAAA;MAAW,SAAO;;MAAO,SAAAK,cAAgB,CAAbF,gBAAAC,gBAAA,KAAA,MAAK,KAAK,GAAA,CAAA,C"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type Ease } from './ease';
|
|
2
|
+
/**
|
|
3
|
+
* A curve point: t in 0…1, v is the value. `ease` sets how to go from this point to the next (linear by default);
|
|
4
|
+
* on the last point it has no effect.
|
|
5
|
+
* Точка кривой: t в 0…1, v значение. `ease` задаёт, как идти от этой точки к следующей (по умолчанию линейно);
|
|
6
|
+
* у последней точки он ни на что не влияет.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Guides from the selected point to the axes: none, lines only, lines and values.
|
|
10
|
+
* Направляющие от выбранной точки к осям: нет, только линии, линии и значения.
|
|
11
|
+
*/
|
|
12
|
+
export type CurveGuides = 'off' | 'lines' | 'values';
|
|
13
|
+
export interface CurvePoint {
|
|
14
|
+
t: number;
|
|
15
|
+
v: number;
|
|
16
|
+
ease?: Ease;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The curve value at t: beyond the end points it equals the end point, between them it follows the `ease` of the left point (linear without it).
|
|
20
|
+
* Значение кривой в t: вне крайних точек равно крайней, между ними по переходу `ease` левой точки (без него линейно).
|
|
21
|
+
*/
|
|
22
|
+
export declare function sampleCurve(points: readonly CurvePoint[], t: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Moves point `i`: along t it stays between its neighbours (the order is kept), along v it is free.
|
|
25
|
+
* Двигает точку `i`: по t она остаётся между соседями (порядок не нарушается), по v свободна.
|
|
26
|
+
*/
|
|
27
|
+
export declare function movePoint(points: readonly CurvePoint[], i: number, t: number, v: number): CurvePoint[];
|
|
28
|
+
/**
|
|
29
|
+
* Adds a point at `t` with value `v` (the curve value at that point by default); returns the new list and the point index.
|
|
30
|
+
* Добавляет точку в `t` со значением `v` (по умолчанию значение кривой в этой точке); возвращает новый список и индекс точки.
|
|
31
|
+
*/
|
|
32
|
+
export declare function addPoint(points: readonly CurvePoint[], t: number, v?: number): {
|
|
33
|
+
points: CurvePoint[];
|
|
34
|
+
index: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Removes a point; never leaves fewer than two (a curve of one point is just a number).
|
|
38
|
+
* Убирает точку; меньше двух точек не оставляет (кривая из одной точки это просто число).
|
|
39
|
+
*/
|
|
40
|
+
export declare function removePoint(points: readonly CurvePoint[], i: number): CurvePoint[];
|
|
41
|
+
/**
|
|
42
|
+
* The polyline of segment a→b for drawing: a straight one has two ends, other transitions `steps` pieces (a step: a corner).
|
|
43
|
+
* Ломаная участка a→b для рисования: у прямой два конца, у остальных переходов `steps` отрезков (ступенька: угол).
|
|
44
|
+
*/
|
|
45
|
+
export declare function sampleSegment(a: CurvePoint, b: CurvePoint, steps?: number): {
|
|
46
|
+
t: number;
|
|
47
|
+
v: number;
|
|
48
|
+
}[];
|
|
49
|
+
/**
|
|
50
|
+
* A copy of the list with the transition of point `i` (`undefined` and `linear` remove the field: the file stays short).
|
|
51
|
+
* Копия списка с переходом точки `i` (`undefined` и `linear` убирают поле: файл остаётся коротким).
|
|
52
|
+
*/
|
|
53
|
+
export declare function setEase(points: readonly CurvePoint[], i: number, ease: Ease | undefined): CurvePoint[];
|
|
54
|
+
/**
|
|
55
|
+
* Value limits for drawing: from 0 (or below the minimum) to the maximum with some headroom, no narrower than 0…1.
|
|
56
|
+
* The given `min`/`max` (the field bounds) fix the view: the plot neither drifts nor leaves the allowed range.
|
|
57
|
+
* Пределы значений для отрисовки: от 0 (или ниже минимума) до максимума с запасом, не уже чем 0…1.
|
|
58
|
+
* Заданные `min`/`max` (границы поля) фиксируют вид: график не плывёт и не выходит за допустимое.
|
|
59
|
+
*/
|
|
60
|
+
export declare function valueBounds(points: readonly CurvePoint[], min?: number, max?: number): {
|
|
61
|
+
min: number;
|
|
62
|
+
max: number;
|
|
63
|
+
};
|
package/dist/curveops.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { clamp01 } from "./num.js";
|
|
2
|
+
import { easeValue } from "./ease.js";
|
|
3
|
+
//#region src/curveops.ts
|
|
4
|
+
/**
|
|
5
|
+
* The curve value at t: beyond the end points it equals the end point, between them it follows the `ease` of the left point (linear without it).
|
|
6
|
+
* Значение кривой в t: вне крайних точек равно крайней, между ними по переходу `ease` левой точки (без него линейно).
|
|
7
|
+
*/
|
|
8
|
+
function sampleCurve(points, t) {
|
|
9
|
+
const n = points.length;
|
|
10
|
+
if (n === 0) return 0;
|
|
11
|
+
const x = clamp01(t);
|
|
12
|
+
if (x <= points[0].t) return points[0].v;
|
|
13
|
+
if (x >= points[n - 1].t) return points[n - 1].v;
|
|
14
|
+
for (let i = 1; i < n; i++) {
|
|
15
|
+
const b = points[i];
|
|
16
|
+
if (x <= b.t) {
|
|
17
|
+
const a = points[i - 1];
|
|
18
|
+
const span = b.t - a.t;
|
|
19
|
+
return span <= 0 ? b.v : a.v + (b.v - a.v) * easeValue(a.ease, (x - a.t) / span);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return points[n - 1].v;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Moves point `i`: along t it stays between its neighbours (the order is kept), along v it is free.
|
|
26
|
+
* Двигает точку `i`: по t она остаётся между соседями (порядок не нарушается), по v свободна.
|
|
27
|
+
*/
|
|
28
|
+
function movePoint(points, i, t, v) {
|
|
29
|
+
const next = points.map((p) => ({ ...p }));
|
|
30
|
+
const lo = i > 0 ? next[i - 1].t : 0;
|
|
31
|
+
const hi = i < next.length - 1 ? next[i + 1].t : 1;
|
|
32
|
+
next[i] = {
|
|
33
|
+
...next[i],
|
|
34
|
+
t: Math.min(hi, Math.max(lo, clamp01(t))),
|
|
35
|
+
v
|
|
36
|
+
};
|
|
37
|
+
return next;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Adds a point at `t` with value `v` (the curve value at that point by default); returns the new list and the point index.
|
|
41
|
+
* Добавляет точку в `t` со значением `v` (по умолчанию значение кривой в этой точке); возвращает новый список и индекс точки.
|
|
42
|
+
*/
|
|
43
|
+
function addPoint(points, t, v) {
|
|
44
|
+
const x = clamp01(t);
|
|
45
|
+
const next = points.map((p) => ({ ...p }));
|
|
46
|
+
const at = next.findIndex((p) => p.t > x);
|
|
47
|
+
const index = at === -1 ? next.length : at;
|
|
48
|
+
next.splice(index, 0, {
|
|
49
|
+
t: x,
|
|
50
|
+
v: v ?? sampleCurve(points, x)
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
points: next,
|
|
54
|
+
index
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Removes a point; never leaves fewer than two (a curve of one point is just a number).
|
|
59
|
+
* Убирает точку; меньше двух точек не оставляет (кривая из одной точки это просто число).
|
|
60
|
+
*/
|
|
61
|
+
function removePoint(points, i) {
|
|
62
|
+
if (points.length <= 2) return points.map((p) => ({ ...p }));
|
|
63
|
+
return points.filter((_, k) => k !== i).map((p) => ({ ...p }));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A segment transition that is neither a straight line nor a step: its shape has to be drawn and taken into account when choosing the view.
|
|
67
|
+
* Переход участка, который не прямая и не ступенька: его форму нужно рисовать и учитывать при подборе вида.
|
|
68
|
+
*/
|
|
69
|
+
var curved = (e) => e !== void 0 && e !== "linear" && e !== "step";
|
|
70
|
+
/**
|
|
71
|
+
* The polyline of segment a→b for drawing: a straight one has two ends, other transitions `steps` pieces (a step: a corner).
|
|
72
|
+
* Ломаная участка a→b для рисования: у прямой два конца, у остальных переходов `steps` отрезков (ступенька: угол).
|
|
73
|
+
*/
|
|
74
|
+
function sampleSegment(a, b, steps = 24) {
|
|
75
|
+
if (a.ease === "step") return [
|
|
76
|
+
{
|
|
77
|
+
t: a.t,
|
|
78
|
+
v: a.v
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
t: b.t,
|
|
82
|
+
v: a.v
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
t: b.t,
|
|
86
|
+
v: b.v
|
|
87
|
+
}
|
|
88
|
+
];
|
|
89
|
+
if (!curved(a.ease)) return [{
|
|
90
|
+
t: a.t,
|
|
91
|
+
v: a.v
|
|
92
|
+
}, {
|
|
93
|
+
t: b.t,
|
|
94
|
+
v: b.v
|
|
95
|
+
}];
|
|
96
|
+
const out = [];
|
|
97
|
+
for (let i = 0; i <= steps; i++) {
|
|
98
|
+
const u = i / steps;
|
|
99
|
+
out.push({
|
|
100
|
+
t: a.t + (b.t - a.t) * u,
|
|
101
|
+
v: a.v + (b.v - a.v) * easeValue(a.ease, u)
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A copy of the list with the transition of point `i` (`undefined` and `linear` remove the field: the file stays short).
|
|
108
|
+
* Копия списка с переходом точки `i` (`undefined` и `linear` убирают поле: файл остаётся коротким).
|
|
109
|
+
*/
|
|
110
|
+
function setEase(points, i, ease) {
|
|
111
|
+
return points.map((p, k) => {
|
|
112
|
+
if (k !== i) return { ...p };
|
|
113
|
+
const { ease: _old, ...rest } = p;
|
|
114
|
+
return ease === void 0 || ease === "linear" ? rest : {
|
|
115
|
+
...rest,
|
|
116
|
+
ease
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Value limits for drawing: from 0 (or below the minimum) to the maximum with some headroom, no narrower than 0…1.
|
|
122
|
+
* The given `min`/`max` (the field bounds) fix the view: the plot neither drifts nor leaves the allowed range.
|
|
123
|
+
* Пределы значений для отрисовки: от 0 (или ниже минимума) до максимума с запасом, не уже чем 0…1.
|
|
124
|
+
* Заданные `min`/`max` (границы поля) фиксируют вид: график не плывёт и не выходит за допустимое.
|
|
125
|
+
*/
|
|
126
|
+
function valueBounds(points, min, max) {
|
|
127
|
+
let lo = 0;
|
|
128
|
+
let hi = 1;
|
|
129
|
+
for (const p of points) {
|
|
130
|
+
lo = Math.min(lo, p.v);
|
|
131
|
+
hi = Math.max(hi, p.v);
|
|
132
|
+
}
|
|
133
|
+
let outLo = Infinity;
|
|
134
|
+
let outHi = -Infinity;
|
|
135
|
+
const see = (v) => {
|
|
136
|
+
lo = Math.min(lo, v);
|
|
137
|
+
hi = Math.max(hi, v);
|
|
138
|
+
outLo = Math.min(outLo, v);
|
|
139
|
+
outHi = Math.max(outHi, v);
|
|
140
|
+
};
|
|
141
|
+
for (let i = 0; i < points.length - 1; i++) {
|
|
142
|
+
const a = points[i];
|
|
143
|
+
if (!curved(a.ease)) continue;
|
|
144
|
+
if (typeof a.ease === "object") {
|
|
145
|
+
const dv = points[i + 1].v - a.v;
|
|
146
|
+
for (const y of [a.ease.bezier[1], a.ease.bezier[3]]) see(a.v + y * dv);
|
|
147
|
+
}
|
|
148
|
+
for (const s of sampleSegment(points[i], points[i + 1])) see(s.v);
|
|
149
|
+
}
|
|
150
|
+
const auto = {
|
|
151
|
+
min: lo,
|
|
152
|
+
max: hi === lo ? lo + 1 : hi * 1.1
|
|
153
|
+
};
|
|
154
|
+
const a = min === void 0 ? auto.min : Math.min(min, outLo);
|
|
155
|
+
const b = max === void 0 ? auto.max : Math.max(max, outHi);
|
|
156
|
+
return b > a ? {
|
|
157
|
+
min: a,
|
|
158
|
+
max: b
|
|
159
|
+
} : {
|
|
160
|
+
min: a,
|
|
161
|
+
max: a + 1
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
export { addPoint, movePoint, removePoint, sampleCurve, sampleSegment, setEase, valueBounds };
|
|
166
|
+
|
|
167
|
+
//# sourceMappingURL=curveops.js.map
|