agentcut 0.2.25 → 0.2.27

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 (127) hide show
  1. package/README.md +177 -148
  2. package/dist/config.d.ts +0 -1
  3. package/dist/config.js +0 -5
  4. package/dist/config.js.map +1 -1
  5. package/dist/studio/agents/claude.js +3 -2
  6. package/dist/studio/agents/claude.js.map +1 -1
  7. package/dist/studio/chat.js +1 -1
  8. package/dist/studio/chat.js.map +1 -1
  9. package/dist/studio/cli.js +40 -21
  10. package/dist/studio/cli.js.map +1 -1
  11. package/dist/studio/download.d.ts +24 -0
  12. package/dist/studio/download.js +234 -0
  13. package/dist/studio/download.js.map +1 -0
  14. package/dist/studio/host.d.ts +1 -2
  15. package/dist/studio/host.js +36 -8
  16. package/dist/studio/host.js.map +1 -1
  17. package/dist/studio/housekeeping.d.ts +2 -2
  18. package/dist/studio/housekeeping.js +18 -17
  19. package/dist/studio/housekeeping.js.map +1 -1
  20. package/dist/studio/mcp-guides.js +1 -18
  21. package/dist/studio/mcp-guides.js.map +1 -1
  22. package/dist/studio/proc.js +16 -6
  23. package/dist/studio/proc.js.map +1 -1
  24. package/dist/studio/proxies.d.ts +4 -0
  25. package/dist/studio/proxies.js +15 -6
  26. package/dist/studio/proxies.js.map +1 -1
  27. package/dist/studio/release-cursor.js +21 -21
  28. package/dist/studio/release-video.js +10 -10
  29. package/dist/studio/schema.d.ts +0 -1
  30. package/dist/studio/schema.js +0 -1
  31. package/dist/studio/schema.js.map +1 -1
  32. package/dist/studio/tools.d.ts +0 -4
  33. package/dist/studio/tools.js +32 -31
  34. package/dist/studio/tools.js.map +1 -1
  35. package/dist/studio/voice/kokoro-catalog.d.ts +56 -28
  36. package/dist/studio/voice/kokoro-catalog.js +56 -28
  37. package/dist/studio/voice/kokoro-catalog.js.map +1 -1
  38. package/dist/studio/voice/ming-catalog.d.ts +19 -0
  39. package/dist/studio/voice/ming-catalog.js +40 -0
  40. package/dist/studio/voice/ming-catalog.js.map +1 -0
  41. package/dist/studio/voice/ming.d.ts +12 -0
  42. package/dist/studio/voice/ming.js +397 -0
  43. package/dist/studio/voice/ming.js.map +1 -0
  44. package/dist/studio/voice/previews.d.ts +5 -0
  45. package/dist/studio/voice/previews.js +50 -0
  46. package/dist/studio/voice/previews.js.map +1 -0
  47. package/dist/studio/voice/registry.js +2 -0
  48. package/dist/studio/voice/registry.js.map +1 -1
  49. package/dist/studio/voice.d.ts +1 -1
  50. package/dist/studio/voice.js +5 -6
  51. package/dist/studio/voice.js.map +1 -1
  52. package/package.json +56 -56
  53. package/template/AGENTS.md +14 -14
  54. package/template/components/README.md +70 -70
  55. package/template/components/before-after/BeforeAfter.tsx +89 -89
  56. package/template/components/catalog.ts +107 -107
  57. package/template/components/cinematic/Device3D.tsx +324 -324
  58. package/template/components/cinematic/devices3d/display-model.ts +184 -184
  59. package/template/components/cinematic/devices3d/iphone-model.ts +643 -643
  60. package/template/components/cinematic/devices3d/macbook-model.ts +608 -608
  61. package/template/components/cinematic/devices3d/models.ts +657 -657
  62. package/template/components/cinematic/devices3d/runtime.ts +267 -267
  63. package/template/components/cinematic/math.ts +100 -100
  64. package/template/components/color/grade-effect.ts +650 -650
  65. package/template/components/color/grade.ts +512 -512
  66. package/template/components/color/looks.ts +154 -154
  67. package/template/components/countdown/Countdown.tsx +166 -166
  68. package/template/components/dot-trace-title/DotTraceTitle.tsx +181 -181
  69. package/template/components/dot-trace-title/meta.json +51 -51
  70. package/template/components/generate/GenerateReveal.tsx +381 -381
  71. package/template/components/hook-card/HookCard.tsx +554 -554
  72. package/template/components/index.ts +199 -199
  73. package/template/components/lib.ts +191 -191
  74. package/template/components/line-diagram/LineDiagram.tsx +205 -205
  75. package/template/components/line-diagram/meta.json +215 -215
  76. package/template/components/list-card/ListCard.tsx +104 -104
  77. package/template/components/live-clip.ts +75 -75
  78. package/template/components/looks.tsx +1447 -1447
  79. package/template/components/loops/LoopCanvas.tsx +132 -132
  80. package/template/components/loops/engine.ts +184 -184
  81. package/template/components/loops/library.ts +667 -667
  82. package/template/components/loops/library2.ts +777 -777
  83. package/template/components/motion-loop/MotionLoop.tsx +37 -37
  84. package/template/components/motion-loop/meta.json +311 -311
  85. package/template/components/props.ts +73 -73
  86. package/template/components/quote-card/QuoteCard.tsx +71 -71
  87. package/template/components/style-layer.tsx +233 -233
  88. package/template/components/styles.ts +113 -113
  89. package/template/components/types.ts +66 -66
  90. package/template/components/word-pop/WordPop.tsx +59 -59
  91. package/template/components/word-stack/WordStack.tsx +122 -122
  92. package/template/presets/charcoal-sketch/PROMPT.md +48 -48
  93. package/template/presets/charcoal-sketch/scripts/duck_music.py +34 -34
  94. package/template/presets/punk-cut-paper/scenes/Motif.tsx +376 -376
  95. package/template/presets/punk-cut-paper/scenes/Photo.tsx +73 -73
  96. package/template/presets/punk-cut-paper/scenes/Ransom.tsx +119 -119
  97. package/template/runtime/composition.tsx +1189 -1185
  98. package/template/runtime/helpers.tsx +230 -230
  99. package/template/runtime/index.tsx +22 -22
  100. package/template/runtime/types.ts +315 -315
  101. package/template/skill/SKILL.md +186 -351
  102. package/template/skill/references/broll.md +44 -44
  103. package/template/skill/references/browser-export.md +61 -61
  104. package/template/skill/references/cinematic.md +206 -206
  105. package/template/skill/references/color.md +79 -79
  106. package/template/skill/references/craft.md +54 -10
  107. package/template/skill/references/editing-styles.md +57 -57
  108. package/template/skill/references/feature-launch.md +5 -1
  109. package/template/skill/references/footage.md +72 -72
  110. package/template/skill/references/format.md +142 -142
  111. package/template/skill/references/how-to.md +0 -15
  112. package/template/skill/references/launch-direction.md +89 -0
  113. package/template/skill/references/loops.md +151 -151
  114. package/template/skill/references/mcp-external.md +19 -0
  115. package/template/skill/references/performance.md +93 -93
  116. package/template/skill/references/person-cutout.md +19 -19
  117. package/template/skill/references/presets.md +60 -60
  118. package/template/skill/references/product-launch.md +4 -1
  119. package/template/skill/references/release-capture.md +53 -0
  120. package/template/skill/references/sound.md +167 -155
  121. package/template/skill/references/style-spy.md +160 -160
  122. package/template/skill/references/website-howto.md +45 -45
  123. package/template/starter/.studio/chat.json +1 -1
  124. package/template/starter/layers.json +46 -46
  125. package/template/starter/notes.md +4 -4
  126. package/template/starter/project.json +13 -13
  127. package/template/starter/scenes/Title.tsx +38 -38
