@kolkrabbi/design-editor 0.20.0 → 0.22.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,469 @@
1
+ import { B as e, L as t, S as n, a as r, c as i, j as a, mn as o, n as s, nt as c, o as l, t as u } from "./rolls-Bg1XHuvJ.js";
2
+ import { n as d, r as f, t as p } from "./useLayerEdit-ieOjHx6x.js";
3
+ import { n as m, t as h } from "./TreePicker-DLmMl0aU.js";
4
+ import { _ as g, a as _, b as v, c as y, f as b, g as x, h as S, i as ee, m as C, n as w, p as T, r as E, s as te, u as ne, v as D, y as O } from "./effectCategories-BcaQSD_V.js";
5
+ import { Button as k, LabeledControl as A, SegmentedToggle as re, Slider as j, ToggleSwitch as M, Tooltip as N, ViewToggle as P } from "@kolkrabbi/kol-component";
6
+ import { useEffect as F, useRef as ie, useState as I } from "react";
7
+ import { Fragment as L, jsx as R, jsxs as z } from "react/jsx-runtime";
8
+ import { Icon as B } from "@kolkrabbi/kol-icons";
9
+ //#region src/editor/compose/inspectors/EffectsPanel.jsx
10
+ var ae = [{
11
+ value: "effect",
12
+ label: "Effect"
13
+ }, {
14
+ value: "anim",
15
+ label: "Motion"
16
+ }];
17
+ function V() {
18
+ let { selectedId: e, layers: t } = a(), n = e && e !== "canvas" ? c(t, e) : null;
19
+ return /* @__PURE__ */ R("div", {
20
+ className: "kol-compose-rail kol-compose-rail--inspector",
21
+ children: /* @__PURE__ */ R("div", {
22
+ className: "kol-compose-inspector-body",
23
+ children: n ? /* @__PURE__ */ R(H, { layer: n }, n.id) : /* @__PURE__ */ R(f, {
24
+ className: "kol-helper-12 text-meta",
25
+ children: "Select a layer to edit its effect."
26
+ })
27
+ })
28
+ });
29
+ }
30
+ function H({ layer: n }) {
31
+ let { updateLayer: r, palette: i, addFilter: o, removeFilter: s, toggleFilter: c, moveFilter: l, replaceFilter: u } = a(), f = p(n.id, { history: "coalesce" }), h = t(n), g = h.some((e) => e.def?.kind === "engine"), { effectable: v, engineHost: x, engineLoop: S } = ee(n), [C, T] = I(h.length ? 0 : null), E = C == null ? null : h[C] ?? null, [D, O] = I(!1);
32
+ F(() => {
33
+ h.length > 0 && O(!1);
34
+ }, [h.length]);
35
+ let [j, M] = I("effect"), [B, V] = I(() => w(h[0]?.id) ?? null), H = ie(h.map((e) => e.key));
36
+ if (F(() => {
37
+ let e = H.current, t = h.map((e) => e.key);
38
+ H.current = t;
39
+ let n = t.find((t) => !e.includes(t));
40
+ if (n != null) {
41
+ let e = t.indexOf(n);
42
+ T(e);
43
+ let r = w(h[e].id);
44
+ r && V(r);
45
+ return;
46
+ }
47
+ C != null && C >= t.length && T(t.length ? t.length - 1 : null);
48
+ }, [h.length]), F(() => {
49
+ if (!E) return;
50
+ let e = w(E.id);
51
+ e && V(e);
52
+ }, [E?.key]), !v) return /* @__PURE__ */ R("p", {
53
+ className: "kol-helper-12 text-meta",
54
+ children: S ? "Engine loops can't host effects yet." : "This layer can't host an effect."
55
+ });
56
+ let G = E?.def?.kind === "engine", se = x && (E ? G || !g && C === h.length - 1 : !g), K = _(b.filter((e) => e.kind !== "engine" || se)), ce = K.map((e) => ({
57
+ value: e.id,
58
+ label: e.label
59
+ })), q = K.some((e) => e.id === B) ? B : K[0]?.id, le = [{
60
+ value: "",
61
+ label: "None"
62
+ }, ...(K.find((e) => e.id === q)?.filters ?? []).map((e) => ({
63
+ value: e.id,
64
+ label: e.label
65
+ }))], ue = E && w(E.id) === q ? E.id : "", de = (e) => {
66
+ if (E) {
67
+ if (!e) {
68
+ s(n.id, C);
69
+ return;
70
+ }
71
+ e !== E.id && u(n.id, C, e);
72
+ return;
73
+ }
74
+ e && o(n.id, e);
75
+ }, fe = h.map(({ def: e, ...t }) => t), J = E ? {
76
+ ...n,
77
+ ...E.params,
78
+ id: n.id
79
+ } : null, Y = (e) => {
80
+ if (C == null) return;
81
+ let t = fe.map((t, n) => n === C ? {
82
+ ...t,
83
+ params: {
84
+ ...t.params,
85
+ ...e
86
+ }
87
+ } : t);
88
+ f.patch({ filters: t });
89
+ }, X = (e, t) => {
90
+ if (e === "cameraDrag") {
91
+ f.setProp(e, t);
92
+ return;
93
+ }
94
+ Y({ [e]: t });
95
+ }, pe = (e) => X("sweeps", e), Z = (e) => /* @__PURE__ */ R(ne, {
96
+ layer: J,
97
+ param: e,
98
+ setProp: X
99
+ }), Q = E?.def ? te(E.def.id) : null, $ = Q ? E.def.params.find((e) => e.key === Q) : null, me = E?.def ? E.def.params.filter((t) => e(t) !== "anim" && t !== $) : [];
100
+ return /* @__PURE__ */ z("div", {
101
+ className: "flex flex-col gap-4",
102
+ children: [
103
+ h.length > 0 && /* @__PURE__ */ R("div", {
104
+ className: "flex flex-col gap-1",
105
+ children: h.map((e, t) => /* @__PURE__ */ R(oe, {
106
+ stage: e,
107
+ selected: t === C,
108
+ onSelect: () => T(t),
109
+ onToggle: () => c(n.id, t),
110
+ onRemove: () => s(n.id, t),
111
+ onUp: () => l(n.id, t, t - 1),
112
+ onDown: () => l(n.id, t, t + 1),
113
+ canUp: t > 0 && e.def?.kind !== "engine",
114
+ canDown: t < h.length - 1 && e.def?.kind !== "engine" && h[t + 1]?.def?.kind !== "engine"
115
+ }, e.key))
116
+ }),
117
+ h.length > 0 && C != null && /* @__PURE__ */ R(N, {
118
+ label: h.length >= 8 ? "Chain is full (8 effects)" : "Add another effect",
119
+ children: /* @__PURE__ */ R(k, {
120
+ "aria-label": h.length >= 8 ? "Chain is full (8 effects)" : "Add another effect",
121
+ tone: "primary",
122
+ size: "sm",
123
+ className: "w-full",
124
+ onClick: () => T(null),
125
+ disabled: h.length >= 8,
126
+ children: "Add effect"
127
+ })
128
+ }),
129
+ h.length === 0 && !D && /* @__PURE__ */ R(k, {
130
+ tone: "primary",
131
+ size: "sm",
132
+ className: "w-full",
133
+ onClick: () => O(!0),
134
+ children: "Add effect"
135
+ }),
136
+ (h.length > 0 || D) && /* @__PURE__ */ z(L, { children: [
137
+ /* @__PURE__ */ R(m, {
138
+ label: "Type",
139
+ options: ce,
140
+ value: q,
141
+ onChange: V
142
+ }),
143
+ /* @__PURE__ */ R(m, {
144
+ label: "Category",
145
+ options: le,
146
+ value: ue,
147
+ onChange: de
148
+ }),
149
+ $ && /* @__PURE__ */ R(m, {
150
+ label: "Preset",
151
+ options: $.options,
152
+ value: E.params[$.key] ?? $.default,
153
+ onChange: (e) => Y(y(E.def, e))
154
+ })
155
+ ] }),
156
+ h.length > 0 && n.imgW != null && /* @__PURE__ */ R("span", {
157
+ className: "kol-helper-12 text-meta",
158
+ children: "Filters don't apply to cropped photos."
159
+ }),
160
+ E?.def?.orbit && /* @__PURE__ */ R(A, {
161
+ label: "Camera drag",
162
+ children: /* @__PURE__ */ R(P, {
163
+ options: [{
164
+ value: "off",
165
+ label: "Off"
166
+ }, {
167
+ value: "on",
168
+ label: "On"
169
+ }],
170
+ viewMode: n.cameraDrag ? "on" : "off",
171
+ onViewChange: (e) => X("cameraDrag", e === "on")
172
+ })
173
+ }),
174
+ E?.def && /* @__PURE__ */ z(L, { children: [
175
+ /* @__PURE__ */ R(re, {
176
+ variant: "filled",
177
+ value: j,
178
+ onChange: M,
179
+ options: ae
180
+ }),
181
+ j === "effect" && /* @__PURE__ */ z(L, { children: [/* @__PURE__ */ R(d, {
182
+ schema: me,
183
+ layer: J,
184
+ setProp: X,
185
+ palette: i,
186
+ renderAnimate: Z
187
+ }), /* @__PURE__ */ R(U, {
188
+ def: E.def,
189
+ view: J,
190
+ tab: "effect",
191
+ onPatch: Y
192
+ })] }),
193
+ j === "anim" && /* @__PURE__ */ z(L, { children: [
194
+ /* @__PURE__ */ R(d, {
195
+ schema: E.def.params,
196
+ layer: J,
197
+ setProp: X,
198
+ palette: i,
199
+ renderAnimate: Z,
200
+ tab: "anim"
201
+ }),
202
+ /* @__PURE__ */ R(U, {
203
+ def: E.def,
204
+ view: J,
205
+ tab: "anim",
206
+ onPatch: Y
207
+ }),
208
+ E.def.sweeps && /* @__PURE__ */ R(W, {
209
+ sweeps: Array.isArray(E.params.sweeps) ? E.params.sweeps : [],
210
+ onChange: pe
211
+ })
212
+ ] })
213
+ ] })
214
+ ]
215
+ });
216
+ }
217
+ function U({ def: t, view: a, tab: o, onPatch: c, inline: d = !1 }) {
218
+ let f = n(), p = i(a), m = o === "anim", h = t.params.filter((t) => e(t) === "anim" === m), g = l(h, a), _ = m ? h.filter((e) => !e.noRandom) : s(h, a), v = (e, t) => {
219
+ e.length && c(r(a, e, p.take(), { stripNoRandom: !!t?.motion }));
220
+ }, y = (e) => {
221
+ let t = {};
222
+ for (let n of e) n.default !== void 0 && (t[n.key] = n.default);
223
+ Object.keys(t).length && c(t);
224
+ };
225
+ return !_.length && !g.length ? null : /* @__PURE__ */ z("div", {
226
+ className: "flex flex-col gap-2",
227
+ children: [
228
+ /* @__PURE__ */ R(u, {
229
+ seed: p,
230
+ inline: d
231
+ }),
232
+ _.length > 0 && /* @__PURE__ */ R(k, {
233
+ tone: "primary",
234
+ size: f,
235
+ className: "w-full",
236
+ onClick: (e) => e.altKey ? y(_) : v(_),
237
+ children: m ? "Randomize motion" : "Randomize all"
238
+ }),
239
+ g.length > 0 && /* @__PURE__ */ R("div", {
240
+ className: "grid grid-cols-2 gap-2",
241
+ children: g.map((e) => /* @__PURE__ */ R(k, {
242
+ tone: "primary",
243
+ size: f,
244
+ onClick: (t) => t.altKey ? y(e.params) : v(e.params, e),
245
+ children: e.label
246
+ }, e.id))
247
+ })
248
+ ]
249
+ });
250
+ }
251
+ function oe({ stage: e, selected: t, onSelect: n, onToggle: r, onRemove: i, onUp: a, onDown: o, canUp: s, canDown: c }) {
252
+ let l = e.enabled !== !1, u = (e, t, n, r) => /* @__PURE__ */ R(N, {
253
+ label: e,
254
+ children: /* @__PURE__ */ R("button", {
255
+ type: "button",
256
+ "aria-label": e,
257
+ disabled: n,
258
+ onClick: (e) => {
259
+ e.stopPropagation(), t();
260
+ },
261
+ className: "inline-flex items-center justify-center w-5 h-5 rounded shrink-0 text-oq-64 hover:text-emphasis disabled:opacity-30",
262
+ style: {
263
+ border: "none",
264
+ background: "transparent",
265
+ cursor: n ? "default" : "pointer"
266
+ },
267
+ children: r
268
+ })
269
+ });
270
+ return /* @__PURE__ */ z("div", {
271
+ role: "button",
272
+ tabIndex: 0,
273
+ onClick: n,
274
+ onKeyDown: (e) => {
275
+ (e.key === "Enter" || e.key === " ") && n();
276
+ },
277
+ className: `flex items-center gap-1 px-2 h-8 rounded cursor-pointer ${t ? "bg-oq-08" : "hover:bg-oq-04"}`,
278
+ children: [
279
+ u(l ? "Disable effect" : "Enable effect", r, !1, /* @__PURE__ */ R(B, {
280
+ name: l ? "eye-on" : "eye-off",
281
+ size: 12
282
+ })),
283
+ /* @__PURE__ */ R("span", {
284
+ className: `kol-helper-12 flex-1 truncate ${l ? "text-emphasis" : "text-meta"}`,
285
+ children: e.def?.label ?? e.id
286
+ }),
287
+ u("Move up", a, !s, /* @__PURE__ */ R(B, {
288
+ name: "chevron-down",
289
+ size: 11,
290
+ style: { transform: "rotate(180deg)" }
291
+ })),
292
+ u("Move down", o, !c, /* @__PURE__ */ R(B, {
293
+ name: "chevron-down",
294
+ size: 11
295
+ })),
296
+ u("Remove effect", i, !1, /* @__PURE__ */ R(B, {
297
+ name: "x",
298
+ size: 11
299
+ }))
300
+ ]
301
+ });
302
+ }
303
+ function W({ sweeps: e, onChange: t, inline: r = !1 }) {
304
+ let i = n(), a = (e) => x.find((t) => t.value === e)?.label ?? e, o = (n) => t([...e, n ? D(n.shape, n) : D()]), s = (n) => t(e.filter((e, t) => t !== n)), c = (n, r, i) => t(e.map((e, t) => t === n ? {
305
+ ...e,
306
+ [r]: i
307
+ } : e)), l = ({ label: e, ...t }) => r ? /* @__PURE__ */ z("div", {
308
+ className: "flex items-center gap-3",
309
+ children: [/* @__PURE__ */ R("span", {
310
+ className: "kol-helper-10 tracking-widest text-meta whitespace-nowrap",
311
+ children: e
312
+ }), /* @__PURE__ */ R("div", {
313
+ className: "flex-1 min-w-0",
314
+ children: /* @__PURE__ */ R(j, { ...t })
315
+ })]
316
+ }) : /* @__PURE__ */ R(A, {
317
+ label: e,
318
+ children: /* @__PURE__ */ R(j, { ...t })
319
+ });
320
+ return /* @__PURE__ */ z("div", {
321
+ className: "flex flex-col gap-3",
322
+ children: [
323
+ /* @__PURE__ */ R("span", {
324
+ className: "kol-helper-10 text-meta",
325
+ children: "Motion"
326
+ }),
327
+ /* @__PURE__ */ R(h, {
328
+ options: [{
329
+ value: "",
330
+ label: "Add motion…"
331
+ }, ...S.map((e) => ({
332
+ value: e.name,
333
+ label: e.name
334
+ }))],
335
+ value: "",
336
+ onChange: (e) => {
337
+ let t = S.find((t) => t.name === e);
338
+ t && o(t);
339
+ }
340
+ }),
341
+ e.map((e, t) => {
342
+ let n = e.enabled !== !1, o = e.target === "reveal", u = C.has(e.shape ?? "linear");
343
+ return /* @__PURE__ */ z("div", {
344
+ className: "flex flex-col gap-2 p-2 rounded bg-oq-04",
345
+ children: [/* @__PURE__ */ z("div", {
346
+ className: "flex items-center gap-2",
347
+ children: [r ? /* @__PURE__ */ z(L, { children: [
348
+ /* @__PURE__ */ R("span", {
349
+ className: `kol-helper-10 tracking-widest ${n ? "text-emphasis" : "text-meta"}`,
350
+ children: a(e.shape ?? "linear")
351
+ }),
352
+ /* @__PURE__ */ R(M, {
353
+ size: i,
354
+ checked: n,
355
+ onChange: (e) => c(t, "enabled", e)
356
+ }),
357
+ /* @__PURE__ */ R("div", { className: "flex-1" })
358
+ ] }) : /* @__PURE__ */ z(L, { children: [/* @__PURE__ */ R(N, {
359
+ label: n ? "Disable sweep" : "Enable sweep",
360
+ children: /* @__PURE__ */ R("button", {
361
+ type: "button",
362
+ "aria-label": n ? "Disable sweep" : "Enable sweep",
363
+ onClick: () => c(t, "enabled", !n),
364
+ className: "inline-flex items-center justify-center w-5 h-5 rounded shrink-0 text-oq-64 hover:text-emphasis",
365
+ style: {
366
+ border: "none",
367
+ background: "transparent",
368
+ cursor: "pointer"
369
+ },
370
+ children: /* @__PURE__ */ R(B, {
371
+ name: n ? "eye-on" : "eye-off",
372
+ size: 12
373
+ })
374
+ })
375
+ }), /* @__PURE__ */ R("span", {
376
+ className: `kol-helper-12 flex-1 truncate ${n ? "text-emphasis" : "text-meta"}`,
377
+ children: a(e.shape ?? "linear")
378
+ })] }), /* @__PURE__ */ R(N, {
379
+ label: "Remove sweep",
380
+ children: /* @__PURE__ */ R("button", {
381
+ type: "button",
382
+ "aria-label": "Remove sweep",
383
+ onClick: () => s(t),
384
+ className: "inline-flex items-center justify-center w-5 h-5 rounded shrink-0 text-oq-64 hover:text-emphasis",
385
+ style: {
386
+ border: "none",
387
+ background: "transparent",
388
+ cursor: "pointer"
389
+ },
390
+ children: /* @__PURE__ */ R(B, {
391
+ name: "x",
392
+ size: 11
393
+ })
394
+ })
395
+ })]
396
+ }), n && /* @__PURE__ */ z(L, { children: [
397
+ /* @__PURE__ */ R(h, {
398
+ options: x,
399
+ value: e.shape ?? "linear",
400
+ onChange: (e) => c(t, "shape", e)
401
+ }),
402
+ /* @__PURE__ */ R(h, {
403
+ options: g,
404
+ value: e.target ?? "brightness",
405
+ onChange: (e) => c(t, "target", e)
406
+ }),
407
+ !o && /* @__PURE__ */ R(l, {
408
+ label: "Amount",
409
+ min: -1,
410
+ max: 1,
411
+ step: .05,
412
+ value: e.amount ?? .6,
413
+ onChange: (e) => c(t, "amount", e)
414
+ }),
415
+ /* @__PURE__ */ R(l, {
416
+ label: "Speed · cycles",
417
+ min: -4,
418
+ max: 4,
419
+ step: 1,
420
+ value: e.speed ?? 1,
421
+ onChange: (e) => c(t, "speed", e)
422
+ }),
423
+ /* @__PURE__ */ R(l, {
424
+ label: "Width",
425
+ min: .05,
426
+ max: 1,
427
+ step: .01,
428
+ value: e.width ?? .35,
429
+ onChange: (e) => c(t, "width", e)
430
+ }),
431
+ u && /* @__PURE__ */ R(l, {
432
+ label: "Angle",
433
+ min: 0,
434
+ max: 360,
435
+ step: 1,
436
+ value: e.angle ?? 0,
437
+ onChange: (e) => c(t, "angle", e)
438
+ })
439
+ ] })]
440
+ }, t);
441
+ }),
442
+ /* @__PURE__ */ R(k, {
443
+ tone: "primary",
444
+ size: i,
445
+ className: "w-full",
446
+ iconLeft: "plus",
447
+ iconSize: 12,
448
+ onClick: () => o(),
449
+ children: "Add custom sweep"
450
+ })
451
+ ]
452
+ });
453
+ }
454
+ //#endregion
455
+ //#region src/packs/effects.js
456
+ var G = {
457
+ FILTERS: b,
458
+ filterById: T,
459
+ makeSweep: D,
460
+ runChain: v,
461
+ invalidateSource: O,
462
+ effectCategories: E,
463
+ EffectsPanel: V,
464
+ loadPixiPipeline: () => import("./pipeline-CMpuPUaX.js"),
465
+ loadGlHost: () => import("./host-be1CWhN1.js")
466
+ };
467
+ o("effects", G);
468
+ //#endregion
469
+ export { U as n, W as r, G as t };
package/dist/effects.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as e } from "./effects-At3W3Ak1.js";
1
+ import { t as e } from "./effects-pCd8YTdQ.js";
2
2
  export { e as effects };