@kolkrabbi/design-editor 0.12.0 → 0.14.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.
@@ -0,0 +1,584 @@
1
+ import { Jt as e, Kt as t, Wt as n, Yt as r, h as i, qt as a, t as o, zt as s } from "./EditorIcon-BbFMmc1G.js";
2
+ import { Button as c, Dropdown as l, Input as u, LabeledControl as d, Section as f, Slider as p, Stepper as m, ViewToggle as h } from "@kolkrabbi/kol-component";
3
+ import { useEffect as g, useRef as _, useState as v } from "react";
4
+ import { Fragment as y, jsx as b, jsxs as x } from "react/jsx-runtime";
5
+ //#region src/editor/params/ModulationEditor.jsx
6
+ var S = [
7
+ {
8
+ code: "wave(t*2)",
9
+ desc: "Fast sine"
10
+ },
11
+ {
12
+ code: "saw(t)*0.8",
13
+ desc: "Ramp to 80"
14
+ },
15
+ {
16
+ code: "tri(t*0.5)",
17
+ desc: "Slow bounce"
18
+ },
19
+ {
20
+ code: "pulse(t, 0.3)",
21
+ desc: "PWM 30%"
22
+ },
23
+ {
24
+ code: "ease(t*2, 4)",
25
+ desc: "Fast + punchy"
26
+ },
27
+ {
28
+ code: "bell(t)",
29
+ desc: "Bell curve"
30
+ },
31
+ {
32
+ code: "step(t, 4)",
33
+ desc: "4 steps"
34
+ },
35
+ {
36
+ code: "rand()",
37
+ desc: "Noise"
38
+ }
39
+ ], C = 196, w = 64;
40
+ function T({ expr: e }) {
41
+ let n = _(null);
42
+ return g(() => {
43
+ let r = n.current;
44
+ if (!r) return;
45
+ let i = Math.min(2, window.devicePixelRatio || 1);
46
+ r.width = C * i, r.height = w * i;
47
+ let a = r.getContext("2d");
48
+ a.setTransform(i, 0, 0, i, 0, 0);
49
+ let o = 0, c = () => {
50
+ o = requestAnimationFrame(c);
51
+ let n = getComputedStyle(r), i = n.getPropertyValue("--kol-accent-primary").trim() || "#2dd4bf", l = n.color || "rgb(160,160,160)", u = t(e), d = s.getLoopSeconds(), f = s.getCtx().t ?? 0, p = C - 12, m = w - 12;
52
+ a.clearRect(0, 0, C, w);
53
+ let h = p, g = new Float64Array(185), _ = Infinity, v = -Infinity;
54
+ for (let e = 0; e <= h; e++) {
55
+ let t = u.ok ? u.fn(e / h * d) : 0;
56
+ g[e] = t, t < _ && (_ = t), t > v && (v = t);
57
+ }
58
+ let y = (_ + v) / 2, b = Math.min(_, 0), x = Math.max(v, 1) - b || 1, S = (e) => 6 + m * (1 - (e - b) / x), T = (e) => 6 + e / h * p;
59
+ a.strokeStyle = "rgba(231,76,60,0.35)", a.lineWidth = 1, a.setLineDash([4, 4]);
60
+ for (let e of [0, 1]) {
61
+ let t = S(e);
62
+ a.beginPath(), a.moveTo(6, t), a.lineTo(C - 6, t), a.stroke();
63
+ }
64
+ if (a.setLineDash([]), u.ok) {
65
+ a.font = "8px var(--kol-font-family-mono, monospace)", a.strokeStyle = l, a.fillStyle = l;
66
+ for (let e of [
67
+ v,
68
+ y,
69
+ _
70
+ ]) {
71
+ let t = S(e);
72
+ a.globalAlpha = .12, a.beginPath(), a.moveTo(6, t), a.lineTo(C - 6, t), a.stroke(), a.globalAlpha = .5, a.fillText(e.toFixed(2), 8, t - 2);
73
+ }
74
+ a.globalAlpha = 1;
75
+ let e = (e) => {
76
+ a.beginPath();
77
+ for (let t = 0; t <= e; t++) {
78
+ let e = S(g[t]);
79
+ t === 0 ? a.moveTo(T(0), e) : a.lineTo(T(t), e);
80
+ }
81
+ a.stroke();
82
+ };
83
+ a.strokeStyle = i, a.lineWidth = 1, a.globalAlpha = .25, e(h);
84
+ let t = 6 + f * p;
85
+ a.globalAlpha = .4, a.beginPath(), a.moveTo(t, 6), a.lineTo(t, w - 6), a.stroke(), a.globalAlpha = 1, a.lineWidth = 1.5, e(Math.round(f * h)), a.fillStyle = i, a.beginPath(), a.arc(t, S(u.fn(f * d)), 2.5, 0, Math.PI * 2), a.fill();
86
+ }
87
+ };
88
+ return c(), () => cancelAnimationFrame(o);
89
+ }, [e]), /* @__PURE__ */ b("canvas", {
90
+ ref: n,
91
+ "aria-label": "Expression plot over one loop",
92
+ style: {
93
+ width: C,
94
+ height: w,
95
+ display: "block",
96
+ borderRadius: 3,
97
+ background: "var(--kol-fg-04, rgba(128,128,128,0.06))"
98
+ }
99
+ });
100
+ }
101
+ function E({ layer: t, param: o, setProp: s }) {
102
+ let c = t[o.key], [l, f] = v(null), [m, g] = v(!1), [_, C] = v(!1);
103
+ if (!i(c) || c.bind !== "mod") return null;
104
+ let w = c.source, E = c.transform ?? {}, D = w.startsWith("lfo-"), O = w === "midi", k = a(w), A = w === "expr", j = E.expr ?? "wave(t)", M = (e) => s(o.key, {
105
+ ...c,
106
+ transform: {
107
+ ...E,
108
+ ...e
109
+ }
110
+ }), N = (e) => {
111
+ f(null);
112
+ let t = String(e).trim();
113
+ t && t !== j && M({ expr: t });
114
+ }, P = async () => {
115
+ g(!0);
116
+ let e = await r();
117
+ g(!1), e != null && M({ cc: e });
118
+ }, F = async () => {
119
+ C(!0);
120
+ let t = await e();
121
+ C(!1), t && s(o.key, {
122
+ ...c,
123
+ source: t
124
+ });
125
+ }, I = E.range ?? (o.min != null && o.max != null ? [o.min, o.max] : [0, 1]), L = (e, t) => {
126
+ let n = Number(e);
127
+ return Number.isFinite(n) ? n : t;
128
+ };
129
+ return /* @__PURE__ */ x("div", {
130
+ className: "flex flex-col gap-3",
131
+ children: [
132
+ /* @__PURE__ */ b(d, {
133
+ label: "Range",
134
+ children: /* @__PURE__ */ x("div", {
135
+ className: "flex items-center gap-2",
136
+ children: [
137
+ /* @__PURE__ */ b(u, {
138
+ variant: "filled",
139
+ size: "sm",
140
+ type: "number",
141
+ chars: 5,
142
+ value: I[0],
143
+ onChange: (e) => M({ range: [L(e.target.value, I[0]), I[1]] })
144
+ }),
145
+ /* @__PURE__ */ b("span", {
146
+ className: "kol-helper-10 text-meta",
147
+ children: "to"
148
+ }),
149
+ /* @__PURE__ */ b(u, {
150
+ variant: "filled",
151
+ size: "sm",
152
+ type: "number",
153
+ chars: 5,
154
+ value: I[1],
155
+ onChange: (e) => M({ range: [I[0], L(e.target.value, I[1])] })
156
+ })
157
+ ]
158
+ })
159
+ }),
160
+ /* @__PURE__ */ x("div", {
161
+ className: "grid grid-cols-2 gap-2",
162
+ children: [/* @__PURE__ */ b(d, {
163
+ label: "Invert",
164
+ children: /* @__PURE__ */ b(h, {
165
+ options: [{
166
+ value: "off",
167
+ label: "Off"
168
+ }, {
169
+ value: "on",
170
+ label: "On"
171
+ }],
172
+ viewMode: E?.invert ? "on" : "off",
173
+ onViewChange: (e) => M({ invert: e === "on" })
174
+ })
175
+ }), /* @__PURE__ */ b(d, {
176
+ label: "Smooth",
177
+ children: /* @__PURE__ */ b(p, {
178
+ min: 0,
179
+ max: .95,
180
+ step: .05,
181
+ value: E?.smooth ?? 0,
182
+ onChange: (e) => M({ smooth: e })
183
+ })
184
+ })]
185
+ }),
186
+ /* @__PURE__ */ b(d, {
187
+ label: "Curve",
188
+ children: /* @__PURE__ */ b(p, {
189
+ min: .25,
190
+ max: 4,
191
+ step: .05,
192
+ value: E?.curve ?? 1,
193
+ onChange: (e) => M({ curve: e })
194
+ })
195
+ }),
196
+ D && /* @__PURE__ */ x("div", {
197
+ className: "grid grid-cols-2 gap-2",
198
+ children: [/* @__PURE__ */ b(d, {
199
+ label: "Rate · cycles",
200
+ children: /* @__PURE__ */ b(p, {
201
+ min: .25,
202
+ max: 16,
203
+ step: .25,
204
+ value: E?.rate ?? 1,
205
+ onChange: (e) => M({ rate: e })
206
+ })
207
+ }), /* @__PURE__ */ b(d, {
208
+ label: "Phase",
209
+ children: /* @__PURE__ */ b(p, {
210
+ min: 0,
211
+ max: 1,
212
+ step: .01,
213
+ value: E?.phase ?? 0,
214
+ onChange: (e) => M({ phase: e })
215
+ })
216
+ })]
217
+ }),
218
+ A && /* @__PURE__ */ x(y, { children: [
219
+ /* @__PURE__ */ b(d, {
220
+ label: "Expression",
221
+ children: /* @__PURE__ */ b(u, {
222
+ variant: "ghost",
223
+ size: "sm",
224
+ value: l ?? j,
225
+ onChange: (e) => f(e.target.value),
226
+ onBlur: (e) => N(e.target.value),
227
+ onKeyDown: (e) => {
228
+ e.key === "Enter" && e.currentTarget.blur();
229
+ }
230
+ })
231
+ }),
232
+ /* @__PURE__ */ b(T, { expr: j }),
233
+ /* @__PURE__ */ b("div", {
234
+ className: "flex flex-col",
235
+ children: S.map((e) => /* @__PURE__ */ x("button", {
236
+ type: "button",
237
+ onClick: () => M({ expr: e.code }),
238
+ className: "w-full kol-helper-10 h-6 inline-flex items-center gap-2 text-body hover:text-emphasis text-left",
239
+ style: {
240
+ background: "transparent",
241
+ border: "none",
242
+ cursor: "pointer",
243
+ fontVariantLigatures: "none"
244
+ },
245
+ children: [/* @__PURE__ */ b("span", {
246
+ className: "truncate",
247
+ style: { fontFamily: "var(--kol-font-family-mono, monospace)" },
248
+ children: e.code
249
+ }), /* @__PURE__ */ b("span", {
250
+ className: "flex-1 text-right text-meta truncate",
251
+ children: e.desc
252
+ })]
253
+ }, e.code))
254
+ })
255
+ ] }),
256
+ O && /* @__PURE__ */ b(d, {
257
+ label: E?.cc == null ? "MIDI · no CC yet" : `MIDI · CC ${E.cc}`,
258
+ children: /* @__PURE__ */ b("button", {
259
+ type: "button",
260
+ onClick: P,
261
+ className: "kol-helper-12 px-2 py-1 rounded border border-oq-08 text-body hover:text-emphasis",
262
+ style: {
263
+ background: "transparent",
264
+ cursor: "pointer"
265
+ },
266
+ children: m ? "Move a knob…" : "Learn"
267
+ })
268
+ }),
269
+ k && /* @__PURE__ */ b(d, {
270
+ label: n(w)?.label ?? "Gamepad",
271
+ children: /* @__PURE__ */ b("button", {
272
+ type: "button",
273
+ onClick: F,
274
+ className: "kol-helper-12 px-2 py-1 rounded border border-oq-08 text-body hover:text-emphasis",
275
+ style: {
276
+ background: "transparent",
277
+ cursor: "pointer"
278
+ },
279
+ children: _ ? "Move a control…" : "Learn"
280
+ })
281
+ })
282
+ ]
283
+ });
284
+ }
285
+ function D({ layer: e, schema: t, setProp: r }) {
286
+ let a = (t ?? []).filter((t) => {
287
+ let n = e[t.key];
288
+ return i(n) && n.bind === "mod";
289
+ });
290
+ return a.length === 0 ? null : /* @__PURE__ */ x("div", {
291
+ className: "flex flex-col gap-4",
292
+ children: [/* @__PURE__ */ b("span", {
293
+ className: "kol-helper-10 text-meta",
294
+ children: "Modulation"
295
+ }), a.map((t) => {
296
+ let i = n(e[t.key].source);
297
+ return /* @__PURE__ */ x("div", {
298
+ className: "flex flex-col gap-2 pt-3 border-t border-oq-08",
299
+ children: [/* @__PURE__ */ x("div", {
300
+ className: "flex items-center justify-between",
301
+ children: [/* @__PURE__ */ b("span", {
302
+ className: "kol-helper-12 text-emphasis",
303
+ children: t.label ?? t.key
304
+ }), /* @__PURE__ */ b("span", {
305
+ className: "kol-helper-10 text-meta",
306
+ children: i?.label ?? e[t.key].source
307
+ })]
308
+ }), /* @__PURE__ */ b(E, {
309
+ layer: e,
310
+ param: t,
311
+ setProp: r
312
+ })]
313
+ }, t.key);
314
+ })]
315
+ });
316
+ }
317
+ //#endregion
318
+ //#region src/editor/modes/pattern/RuleRow.jsx
319
+ var O = [
320
+ {
321
+ value: "all",
322
+ label: "All cells"
323
+ },
324
+ {
325
+ value: "every-col",
326
+ label: "Every Nth col"
327
+ },
328
+ {
329
+ value: "every-row",
330
+ label: "Every Nth row"
331
+ },
332
+ {
333
+ value: "both",
334
+ label: "Nth col × Nth row"
335
+ },
336
+ {
337
+ value: "every-nth",
338
+ label: "Every Nth (flat)"
339
+ },
340
+ {
341
+ value: "checker",
342
+ label: "Checker"
343
+ },
344
+ {
345
+ value: "expression",
346
+ label: "Expression…"
347
+ }
348
+ ], k = [
349
+ {
350
+ value: 0,
351
+ label: "0°"
352
+ },
353
+ {
354
+ value: 90,
355
+ label: "90°"
356
+ },
357
+ {
358
+ value: 180,
359
+ label: "180°"
360
+ },
361
+ {
362
+ value: 270,
363
+ label: "270°"
364
+ }
365
+ ], A = [
366
+ "every-col",
367
+ "every-row",
368
+ "both",
369
+ "every-nth",
370
+ "checker"
371
+ ], j = [
372
+ 0,
373
+ 90,
374
+ 180,
375
+ 270
376
+ ], M = 1, N = () => `r${M++}`, P = () => ({
377
+ id: N(),
378
+ selectKind: "every-col",
379
+ n: 2,
380
+ offset: 0,
381
+ n2: 2,
382
+ offset2: 0,
383
+ expression: "sin(col * 0.6) + cos(row * 0.6)",
384
+ groupW: 1,
385
+ groupH: 1,
386
+ rotate: 90,
387
+ flipH: !1,
388
+ flipV: !1,
389
+ hide: !1,
390
+ opacity: 1
391
+ }), F = (e) => e[Math.floor(Math.random() * e.length)], I = () => ({
392
+ id: N(),
393
+ selectKind: F(A),
394
+ n: Math.floor(Math.random() * 5) + 2,
395
+ offset: Math.floor(Math.random() * 3),
396
+ n2: Math.floor(Math.random() * 5) + 2,
397
+ offset2: Math.floor(Math.random() * 3),
398
+ expression: "sin(col * 0.6) + cos(row * 0.6)",
399
+ groupW: Math.random() > .6 ? Math.floor(Math.random() * 3) + 1 : 1,
400
+ groupH: Math.random() > .6 ? Math.floor(Math.random() * 3) + 1 : 1,
401
+ rotate: F(j),
402
+ flipH: Math.random() > .6,
403
+ flipV: Math.random() > .6,
404
+ hide: Math.random() > .85,
405
+ opacity: Math.random() > .7 ? .4 + Math.random() * .6 : 1
406
+ });
407
+ function L({ value: e, onChange: t, min: n = 0, max: r = 99 }) {
408
+ return /* @__PURE__ */ b(m, {
409
+ size: "sm",
410
+ value: e,
411
+ min: n,
412
+ max: r,
413
+ onChange: (e) => t(Number(e.target.value)),
414
+ className: "w-full"
415
+ });
416
+ }
417
+ function R({ active: e, onClick: t, children: n, title: r }) {
418
+ return /* @__PURE__ */ b(c, {
419
+ variant: e ? "primary" : "outline",
420
+ size: "sm",
421
+ onClick: t,
422
+ title: r,
423
+ "aria-pressed": e,
424
+ children: n
425
+ });
426
+ }
427
+ function z({ rule: e, onChange: t, onRemove: n, onReroll: r }) {
428
+ let i = (n) => t({
429
+ ...e,
430
+ ...n
431
+ }), a = e.selectKind === "every-col" || e.selectKind === "every-row" || e.selectKind === "every-nth" || e.selectKind === "both", s = e.selectKind === "both", d = e.selectKind === "expression";
432
+ return /* @__PURE__ */ x("div", {
433
+ className: "flex flex-col gap-2 p-2 border border-oq-08 rounded",
434
+ children: [
435
+ /* @__PURE__ */ x("div", {
436
+ className: "flex items-center gap-2",
437
+ children: [
438
+ /* @__PURE__ */ b("div", {
439
+ className: "flex-1 min-w-0",
440
+ children: /* @__PURE__ */ b(l, {
441
+ variant: "subtle",
442
+ size: "sm",
443
+ className: "w-full",
444
+ options: O,
445
+ value: e.selectKind,
446
+ onChange: (e) => i({ selectKind: e })
447
+ })
448
+ }),
449
+ /* @__PURE__ */ b(c, {
450
+ iconComponent: o,
451
+ variant: "ghost",
452
+ size: "sm",
453
+ iconOnly: "refresh",
454
+ iconSize: 12,
455
+ onClick: r,
456
+ "aria-label": "Re-randomize rule",
457
+ title: "Re-randomize this rule",
458
+ className: "shrink-0",
459
+ style: { padding: 6 }
460
+ }),
461
+ /* @__PURE__ */ b(c, {
462
+ iconComponent: o,
463
+ variant: "ghost",
464
+ size: "sm",
465
+ iconOnly: "close",
466
+ iconSize: 12,
467
+ onClick: n,
468
+ "aria-label": "Remove rule",
469
+ className: "shrink-0",
470
+ style: { padding: 6 }
471
+ })
472
+ ]
473
+ }),
474
+ a && /* @__PURE__ */ x("div", {
475
+ className: "grid grid-cols-2 gap-2",
476
+ children: [/* @__PURE__ */ b(f, {
477
+ label: "N",
478
+ children: /* @__PURE__ */ b(L, {
479
+ value: e.n,
480
+ onChange: (e) => i({ n: e }),
481
+ min: 1
482
+ })
483
+ }), /* @__PURE__ */ b(f, {
484
+ label: "Offset",
485
+ children: /* @__PURE__ */ b(L, {
486
+ value: e.offset,
487
+ onChange: (e) => i({ offset: e })
488
+ })
489
+ })]
490
+ }),
491
+ s && /* @__PURE__ */ x("div", {
492
+ className: "grid grid-cols-2 gap-2",
493
+ children: [/* @__PURE__ */ b(f, {
494
+ label: "Row N",
495
+ children: /* @__PURE__ */ b(L, {
496
+ value: e.n2,
497
+ onChange: (e) => i({ n2: e }),
498
+ min: 1
499
+ })
500
+ }), /* @__PURE__ */ b(f, {
501
+ label: "Row offset",
502
+ children: /* @__PURE__ */ b(L, {
503
+ value: e.offset2,
504
+ onChange: (e) => i({ offset2: e })
505
+ })
506
+ })]
507
+ }),
508
+ d && /* @__PURE__ */ x(f, {
509
+ label: "Expression",
510
+ hint: "matches when > 0",
511
+ children: [/* @__PURE__ */ b(u, {
512
+ variant: "filled",
513
+ size: "sm",
514
+ value: e.expression,
515
+ onChange: (e) => i({ expression: e.target.value }),
516
+ placeholder: "sin(col * 0.6) + cos(row * 0.6)"
517
+ }), /* @__PURE__ */ b("span", {
518
+ className: "kol-helper-10 text-subtle mt-1",
519
+ children: "vars: i, col, row, cols, rows · Math.* in scope"
520
+ })]
521
+ }),
522
+ /* @__PURE__ */ x("div", {
523
+ className: "grid grid-cols-2 gap-2",
524
+ children: [/* @__PURE__ */ b(f, {
525
+ label: "Group W",
526
+ children: /* @__PURE__ */ b(L, {
527
+ value: e.groupW,
528
+ onChange: (e) => i({ groupW: Math.max(1, e) }),
529
+ min: 1
530
+ })
531
+ }), /* @__PURE__ */ b(f, {
532
+ label: "Group H",
533
+ children: /* @__PURE__ */ b(L, {
534
+ value: e.groupH,
535
+ onChange: (e) => i({ groupH: Math.max(1, e) }),
536
+ min: 1
537
+ })
538
+ })]
539
+ }),
540
+ /* @__PURE__ */ x("div", {
541
+ className: "flex flex-wrap gap-1",
542
+ children: [
543
+ /* @__PURE__ */ b(l, {
544
+ variant: "subtle",
545
+ size: "sm",
546
+ options: k,
547
+ value: e.rotate,
548
+ onChange: (e) => i({ rotate: Number(e) })
549
+ }),
550
+ /* @__PURE__ */ b(R, {
551
+ active: e.flipH,
552
+ onClick: () => i({ flipH: !e.flipH }),
553
+ title: "Flip horizontal",
554
+ children: "⇋"
555
+ }),
556
+ /* @__PURE__ */ b(R, {
557
+ active: e.flipV,
558
+ onClick: () => i({ flipV: !e.flipV }),
559
+ title: "Flip vertical",
560
+ children: "⇵"
561
+ }),
562
+ /* @__PURE__ */ b(R, {
563
+ active: e.hide,
564
+ onClick: () => i({ hide: !e.hide }),
565
+ title: "Hide cell",
566
+ children: "hide"
567
+ })
568
+ ]
569
+ }),
570
+ /* @__PURE__ */ b(f, {
571
+ label: "Opacity",
572
+ hint: `${Math.round(e.opacity * 100)}%`,
573
+ children: /* @__PURE__ */ b(p, {
574
+ min: 0,
575
+ max: 100,
576
+ value: Math.round(e.opacity * 100),
577
+ onChange: (e) => i({ opacity: e / 100 })
578
+ })
579
+ })
580
+ ]
581
+ });
582
+ }
583
+ //#endregion
584
+ export { D as i, P as n, I as r, z as t };