@@ -1,132 +1,132 @@
1
- // Draws a seamless loop (or your own draw function) on a canvas for the current frame.
2
- import { useLayoutEffect, useRef, type CSSProperties } from "react";
3
- import { useCurrentFrame, useRemotionEnvironment, useVideoConfig } from "remotion";
4
- import { LOOP, loopPalette, M, type LoopDraw, type LoopPalette, type LoopTone } from "./engine";
5
- import { getLoop } from "./library";
6
-
7
- export interface LoopCanvasProps {
8
- /** A library loop id (see LOOPS) or your own draw function with the same contract. */
9
- loop: string | LoopDraw;
10
- /** Brand colours; the palette's three tones derive from them. */
11
- accent?: string;
12
- accent2?: string;
13
- tone?: LoopTone;
14
- /** Or a full palette (overrides accent, accent2 and tone). */
15
- palette?: LoopPalette;
16
- /** Playback speed (1 = the loop's 12 s cycle). Seamless at any speed; to repeat a clip, make duration × speed a multiple of 12 s. */
17
- speed?: number;
18
- /** Shifts where in the cycle it starts (seconds). */
19
- offset?: number;
20
- /** Varies the layout of the loop's elements. */
21
- seed?: number;
22
- /** Don't fill the background (shapes over footage or a Stage). */
23
- transparent?: boolean;
24
- /** Motion blur sub-frames in captures and exports (1 = none, 4 default, 8 for fast loops); the live preview draws 1. */
25
- blur?: number;
26
- /**
27
- * Size in world px. Without them the loop is frame-sized and stretches to fill its parent (a
28
- * full-frame parent, or one with the frame's aspect). With them it is drawn at exactly that size
29
- * (CSS too), so it never distorts: pass the size of the box it sits in (a card, a Plane).
30
- */
31
- width?: number;
32
- height?: number;
33
- style?: CSSProperties;
34
- }
35
-
36
- /** A seamless motion loop drawn from the brand palette, frame-accurate in preview and export. */
37
- export function LoopCanvas({
38
- loop,
39
- accent = "#7c5cff",
40
- accent2 = "#ff5ca8",
41
- tone = "dark",
42
- palette,
43
- speed = 1,
44
- offset = 0,
45
- seed = 0,
46
- transparent = false,
47
- blur = 4,
48
- width,
49
- height,
50
- style,
51
- }: LoopCanvasProps) {
52
- const frame = useCurrentFrame();
53
- const config = useVideoConfig();
54
- const env = useRemotionEnvironment();
55
- const ref = useRef<HTMLCanvasElement>(null);
56
- const scratch = useRef<HTMLCanvasElement | null>(null);
57
- const acc = useRef<Float32Array | null>(null);
58
- const w = Math.round(width ?? config.width);
59
- const h = Math.round(height ?? config.height);
60
- const draw = typeof loop === "function" ? loop : getLoop(loop).draw;
61
- const P = palette ?? loopPalette(accent, accent2, tone);
62
- // The live preview skips motion blur; captures and exports draw every sub-frame.
63
- const samples = env.isPlayer && !env.isRendering ? 1 : Math.max(1, Math.min(12, Math.round(blur)));
64
-
65
- useLayoutEffect(() => {
66
- const canvas = ref.current;
67
- const ctx = canvas?.getContext("2d");
68
- if (!canvas || !ctx) return;
69
- const paint = (target: CanvasRenderingContext2D, t: number) => {
70
- target.save();
71
- target.clearRect(0, 0, w, h);
72
- if (!transparent) {
73
- target.fillStyle = P.bg;
74
- target.fillRect(0, 0, w, h);
75
- }
76
- draw(target, w, h, ((t % LOOP) + LOOP) % LOOP, P, M, seed);
77
- target.restore();
78
- };
79
- const t0 = (frame / config.fps) * speed + offset;
80
- if (samples === 1) {
81
- paint(ctx, t0);
82
- return;
83
- }
84
- // Average sub-frames across a 180° shutter (half a frame), in premultiplied float so transparent
85
- // pixels average correctly and 8-bit rounding happens once.
86
- scratch.current ??= document.createElement("canvas");
87
- const sc = scratch.current;
88
- if (sc.width !== w || sc.height !== h) {
89
- sc.width = w;
90
- sc.height = h;
91
- }
92
- const sctx = sc.getContext("2d", { willReadFrequently: true });
93
- if (!sctx) return;
94
- if (acc.current?.length !== w * h * 4) acc.current = new Float32Array(w * h * 4);
95
- const sum = acc.current;
96
- sum.fill(0);
97
- for (let i = 0; i < samples; i++) {
98
- const dt = ((i + 0.5) / samples - 0.5) * 0.5 * (speed / config.fps);
99
- paint(sctx, t0 + dt);
100
- const d = sctx.getImageData(0, 0, w, h).data;
101
- for (let p = 0; p < d.length; p += 4) {
102
- const a = d[p + 3];
103
- if (!a) continue;
104
- sum[p] += d[p] * a;
105
- sum[p + 1] += d[p + 1] * a;
106
- sum[p + 2] += d[p + 2] * a;
107
- sum[p + 3] += a;
108
- }
109
- }
110
- const out = ctx.createImageData(w, h);
111
- const o = out.data;
112
- for (let p = 0; p < o.length; p += 4) {
113
- const a = sum[p + 3];
114
- if (!a) continue;
115
- o[p] = sum[p] / a;
116
- o[p + 1] = sum[p + 1] / a;
117
- o[p + 2] = sum[p + 2] / a;
118
- o[p + 3] = a / samples;
119
- }
120
- ctx.putImageData(out, 0, 0);
121
- });
122
-
123
- const sized = width !== undefined || height !== undefined;
124
- return (
125
- <canvas
126
- ref={ref}
127
- width={w}
128
- height={h}
129
- style={{ position: "absolute", left: 0, top: 0, width: sized ? w : "100%", height: sized ? h : "100%", ...style }}
130
- />
131
- );
132
- }
1
+ // Draws a seamless loop (or your own draw function) on a canvas for the current frame.
2
+ import { useLayoutEffect, useRef, type CSSProperties } from "react";
3
+ import { useCurrentFrame, useRemotionEnvironment, useVideoConfig } from "remotion";
4
+ import { LOOP, loopPalette, M, type LoopDraw, type LoopPalette, type LoopTone } from "./engine";
5
+ import { getLoop } from "./library";
6
+
7
+ export interface LoopCanvasProps {
8
+ /** A library loop id (see LOOPS) or your own draw function with the same contract. */
9
+ loop: string | LoopDraw;
10
+ /** Brand colours; the palette's three tones derive from them. */
11
+ accent?: string;
12
+ accent2?: string;
13
+ tone?: LoopTone;
14
+ /** Or a full palette (overrides accent, accent2 and tone). */
15
+ palette?: LoopPalette;
16
+ /** Playback speed (1 = the loop's 12 s cycle). Seamless at any speed; to repeat a clip, make duration × speed a multiple of 12 s. */
17
+ speed?: number;
18
+ /** Shifts where in the cycle it starts (seconds). */
19
+ offset?: number;
20
+ /** Varies the layout of the loop's elements. */
21
+ seed?: number;
22
+ /** Don't fill the background (shapes over footage or a Stage). */
23
+ transparent?: boolean;
24
+ /** Motion blur sub-frames in captures and exports (1 = none, 4 default, 8 for fast loops); the live preview draws 1. */
25
+ blur?: number;
26
+ /**
27
+ * Size in world px. Without them the loop is frame-sized and stretches to fill its parent (a
28
+ * full-frame parent, or one with the frame's aspect). With them it is drawn at exactly that size
29
+ * (CSS too), so it never distorts: pass the size of the box it sits in (a card, a Plane).
30
+ */
31
+ width?: number;
32
+ height?: number;
33
+ style?: CSSProperties;
34
+ }
35
+
36
+ /** A seamless motion loop drawn from the brand palette, frame-accurate in preview and export. */
37
+ export function LoopCanvas({
38
+ loop,
39
+ accent = "#7c5cff",
40
+ accent2 = "#ff5ca8",
41
+ tone = "dark",
42
+ palette,
43
+ speed = 1,
44
+ offset = 0,
45
+ seed = 0,
46
+ transparent = false,
47
+ blur = 4,
48
+ width,
49
+ height,
50
+ style,
51
+ }: LoopCanvasProps) {
52
+ const frame = useCurrentFrame();
53
+ const config = useVideoConfig();
54
+ const env = useRemotionEnvironment();
55
+ const ref = useRef<HTMLCanvasElement>(null);
56
+ const scratch = useRef<HTMLCanvasElement | null>(null);
57
+ const acc = useRef<Float32Array | null>(null);
58
+ const w = Math.round(width ?? config.width);
59
+ const h = Math.round(height ?? config.height);
60
+ const draw = typeof loop === "function" ? loop : getLoop(loop).draw;
61
+ const P = palette ?? loopPalette(accent, accent2, tone);
62
+ // The live preview skips motion blur; captures and exports draw every sub-frame.
63
+ const samples = env.isPlayer && !env.isRendering ? 1 : Math.max(1, Math.min(12, Math.round(blur)));
64
+
65
+ useLayoutEffect(() => {
66
+ const canvas = ref.current;
67
+ const ctx = canvas?.getContext("2d");
68
+ if (!canvas || !ctx) return;
69
+ const paint = (target: CanvasRenderingContext2D, t: number) => {
70
+ target.save();
71
+ target.clearRect(0, 0, w, h);
72
+ if (!transparent) {
73
+ target.fillStyle = P.bg;
74
+ target.fillRect(0, 0, w, h);
75
+ }
76
+ draw(target, w, h, ((t % LOOP) + LOOP) % LOOP, P, M, seed);
77
+ target.restore();
78
+ };
79
+ const t0 = (frame / config.fps) * speed + offset;
80
+ if (samples === 1) {
81
+ paint(ctx, t0);
82
+ return;
83
+ }
84
+ // Average sub-frames across a 180° shutter (half a frame), in premultiplied float so transparent
85
+ // pixels average correctly and 8-bit rounding happens once.
86
+ scratch.current ??= document.createElement("canvas");
87
+ const sc = scratch.current;
88
+ if (sc.width !== w || sc.height !== h) {
89
+ sc.width = w;
90
+ sc.height = h;
91
+ }
92
+ const sctx = sc.getContext("2d", { willReadFrequently: true });
93
+ if (!sctx) return;
94
+ if (acc.current?.length !== w * h * 4) acc.current = new Float32Array(w * h * 4);
95
+ const sum = acc.current;
96
+ sum.fill(0);
97
+ for (let i = 0; i < samples; i++) {
98
+ const dt = ((i + 0.5) / samples - 0.5) * 0.5 * (speed / config.fps);
99
+ paint(sctx, t0 + dt);
100
+ const d = sctx.getImageData(0, 0, w, h).data;
101
+ for (let p = 0; p < d.length; p += 4) {
102
+ const a = d[p + 3];
103
+ if (!a) continue;
104
+ sum[p] += d[p] * a;
105
+ sum[p + 1] += d[p + 1] * a;
106
+ sum[p + 2] += d[p + 2] * a;
107
+ sum[p + 3] += a;
108
+ }
109
+ }
110
+ const out = ctx.createImageData(w, h);
111
+ const o = out.data;
112
+ for (let p = 0; p < o.length; p += 4) {
113
+ const a = sum[p + 3];
114
+ if (!a) continue;
115
+ o[p] = sum[p] / a;
116
+ o[p + 1] = sum[p + 1] / a;
117
+ o[p + 2] = sum[p + 2] / a;
118
+ o[p + 3] = a / samples;
119
+ }
120
+ ctx.putImageData(out, 0, 0);
121
+ });
122
+
123
+ const sized = width !== undefined || height !== undefined;
124
+ return (
125
+ <canvas
126
+ ref={ref}
127
+ width={w}
128
+ height={h}
129
+ style={{ position: "absolute", left: 0, top: 0, width: sized ? w : "100%", height: sized ? h : "100%", ...style }}
130
+ />
131
+ );
132
+ }
@@ -1,184 +1,184 @@
1
- // Seamless motion loops: each loop is a pure function of time drawn on a 2D canvas. Every motion in a
2
- // loop repeats with a period that divides LOOP (12 s), so the frame at 12 s is the frame at 0 s and a
3
- // loop can run under a clip of any length, or repeat, without a seam. No React here.
4
-
5
- /** The loop length in seconds. Periods must divide it: 1, 1.5, 2, 3, 4, 6, 12. */
6
- export const LOOP = 12;
7
- export const TAU = Math.PI * 2;
8
-
9
- export const clamp = (v: number, a = 0, b = 1) => Math.min(b, Math.max(a, v));
10
- /** Fractional part in [0, 1): a tiny negative (float error) gives 0, never 1, so it is safe to index with. */
11
- export const fract = (v: number) => {
12
- const f = v - Math.floor(v);
13
- return f < 1 ? f : 0;
14
- };
15
- /** Modulo that stays positive. */
16
- export const mod = (a: number, n: number) => ((a % n) + n) % n;
17
- export const lerp = (a: number, b: number, k: number) => a + (b - a) * k;
18
-
19
- /** 0…1 position inside a cycle of `period` seconds (offset in cycles). */
20
- export const phase = (t: number, period: number, offset = 0) => fract(t / period + offset);
21
-
22
- /** A fixed pseudo-random number in [0, 1) per element index and salt (never Math.random). */
23
- export function rand(i: number, salt = 0) {
24
- return fract(Math.sin(i * 127.1 + salt * 311.7 + 74.7) * 43758.5453123);
25
- }
26
-
27
- /** 0 before a, eases 0→1 between a and b (as a linear 0…1), 1 after b. */
28
- export const win = (p: number, a: number, b: number) => clamp((p - a) / Math.max(1e-6, b - a));
29
-
30
- export const smoothstep = (a: number, b: number, v: number) => {
31
- const x = clamp((v - a) / (b - a));
32
- return x * x * (3 - 2 * x);
33
- };
34
-
35
- export const ease = {
36
- linear: (k: number) => k,
37
- inSine: (k: number) => 1 - Math.cos((k * Math.PI) / 2),
38
- outSine: (k: number) => Math.sin((k * Math.PI) / 2),
39
- inOutSine: (k: number) => -(Math.cos(Math.PI * k) - 1) / 2,
40
- inCubic: (k: number) => k * k * k,
41
- outCubic: (k: number) => 1 - Math.pow(1 - k, 3),
42
- inOutCubic: (k: number) => (k < 0.5 ? 4 * k * k * k : 1 - Math.pow(-2 * k + 2, 3) / 2),
43
- outExpo: (k: number) => (k >= 1 ? 1 : 1 - Math.pow(2, -10 * k)),
44
- inOutExpo: (k: number) =>
45
- k <= 0 ? 0 : k >= 1 ? 1 : k < 0.5 ? Math.pow(2, 20 * k - 10) / 2 : (2 - Math.pow(2, -20 * k + 10)) / 2,
46
- outBack: (k: number, s = 1.70158) => 1 + (s + 1) * Math.pow(k - 1, 3) + s * Math.pow(k - 1, 2),
47
- inBack: (k: number, s = 1.70158) => (s + 1) * k * k * k - s * k * k,
48
- /** Settles from 0 to 1 with a wobble; exactly 1 at k = 1. */
49
- spring: (k: number, zeta = 0.35, freq = 3) => {
50
- if (k >= 1) return 1;
51
- const w = TAU * freq;
52
- const v = 1 - Math.exp(-zeta * w * k) * Math.cos(w * Math.sqrt(1 - zeta * zeta) * k);
53
- return lerp(v, 1, smoothstep(0.75, 1, k));
54
- },
55
- };
56
-
57
- /** Smooth noise that repeats every `period` seconds (sines on a circle): drift, sway, breathing. */
58
- export function loopNoise(t: number, seed = 0, period = LOOP) {
59
- const a = TAU * phase(t, period);
60
- return (
61
- Math.sin(a + rand(seed, 1) * TAU) * 0.5 +
62
- Math.sin(2 * a + rand(seed, 2) * TAU) * 0.3 +
63
- Math.sin(3 * a + rand(seed, 3) * TAU) * 0.2
64
- );
65
- }
66
-
67
- /** Perspective projection, divided by depth once. */
68
- export function proj(x: number, y: number, z: number, f: number, cx: number, cy: number) {
69
- const s = f / Math.max(1e-3, z);
70
- return { x: cx + x * s, y: cy + y * s, s };
71
- }
72
-
73
- // ─── Colour ──────────────────────────────────────────────────────────────────────────────────────
74
-
75
- function parse(c: string): [number, number, number] {
76
- const hex = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(c.trim());
77
- if (hex) {
78
- const h = hex[1].length === 3 ? hex[1].replace(/./g, (x) => x + x) : hex[1];
79
- const n = parseInt(h, 16);
80
- return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
81
- }
82
- const rgb = /rgba?\(([^)]+)\)/i.exec(c);
83
- if (rgb) {
84
- const [r, g, b] = rgb[1].split(",").map((v) => parseFloat(v));
85
- return [r || 0, g || 0, b || 0];
86
- }
87
- return [0, 0, 0];
88
- }
89
-
90
- /** A colour (hex or rgb()) at an alpha. */
91
- export function rgba(c: string, a: number) {
92
- const [r, g, b] = parse(c);
93
- return `rgba(${r},${g},${b},${clamp(a)})`;
94
- }
95
-
96
- /** Mix two colours (hex or rgb()). */
97
- export function mixColor(a: string, b: string, k: number) {
98
- const x = parse(a);
99
- const y = parse(b);
100
- return `rgb(${Math.round(lerp(x[0], y[0], k))},${Math.round(lerp(x[1], y[1], k))},${Math.round(lerp(x[2], y[2], k))})`;
101
- }
102
-
103
- const luma = (c: string) => {
104
- const [r, g, b] = parse(c);
105
- return (0.299 * r + 0.587 * g + 0.114 * b) / 255;
106
- };
107
-
108
- export type LoopTone = "dark" | "accent" | "light";
109
-
110
- /** The palette a loop draws with. Never use other colours inside a loop. */
111
- export interface LoopPalette {
112
- /** Filled before draw() unless the loop is transparent. */
113
- bg: string;
114
- /** Main motif. */
115
- fg: string;
116
- /** Second colour, sparingly. */
117
- fg2: string;
118
- /** Between bg and fg: grids, quiet details. */
119
- mid: string;
120
- accent: string;
121
- accent2: string;
122
- paper: string;
123
- ink: string;
124
- tone: LoopTone;
125
- }
126
-
127
- /**
128
- * Three tones from the brand colours: dark (deep brand-tinted background, accent motif), accent
129
- * (accent background, ink motif), light (paper background, ink motif, accent as the second colour).
130
- */
131
- export function loopPalette(accent: string, accent2: string, tone: LoopTone, paper = "#f5f3ee", ink = "#111216"): LoopPalette {
132
- if (tone === "accent") {
133
- const onAccent = luma(accent) > 0.6 ? ink : paper;
134
- return { bg: accent, fg: onAccent, fg2: accent2, mid: mixColor(accent, onAccent, 0.3), accent, accent2, paper, ink, tone };
135
- }
136
- if (tone === "light") {
137
- return { bg: paper, fg: ink, fg2: accent, mid: mixColor(paper, ink, 0.18), accent, accent2, paper, ink, tone };
138
- }
139
- const bg = mixColor(accent, "#07070b", 0.9);
140
- return { bg, fg: accent, fg2: accent2, mid: mixColor(bg, accent, 0.28), accent, accent2, paper, ink, tone };
141
- }
142
-
143
- /** What a loop's draw() receives besides the context. */
144
- export interface LoopHelpers {
145
- phase: typeof phase;
146
- rand: typeof rand;
147
- win: typeof win;
148
- ease: typeof ease;
149
- loopNoise: typeof loopNoise;
150
- proj: typeof proj;
151
- rgba: typeof rgba;
152
- mixColor: typeof mixColor;
153
- smoothstep: typeof smoothstep;
154
- clamp: typeof clamp;
155
- fract: typeof fract;
156
- mod: typeof mod;
157
- lerp: typeof lerp;
158
- TAU: number;
159
- LOOP: number;
160
- }
161
-
162
- export const M: LoopHelpers = { phase, rand, win, ease, loopNoise, proj, rgba, mixColor, smoothstep, clamp, fract, mod, lerp, TAU, LOOP };
163
-
164
- /**
165
- * draw(ctx, w, h, t, P, M): paint the frame at t seconds (0 ≤ t < 12). The background is already
166
- * filled (unless transparent). Sizes from u = h / 100 (min(w, h) for shapes); counts from w.
167
- * `seed` varies element layouts so the same loop can look different per video.
168
- */
169
- export type LoopDraw = (ctx: CanvasRenderingContext2D, w: number, h: number, t: number, P: LoopPalette, M: LoopHelpers, seed: number) => void;
170
-
171
- export const LOOP_CATEGORIES = ["Backgrounds", "Shapes", "Symmetry", "Morphing", "Games", "Physics", "Generative"] as const;
172
- export type LoopCategory = (typeof LOOP_CATEGORIES)[number];
173
-
174
- export interface LoopDef {
175
- id: string;
176
- name: string;
177
- kind: "background" | "shape";
178
- /** Gallery group (defaults from kind). */
179
- category?: LoopCategory;
180
- /** What it looks like and when it works (Claude reads this). */
181
- description: string;
182
- tags: string[];
183
- draw: LoopDraw;
184
- }
1
+ // Seamless motion loops: each loop is a pure function of time drawn on a 2D canvas. Every motion in a
2
+ // loop repeats with a period that divides LOOP (12 s), so the frame at 12 s is the frame at 0 s and a
3
+ // loop can run under a clip of any length, or repeat, without a seam. No React here.
4
+
5
+ /** The loop length in seconds. Periods must divide it: 1, 1.5, 2, 3, 4, 6, 12. */
6
+ export const LOOP = 12;
7
+ export const TAU = Math.PI * 2;
8
+
9
+ export const clamp = (v: number, a = 0, b = 1) => Math.min(b, Math.max(a, v));
10
+ /** Fractional part in [0, 1): a tiny negative (float error) gives 0, never 1, so it is safe to index with. */
11
+ export const fract = (v: number) => {
12
+ const f = v - Math.floor(v);
13
+ return f < 1 ? f : 0;
14
+ };
15
+ /** Modulo that stays positive. */
16
+ export const mod = (a: number, n: number) => ((a % n) + n) % n;
17
+ export const lerp = (a: number, b: number, k: number) => a + (b - a) * k;
18
+
19
+ /** 0…1 position inside a cycle of `period` seconds (offset in cycles). */
20
+ export const phase = (t: number, period: number, offset = 0) => fract(t / period + offset);
21
+
22
+ /** A fixed pseudo-random number in [0, 1) per element index and salt (never Math.random). */
23
+ export function rand(i: number, salt = 0) {
24
+ return fract(Math.sin(i * 127.1 + salt * 311.7 + 74.7) * 43758.5453123);
25
+ }
26
+
27
+ /** 0 before a, eases 0→1 between a and b (as a linear 0…1), 1 after b. */
28
+ export const win = (p: number, a: number, b: number) => clamp((p - a) / Math.max(1e-6, b - a));
29
+
30
+ export const smoothstep = (a: number, b: number, v: number) => {
31
+ const x = clamp((v - a) / (b - a));
32
+ return x * x * (3 - 2 * x);
33
+ };
34
+
35
+ export const ease = {
36
+ linear: (k: number) => k,
37
+ inSine: (k: number) => 1 - Math.cos((k * Math.PI) / 2),
38
+ outSine: (k: number) => Math.sin((k * Math.PI) / 2),
39
+ inOutSine: (k: number) => -(Math.cos(Math.PI * k) - 1) / 2,
40
+ inCubic: (k: number) => k * k * k,
41
+ outCubic: (k: number) => 1 - Math.pow(1 - k, 3),
42
+ inOutCubic: (k: number) => (k < 0.5 ? 4 * k * k * k : 1 - Math.pow(-2 * k + 2, 3) / 2),
43
+ outExpo: (k: number) => (k >= 1 ? 1 : 1 - Math.pow(2, -10 * k)),
44
+ inOutExpo: (k: number) =>
45
+ k <= 0 ? 0 : k >= 1 ? 1 : k < 0.5 ? Math.pow(2, 20 * k - 10) / 2 : (2 - Math.pow(2, -20 * k + 10)) / 2,
46
+ outBack: (k: number, s = 1.70158) => 1 + (s + 1) * Math.pow(k - 1, 3) + s * Math.pow(k - 1, 2),
47
+ inBack: (k: number, s = 1.70158) => (s + 1) * k * k * k - s * k * k,
48
+ /** Settles from 0 to 1 with a wobble; exactly 1 at k = 1. */
49
+ spring: (k: number, zeta = 0.35, freq = 3) => {
50
+ if (k >= 1) return 1;
51
+ const w = TAU * freq;
52
+ const v = 1 - Math.exp(-zeta * w * k) * Math.cos(w * Math.sqrt(1 - zeta * zeta) * k);
53
+ return lerp(v, 1, smoothstep(0.75, 1, k));
54
+ },
55
+ };
56
+
57
+ /** Smooth noise that repeats every `period` seconds (sines on a circle): drift, sway, breathing. */
58
+ export function loopNoise(t: number, seed = 0, period = LOOP) {
59
+ const a = TAU * phase(t, period);
60
+ return (
61
+ Math.sin(a + rand(seed, 1) * TAU) * 0.5 +
62
+ Math.sin(2 * a + rand(seed, 2) * TAU) * 0.3 +
63
+ Math.sin(3 * a + rand(seed, 3) * TAU) * 0.2
64
+ );
65
+ }
66
+
67
+ /** Perspective projection, divided by depth once. */
68
+ export function proj(x: number, y: number, z: number, f: number, cx: number, cy: number) {
69
+ const s = f / Math.max(1e-3, z);
70
+ return { x: cx + x * s, y: cy + y * s, s };
71
+ }
72
+
73
+ // ─── Colour ──────────────────────────────────────────────────────────────────────────────────────
74
+
75
+ function parse(c: string): [number, number, number] {
76
+ const hex = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(c.trim());
77
+ if (hex) {
78
+ const h = hex[1].length === 3 ? hex[1].replace(/./g, (x) => x + x) : hex[1];
79
+ const n = parseInt(h, 16);
80
+ return [(n >> 16) & 255, (n >> 8) & 255, n & 255];
81
+ }
82
+ const rgb = /rgba?\(([^)]+)\)/i.exec(c);
83
+ if (rgb) {
84
+ const [r, g, b] = rgb[1].split(",").map((v) => parseFloat(v));
85
+ return [r || 0, g || 0, b || 0];
86
+ }
87
+ return [0, 0, 0];
88
+ }
89
+
90
+ /** A colour (hex or rgb()) at an alpha. */
91
+ export function rgba(c: string, a: number) {
92
+ const [r, g, b] = parse(c);
93
+ return `rgba(${r},${g},${b},${clamp(a)})`;
94
+ }
95
+
96
+ /** Mix two colours (hex or rgb()). */
97
+ export function mixColor(a: string, b: string, k: number) {
98
+ const x = parse(a);
99
+ const y = parse(b);
100
+ return `rgb(${Math.round(lerp(x[0], y[0], k))},${Math.round(lerp(x[1], y[1], k))},${Math.round(lerp(x[2], y[2], k))})`;
101
+ }
102
+
103
+ const luma = (c: string) => {
104
+ const [r, g, b] = parse(c);
105
+ return (0.299 * r + 0.587 * g + 0.114 * b) / 255;
106
+ };
107
+
108
+ export type LoopTone = "dark" | "accent" | "light";
109
+
110
+ /** The palette a loop draws with. Never use other colours inside a loop. */
111
+ export interface LoopPalette {
112
+ /** Filled before draw() unless the loop is transparent. */
113
+ bg: string;
114
+ /** Main motif. */
115
+ fg: string;
116
+ /** Second colour, sparingly. */
117
+ fg2: string;
118
+ /** Between bg and fg: grids, quiet details. */
119
+ mid: string;
120
+ accent: string;
121
+ accent2: string;
122
+ paper: string;
123
+ ink: string;
124
+ tone: LoopTone;
125
+ }
126
+
127
+ /**
128
+ * Three tones from the brand colours: dark (deep brand-tinted background, accent motif), accent
129
+ * (accent background, ink motif), light (paper background, ink motif, accent as the second colour).
130
+ */
131
+ export function loopPalette(accent: string, accent2: string, tone: LoopTone, paper = "#f5f3ee", ink = "#111216"): LoopPalette {
132
+ if (tone === "accent") {
133
+ const onAccent = luma(accent) > 0.6 ? ink : paper;
134
+ return { bg: accent, fg: onAccent, fg2: accent2, mid: mixColor(accent, onAccent, 0.3), accent, accent2, paper, ink, tone };
135
+ }
136
+ if (tone === "light") {
137
+ return { bg: paper, fg: ink, fg2: accent, mid: mixColor(paper, ink, 0.18), accent, accent2, paper, ink, tone };
138
+ }
139
+ const bg = mixColor(accent, "#07070b", 0.9);
140
+ return { bg, fg: accent, fg2: accent2, mid: mixColor(bg, accent, 0.28), accent, accent2, paper, ink, tone };
141
+ }
142
+
143
+ /** What a loop's draw() receives besides the context. */
144
+ export interface LoopHelpers {
145
+ phase: typeof phase;
146
+ rand: typeof rand;
147
+ win: typeof win;
148
+ ease: typeof ease;
149
+ loopNoise: typeof loopNoise;
150
+ proj: typeof proj;
151
+ rgba: typeof rgba;
152
+ mixColor: typeof mixColor;
153
+ smoothstep: typeof smoothstep;
154
+ clamp: typeof clamp;
155
+ fract: typeof fract;
156
+ mod: typeof mod;
157
+ lerp: typeof lerp;
158
+ TAU: number;
159
+ LOOP: number;
160
+ }
161
+
162
+ export const M: LoopHelpers = { phase, rand, win, ease, loopNoise, proj, rgba, mixColor, smoothstep, clamp, fract, mod, lerp, TAU, LOOP };
163
+
164
+ /**
165
+ * draw(ctx, w, h, t, P, M): paint the frame at t seconds (0 ≤ t < 12). The background is already
166
+ * filled (unless transparent). Sizes from u = h / 100 (min(w, h) for shapes); counts from w.
167
+ * `seed` varies element layouts so the same loop can look different per video.
168
+ */
169
+ export type LoopDraw = (ctx: CanvasRenderingContext2D, w: number, h: number, t: number, P: LoopPalette, M: LoopHelpers, seed: number) => void;
170
+
171
+ export const LOOP_CATEGORIES = ["Backgrounds", "Shapes", "Symmetry", "Morphing", "Games", "Physics", "Generative"] as const;
172
+ export type LoopCategory = (typeof LOOP_CATEGORIES)[number];
173
+
174
+ export interface LoopDef {
175
+ id: string;
176
+ name: string;
177
+ kind: "background" | "shape";
178
+ /** Gallery group (defaults from kind). */
179
+ category?: LoopCategory;
180
+ /** What it looks like and when it works (Claude reads this). */
181
+ description: string;
182
+ tags: string[];
183
+ draw: LoopDraw;
184
+ }