react-native-webrtc-kaleidoscope 2.2.1 → 2.3.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 (51) hide show
  1. package/README.md +30 -0
  2. package/android/src/main/java/com/simiancraft/kaleidoscope/gpu/ShadersGenerated.kt +57 -23
  3. package/catalog/shaders/clouds/clouds.frag +21 -6
  4. package/catalog/shaders/nebula/nebula.frag +22 -10
  5. package/catalog/shaders/simianlights/simianlights.frag +19 -9
  6. package/dist/src/components/preset-control-panel/preset-control-panel.d.ts +9 -1
  7. package/dist/src/components/preset-control-panel/preset-control-panel.d.ts.map +1 -1
  8. package/dist/src/components/preset-control-panel/preset-control-panel.js +7 -3
  9. package/dist/src/components/preset-control-panel/preset-control-panel.js.map +1 -1
  10. package/dist/src/kaleidoscope/controls.d.ts.map +1 -1
  11. package/dist/src/kaleidoscope/controls.js +6 -3
  12. package/dist/src/kaleidoscope/controls.js.map +1 -1
  13. package/dist/src/kaleidoscope/shader-to-spec.d.ts +15 -1
  14. package/dist/src/kaleidoscope/shader-to-spec.d.ts.map +1 -1
  15. package/dist/src/kaleidoscope/shader-to-spec.js +23 -4
  16. package/dist/src/kaleidoscope/shader-to-spec.js.map +1 -1
  17. package/dist/src/kaleidoscope/types.d.ts +3 -1
  18. package/dist/src/kaleidoscope/types.d.ts.map +1 -1
  19. package/dist/src/kaleidoscope/types.js.map +1 -1
  20. package/dist/src/persistence/async-storage-store.d.ts +3 -0
  21. package/dist/src/persistence/async-storage-store.d.ts.map +1 -0
  22. package/dist/src/persistence/async-storage-store.js +26 -0
  23. package/dist/src/persistence/async-storage-store.js.map +1 -0
  24. package/dist/src/persistence/index.d.ts +4 -0
  25. package/dist/src/persistence/index.d.ts.map +1 -0
  26. package/dist/src/persistence/index.js +22 -0
  27. package/dist/src/persistence/index.js.map +1 -0
  28. package/dist/src/persistence/provider.d.ts +38 -0
  29. package/dist/src/persistence/provider.d.ts.map +1 -0
  30. package/dist/src/persistence/provider.js +96 -0
  31. package/dist/src/persistence/provider.js.map +1 -0
  32. package/dist/src/persistence/state.d.ts +54 -0
  33. package/dist/src/persistence/state.d.ts.map +1 -0
  34. package/dist/src/persistence/state.js +126 -0
  35. package/dist/src/persistence/state.js.map +1 -0
  36. package/dist/web-driver/shaders.generated.d.ts +3 -3
  37. package/dist/web-driver/shaders.generated.d.ts.map +1 -1
  38. package/dist/web-driver/shaders.generated.js +57 -23
  39. package/dist/web-driver/shaders.generated.js.map +1 -1
  40. package/ios/KaleidoscopeModule/shaders/clouds.metalsrc +100 -99
  41. package/ios/KaleidoscopeModule/shaders/nebula.metalsrc +63 -45
  42. package/ios/KaleidoscopeModule/shaders/simianlights.metalsrc +63 -45
  43. package/package.json +14 -2
  44. package/src/components/preset-control-panel/preset-control-panel.tsx +15 -2
  45. package/src/kaleidoscope/controls.ts +6 -3
  46. package/src/kaleidoscope/shader-to-spec.ts +32 -5
  47. package/src/kaleidoscope/types.ts +3 -1
  48. package/src/persistence/async-storage-store.ts +33 -0
  49. package/src/persistence/index.ts +28 -0
  50. package/src/persistence/provider.tsx +165 -0
  51. package/src/persistence/state.ts +167 -0
package/README.md CHANGED
@@ -245,6 +245,36 @@ Like the picker, the editor is controlled and presentational: it emits patches a
245
245
 
246
246
  Live per-layer tuning runs on web today; on native the editor renders but the live per-layer uniform channel is in progress. Mask and transform are live on every platform.
247
247
 
