@1337exp/taoux 0.0.0-stage → 0.1.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.
Files changed (94) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +21 -0
  3. package/README.md +137 -2
  4. package/README.ru.md +140 -0
  5. package/dist/camera.d.ts +22 -0
  6. package/dist/camera.js +38 -0
  7. package/dist/camera.js.map +1 -0
  8. package/dist/canvas/TaoxCanvas.vue.d.ts +37 -0
  9. package/dist/canvas/host.d.ts +138 -0
  10. package/dist/canvas/index.d.ts +3 -0
  11. package/dist/canvas/useCanvasGestures.d.ts +44 -0
  12. package/dist/canvas.css +55 -0
  13. package/dist/canvas.js +696 -0
  14. package/dist/canvas.js.map +1 -0
  15. package/dist/chunks/curveeditor-goX9maE5.js +759 -0
  16. package/dist/chunks/curveeditor-goX9maE5.js.map +1 -0
  17. package/dist/curve.d.ts +53 -0
  18. package/dist/curve.js +81 -0
  19. package/dist/curve.js.map +1 -0
  20. package/dist/curveeditor/TaoxCurveEditor.vue.d.ts +74 -0
  21. package/dist/curveeditor/index.d.ts +3 -0
  22. package/dist/curveeditor/ops.d.ts +63 -0
  23. package/dist/curveeditor.css +115 -0
  24. package/dist/curveeditor.js +1 -0
  25. package/dist/curvefield/TaoxCurveField.vue.d.ts +64 -0
  26. package/dist/curvefield/index.d.ts +2 -0
  27. package/dist/curvefield/labels.d.ts +13 -0
  28. package/dist/curvefield.css +57 -0
  29. package/dist/curvefield.js +252 -0
  30. package/dist/curvefield.js.map +1 -0
  31. package/dist/ease.d.ts +62 -0
  32. package/dist/ease.js +157 -0
  33. package/dist/ease.js.map +1 -0
  34. package/dist/edgescroll.d.ts +77 -0
  35. package/dist/edgescroll.js +78 -0
  36. package/dist/edgescroll.js.map +1 -0
  37. package/dist/file.d.ts +10 -0
  38. package/dist/file.js +22 -0
  39. package/dist/file.js.map +1 -0
  40. package/dist/gestures.d.ts +174 -0
  41. package/dist/gestures.js +229 -0
  42. package/dist/gestures.js.map +1 -0
  43. package/dist/gradienteditor/TaoxGradientEditor.vue.d.ts +48 -0
  44. package/dist/gradienteditor/index.d.ts +2 -0
  45. package/dist/gradienteditor/ops.d.ts +83 -0
  46. package/dist/gradienteditor.css +81 -0
  47. package/dist/gradienteditor.js +337 -0
  48. package/dist/gradienteditor.js.map +1 -0
  49. package/dist/history.d.ts +42 -0
  50. package/dist/history.js +89 -0
  51. package/dist/history.js.map +1 -0
  52. package/dist/i18n.d.ts +51 -0
  53. package/dist/i18n.js +102 -0
  54. package/dist/i18n.js.map +1 -0
  55. package/dist/ids.d.ts +5 -0
  56. package/dist/ids.js +17 -0
  57. package/dist/ids.js.map +1 -0
  58. package/dist/links/TaoxLinks.vue.d.ts +14 -0
  59. package/dist/links/index.d.ts +2 -0
  60. package/dist/links/types.d.ts +37 -0
  61. package/dist/links.css +80 -0
  62. package/dist/links.js +72 -0
  63. package/dist/links.js.map +1 -0
  64. package/dist/num.d.ts +35 -0
  65. package/dist/num.js +60 -0
  66. package/dist/num.js.map +1 -0
  67. package/dist/palette.d.ts +34 -0
  68. package/dist/palette.js +41 -0
  69. package/dist/palette.js.map +1 -0
  70. package/dist/pins.d.ts +66 -0
  71. package/dist/pins.js +83 -0
  72. package/dist/pins.js.map +1 -0
  73. package/dist/playback/core.d.ts +81 -0
  74. package/dist/playback/index.d.ts +2 -0
  75. package/dist/playback/use.d.ts +38 -0
  76. package/dist/playback.js +199 -0
  77. package/dist/playback.js.map +1 -0
  78. package/dist/session.d.ts +125 -0
  79. package/dist/session.js +195 -0
  80. package/dist/session.js.map +1 -0
  81. package/dist/snap.d.ts +24 -0
  82. package/dist/snap.js +34 -0
  83. package/dist/snap.js.map +1 -0
  84. package/dist/storage.d.ts +16 -0
  85. package/dist/storage.js +30 -0
  86. package/dist/storage.js.map +1 -0
  87. package/dist/touch.d.ts +9 -0
  88. package/dist/touch.js +20 -0
  89. package/dist/touch.js.map +1 -0
  90. package/dist/wheel.d.ts +31 -0
  91. package/dist/wheel.js +47 -0
  92. package/dist/wheel.js.map +1 -0
  93. package/package.json +183 -4
  94. package/theme/taoui.css +43 -0