248
+ ### Persistence (the selection that survives a reload)
249
+
250
+ `react-native-webrtc-kaleidoscope/persistence` ships a provider + hook that keep the person's selection across launches: the last applied preset id, the per-layer uniform patches they dialed in through the control panels (kept per preset, so tweaks to several presets all survive), and the mask edge.
251
+
252
+ ```tsx
253
+ // App root:
254
+ import { KaleidoscopeStateProvider } from 'react-native-webrtc-kaleidoscope/persistence';
255
+ import { presets } from './kaleidoscope.preset-book';
256
+
257
+ <KaleidoscopeStateProvider presets={presets}>
258
+ <App />
259
+ </KaleidoscopeStateProvider>;
260
+
261
+ // In the screen that binds the track:
262
+ import { useKaleidoscopeState } from 'react-native-webrtc-kaleidoscope/persistence';
263
+
264
+ const { hydrated, presetId, mask, setPreset, setMask, setPatch, patchesFor, reset } =
265
+ useKaleidoscopeState<typeof presets>();
266
+
267
+ useEffect(() => {
268
+ if (!hydrated || !controls) return; // wait: don't flash the default over the restored preset
269
+ if (presetId) controls.kaleidoscope(presetId, patchesFor(presetId));
270
+ else controls.kaleidoscope(null);
271
+ }, [hydrated, controls, presetId]);
272
+ ```
273
+
274
+ Route the picker's `onSelect` into `setPreset`, the editor's `onPatch` into `setPatch(presetId, patch)` (and apply the live patch as usual), and the mask panel into `setMask`; every write persists. Pass the editor `patches={patches[presetId]}` so restored tweaks appear in the sliders, and mount it after `hydrated` (the forms seed at mount). A stored preset that no longer exists in your book reads as "none" instead of crashing the picker.
275
+
276
+ The default store is [`@react-native-async-storage/async-storage`](https://github.com/react-native-async-storage/async-storage) (an optional peer; install it alongside the library when you use this subpath; on web it is localStorage-backed). To back it with something else (MMKV, a server), pass any `{ load, save }` pair as the `store` prop; the stored shape is versioned and parses tolerantly, so a malformed payload reads as empty rather than throwing.
277
+
248
278
  ## Worlds
249
279
 
250
280
  Packaged composites: a multi-layer stack (a generative shader or a cut-out image, the masked person on top), imported and spread into your book (e.g. `import { wizardTower } from 'react-native-webrtc-kaleidoscope/composites/wizard-tower'`). They carry their own `taxonomy: ['Worlds', <group>]`, so the menu groups them under the Worlds tab.
@@ -174,7 +174,9 @@ in highp vec2 vUv;
174
174
  out vec4 oColor;
175
175
 
176
176
  // STEPS must stay a compile-time constant (GLSL ES loop bound).
177
- #define STEPS 48
177
+ // 32 (was 48; issue #37): the distance-growing step in main() keeps the
178
+ // marched range, so fewer steps buys speed instead of clipping the horizon.
179
+ #define STEPS 32
178
180
 
179
181
  float hash(vec3 p) {
180
182
  p = fract(p * 0.3183099 + 0.1);
@@ -202,10 +204,13 @@ float noise(vec3 p) {
202
204
  f.z);
203
205
  }
204
206
 
207
+ // 4 octaves (was 5; issue #37): the 5th octave is fine wisp detail the
208
+ // smoothstep(uCoverage, uCoverage + uSoftness, n) threshold mostly eats; each
209
+ // octave is 8 hash() calls per sample, so this is a flat -20% on the march.
205
210
  float fbm(vec3 p) {
206
211
  float v = 0.0;
207
212
  float a = 0.5;
208
- for (int i = 0; i < 5; i++) {
213
+ for (int i = 0; i < 4; i++) {
209
214
  v += a * noise(p);
210
215
  p *= 2.03;
211
216
  a *= 0.5;
@@ -241,14 +246,21 @@ void main() {
241
246
  if (rd.y > 0.0 && p.y >= 3.0) break;
242
247
  if (rd.y < 0.0 && p.y <= 0.0) break;
243
248
  float d = cloudDensity(p);
249
+ // Distance-growing step (issue #37): far clouds are small on screen and
250
+ // tolerate coarser sampling, so the step stretches with t. 32 growing
251
+ // steps reach slightly past where 48 uniform steps did, spending the
252
+ // samples up close where banding would show. growth also scales the
253
+ // per-sample opacity so optical depth per unit distance stays consistent
254
+ // with the uniform-step tuning the presets were dialed against.
255
+ float growth = 1.0 + t * 0.15;
244
256
  if (d > 0.01) {
245
257
  float light = smoothstep(0.4, 2.8, p.y);
246
258
  vec3 sampleColor = mix(uCloudDarkColor, uCloudLightColor, light);
247
- float a = d * uDensity;
259
+ float a = min(d * uDensity * growth, 1.0);
248
260
  accum += (1.0 - alpha) * sampleColor * a;
249
261
  alpha += (1.0 - alpha) * a;
250
262
  }
251
- t += uStepSize;
263
+ t += uStepSize * growth;
252
264
  if (alpha > 0.95) break;
253
265
  }
254
266
  vec3 color = mix(skyColor, accum, alpha);
@@ -278,7 +290,9 @@ const float MIN_DIVIDE = 64.0;
278
290
  const float MAX_DIVIDE = 0.01;
279
291
  // Number of stacked starfield layers. Compile-time constant so the layer
280
292
  // loop has a fixed integer bound (cross-compile-safe; no float loop counter).
281
- const int STARFIELD_LAYERS_COUNT = 12;
293
+ // 8 (was 12) for low-end-mobile cost (issue #39); the work is linear in the
294
+ // count and dimByDensity rebalances per-star brightness automatically.
295
+ const int STARFIELD_LAYERS_COUNT = 8;
282
296
 
283
297
  mat2 Rotate(float angle) {
284
298
  float s = sin(angle);
@@ -288,20 +302,30 @@ mat2 Rotate(float angle) {
288
302
 
289
303
  float Star(vec2 uv, float flaresize, float rotAngle, float randomN) {
290
304
  float d = length(uv);
305
+ // The concentric fade at the bottom is exactly 0 for d >= 1.0; the star is
306
+ // invisible there, so skip everything (issue #39: a large share of the 3x3
307
+ // neighbor sweep lands outside this radius; the cull is output-identical).
308
+ if (d >= 1.0) return 0.0;
291
309
  // Star core. Guard the division: length(uv) can be exactly 0 at a cell
292
310
  // center, which yields inf/NaN under Metal. max(d, 1e-4) caps the core
293
311
  // brightness without visibly changing the look (the concentric
294
312
  // smoothstep fade below already clamps it).
295
313
  float starcore = 0.05 * uStarGlow / max(d, 1e-4);
296
- uv *= Rotate(-2.0 * PI * rotAngle);
297
- float flareMax = 1.0;
298
-
299
- // flares
300
- float starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
301
- starcore += starflares * flaresize;
302
- uv *= Rotate(PI * 0.25);
303
- starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
304
- starcore += starflares * 0.3 * flaresize;
314
+ // Flares exist only on the brightest stars: flaresize is exactly 0 below the
315
+ // smoothstep(0.9, 1.0, size) knee (~90% of cells), and both Rotates feed
316
+ // nothing but the flares. Skipping the block is output-identical, and
317
+ // flaresize is constant per cell, so the branch is coherent (issue #39).
318
+ if (flaresize > 0.0) {
319
+ uv *= Rotate(-2.0 * PI * rotAngle);
320
+ float flareMax = 1.0;
321
+
322
+ // flares
323
+ float starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
324
+ starcore += starflares * flaresize;
325
+ uv *= Rotate(PI * 0.25);
326
+ starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
327
+ starcore += starflares * 0.3 * flaresize;
328
+ }
305
329
  // light can't go forever, fade it concentrically.
306
330
  starcore *= smoothstep(1.0, 0.05, d);
307
331
  return starcore;
@@ -548,20 +572,30 @@ mat2 Rotate(float angle) {
548
572
 
549
573
  float Star(vec2 uv, float flaresize, float rotAngle, float randomN) {
550
574
  float d = length(uv);
575
+ // The concentric fade at the bottom is exactly 0 for d >= 1.0; the star is
576
+ // invisible there, so skip everything (issue #39: a large share of the 3x3
577
+ // neighbor sweep lands outside this radius; the cull is output-identical).
578
+ if (d >= 1.0) return 0.0;
551
579
  // Star core. Guard the division: length(uv) can be exactly 0 at a cell
552
580
  // center, which yields inf/NaN under Metal. max(d, 1e-4) caps the core
553
581
  // brightness without visibly changing the look (the concentric
554
582
  // smoothstep fade below already clamps it).
555
583
  float starcore = 0.09 * uStarGlow / max(d, 1e-4);
556
- uv *= Rotate(-2.0 * PI * rotAngle);
557
- float flareMax = 1.0;
558
-
559
- // flares
560
- float starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
561
- starcore += starflares * flaresize;
562
- uv *= Rotate(PI * 0.25);
563
- starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
564
- starcore += starflares * 0.3 * flaresize;
584
+ // Flares exist only on the brightest stars: flaresize is exactly 0 below the
585
+ // smoothstep(0.9, 1.0, size) knee (~90% of cells), and both Rotates feed
586
+ // nothing but the flares. Skipping the block is output-identical, and
587
+ // flaresize is constant per cell, so the branch is coherent (issue #39).
588
+ if (flaresize > 0.0) {
589
+ uv *= Rotate(-2.0 * PI * rotAngle);
590
+ float flareMax = 1.0;
591
+
592
+ // flares
593
+ float starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
594
+ starcore += starflares * flaresize;
595
+ uv *= Rotate(PI * 0.25);
596
+ starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
597
+ starcore += starflares * 0.3 * flaresize;
598
+ }
565
599
  // light can't go forever, fade it concentrically.
566
600
  starcore *= smoothstep(1.0, 0.05, d);
567
601
  return starcore;
@@ -6,9 +6,12 @@
6
6
  // compile-time constant (GLSL ES loop bound).
7
7
  //
8
8
  // Slab-bounded march (issue #37): the clouds live in 0 < p.y < 3 (the height
9
- // mask is 0 outside it), so cloudDensity() returns 0 before the 5-octave fbm()
9
+ // mask is 0 outside it), so cloudDensity() returns 0 before the 4-octave fbm()
10
10
  // when p.y leaves the slab, and the march breaks once the ray exits it. Both
11
- // skip only zero-contribution samples; output is unchanged.
11
+ // skip only zero-contribution samples; output is unchanged. The march itself
12
+ // uses a distance-growing step (see main) so 32 steps cover the old 48-step
13
+ // range; the growth factor also weights per-sample opacity to keep optical
14
+ // depth per unit distance consistent.
12
15
  //
13
16
  // UV convention: matches passthrough.vert. vUv = (0, 0) bottom-left, (1, 1)
14
17
  // top-right; fragCoord is reconstructed as vUv * uResolution. Fully procedural
@@ -44,7 +47,9 @@ in highp vec2 vUv;
44
47
  out vec4 oColor;
45
48
 
46
49
  // STEPS must stay a compile-time constant (GLSL ES loop bound).
47
- #define STEPS 48
50
+ // 32 (was 48; issue #37): the distance-growing step in main() keeps the
51
+ // marched range, so fewer steps buys speed instead of clipping the horizon.
52
+ #define STEPS 32
48
53
 
49
54
  float hash(vec3 p) {
50
55
  p = fract(p * 0.3183099 + 0.1);
@@ -72,10 +77,13 @@ float noise(vec3 p) {
72
77
  f.z);
73
78
  }
74
79
 
80
+ // 4 octaves (was 5; issue #37): the 5th octave is fine wisp detail the
81
+ // smoothstep(uCoverage, uCoverage + uSoftness, n) threshold mostly eats; each
82
+ // octave is 8 hash() calls per sample, so this is a flat -20% on the march.
75
83
  float fbm(vec3 p) {
76
84
  float v = 0.0;
77
85
  float a = 0.5;
78
- for (int i = 0; i < 5; i++) {
86
+ for (int i = 0; i < 4; i++) {
79
87
  v += a * noise(p);
80
88
  p *= 2.03;
81
89
  a *= 0.5;
@@ -111,14 +119,21 @@ void main() {
111
119
  if (rd.y > 0.0 && p.y >= 3.0) break;
112
120
  if (rd.y < 0.0 && p.y <= 0.0) break;
113
121
  float d = cloudDensity(p);
122
+ // Distance-growing step (issue #37): far clouds are small on screen and
123
+ // tolerate coarser sampling, so the step stretches with t. 32 growing
124
+ // steps reach slightly past where 48 uniform steps did, spending the
125
+ // samples up close where banding would show. growth also scales the
126
+ // per-sample opacity so optical depth per unit distance stays consistent
127
+ // with the uniform-step tuning the presets were dialed against.
128
+ float growth = 1.0 + t * 0.15;
114
129
  if (d > 0.01) {
115
130
  float light = smoothstep(0.4, 2.8, p.y);
116
131
  vec3 sampleColor = mix(uCloudDarkColor, uCloudLightColor, light);
117
- float a = d * uDensity;
132
+ float a = min(d * uDensity * growth, 1.0);
118
133
  accum += (1.0 - alpha) * sampleColor * a;
119
134
  alpha += (1.0 - alpha) * a;
120
135
  }
121
- t += uStepSize;
136
+ t += uStepSize * growth;
122
137
  if (alpha > 0.95) break;
123
138
  }
124
139
  vec3 color = mix(skyColor, accum, alpha);
@@ -40,7 +40,9 @@ const float MIN_DIVIDE = 64.0;
40
40
  const float MAX_DIVIDE = 0.01;
41
41
  // Number of stacked starfield layers. Compile-time constant so the layer
42
42
  // loop has a fixed integer bound (cross-compile-safe; no float loop counter).
43
- const int STARFIELD_LAYERS_COUNT = 12;
43
+ // 8 (was 12) for low-end-mobile cost (issue #39); the work is linear in the
44
+ // count and dimByDensity rebalances per-star brightness automatically.
45
+ const int STARFIELD_LAYERS_COUNT = 8;
44
46
 
45
47
  mat2 Rotate(float angle) {
46
48
  float s = sin(angle);
@@ -50,20 +52,30 @@ mat2 Rotate(float angle) {
50
52
 
51
53
  float Star(vec2 uv, float flaresize, float rotAngle, float randomN) {
52
54
  float d = length(uv);
55
+ // The concentric fade at the bottom is exactly 0 for d >= 1.0; the star is
56
+ // invisible there, so skip everything (issue #39: a large share of the 3x3
57
+ // neighbor sweep lands outside this radius; the cull is output-identical).
58
+ if (d >= 1.0) return 0.0;
53
59
  // Star core. Guard the division: length(uv) can be exactly 0 at a cell
54
60
  // center, which yields inf/NaN under Metal. max(d, 1e-4) caps the core
55
61
  // brightness without visibly changing the look (the concentric
56
62
  // smoothstep fade below already clamps it).
57
63
  float starcore = 0.05 * uStarGlow / max(d, 1e-4);
58
- uv *= Rotate(-2.0 * PI * rotAngle);
59
- float flareMax = 1.0;
60
-
61
- // flares
62
- float starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
63
- starcore += starflares * flaresize;
64
- uv *= Rotate(PI * 0.25);
65
- starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
66
- starcore += starflares * 0.3 * flaresize;
64
+ // Flares exist only on the brightest stars: flaresize is exactly 0 below the
65
+ // smoothstep(0.9, 1.0, size) knee (~90% of cells), and both Rotates feed
66
+ // nothing but the flares. Skipping the block is output-identical, and
67
+ // flaresize is constant per cell, so the branch is coherent (issue #39).
68
+ if (flaresize > 0.0) {
69
+ uv *= Rotate(-2.0 * PI * rotAngle);
70
+ float flareMax = 1.0;
71
+
72
+ // flares
73
+ float starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
74
+ starcore += starflares * flaresize;
75
+ uv *= Rotate(PI * 0.25);
76
+ starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
77
+ starcore += starflares * 0.3 * flaresize;
78
+ }
67
79
  // light can't go forever, fade it concentrically.
68
80
  starcore *= smoothstep(1.0, 0.05, d);
69
81
  return starcore;
@@ -50,20 +50,30 @@ mat2 Rotate(float angle) {
50
50
 
51
51
  float Star(vec2 uv, float flaresize, float rotAngle, float randomN) {
52
52
  float d = length(uv);
53
+ // The concentric fade at the bottom is exactly 0 for d >= 1.0; the star is
54
+ // invisible there, so skip everything (issue #39: a large share of the 3x3
55
+ // neighbor sweep lands outside this radius; the cull is output-identical).
56
+ if (d >= 1.0) return 0.0;
53
57
  // Star core. Guard the division: length(uv) can be exactly 0 at a cell
54
58
  // center, which yields inf/NaN under Metal. max(d, 1e-4) caps the core
55
59
  // brightness without visibly changing the look (the concentric
56
60
  // smoothstep fade below already clamps it).
57
61
  float starcore = 0.09 * uStarGlow / max(d, 1e-4);
58
- uv *= Rotate(-2.0 * PI * rotAngle);
59
- float flareMax = 1.0;
60
-
61
- // flares
62
- float starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
63
- starcore += starflares * flaresize;
64
- uv *= Rotate(PI * 0.25);
65
- starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
66
- starcore += starflares * 0.3 * flaresize;
62
+ // Flares exist only on the brightest stars: flaresize is exactly 0 below the
63
+ // smoothstep(0.9, 1.0, size) knee (~90% of cells), and both Rotates feed
64
+ // nothing but the flares. Skipping the block is output-identical, and
65
+ // flaresize is constant per cell, so the branch is coherent (issue #39).
66
+ if (flaresize > 0.0) {
67
+ uv *= Rotate(-2.0 * PI * rotAngle);
68
+ float flareMax = 1.0;
69
+
70
+ // flares
71
+ float starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
72
+ starcore += starflares * flaresize;
73
+ uv *= Rotate(PI * 0.25);
74
+ starflares = max(0.0, flareMax - abs(uv.x * uv.y * 3000.0));
75
+ starcore += starflares * 0.3 * flaresize;
76
+ }
67
77
  // light can't go forever, fade it concentrically.
68
78
  starcore *= smoothstep(1.0, 0.05, d);
69
79
  return starcore;
@@ -6,7 +6,15 @@ export type PresetControlPanelProps<P extends KaleidoscopePresetBook> = {
6
6
  readonly value: (keyof P & string) | null;
7
7
  /** Routed to the host, which applies it via `kaleidoscope(value, [patch])`. */
8
8
  readonly onPatch: KaleidoscopeControls['onPatch'];
9
+ /**
10
+ * Per-layer uniform overrides (e.g. a persisted selection's stored patches)
11
+ * merged over the preset's baked uniforms when the forms seed. Seed-time
12
+ * only: the forms re-seed on a preset switch, not when this prop changes
13
+ * mid-mount, so hosts restoring persisted patches should mount the panel
14
+ * after hydration.
15
+ */
16
+ readonly patches?: KaleidoscopeControls['uniforms'];
9
17
  readonly disabled?: boolean;
10
18
  };
11
- export declare function PresetControlPanel<P extends KaleidoscopePresetBook>({ presets, value, onPatch, disabled, }: PresetControlPanelProps<P>): ReactElement | null;
19
+ export declare function PresetControlPanel<P extends KaleidoscopePresetBook>({ presets, value, onPatch, patches, disabled, }: PresetControlPanelProps<P>): ReactElement | null;
12
20
  //# sourceMappingURL=preset-control-panel.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"preset-control-panel.d.ts","sourceRoot":"","sources":["../../../../src/components/preset-control-panel/preset-control-panel.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,sCAAsC,CAAC;AAG9C,MAAM,MAAM,uBAAuB,CAAC,CAAC,SAAS,sBAAsB,IAAI;IACtE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC;IAC1C,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAClD,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,sBAAsB,EAAE,EACnE,OAAO,EACP,KAAK,EACL,OAAO,EACP,QAAgB,GACjB,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,IAAI,CAoBlD"}
1
+ {"version":3,"file":"preset-control-panel.d.ts","sourceRoot":"","sources":["../../../../src/components/preset-control-panel/preset-control-panel.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,sCAAsC,CAAC;AAG9C,MAAM,MAAM,uBAAuB,CAAC,CAAC,SAAS,sBAAsB,IAAI;IACtE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC;IAC1C,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAClD;;;;;;OAMG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC;IACpD,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,sBAAsB,EAAE,EACnE,OAAO,EACP,KAAK,EACL,OAAO,EACP,OAAO,EACP,QAAgB,GACjB,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,IAAI,CAwBlD"}
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PresetControlPanel = PresetControlPanel;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const scope_1 = require("../form/scope");
6
- function PresetControlPanel({ presets, value, onPatch, disabled = false, }) {
6
+ function PresetControlPanel({ presets, value, onPatch, patches, disabled = false, }) {
7
7
  if (value === null)
8
8
  return null;
9
9
  const preset = presets[value];
@@ -11,11 +11,15 @@ function PresetControlPanel({ presets, value, onPatch, disabled = false, }) {
11
11
  if (!Controls)
12
12
  return null;
13
13
  // Per-layer baked uniforms keyed by id, for the controls component to seed each
14
- // layer's ControlForm. Only tunable layers carry uniforms.
14
+ // layer's ControlForm. Only tunable layers carry uniforms; stored overrides
15
+ // merge over the baked values so restored tweaks appear in the forms.
15
16
  const uniforms = {};
16
17
  for (const layer of preset.layers) {
17
18
  if ('uniforms' in layer) {
18
- uniforms[layer.id] = { ...layer.uniforms };
19
+ uniforms[layer.id] = {
20
+ ...layer.uniforms,
21
+ ...patches?.[layer.id],
22
+ };
19
23
  }
20
24
  }
21
25
  return ((0, jsx_runtime_1.jsx)(scope_1.ControlScopeContext.Provider, { value: value, children: (0, jsx_runtime_1.jsx)(Controls, { uniforms: uniforms, onPatch: onPatch, disabled: disabled }, value) }));
@@ -1 +1 @@
1
- {"version":3,"file":"preset-control-panel.js","sourceRoot":"","sources":["../../../../src/components/preset-control-panel/preset-control-panel.tsx"],"names":[],"mappings":";;;;AAWA,yCAAoD;AAWpD,4BAAqE,EACnE,OAAO,EACP,KAAK,EACL,OAAO,EACP,QAAQ,GAAG,KAAK,GACW;IAC3B,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,CAAC;IAClC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,gFAAgF;IAChF,2DAA2D;IAC3D,MAAM,QAAQ,GAA+D,EAAE,CAAC;IAChF,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClC,IAAI,UAAU,IAAI,KAAK,EAAE,CAAC;YACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAgD,CAAC;QAC3F,CAAC;IACH,CAAC;IAED,OAAO,CACL,uBAAC,2BAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACxC,uBAAC,QAAQ,IAAa,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,IAA/D,KAAK,CAA8D,GACrD,CAChC,CAAC;AACJ,CAAC","sourcesContent":["// PresetControlPanel: the thin, controlled editor. For the active preset it\n// renders that preset's `controls` component (keyed by preset id, so a switch\n// remounts and the ControlForms re-seed), handing it the per-layer baked\n// uniforms and a single shared onPatch. It never calls `kaleidoscope` itself;\n// the host routes onPatch into `kaleidoscope(activeId, [patch])`.\n\nimport type { ReactElement } from 'react';\nimport type {\n KaleidoscopeControls,\n KaleidoscopePresetBook,\n} from '../../kaleidoscope.preset-book.types';\nimport { ControlScopeContext } from '../form/scope';\n\nexport type PresetControlPanelProps<P extends KaleidoscopePresetBook> = {\n readonly presets: P;\n /** The active preset id, or null when nothing is selected. */\n readonly value: (keyof P & string) | null;\n /** Routed to the host, which applies it via `kaleidoscope(value, [patch])`. */\n readonly onPatch: KaleidoscopeControls['onPatch'];\n readonly disabled?: boolean;\n};\n\nexport function PresetControlPanel<P extends KaleidoscopePresetBook>({\n presets,\n value,\n onPatch,\n disabled = false,\n}: PresetControlPanelProps<P>): ReactElement | null {\n if (value === null) return null;\n const preset = presets[value];\n const Controls = preset?.controls;\n if (!Controls) return null;\n\n // Per-layer baked uniforms keyed by id, for the controls component to seed each\n // layer's ControlForm. Only tunable layers carry uniforms.\n const uniforms: Record<string, Record<string, number | readonly number[]>> = {};\n for (const layer of preset.layers) {\n if ('uniforms' in layer) {\n uniforms[layer.id] = { ...layer.uniforms } as Record<string, number | readonly number[]>;\n }\n }\n\n return (\n <ControlScopeContext.Provider value={value}>\n <Controls key={value} uniforms={uniforms} onPatch={onPatch} disabled={disabled} />\n </ControlScopeContext.Provider>\n );\n}\n"]}
1
+ {"version":3,"file":"preset-control-panel.js","sourceRoot":"","sources":["../../../../src/components/preset-control-panel/preset-control-panel.tsx"],"names":[],"mappings":";;;;AAWA,yCAAoD;AAmBpD,4BAAqE,EACnE,OAAO,EACP,KAAK,EACL,OAAO,EACP,OAAO,EACP,QAAQ,GAAG,KAAK,GACW;IAC3B,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,MAAM,QAAQ,GAAG,MAAM,EAAE,QAAQ,CAAC;IAClC,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,gFAAgF;IAChF,4EAA4E;IAC5E,sEAAsE;IACtE,MAAM,QAAQ,GAA+D,EAAE,CAAC;IAChF,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClC,IAAI,UAAU,IAAI,KAAK,EAAE,CAAC;YACxB,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG;gBACnB,GAAG,KAAK,CAAC,QAAQ;gBACjB,GAAG,OAAO,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC;aACuB,CAAC;QAClD,CAAC;IACH,CAAC;IAED,OAAO,CACL,uBAAC,2BAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACxC,uBAAC,QAAQ,IAAa,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,IAA/D,KAAK,CAA8D,GACrD,CAChC,CAAC;AACJ,CAAC","sourcesContent":["// PresetControlPanel: the thin, controlled editor. For the active preset it\n// renders that preset's `controls` component (keyed by preset id, so a switch\n// remounts and the ControlForms re-seed), handing it the per-layer baked\n// uniforms and a single shared onPatch. It never calls `kaleidoscope` itself;\n// the host routes onPatch into `kaleidoscope(activeId, [patch])`.\n\nimport type { ReactElement } from 'react';\nimport type {\n KaleidoscopeControls,\n KaleidoscopePresetBook,\n} from '../../kaleidoscope.preset-book.types';\nimport { ControlScopeContext } from '../form/scope';\n\nexport type PresetControlPanelProps<P extends KaleidoscopePresetBook> = {\n readonly presets: P;\n /** The active preset id, or null when nothing is selected. */\n readonly value: (keyof P & string) | null;\n /** Routed to the host, which applies it via `kaleidoscope(value, [patch])`. */\n readonly onPatch: KaleidoscopeControls['onPatch'];\n /**\n * Per-layer uniform overrides (e.g. a persisted selection's stored patches)\n * merged over the preset's baked uniforms when the forms seed. Seed-time\n * only: the forms re-seed on a preset switch, not when this prop changes\n * mid-mount, so hosts restoring persisted patches should mount the panel\n * after hydration.\n */\n readonly patches?: KaleidoscopeControls['uniforms'];\n readonly disabled?: boolean;\n};\n\nexport function PresetControlPanel<P extends KaleidoscopePresetBook>({\n presets,\n value,\n onPatch,\n patches,\n disabled = false,\n}: PresetControlPanelProps<P>): ReactElement | null {\n if (value === null) return null;\n const preset = presets[value];\n const Controls = preset?.controls;\n if (!Controls) return null;\n\n // Per-layer baked uniforms keyed by id, for the controls component to seed each\n // layer's ControlForm. Only tunable layers carry uniforms; stored overrides\n // merge over the baked values so restored tweaks appear in the forms.\n const uniforms: Record<string, Record<string, number | readonly number[]>> = {};\n for (const layer of preset.layers) {\n if ('uniforms' in layer) {\n uniforms[layer.id] = {\n ...layer.uniforms,\n ...patches?.[layer.id],\n } as Record<string, number | readonly number[]>;\n }\n }\n\n return (\n <ControlScopeContext.Provider value={value}>\n <Controls key={value} uniforms={uniforms} onPatch={onPatch} disabled={disabled} />\n </ControlScopeContext.Provider>\n );\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"controls.d.ts","sourceRoot":"","sources":["../../../src/kaleidoscope/controls.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAsB,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AACpG,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,gBAAgB,CAAC;AAEhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,uBAAuB,EAAkB,MAAM,SAAS,CAAC;AAE5F,uEAAuE;AACvE,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,KAAK,gBAAgB,CAAC;IAC9D,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,kEAAkE;AAClE,MAAM,MAAM,OAAO,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;AAEpE;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC,CAAC,KAC3D,IAAI,CAAC;AAEV;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC;AAiB5C,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,sBAAsB,aAClD,gBAAgB,wBACL,uBAAuB,CAAC,CAAC,CAAC,aACrC,SAAS,WACX,OAAO,oBACE,gBAAgB,sBACd,kBAAkB,KACrC,mBAAmB,CAAC,CAAC,CA0DvB,CAAC"}
1
+ {"version":3,"file":"controls.d.ts","sourceRoot":"","sources":["../../../src/kaleidoscope/controls.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAsB,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AACpG,OAAO,KAAK,EAAE,UAAU,EAAiB,MAAM,gBAAgB,CAAC;AAEhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,uBAAuB,EAAkB,MAAM,SAAS,CAAC;AAE5F,uEAAuE;AACvE,MAAM,MAAM,SAAS,GAAG;IACtB,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,KAAK,gBAAgB,CAAC;IAC9D,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,kEAAkE;AAClE,MAAM,MAAM,OAAO,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;AAEpE;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC,CAAC,KAC3D,IAAI,CAAC;AAEV;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC;AAiB5C,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,sBAAsB,aAClD,gBAAgB,wBACL,uBAAuB,CAAC,CAAC,CAAC,aACrC,SAAS,WACX,OAAO,oBACE,gBAAgB,sBACd,kBAAkB,KACrC,mBAAmB,CAAC,CAAC,CA6DvB,CAAC"}
@@ -65,10 +65,13 @@ const createControls = (baseTrack, { presets, onTrack }, reconcile, setMask, set
65
65
  // Switch the preset (or clear): rebuild. Drop every live override first so
66
66
  // a reused layer id (e.g. 'blur', shared by the low/medium/high blur
67
67
  // presets) takes the new preset's baked uniforms instead of carrying a
68
- // stale slider override across. A transform rebuild does NOT pass through
69
- // here, so slider tweaks survive flips/rotations of the active preset.
68
+ // stale slider override across. Patches given WITH the switch (e.g. a
69
+ // persisted selection's overrides) merge into the rebuilt stack itself,
70
+ // so they land on every platform, native included. A transform rebuild
71
+ // does NOT pass through here, so slider tweaks survive flips/rotations
72
+ // of the active preset.
70
73
  activeId = cmd;
71
- art = cmd == null ? null : (0, shader_to_spec_1.compositeToEffectSpec)(presets[cmd]);
74
+ art = cmd == null ? null : (0, shader_to_spec_1.compositeToEffectSpec)(presets[cmd], patches);
72
75
  resetLayerUniforms();
73
76
  apply();
74
77
  },
@@ -1 +1 @@
1
- {"version":3,"file":"controls.js","sourceRoot":"","sources":["../../../src/kaleidoscope/controls.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,0EAA0E;AAC1E,+EAA+E;AAC/E,gFAAgF;AAChF,gEAAgE;AAChE,EAAE;AACF,+EAA+E;AAC/E,uEAAuE;AACvE,iFAAiF;AACjF,mDAAmD;;;AAInD,qDAAyD;AA6BzD,6EAA6E;AAC7E,iFAAiF;AACjF,+DAA+D;AAC/D,MAAM,kBAAkB,GAAG,CAAC,CAAkB,EAAgB,EAAE;IAC9D,IAAI,CAAC,CAAC;QAAE,OAAO,EAAE,CAAC;IAClB,MAAM,KAAK,GAAoB,EAAE,CAAC;IAClC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,C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ACF,uEAAuE;YACvE,wEAAwE;YACxE,2CAA2C;YAC3C,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,KAAK,QAAQ,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrE,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;oBAC5B,gBAAgB,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;gBAC7C,CAAC;gBACD,OAAO;YACT,CAAC;YACD,2EAA2E;YAC3E,qEAAqE;YACrE,uEAAuE;YACvE,0EAA0E;YAC1E,uEAAuE;YACvE,QAAQ,GAAG,GAAG,CAAC;YACf,GAAG,GAAG,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,sCAAqB,EAAC,OAAO,CAAC,GAAG,CAAuB,CAAC,CAAC;YACrF,kBAAkB,EAAE,CAAC;YACrB,KAAK,EAAE,CAAC;QACV,CAAC;QACD,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE;YACf,YAAY,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;YACrC,KAAK,EAAE,CAAC;QACV,CAAC;QACD,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE;YACV,uEAAuE;YACvE,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,KAAK;YACP,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;YACZ,SAAS,CAAC,OAAO,EAAE,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAjEW,QAAA,cAAc,GAAd,cAAc,CAiEzB","sourcesContent":["// The three-verb controls: shared composite-state machine, platform-agnostic.\n//\n// Holds the art effect (one composite) and the transform op list, reconciles\n// them into an ordered EffectSpec array (art FIRST so segmentation sees the\n// upright frame, transform LAST so it reorients the finished composite), and\n// applies them through an injected platform `reconcile`. Web rebuilds the\n// pipeline and yields a new track (disposing the prior one); native mutates in\n// place. `mask` writes the segmentation edge through an injected `setMask`; the\n// running composite reads it per frame, so it needs no rebuild.\n//\n// The art verb is rebuild-aware: switching to a different preset rebuilds, but\n// patching the currently-active preset routes through an injected live\n// layer-uniform channel (`setLayerUniforms`, keyed by layer id) so a slider drag\n// updates the running composite without a rebuild.\n\nimport type { KaleidoscopePreset, KaleidoscopePresetBook } from '../kaleidoscope.preset-book.types';\nimport type { EffectSpec, TransformName } from './effect.types';\nimport { compositeToEffectSpec } from './shader-to-spec';\nimport type { KaleidoscopeBinding, KaleidoscopeBindOptions, TransformInput } from './types';\n\n/** Apply the ordered specs to the base track and return the output. */\nexport type Reconcile = {\n apply: (specs: ReadonlyArray<EffectSpec>) => MediaStreamTrack;\n dispose: () => void;\n};\n\n/** Write the segmentation mask edge (platform tuning channel). */\nexport type SetMask = (hardness: number, threshold: number) => void;\n\n/**\n * Write a live per-layer uniform override (platform tuning channel), keyed by\n * layer id. The running composite merges these over the layer's baked uniforms\n * each frame, with no rebuild. Mirrors `setMask`.\n */\nexport type SetLayerUniforms = (\n id: string,\n uniforms: Readonly<Record<string, number | readonly number[]>>,\n) => void;\n\n/**\n * Drop every live per-layer override (platform tuning channel). A preset switch\n * calls this so a reused layer id reverts to the new preset's baked uniforms\n * rather than inheriting a stale override from the prior preset.\n */\nexport type ResetLayerUniforms = () => void;\n\n// Decompose an absolute transform into the discrete ops the pipeline already\n// runs (reused on web and native). Flips first, then rotation; rotation snaps to\n// the nearest 90°. 180° is two CW steps; 270° is one CCW step.\nconst decomposeTransform = (t?: TransformInput): EffectSpec[] => {\n if (!t) return [];\n const names: TransformName[] = [];\n if (t.flip?.x) names.push('flip-x');\n if (t.flip?.y) names.push('flip-y');\n const deg = (((Math.round((t.rotate ?? 0) / 90) * 90) % 360) + 360) % 360;\n if (deg === 90) names.push('rotate-cw');\n else if (deg === 180) names.push('rotate-cw', 'rotate-cw');\n else if (deg === 270) names.push('rotate-ccw');\n return names.map((name) => ({ name }));\n};\n\nexport const createControls = <P extends KaleidoscopePresetBook>(\n baseTrack: MediaStreamTrack,\n { presets, onTrack }: KaleidoscopeBindOptions<P>,\n reconcile: Reconcile,\n setMask: SetMask,\n setLayerUniforms: SetLayerUniforms,\n resetLayerUniforms: ResetLayerUniforms,\n): KaleidoscopeBinding<P> => {\n let art: EffectSpec | null = null;\n let transformOps: EffectSpec[] = [];\n let current = baseTrack;\n // The id of the active preset (null when cleared). A patch of THIS id routes\n // through the live channel; any other cmd rebuilds.\n let activeId: keyof P | null = null;\n\n const apply = (): void => {\n const specs: EffectSpec[] = [];\n if (art) specs.push(art);\n specs.push(...transformOps);\n current = reconcile.apply(specs);\n onTrack?.(current);\n };\n\n return {\n kaleidoscope: (\n cmd: keyof P | null,\n patches?: ReadonlyArray<{\n readonly id: string;\n readonly uniforms: Readonly<Record<string, number | readonly number[]>>;\n }>,\n ) => {\n // Patch the currently-active preset: route through the live no-rebuild\n // channel, keyed by layer id. The `shader` field on a patch is only for\n // narrowing; the channel resolves by `id`.\n if (cmd != null && cmd === activeId && patches && patches.length > 0) {\n for (const patch of patches) {\n setLayerUniforms(patch.id, patch.uniforms);\n }\n return;\n }\n // Switch the preset (or clear): rebuild. Drop every live override first so\n // a reused layer id (e.g. 'blur', shared by the low/medium/high blur\n // presets) takes the new preset's baked uniforms instead of carrying a\n // stale slider override across. A transform rebuild does NOT pass through\n // here, so slider tweaks survive flips/rotations of the active preset.\n activeId = cmd;\n art = cmd == null ? null : compositeToEffectSpec(presets[cmd] as KaleidoscopePreset);\n resetLayerUniforms();\n apply();\n },\n transform: (t) => {\n transformOps = decomposeTransform(t);\n apply();\n },\n mask: (m) => {\n // Updates the edge the per-frame composite reads; no pipeline rebuild.\n setMask(m.hardness, m.threshold);\n },\n get track() {\n return current;\n },\n dispose: () => {\n reconcile.dispose();\n },\n };\n};\n"]}
1
+ {"version":3,"file":"controls.js","sourceRoot":"","sources":["../../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qB,EAAC,OAAO,CAAC,GAAG,CAAuB,EAAE,OAAO,CAAC,CAAC;YAC9F,kBAAkB,EAAE,CAAC;YACrB,KAAK,EAAE,CAAC;QACV,CAAC;QACD,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE;YACf,YAAY,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;YACrC,KAAK,EAAE,CAAC;QACV,CAAC;QACD,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE;YACV,uEAAuE;YACvE,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,KAAK;YACP,OAAO,OAAO,CAAC;QACjB,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;YACZ,SAAS,CAAC,OAAO,EAAE,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AApEW,QAAA,cAAc,GAAd,cAAc,CAoEzB","sourcesContent":["// The three-verb controls: shared composite-state machine, platform-agnostic.\n//\n// Holds the art effect (one composite) and the transform op list, reconciles\n// them into an ordered EffectSpec array (art FIRST so segmentation sees the\n// upright frame, transform LAST so it reorients the finished composite), and\n// applies them through an injected platform `reconcile`. Web rebuilds the\n// pipeline and yields a new track (disposing the prior one); native mutates in\n// place. `mask` writes the segmentation edge through an injected `setMask`; the\n// running composite reads it per frame, so it needs no rebuild.\n//\n// The art verb is rebuild-aware: switching to a different preset rebuilds, but\n// patching the currently-active preset routes through an injected live\n// layer-uniform channel (`setLayerUniforms`, keyed by layer id) so a slider drag\n// updates the running composite without a rebuild.\n\nimport type { KaleidoscopePreset, KaleidoscopePresetBook } from '../kaleidoscope.preset-book.types';\nimport type { EffectSpec, TransformName } from './effect.types';\nimport { compositeToEffectSpec } from './shader-to-spec';\nimport type { KaleidoscopeBinding, KaleidoscopeBindOptions, TransformInput } from './types';\n\n/** Apply the ordered specs to the base track and return the output. */\nexport type Reconcile = {\n apply: (specs: ReadonlyArray<EffectSpec>) => MediaStreamTrack;\n dispose: () => void;\n};\n\n/** Write the segmentation mask edge (platform tuning channel). */\nexport type SetMask = (hardness: number, threshold: number) => void;\n\n/**\n * Write a live per-layer uniform override (platform tuning channel), keyed by\n * layer id. The running composite merges these over the layer's baked uniforms\n * each frame, with no rebuild. Mirrors `setMask`.\n */\nexport type SetLayerUniforms = (\n id: string,\n uniforms: Readonly<Record<string, number | readonly number[]>>,\n) => void;\n\n/**\n * Drop every live per-layer override (platform tuning channel). A preset switch\n * calls this so a reused layer id reverts to the new preset's baked uniforms\n * rather than inheriting a stale override from the prior preset.\n */\nexport type ResetLayerUniforms = () => void;\n\n// Decompose an absolute transform into the discrete ops the pipeline already\n// runs (reused on web and native). Flips first, then rotation; rotation snaps to\n// the nearest 90°. 180° is two CW steps; 270° is one CCW step.\nconst decomposeTransform = (t?: TransformInput): EffectSpec[] => {\n if (!t) return [];\n const names: TransformName[] = [];\n if (t.flip?.x) names.push('flip-x');\n if (t.flip?.y) names.push('flip-y');\n const deg = (((Math.round((t.rotate ?? 0) / 90) * 90) % 360) + 360) % 360;\n if (deg === 90) names.push('rotate-cw');\n else if (deg === 180) names.push('rotate-cw', 'rotate-cw');\n else if (deg === 270) names.push('rotate-ccw');\n return names.map((name) => ({ name }));\n};\n\nexport const createControls = <P extends KaleidoscopePresetBook>(\n baseTrack: MediaStreamTrack,\n { presets, onTrack }: KaleidoscopeBindOptions<P>,\n reconcile: Reconcile,\n setMask: SetMask,\n setLayerUniforms: SetLayerUniforms,\n resetLayerUniforms: ResetLayerUniforms,\n): KaleidoscopeBinding<P> => {\n let art: EffectSpec | null = null;\n let transformOps: EffectSpec[] = [];\n let current = baseTrack;\n // The id of the active preset (null when cleared). A patch of THIS id routes\n // through the live channel; any other cmd rebuilds.\n let activeId: keyof P | null = null;\n\n const apply = (): void => {\n const specs: EffectSpec[] = [];\n if (art) specs.push(art);\n specs.push(...transformOps);\n current = reconcile.apply(specs);\n onTrack?.(current);\n };\n\n return {\n kaleidoscope: (\n cmd: keyof P | null,\n patches?: ReadonlyArray<{\n readonly id: string;\n readonly uniforms: Readonly<Record<string, number | readonly number[]>>;\n }>,\n ) => {\n // Patch the currently-active preset: route through the live no-rebuild\n // channel, keyed by layer id. The `shader` field on a patch is only for\n // narrowing; the channel resolves by `id`.\n if (cmd != null && cmd === activeId && patches && patches.length > 0) {\n for (const patch of patches) {\n setLayerUniforms(patch.id, patch.uniforms);\n }\n return;\n }\n // Switch the preset (or clear): rebuild. Drop every live override first so\n // a reused layer id (e.g. 'blur', shared by the low/medium/high blur\n // presets) takes the new preset's baked uniforms instead of carrying a\n // stale slider override across. Patches given WITH the switch (e.g. a\n // persisted selection's overrides) merge into the rebuilt stack itself,\n // so they land on every platform, native included. A transform rebuild\n // does NOT pass through here, so slider tweaks survive flips/rotations\n // of the active preset.\n activeId = cmd;\n art = cmd == null ? null : compositeToEffectSpec(presets[cmd] as KaleidoscopePreset, patches);\n resetLayerUniforms();\n apply();\n },\n transform: (t) => {\n transformOps = decomposeTransform(t);\n apply();\n },\n mask: (m) => {\n // Updates the edge the per-frame composite reads; no pipeline rebuild.\n setMask(m.hardness, m.threshold);\n },\n get track() {\n return current;\n },\n dispose: () => {\n reconcile.dispose();\n },\n };\n};\n"]}
@@ -1,4 +1,18 @@
1
1
  import type { KaleidoscopePreset } from '../kaleidoscope.preset-book.types';
2
2
  import type { EffectSpec } from './effect.types';
3
- export declare const compositeToEffectSpec: (composite: KaleidoscopePreset) => EffectSpec;
3
+ /** The patch wire shape (layer id + partial uniforms), as the verb receives it. */
4
+ type LayerPatchInput = {
5
+ readonly id: string;
6
+ readonly uniforms: Readonly<Record<string, number | readonly number[]>>;
7
+ };
8
+ /**
9
+ * Project a composite into the spec, optionally merging per-layer uniform
10
+ * patches over the baked values (a switch-with-patches, e.g. restoring a
11
+ * persisted selection). Merging here, at the seam, is what carries the patches
12
+ * to EVERY platform: web rebuilds from these layers, and native re-sends them
13
+ * over setCompositeLayers. A patch addressing a non-tunable or unknown layer id
14
+ * is ignored.
15
+ */
16
+ export declare const compositeToEffectSpec: (composite: KaleidoscopePreset, patches?: ReadonlyArray<LayerPatchInput>) => EffectSpec;
17
+ export {};
4
18
  //# sourceMappingURL=shader-to-spec.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shader-to-spec.d.ts","sourceRoot":"","sources":["../../../src/kaleidoscope/shader-to-spec.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,eAAO,MAAM,qBAAqB,cAAe,kBAAkB,KAAG,UAGpE,CAAC"}
1
+ {"version":3,"file":"shader-to-spec.d.ts","sourceRoot":"","sources":["../../../src/kaleidoscope/shader-to-spec.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAqB,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAC/F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,mFAAmF;AACnF,KAAK,eAAe,GAAG;IACrB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC,CAAC,CAAC;CACzE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,cACrB,kBAAkB,YACnB,aAAa,CAAC,eAAe,CAAC,KACvC,UAaF,CAAC"}
@@ -9,9 +9,28 @@
9
9
  // blend. Transforms are not book entries; the transform verb handles them.
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.compositeToEffectSpec = void 0;
12
- const compositeToEffectSpec = (composite) => ({
13
- name: 'composite',
14
- layers: composite.layers,
15
- });
12
+ /**
13
+ * Project a composite into the spec, optionally merging per-layer uniform
14
+ * patches over the baked values (a switch-with-patches, e.g. restoring a
15
+ * persisted selection). Merging here, at the seam, is what carries the patches
16
+ * to EVERY platform: web rebuilds from these layers, and native re-sends them
17
+ * over setCompositeLayers. A patch addressing a non-tunable or unknown layer id
18
+ * is ignored.
19
+ */
20
+ const compositeToEffectSpec = (composite, patches) => {
21
+ if (!patches || patches.length === 0) {
22
+ return { name: 'composite', layers: composite.layers };
23
+ }
24
+ const byId = new Map(patches.map((patch) => [patch.id, patch.uniforms]));
25
+ return {
26
+ name: 'composite',
27
+ layers: composite.layers.map((layer) => {
28
+ const override = byId.get(layer.id);
29
+ if (!override || !('uniforms' in layer))
30
+ return layer;
31
+ return { ...layer, uniforms: { ...layer.uniforms, ...override } };
32
+ }),
33
+ };
34
+ };
16
35
  exports.compositeToEffectSpec = compositeToEffectSpec;
17
36
  //# sourceMappingURL=shader-to-spec.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shader-to-spec.js","sourceRoot":"","sources":["../../../src/kaleidoscope/shader-to-spec.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iFAAiF;AACjF,8EAA8E;AAC9E,wCAAwC;AACxC,EAAE;AACF,8EAA8E;AAC9E,6EAA6E;AAC7E,2EAA2E;;;AAKpE,MAAM,qBAAqB,GAAG,CAAC,SAA6B,EAAc,EAAE,CAAC,CAAC;IACnF,IAAI,EAAE,WAAW;IACjB,MAAM,EAAE,SAAS,CAAC,MAAM;CACzB,CAAC,CAAC;AAHU,QAAA,qBAAqB,GAArB,qBAAqB,CAG/B","sourcesContent":["// Translate a book composite into the lower-level EffectSpec the primitive\n// `applyVideoEffects` consumes. This is the seam between the book vocabulary the\n// consumer sees and the effect the pipeline runs; the controls own the active\n// composite and reconcile through here.\n//\n// Every book entry is a composite (an ordered layer stack), so this is a thin\n// projection: the layers already carry their own ids, sources, uniforms, and\n// blend. Transforms are not book entries; the transform verb handles them.\n\nimport type { KaleidoscopePreset } from '../kaleidoscope.preset-book.types';\nimport type { EffectSpec } from './effect.types';\n\nexport const compositeToEffectSpec = (composite: KaleidoscopePreset): EffectSpec => ({\n name: 'composite',\n layers: composite.layers,\n});\n"]}
1
+ {"version":3,"file":"shader-to-spec.js","sourceRoot":"","sources":["../../../src/kaleidoscope/shader-to-spec.ts"],"names":[],"mappings":";AAAA,2EAA2E;AAC3E,iFAAiF;AACjF,8EAA8E;AAC9E,wCAAwC;AACxC,EAAE;AACF,8EAA8E;AAC9E,6EAA6E;AAC7E,2EAA2E;;;AAW3E;;;;;;;GAOG;AACI,MAAM,qBAAqB,GAAG,CACnC,SAA6B,EAC7B,OAAwC,EAC5B,EAAE;IACd,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrC,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,CAAC;IACzD,CAAC;IACD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACzE,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACrC,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACpC,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,UAAU,IAAI,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAC;YACtD,OAAO,EAAE,GAAG,KAAK,EAAE,QAAQ,EAAE,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE,GAAG,QAAQ,EAAE,EAAuB,CAAC;QACzF,CAAC,CAAC;KACH,CAAC;AACJ,CAAC,CAAC;AAhBW,QAAA,qBAAqB,GAArB,qBAAqB,CAgBhC","sourcesContent":["// Translate a book composite into the lower-level EffectSpec the primitive\n// `applyVideoEffects` consumes. This is the seam between the book vocabulary the\n// consumer sees and the effect the pipeline runs; the controls own the active\n// composite and reconcile through here.\n//\n// Every book entry is a composite (an ordered layer stack), so this is a thin\n// projection: the layers already carry their own ids, sources, uniforms, and\n// blend. Transforms are not book entries; the transform verb handles them.\n\nimport type { KaleidoscopeLayer, KaleidoscopePreset } from '../kaleidoscope.preset-book.types';\nimport type { EffectSpec } from './effect.types';\n\n/** The patch wire shape (layer id + partial uniforms), as the verb receives it. */\ntype LayerPatchInput = {\n readonly id: string;\n readonly uniforms: Readonly<Record<string, number | readonly number[]>>;\n};\n\n/**\n * Project a composite into the spec, optionally merging per-layer uniform\n * patches over the baked values (a switch-with-patches, e.g. restoring a\n * persisted selection). Merging here, at the seam, is what carries the patches\n * to EVERY platform: web rebuilds from these layers, and native re-sends them\n * over setCompositeLayers. A patch addressing a non-tunable or unknown layer id\n * is ignored.\n */\nexport const compositeToEffectSpec = (\n composite: KaleidoscopePreset,\n patches?: ReadonlyArray<LayerPatchInput>,\n): EffectSpec => {\n if (!patches || patches.length === 0) {\n return { name: 'composite', layers: composite.layers };\n }\n const byId = new Map(patches.map((patch) => [patch.id, patch.uniforms]));\n return {\n name: 'composite',\n layers: composite.layers.map((layer) => {\n const override = byId.get(layer.id);\n if (!override || !('uniforms' in layer)) return layer;\n return { ...layer, uniforms: { ...layer.uniforms, ...override } } as KaleidoscopeLayer;\n }),\n };\n};\n"]}
@@ -58,7 +58,9 @@ export type KaleidoscopeBindOptions<P extends KaleidoscopePresetBook> = {
58
58
  * The art verb: select a composite by id (rebuilding the pipeline), or clear it
59
59
  * with `null`. When `cmd` is the currently-active preset id and `patches` is
60
60
  * given, the patches merge through the live no-rebuild uniform channel (keyed by
61
- * layer id) instead of rebuilding, so a slider drag stays smooth.
61
+ * layer id) instead of rebuilding, so a slider drag stays smooth. On a preset
62
+ * SWITCH, patches merge into the rebuilt layer stack itself, so a restored
63
+ * selection lands tuned on every platform, native included.
62
64
  */
63
65
  type KaleidoscopeCommand<P extends KaleidoscopePresetBook> = <K extends keyof P>(cmd: K | null, patches?: PatchesFor<P, K>) => void;
64
66
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/kaleidoscope/types.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAEhF;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS;IAClC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC,SAAS,MAAM,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,SAAS,mBAAmB,CAAC;CACtD,GACG;IAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAA;CAAE,GACpE,KAAK,CAAC;AAEV;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,sBAAsB,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,aAAa,CACzF,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CACjC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,oCAAoC;IACpC,QAAQ,CAAC,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAC/D,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,+EAA+E;AAC/E,MAAM,MAAM,SAAS,GAAG;IACtB,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,E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CAAC,CAAC,SAAS,MAAM,CAAC,EAC7E,GAAG,EAAE,CAAC,GAAG,IAAI,EACb,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KACvB,IAAI,CAAC;AAEV;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,sBAAsB;IACnE,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC;IAC9C,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IACjD,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,SAAS,KAAK,IAAI,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAC;CAC9B"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/kaleidoscope/types.ts"],"names":[],"mappings":";AAAA,iCAAiC;AACjC,EAAE;AACF,mEAAmE;AACnE,+EAA+E;AAC/E,+EAA+E;AAC/E,gFAAgF;AAChF,8EAA8E;AAC9E,kDAAkD;AAClD,kFAAkF;AAClF,kFAAkF;AAClF,EAAE;AACF,6EAA6E;AAC7E,uEAAuE;AACvE,+EAA+E;AAC/E,8EAA8E","sourcesContent":["// The three-verb surface: types.\n//\n// Bind a track and a preset book once; get three typed verbs back:\n// - kaleidoscope(cmd, patches?) the art axis: which composite (layer stack)\n// fills the frame. cmd is a preset id from the book (narrowed), or null to\n// clear. patches optionally merge per-layer uniform overrides (addressed by\n// layer id); patching the currently-active preset routes through the live\n// no-rebuild channel, so sliders stay smooth.\n// - transform(t?) the geometry axis: absolute flips + 90° rotation.\n// - mask(m) the segmentation edge shared by every art effect.\n//\n// Shaders live in the library; consumers add presets (composites) over them,\n// never new shaders. Per shader-world convention, numeric uniforms are\n// normalized 0..1 where practical; ranges are documented in JSDoc as hints for\n// IntelliSense and tooling, not enforced at runtime (validation is userland).\n\nimport type { PatchableShaderName, ShaderUniformsMap } from '../../catalog/shaders';\nimport type { KaleidoscopePresetBook } from '../kaleidoscope.preset-book.types';\n\n/**\n * A live per-layer uniform override for ONE layer, derived from the layer's own\n * type: `id` is the layer's id, `uniforms` is `Partial` of the shader's uniform\n * type (re-indexed from `ShaderUniformsMap` by the layer's literal `shader`).\n * Non-tunable layers (`image`, `direct`) distribute to `never`, so they cannot be\n * patched. The runtime resolves by `id`; the shader is never sent on the wire.\n */\nexport type PatchFor<L> = L extends {\n readonly id: infer I extends string;\n readonly shader: infer S extends PatchableShaderName;\n}\n ? { readonly id: I; readonly uniforms: Partial<ShaderUniformsMap[S]> }\n : never;\n\n/**\n * The patches `kaleidoscope` accepts for preset `K` in book `P`: per-layer\n * overrides, each addressed by one of that preset's tunable layer ids and typed\n * by that layer's shader. At a literal `cmd` call site this narrows to the\n * preset's ids/uniforms; with a variable `cmd` it widens to the book-wide union\n * and is runtime-checked by id.\n */\nexport type PatchesFor<P extends KaleidoscopePresetBook, K extends keyof P> = ReadonlyArray<\n PatchFor<P[K]['layers'][number]>\n>;\n\n/**\n * Absolute, stateless geometric transform. Every call is the full desired state\n * from the identity orientation: re-passing is the caller's responsibility, and\n * `transform()` (or `transform({})`) resets to identity. Rotation snaps to the\n * nearest 90°; arbitrary angles and offset are a later step.\n */\nexport type TransformInput = {\n /** Mirror flips about each axis. */\n readonly flip?: { readonly x?: boolean; readonly y?: boolean };\n /** Clockwise rotation in degrees; snapped to the nearest 90 (0/90/180/270). */\n readonly rotate?: number;\n};\n\n/** The segmentation mask edge, shared by every art effect (not transforms). */\nexport type MaskInput = {\n /** Edge hardness, 0..1. 0 = soft halo, 1 = near-step. */\n readonly hardness: number;\n /** Edge threshold, 0..1. Higher rejects low-confidence (chair-edge) pixels. */\n readonly threshold: number;\n};\n\nexport type KaleidoscopeBindOptions<P extends KaleidoscopePresetBook> = {\n /** The consumer's preset book. Declare it `as const satisfies KaleidoscopePresetBook`. */\n readonly presets: P;\n /**\n * Called with the live output track after every art/transform command. On web\n * each command yields a NEW MediaStreamTrack (the pipeline is rebuilt); on\n * native the same track is mutated in place and passed back.\n */\n readonly onTrack?: (track: MediaStreamTrack) => void;\n};\n\n/**\n * The art verb: select a composite by id (rebuilding the pipeline), or clear it\n * with `null`. When `cmd` is the currently-active preset id and `patches` is\n * given, the patches merge through the live no-rebuild uniform channel (keyed by\n * layer id) instead of rebuilding, so a slider drag stays smooth.\n */\ntype KaleidoscopeCommand<P extends KaleidoscopePresetBook> = <K extends keyof P>(\n cmd: K | null,\n patches?: PatchesFor<P, K>,\n) => void;\n\n/**\n * The three verbs for one bound track and book, plus the live track and a\n * teardown. `kaleidoscope` (preset switch) and `transform` rebuild the composite\n * (web yields a new track via onTrack); a `kaleidoscope` patch of the active\n * preset and `mask` both update what the running composite reads each frame, so\n * they need no rebuild.\n */\nexport interface KaleidoscopeBinding<P extends KaleidoscopePresetBook> {\n readonly kaleidoscope: KaleidoscopeCommand<P>;\n readonly transform: (t?: TransformInput) => void;\n readonly mask: (m: MaskInput) => void;\n readonly track: MediaStreamTrack;\n readonly dispose: () => void;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/kaleidoscope/types.ts"],"names":[],"mappings":";AAAA,iCAAiC;AACjC,EAAE;AACF,mEAAmE;AACnE,+EAA+E;AAC/E,+EAA+E;AAC/E,gFAAgF;AAChF,8EAA8E;AAC9E,kDAAkD;AAClD,kFAAkF;AAClF,kFAAkF;AAClF,EAAE;AACF,6EAA6E;AAC7E,uEAAuE;AACvE,+EAA+E;AAC/E,8EAA8E","sourcesContent":["// The three-verb surface: types.\n//\n// Bind a track and a preset book once; get three typed verbs back:\n// - kaleidoscope(cmd, patches?) the art axis: which composite (layer stack)\n// fills the frame. cmd is a preset id from the book (narrowed), or null to\n// clear. patches optionally merge per-layer uniform overrides (addressed by\n// layer id); patching the currently-active preset routes through the live\n// no-rebuild channel, so sliders stay smooth.\n// - transform(t?) the geometry axis: absolute flips + 90° rotation.\n// - mask(m) the segmentation edge shared by every art effect.\n//\n// Shaders live in the library; consumers add presets (composites) over them,\n// never new shaders. Per shader-world convention, numeric uniforms are\n// normalized 0..1 where practical; ranges are documented in JSDoc as hints for\n// IntelliSense and tooling, not enforced at runtime (validation is userland).\n\nimport type { PatchableShaderName, ShaderUniformsMap } from '../../catalog/shaders';\nimport type { KaleidoscopePresetBook } from '../kaleidoscope.preset-book.types';\n\n/**\n * A live per-layer uniform override for ONE layer, derived from the layer's own\n * type: `id` is the layer's id, `uniforms` is `Partial` of the shader's uniform\n * type (re-indexed from `ShaderUniformsMap` by the layer's literal `shader`).\n * Non-tunable layers (`image`, `direct`) distribute to `never`, so they cannot be\n * patched. The runtime resolves by `id`; the shader is never sent on the wire.\n */\nexport type PatchFor<L> = L extends {\n readonly id: infer I extends string;\n readonly shader: infer S extends PatchableShaderName;\n}\n ? { readonly id: I; readonly uniforms: Partial<ShaderUniformsMap[S]> }\n : never;\n\n/**\n * The patches `kaleidoscope` accepts for preset `K` in book `P`: per-layer\n * overrides, each addressed by one of that preset's tunable layer ids and typed\n * by that layer's shader. At a literal `cmd` call site this narrows to the\n * preset's ids/uniforms; with a variable `cmd` it widens to the book-wide union\n * and is runtime-checked by id.\n */\nexport type PatchesFor<P extends KaleidoscopePresetBook, K extends keyof P> = ReadonlyArray<\n PatchFor<P[K]['layers'][number]>\n>;\n\n/**\n * Absolute, stateless geometric transform. Every call is the full desired state\n * from the identity orientation: re-passing is the caller's responsibility, and\n * `transform()` (or `transform({})`) resets to identity. Rotation snaps to the\n * nearest 90°; arbitrary angles and offset are a later step.\n */\nexport type TransformInput = {\n /** Mirror flips about each axis. */\n readonly flip?: { readonly x?: boolean; readonly y?: boolean };\n /** Clockwise rotation in degrees; snapped to the nearest 90 (0/90/180/270). */\n readonly rotate?: number;\n};\n\n/** The segmentation mask edge, shared by every art effect (not transforms). */\nexport type MaskInput = {\n /** Edge hardness, 0..1. 0 = soft halo, 1 = near-step. */\n readonly hardness: number;\n /** Edge threshold, 0..1. Higher rejects low-confidence (chair-edge) pixels. */\n readonly threshold: number;\n};\n\nexport type KaleidoscopeBindOptions<P extends KaleidoscopePresetBook> = {\n /** The consumer's preset book. Declare it `as const satisfies KaleidoscopePresetBook`. */\n readonly presets: P;\n /**\n * Called with the live output track after every art/transform command. On web\n * each command yields a NEW MediaStreamTrack (the pipeline is rebuilt); on\n * native the same track is mutated in place and passed back.\n */\n readonly onTrack?: (track: MediaStreamTrack) => void;\n};\n\n/**\n * The art verb: select a composite by id (rebuilding the pipeline), or clear it\n * with `null`. When `cmd` is the currently-active preset id and `patches` is\n * given, the patches merge through the live no-rebuild uniform channel (keyed by\n * layer id) instead of rebuilding, so a slider drag stays smooth. On a preset\n * SWITCH, patches merge into the rebuilt layer stack itself, so a restored\n * selection lands tuned on every platform, native included.\n */\ntype KaleidoscopeCommand<P extends KaleidoscopePresetBook> = <K extends keyof P>(\n cmd: K | null,\n patches?: PatchesFor<P, K>,\n) => void;\n\n/**\n * The three verbs for one bound track and book, plus the live track and a\n * teardown. `kaleidoscope` (preset switch) and `transform` rebuild the composite\n * (web yields a new track via onTrack); a `kaleidoscope` patch of the active\n * preset and `mask` both update what the running composite reads each frame, so\n * they need no rebuild.\n */\nexport interface KaleidoscopeBinding<P extends KaleidoscopePresetBook> {\n readonly kaleidoscope: KaleidoscopeCommand<P>;\n readonly transform: (t?: TransformInput) => void;\n readonly mask: (m: MaskInput) => void;\n readonly track: MediaStreamTrack;\n readonly dispose: () => void;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ import { type KaleidoscopeStateStore } from './state';
2
+ export declare const kaleidoscopeAsyncStorageStore: KaleidoscopeStateStore;
3
+ //# sourceMappingURL=async-storage-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"async-storage-store.d.ts","sourceRoot":"","sources":["../../../src/persistence/async-storage-store.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,KAAK,sBAAsB,EAI5B,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,6BAA6B,EAAE,sBAe3C,CAAC"}