@@ -0,0 +1,759 @@
1
+ import { createEdgeScroller } from "../edgescroll.js";
2
+ import { clamp01, clampTo, niceStep, roundTo, snapTo, ticks } from "../num.js";
3
+ import { easeValue } from "../ease.js";
4
+ import { Fragment, computed, createCommentVNode, createElementBlock, createElementVNode, defineComponent, nextTick, normalizeClass, onBeforeUnmount, openBlock, ref, renderList, toDisplayString, withModifiers } from "vue";
5
+ //#region src/curveeditor/ops.ts
6
+ /**
7
+ * 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).
8
+ * Значение кривой в t: вне крайних точек равно крайней, между ними по переходу `ease` левой точки (без него линейно).
9
+ */
10
+ function sampleCurve(points, t) {
11
+ const n = points.length;
12
+ if (n === 0) return 0;
13
+ const x = clamp01(t);
14
+ if (x <= points[0].t) return points[0].v;
15
+ if (x >= points[n - 1].t) return points[n - 1].v;
16
+ for (let i = 1; i < n; i++) {
17
+ const b = points[i];
18
+ if (x <= b.t) {
19
+ const a = points[i - 1];
20
+ const span = b.t - a.t;
21
+ return span <= 0 ? b.v : a.v + (b.v - a.v) * easeValue(a.ease, (x - a.t) / span);
22
+ }
23
+ }
24
+ return points[n - 1].v;
25
+ }
26
+ /**
27
+ * Moves point `i`: along t it stays between its neighbours (the order is kept), along v it is free.
28
+ * Двигает точку `i`: по t она остаётся между соседями (порядок не нарушается), по v свободна.
29
+ */
30
+ function movePoint(points, i, t, v) {
31
+ const next = points.map((p) => ({ ...p }));
32
+ const lo = i > 0 ? next[i - 1].t : 0;
33
+ const hi = i < next.length - 1 ? next[i + 1].t : 1;
34
+ next[i] = {
35
+ ...next[i],
36
+ t: Math.min(hi, Math.max(lo, clamp01(t))),
37
+ v
38
+ };
39
+ return next;
40
+ }
41
+ /**
42
+ * Adds a point at `t` with value `v` (the curve value at that point by default); returns the new list and the point index.
43
+ * Добавляет точку в `t` со значением `v` (по умолчанию значение кривой в этой точке); возвращает новый список и индекс точки.
44
+ */
45
+ function addPoint(points, t, v) {
46
+ const x = clamp01(t);
47
+ const next = points.map((p) => ({ ...p }));
48
+ const at = next.findIndex((p) => p.t > x);
49
+ const index = at === -1 ? next.length : at;
50
+ next.splice(index, 0, {
51
+ t: x,
52
+ v: v ?? sampleCurve(points, x)
53
+ });
54
+ return {
55
+ points: next,
56
+ index
57
+ };
58
+ }
59
+ /**
60
+ * Removes a point; never leaves fewer than two (a curve of one point is just a number).
61
+ * Убирает точку; меньше двух точек не оставляет (кривая из одной точки это просто число).
62
+ */
63
+ function removePoint(points, i) {
64
+ if (points.length <= 2) return points.map((p) => ({ ...p }));
65
+ return points.filter((_, k) => k !== i).map((p) => ({ ...p }));
66
+ }
67
+ /**
68
+ * 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.
69
+ * Переход участка, который не прямая и не ступенька: его форму нужно рисовать и учитывать при подборе вида.
70
+ */
71
+ var curved = (e) => e !== void 0 && e !== "linear" && e !== "step";
72
+ /**
73
+ * The polyline of segment a→b for drawing: a straight one has two ends, other transitions `steps` pieces (a step: a corner).
74
+ * Ломаная участка a→b для рисования: у прямой два конца, у остальных переходов `steps` отрезков (ступенька: угол).
75
+ */
76
+ function sampleSegment(a, b, steps = 24) {
77
+ if (a.ease === "step") return [
78
+ {
79
+ t: a.t,
80
+ v: a.v
81
+ },
82
+ {
83
+ t: b.t,
84
+ v: a.v
85
+ },
86
+ {
87
+ t: b.t,
88
+ v: b.v
89
+ }
90
+ ];
91
+ if (!curved(a.ease)) return [{
92
+ t: a.t,
93
+ v: a.v
94
+ }, {
95
+ t: b.t,
96
+ v: b.v
97
+ }];
98
+ const out = [];
99
+ for (let i = 0; i <= steps; i++) {
100
+ const u = i / steps;
101
+ out.push({
102
+ t: a.t + (b.t - a.t) * u,
103
+ v: a.v + (b.v - a.v) * easeValue(a.ease, u)
104
+ });
105
+ }
106
+ return out;
107
+ }
108
+ /**
109
+ * A copy of the list with the transition of point `i` (`undefined` and `linear` remove the field: the file stays short).
110
+ * Копия списка с переходом точки `i` (`undefined` и `linear` убирают поле: файл остаётся коротким).
111
+ */
112
+ function setEase(points, i, ease) {
113
+ return points.map((p, k) => {
114
+ if (k !== i) return { ...p };
115
+ const { ease: _old, ...rest } = p;
116
+ return ease === void 0 || ease === "linear" ? rest : {
117
+ ...rest,
118
+ ease
119
+ };
120
+ });
121
+ }
122
+ /**
123
+ * Value limits for drawing: from 0 (or below the minimum) to the maximum with some headroom, no narrower than 0…1.
124
+ * The given `min`/`max` (the field bounds) fix the view: the plot neither drifts nor leaves the allowed range.
125
+ * Пределы значений для отрисовки: от 0 (или ниже минимума) до максимума с запасом, не уже чем 0…1.
126
+ * Заданные `min`/`max` (границы поля) фиксируют вид: график не плывёт и не выходит за допустимое.
127
+ */
128
+ function valueBounds(points, min, max) {
129
+ let lo = 0;
130
+ let hi = 1;
131
+ for (const p of points) {
132
+ lo = Math.min(lo, p.v);
133
+ hi = Math.max(hi, p.v);
134
+ }
135
+ let outLo = Infinity;
136
+ let outHi = -Infinity;
137
+ const see = (v) => {
138
+ lo = Math.min(lo, v);
139
+ hi = Math.max(hi, v);
140
+ outLo = Math.min(outLo, v);
141
+ outHi = Math.max(outHi, v);
142
+ };
143
+ for (let i = 0; i < points.length - 1; i++) {
144
+ const a = points[i];
145
+ if (!curved(a.ease)) continue;
146
+ if (typeof a.ease === "object") {
147
+ const dv = points[i + 1].v - a.v;
148
+ for (const y of [a.ease.bezier[1], a.ease.bezier[3]]) see(a.v + y * dv);
149
+ }
150
+ for (const s of sampleSegment(points[i], points[i + 1])) see(s.v);
151
+ }
152
+ const auto = {
153
+ min: lo,
154
+ max: hi === lo ? lo + 1 : hi * 1.1
155
+ };
156
+ const a = min === void 0 ? auto.min : Math.min(min, outLo);
157
+ const b = max === void 0 ? auto.max : Math.max(max, outHi);
158
+ return b > a ? {
159
+ min: a,
160
+ max: b
161
+ } : {
162
+ min: a,
163
+ max: a + 1
164
+ };
165
+ }
166
+ //#endregion
167
+ //#region src/curveeditor/TaoxCurveEditor.vue?vue&type=script&setup=true&lang.ts
168
+ var _hoisted_1 = ["viewBox", "title"];
169
+ var _hoisted_2 = [
170
+ "x1",
171
+ "x2",
172
+ "y2"
173
+ ];
174
+ var _hoisted_3 = [
175
+ "x2",
176
+ "y1",
177
+ "y2"
178
+ ];
179
+ var _hoisted_4 = ["x", "y"];
180
+ var _hoisted_5 = [
181
+ "x",
182
+ "y",
183
+ "text-anchor"
184
+ ];
185
+ var _hoisted_6 = {
186
+ key: 0,
187
+ class: "tx-curve-tags",
188
+ "aria-hidden": "true"
189
+ };
190
+ var _hoisted_7 = [
191
+ "x1",
192
+ "x2",
193
+ "y1",
194
+ "y2"
195
+ ];
196
+ var _hoisted_8 = [
197
+ "x2",
198
+ "y1",
199
+ "y2"
200
+ ];
201
+ var _hoisted_9 = [
202
+ "x",
203
+ "y",
204
+ "width"
205
+ ];
206
+ var _hoisted_10 = ["x", "y"];
207
+ var _hoisted_11 = [
208
+ "x",
209
+ "y",
210
+ "width"
211
+ ];
212
+ var _hoisted_12 = ["x", "y"];
213
+ var _hoisted_13 = ["d"];
214
+ var _hoisted_14 = ["x", "y"];
215
+ var _hoisted_15 = {
216
+ key: 1,
217
+ class: "tx-curve-bezier"
218
+ };
219
+ var _hoisted_16 = [
220
+ "x1",
221
+ "y1",
222
+ "x2",
223
+ "y2"
224
+ ];
225
+ var _hoisted_17 = [
226
+ "cx",
227
+ "cy",
228
+ "aria-label",
229
+ "onPointerdown",
230
+ "onKeydown"
231
+ ];
232
+ var _hoisted_18 = [
233
+ "cx",
234
+ "cy",
235
+ "data-index",
236
+ "aria-label",
237
+ "onFocus",
238
+ "onPointerdown"
239
+ ];
240
+ var W = 280;
241
+ var H = 132;
242
+ var PAD_L = 30;
243
+ var PAD_T = 10;
244
+ var CHAR_W = 4.6;
245
+ /**
246
+ * Pointer coordinates in curve units as they are: no snapping, rounding or bounds.
247
+ * Координаты указателя в единицах кривой, как есть: без прилипания, округления и границ.
248
+ */
249
+ var BEZIER_STEP = .05;
250
+ /**
251
+ * Handle `n` is put at (x, y) of the normalised segment: x in 0…1, y free within reasonable limits (overshoot).
252
+ * Ручка `n` ставится в (x, y) нормализованного участка: x в 0…1, y свободный в разумных пределах (заступ).
253
+ */
254
+ var COARSE = 5;
255
+ //#endregion
256
+ //#region src/curveeditor/TaoxCurveEditor.vue
257
+ var TaoxCurveEditor_default = /* @__PURE__ */ defineComponent({
258
+ __name: "TaoxCurveEditor",
259
+ props: {
260
+ modelValue: {},
261
+ selected: { default: 0 },
262
+ min: {},
263
+ max: {},
264
+ precision: {},
265
+ snap: {
266
+ type: Boolean,
267
+ default: true
268
+ },
269
+ stepT: { default: .05 },
270
+ majorT: { default: .25 },
271
+ hint: {},
272
+ pointLabel: {},
273
+ guides: { default: "lines" },
274
+ handleLabel: {}
275
+ },
276
+ emits: [
277
+ "update:modelValue",
278
+ "update:selected",
279
+ "commit"
280
+ ],
281
+ setup(__props, { emit: __emit }) {
282
+ const props = __props;
283
+ const emit = __emit;
284
+ const PLOT_W = 240;
285
+ const PLOT_H = 106;
286
+ const svg = ref(null);
287
+ const points = computed(() => props.modelValue);
288
+ const frozen = ref(null);
289
+ const shift = ref(0);
290
+ const bounds = computed(() => frozen.value ? {
291
+ min: frozen.value.min + shift.value,
292
+ max: frozen.value.max + shift.value
293
+ } : valueBounds(points.value, props.min, props.max));
294
+ const span = computed(() => bounds.value.max - bounds.value.min);
295
+ const majorV = computed(() => niceStep(span.value, 4));
296
+ const stepV = computed(() => niceStep(span.value, 20));
297
+ const gridT = computed(() => ticks(0, 1, props.stepT));
298
+ const gridV = computed(() => ticks(bounds.value.min, bounds.value.max, stepV.value));
299
+ const labelsV = computed(() => ticks(bounds.value.min, bounds.value.max, majorV.value));
300
+ const labelsT = computed(() => ticks(0, 1, props.majorT));
301
+ const isMajorT = (x) => Math.abs(x / props.majorT - Math.round(x / props.majorT)) < 1e-6;
302
+ const isMajorV = (v) => Math.abs(v / majorV.value - Math.round(v / majorV.value)) < 1e-6;
303
+ const px = (tt) => PAD_L + tt * PLOT_W;
304
+ const py = (v) => PAD_T + (1 - (v - bounds.value.min) / span.value) * PLOT_H;
305
+ const path = computed(() => {
306
+ const pts = points.value;
307
+ const out = [];
308
+ for (let i = 0; i < pts.length - 1; i++) sampleSegment(pts[i], pts[i + 1]).forEach((p, k) => out.push(`${i === 0 && k === 0 ? "M" : "L"} ${px(p.t).toFixed(1)} ${py(p.v).toFixed(1)}`));
309
+ return out.join(" ");
310
+ });
311
+ const fmt = (n) => String(Math.round(n * 1e3) / 1e3);
312
+ const tagWidth = (text) => text.length * CHAR_W + 5;
313
+ const tags = computed(() => {
314
+ const p = points.value[Math.min(props.selected, points.value.length - 1)];
315
+ if (!p) return null;
316
+ const t = fmt(p.t);
317
+ const v = fmt(p.v);
318
+ const wt = tagWidth(t);
319
+ const wv = tagWidth(v);
320
+ const cx = Math.min(W - wt / 2 - 1, Math.max(wt / 2 + 1, px(p.t)));
321
+ const cy = Math.min(111, Math.max(15, py(p.v)));
322
+ return {
323
+ x: px(p.t),
324
+ y: py(p.v),
325
+ t: {
326
+ text: t,
327
+ cx,
328
+ w: wt
329
+ },
330
+ v: {
331
+ text: v,
332
+ cy,
333
+ w: wv
334
+ }
335
+ };
336
+ });
337
+ function rawCurve(e) {
338
+ const r = svg.value.getBoundingClientRect();
339
+ const x = (e.clientX - r.left) / r.width * W;
340
+ const y = (e.clientY - r.top) / r.height * H;
341
+ const { min, max } = bounds.value;
342
+ return {
343
+ t: (x - PAD_L) / PLOT_W,
344
+ v: min + (1 - (y - PAD_T) / PLOT_H) * (max - min)
345
+ };
346
+ }
347
+ /**
348
+ * Pointer coordinates in curve units; Shift temporarily flips the snapping mode.
349
+ * Координаты указателя в единицах кривой; Shift временно меняет режим шага.
350
+ */
351
+ function toCurve(e) {
352
+ let { t: tt, v } = rawCurve(e);
353
+ if (props.snap !== e.shiftKey) {
354
+ tt = snapTo(tt, props.stepT);
355
+ v = snapTo(v, stepV.value);
356
+ }
357
+ return {
358
+ t: roundTo(tt, props.precision),
359
+ v: clampTo(roundTo(v, props.precision), props.min, props.max)
360
+ };
361
+ }
362
+ let dragging = -1;
363
+ let lastPointer = {
364
+ clientX: 0,
365
+ clientY: 0,
366
+ shiftKey: false
367
+ };
368
+ /**
369
+ * The point follows the pointer: both when it moves and when the view moved under a still pointer.
370
+ * Точка идёт за указателем: и при его движении, и когда вид уехал под неподвижным указателем.
371
+ */
372
+ function followPointer() {
373
+ if (dragging < 0) return;
374
+ const { t: tt, v } = toCurve(lastPointer);
375
+ emit("update:modelValue", movePoint(points.value, dragging, tt, v));
376
+ }
377
+ const scroller = createEdgeScroller({
378
+ bounds: () => svg.value?.getBoundingClientRect() ?? null,
379
+ pointer: () => [lastPointer.clientX, lastPointer.clientY],
380
+ enabled: () => dragging >= 0,
381
+ zone: 18,
382
+ maxSpeed: 240,
383
+ onScroll: (_dx, dy) => {
384
+ const base = frozen.value;
385
+ const r = svg.value?.getBoundingClientRect();
386
+ if (!base || !r) return;
387
+ const dv = dy * H / r.height / PLOT_H * (base.max - base.min);
388
+ const lo = props.min === void 0 ? -Infinity : props.min - base.min;
389
+ const hi = props.max === void 0 ? Infinity : props.max - base.max;
390
+ shift.value = Math.min(hi, Math.max(lo, shift.value - dv));
391
+ followPointer();
392
+ }
393
+ });
394
+ onBeforeUnmount(scroller.stop);
395
+ function onDown(e, i) {
396
+ emit("update:selected", i);
397
+ if (e.altKey) {
398
+ emit("update:modelValue", removePoint(points.value, i));
399
+ emit("update:selected", 0);
400
+ emit("commit");
401
+ return;
402
+ }
403
+ dragging = i;
404
+ lastPointer = e;
405
+ shift.value = 0;
406
+ frozen.value = valueBounds(points.value, props.min, props.max);
407
+ try {
408
+ e.currentTarget.setPointerCapture(e.pointerId);
409
+ } catch {}
410
+ }
411
+ function onMove(e) {
412
+ if (dragging < 0) return;
413
+ lastPointer = e;
414
+ followPointer();
415
+ scroller.kick();
416
+ }
417
+ function onUp() {
418
+ if (dragging < 0) return;
419
+ dragging = -1;
420
+ scroller.stop();
421
+ frozen.value = null;
422
+ shift.value = 0;
423
+ emit("commit");
424
+ }
425
+ /**
426
+ * The segment that starts at the selected point and follows a Bezier: only it has handles (and only if the segment has height).
427
+ * Участок, который начинается в выбранной точке и идёт по Безье: ручки есть только у него (и только если у участка есть высота).
428
+ */
429
+ const bezierSegment = computed(() => {
430
+ const i = Math.min(props.selected, points.value.length - 1);
431
+ const a = points.value[i];
432
+ const b = points.value[i + 1];
433
+ if (!a || !b || typeof a.ease !== "object" || Math.abs(b.v - a.v) < 1e-9 || b.t - a.t <= 0) return null;
434
+ return {
435
+ i,
436
+ a,
437
+ b,
438
+ bezier: a.ease.bezier
439
+ };
440
+ });
441
+ /**
442
+ * The two handles of the segment in plot coordinates.
443
+ * Две ручки участка в координатах плота.
444
+ */
445
+ const bezierHandles = computed(() => {
446
+ const s = bezierSegment.value;
447
+ if (!s) return [];
448
+ const [x1, y1, x2, y2] = s.bezier;
449
+ return [{
450
+ n: 0,
451
+ t: s.a.t + x1 * (s.b.t - s.a.t),
452
+ v: s.a.v + y1 * (s.b.v - s.a.v),
453
+ from: s.a
454
+ }, {
455
+ n: 1,
456
+ t: s.a.t + x2 * (s.b.t - s.a.t),
457
+ v: s.a.v + y2 * (s.b.v - s.a.v),
458
+ from: s.b
459
+ }];
460
+ });
461
+ /**
462
+ * Starts of segments with a Bezier: the "B" mark is drawn above them.
463
+ * Начала участков с Безье: над ними рисуется метка «B».
464
+ */
465
+ const bezierMarks = computed(() => points.value.flatMap((p, i) => typeof p.ease === "object" && i < points.value.length - 1 ? [{
466
+ i,
467
+ t: p.t,
468
+ v: p.v
469
+ }] : []));
470
+ const round2 = (x) => Math.round(x * 100) / 100;
471
+ function setBezierHandle(n, x, y, commitNow = false) {
472
+ const s = bezierSegment.value;
473
+ if (!s) return;
474
+ const next = [...s.bezier];
475
+ next[n * 2] = Math.min(1, Math.max(0, round2(x)));
476
+ next[n * 2 + 1] = Math.min(3, Math.max(-2, round2(y)));
477
+ emit("update:modelValue", setEase(points.value, s.i, { bezier: next }));
478
+ if (commitNow) emit("commit");
479
+ }
480
+ let handleDrag = -1;
481
+ function onHandleDown(e, n) {
482
+ handleDrag = n;
483
+ frozen.value = valueBounds(points.value, props.min, props.max);
484
+ try {
485
+ e.currentTarget.setPointerCapture(e.pointerId);
486
+ } catch {}
487
+ }
488
+ function onHandleMove(e) {
489
+ const s = bezierSegment.value;
490
+ if (handleDrag < 0 || !s) return;
491
+ const { t, v } = rawCurve(e);
492
+ setBezierHandle(handleDrag, (t - s.a.t) / (s.b.t - s.a.t), (v - s.a.v) / (s.b.v - s.a.v));
493
+ }
494
+ function onHandleUp() {
495
+ if (handleDrag < 0) return;
496
+ handleDrag = -1;
497
+ frozen.value = null;
498
+ emit("commit");
499
+ }
500
+ /**
501
+ * Arrows on a handle move it by a step (Shift larger): left and right along x, up and down along y.
502
+ * Стрелки на ручке сдвигают её на шаг (Shift крупнее): влево и вправо по x, вверх и вниз по y.
503
+ */
504
+ function onHandleKey(e, n) {
505
+ const s = bezierSegment.value;
506
+ const d = {
507
+ ArrowLeft: [-1, 0],
508
+ ArrowRight: [1, 0],
509
+ ArrowUp: [0, 1],
510
+ ArrowDown: [0, -1]
511
+ }[e.key];
512
+ if (!s || !d) return;
513
+ e.preventDefault();
514
+ e.stopPropagation();
515
+ const k = BEZIER_STEP * (e.shiftKey ? 5 : 1);
516
+ setBezierHandle(n, s.bezier[n * 2] + d[0] * k, s.bezier[n * 2 + 1] + d[1] * k, true);
517
+ }
518
+ /**
519
+ * A double click on the plot must not select the page text around it.
520
+ * Двойной клик по графику не должен выделять текст страницы вокруг.
521
+ */
522
+ function noSelect(e) {
523
+ if (e.detail > 1) e.preventDefault();
524
+ }
525
+ function onDouble(e) {
526
+ const { t: tt, v } = toCurve(e);
527
+ const r = addPoint(points.value, tt, v);
528
+ emit("update:selected", r.index);
529
+ emit("update:modelValue", r.points);
530
+ emit("commit");
531
+ }
532
+ /**
533
+ * The arrow step with Shift: this many times larger.
534
+ * Шаг стрелки с Shift: во столько раз крупнее.
535
+ */
536
+ function nudge(i, dx, dy, coarse) {
537
+ const p = points.value[i];
538
+ if (!p) return;
539
+ const k = coarse ? COARSE : 1;
540
+ const tt = roundTo(snapTo(p.t + dx * k * props.stepT, props.stepT), props.precision);
541
+ const v = clampTo(roundTo(snapTo(p.v + dy * k * stepV.value, stepV.value), props.precision), props.min, props.max);
542
+ emit("update:modelValue", movePoint(points.value, i, tt, v));
543
+ emit("commit");
544
+ }
545
+ /**
546
+ * Insert adds a point between the selected one and the next (for the last: between it and the previous) on the curve itself.
547
+ * Insert добавляет точку между выбранной и следующей (у последней: между ней и предыдущей) на самой кривой.
548
+ */
549
+ /**
550
+ * Focus on point `i` after a re-render: keys go to the selected point, and focus must not stay on the old one.
551
+ * Фокус на точку `i` после перерисовки: клавиши идут к той точке, что выбрана, и фокус не должен оставаться на старой.
552
+ */
553
+ function focusDot(i) {
554
+ nextTick(() => svg.value?.querySelectorAll(".tx-curve-dot")[i]?.focus());
555
+ }
556
+ function insertAfter(i) {
557
+ const a = points.value[i];
558
+ const b = points.value[i + 1] ?? points.value[i - 1];
559
+ if (!a || !b) return;
560
+ const r = addPoint(points.value, roundTo((a.t + b.t) / 2, props.precision));
561
+ emit("update:selected", r.index);
562
+ emit("update:modelValue", r.points);
563
+ emit("commit");
564
+ focusDot(r.index);
565
+ }
566
+ function removeAt(i) {
567
+ const next = Math.max(0, i - 1);
568
+ emit("update:modelValue", removePoint(points.value, i));
569
+ emit("update:selected", next);
570
+ emit("commit");
571
+ focusDot(next);
572
+ }
573
+ /**
574
+ * Point keys (focus on it): arrows move by a grid step, Shift larger; Insert adds, Delete removes.
575
+ * Клавиши точки (фокус на ней): стрелки двигают на шаг сетки, Shift крупнее; Insert добавляет, Delete убирает.
576
+ */
577
+ function onKey(e) {
578
+ const target = e.target?.closest(".tx-curve-dot");
579
+ const index = target ? Number(target.getAttribute("data-index")) : NaN;
580
+ const i = Number.isInteger(index) ? index : Math.min(props.selected, points.value.length - 1);
581
+ const move = {
582
+ ArrowLeft: [-1, 0],
583
+ ArrowRight: [1, 0],
584
+ ArrowUp: [0, 1],
585
+ ArrowDown: [0, -1]
586
+ }[e.key];
587
+ if (move) {
588
+ e.preventDefault();
589
+ nudge(i, move[0], move[1], e.shiftKey);
590
+ } else if (e.key === "Insert") {
591
+ e.preventDefault();
592
+ insertAfter(i);
593
+ } else if (e.key === "Delete" || e.key === "Backspace") {
594
+ e.preventDefault();
595
+ removeAt(i);
596
+ }
597
+ }
598
+ const labelOf = (i, p) => props.pointLabel ? props.pointLabel(i, p) : `Point ${i + 1}: ${fmt(p.t)}, ${fmt(p.v)}`;
599
+ return (_ctx, _cache) => {
600
+ return openBlock(), createElementBlock("svg", {
601
+ ref_key: "svg",
602
+ ref: svg,
603
+ class: "tx-curve",
604
+ viewBox: `0 0 ${W} ${H}`,
605
+ title: __props.hint,
606
+ tabindex: "-1",
607
+ role: "group",
608
+ onDblclick: withModifiers(onDouble, ["self"]),
609
+ onMousedown: noSelect,
610
+ onKeydown: onKey
611
+ }, [
612
+ (openBlock(true), createElementBlock(Fragment, null, renderList(gridT.value, (x) => {
613
+ return openBlock(), createElementBlock("line", {
614
+ key: `gt${x}`,
615
+ class: normalizeClass(["tx-curve-grid", { major: isMajorT(x) }]),
616
+ x1: px(x),
617
+ x2: px(x),
618
+ y1: PAD_T,
619
+ y2: 116
620
+ }, null, 10, _hoisted_2);
621
+ }), 128)),
622
+ (openBlock(true), createElementBlock(Fragment, null, renderList(gridV.value, (v) => {
623
+ return openBlock(), createElementBlock("line", {
624
+ key: `gv${v}`,
625
+ class: normalizeClass(["tx-curve-grid", { major: isMajorV(v) }]),
626
+ x1: PAD_L,
627
+ x2: 270,
628
+ y1: py(v),
629
+ y2: py(v)
630
+ }, null, 10, _hoisted_3);
631
+ }), 128)),
632
+ (openBlock(true), createElementBlock(Fragment, null, renderList(labelsV.value, (v, i) => {
633
+ return openBlock(), createElementBlock("text", {
634
+ key: `lv${v}`,
635
+ class: normalizeClass(["tx-curve-label", { edge: i === 0 || i === labelsV.value.length - 1 }]),
636
+ x: 26,
637
+ y: py(v),
638
+ "text-anchor": "end",
639
+ "dominant-baseline": "middle"
640
+ }, toDisplayString(fmt(v)), 11, _hoisted_4);
641
+ }), 128)),
642
+ (openBlock(true), createElementBlock(Fragment, null, renderList(labelsT.value, (x) => {
643
+ return openBlock(), createElementBlock("text", {
644
+ key: `lt${x}`,
645
+ class: normalizeClass(["tx-curve-label", { edge: x === 0 || x === 1 }]),
646
+ x: px(x),
647
+ y: 128,
648
+ "text-anchor": x === 0 ? "start" : x === 1 ? "end" : "middle"
649
+ }, toDisplayString(fmt(x)), 11, _hoisted_5);
650
+ }), 128)),
651
+ tags.value && __props.guides !== "off" ? (openBlock(), createElementBlock("g", _hoisted_6, [
652
+ createElementVNode("line", {
653
+ class: "tx-curve-guide",
654
+ x1: tags.value.x,
655
+ x2: tags.value.x,
656
+ y1: tags.value.y,
657
+ y2: 116
658
+ }, null, 8, _hoisted_7),
659
+ createElementVNode("line", {
660
+ class: "tx-curve-guide",
661
+ x1: PAD_L,
662
+ x2: tags.value.x,
663
+ y1: tags.value.y,
664
+ y2: tags.value.y
665
+ }, null, 8, _hoisted_8),
666
+ __props.guides === "values" ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
667
+ createElementVNode("rect", {
668
+ class: "tx-curve-tag-bg",
669
+ x: tags.value.t.cx - tags.value.t.w / 2,
670
+ y: 120,
671
+ width: tags.value.t.w,
672
+ height: "11",
673
+ rx: "2"
674
+ }, null, 8, _hoisted_9),
675
+ createElementVNode("text", {
676
+ class: "tx-curve-tag",
677
+ x: tags.value.t.cx,
678
+ y: 128,
679
+ "text-anchor": "middle"
680
+ }, toDisplayString(tags.value.t.text), 9, _hoisted_10),
681
+ createElementVNode("rect", {
682
+ class: "tx-curve-tag-bg",
683
+ x: 27 - tags.value.v.w,
684
+ y: tags.value.v.cy - 5.5,
685
+ width: tags.value.v.w,
686
+ height: "11",
687
+ rx: "2"
688
+ }, null, 8, _hoisted_11),
689
+ createElementVNode("text", {
690
+ class: "tx-curve-tag",
691
+ x: 25,
692
+ y: tags.value.v.cy,
693
+ "text-anchor": "end",
694
+ "dominant-baseline": "middle"
695
+ }, toDisplayString(tags.value.v.text), 9, _hoisted_12)
696
+ ], 64)) : createCommentVNode("", true)
697
+ ])) : createCommentVNode("", true),
698
+ createElementVNode("path", {
699
+ class: "tx-curve-line",
700
+ d: path.value
701
+ }, null, 8, _hoisted_13),
702
+ (openBlock(true), createElementBlock(Fragment, null, renderList(bezierMarks.value, (m) => {
703
+ return openBlock(), createElementBlock("text", {
704
+ key: `b${m.i}`,
705
+ class: "tx-curve-mark",
706
+ x: px(m.t),
707
+ y: py(m.v) - 8,
708
+ "text-anchor": "middle",
709
+ "aria-hidden": "true"
710
+ }, "B", 8, _hoisted_14);
711
+ }), 128)),
712
+ bezierHandles.value.length ? (openBlock(), createElementBlock("g", _hoisted_15, [(openBlock(true), createElementBlock(Fragment, null, renderList(bezierHandles.value, (h) => {
713
+ return openBlock(), createElementBlock(Fragment, { key: h.n }, [createElementVNode("line", {
714
+ class: "tx-curve-arm",
715
+ x1: px(h.from.t),
716
+ y1: py(h.from.v),
717
+ x2: px(h.t),
718
+ y2: py(h.v)
719
+ }, null, 8, _hoisted_16), createElementVNode("circle", {
720
+ class: "tx-curve-handle",
721
+ cx: px(h.t),
722
+ cy: py(h.v),
723
+ r: "4",
724
+ tabindex: "0",
725
+ role: "slider",
726
+ "aria-label": __props.handleLabel ? __props.handleLabel(h.n + 1, bezierSegment.value.i) : `Bezier handle ${h.n + 1}`,
727
+ onPointerdown: withModifiers(($event) => onHandleDown($event, h.n), ["stop"]),
728
+ onPointermove: onHandleMove,
729
+ onPointerup: onHandleUp,
730
+ onPointercancel: onHandleUp,
731
+ onKeydown: ($event) => onHandleKey($event, h.n)
732
+ }, null, 40, _hoisted_17)], 64);
733
+ }), 128))])) : createCommentVNode("", true),
734
+ (openBlock(true), createElementBlock(Fragment, null, renderList(points.value, (p, i) => {
735
+ return openBlock(), createElementBlock("circle", {
736
+ key: i,
737
+ class: normalizeClass(["tx-curve-dot", { on: i === __props.selected }]),
738
+ cx: px(p.t),
739
+ cy: py(p.v),
740
+ r: "5",
741
+ "data-index": i,
742
+ tabindex: "0",
743
+ role: "button",
744
+ "aria-label": labelOf(i, p),
745
+ onFocus: ($event) => emit("update:selected", i),
746
+ onPointerdown: withModifiers(($event) => onDown($event, i), ["stop"]),
747
+ onPointermove: onMove,
748
+ onPointerup: onUp,
749
+ onPointercancel: onUp
750
+ }, null, 42, _hoisted_18);
751
+ }), 128))
752
+ ], 40, _hoisted_1);
753
+ };
754
+ }
755
+ });
756
+ //#endregion
757
+ export { sampleCurve as a, valueBounds as c, removePoint as i, addPoint as n, sampleSegment as o, movePoint as r, setEase as s, TaoxCurveEditor_default as t };
758
+
759
+ //# sourceMappingURL=curveeditor-goX9maE5.js.map