@hyperframes/studio 0.9.29 → 0.9.31

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.
@@ -1 +1 @@
1
- import{l as V}from"./index-D3lR9-ik.js";import{bw as G,bN as K,cH as Q,bE as X}from"./codec-D84nARi6.js";const x=1e-5,k=1e-9,T=h=>!h.variableFrameRate&&(h.frameRate??0)>0;function Y(h,i){const{sourceLead:r,inputLead:l,timeResolution:w,frameRate:p=0}=i;if(!T(i))return Math.max(l,h-r+l)+k;const d=Math.max(0,Math.floor((h-r)*p+k)),f=l+d/p;return(w>0?Math.round(f*w)/w:f)+x}function J(h,i,r){const{frameRate:l=0,sourceLead:w,inputLead:p}=r,d=T(r)?Math.round((h-p)*l)/l+w:h-p+w,f=Math.min(i,d);return{timestamp:f,duration:Math.max(T(r)?1/l:0,i-f+x)}}const E=64*1024*1024,M=4,Z=.5,$=2e3;async function q(h,i){if(!h.transparent)return h.sink.getSample(i);let r=null;try{for await(const l of h.sink.samplesAtTimestamps([i]))r==null||r.close(),r=l;return r}catch(l){throw r==null||r.close(),l}}function ot(h){const i=new Map,r=new Map,l=new Map,w=new Map,p=new Map;let d=0,f=!1;const _=t=>{var o,n;let e=new URL(t,location.href).pathname;try{e=decodeURIComponent(e)}catch{}return(n=Object.entries(((o=h.contentWindow)==null?void 0:o.__HF_MEDIA_SOURCE_FACTS__)??{}).filter(([s])=>e.endsWith(s)).sort(([s],[a])=>a.length-s.length)[0])==null?void 0:n[1]},g=(t=E)=>{for(const[e,o]of p){if(d<=t)break;e.pins>0||(p.delete(e),o.cache.delete(e.timestamp),d-=e.bytes,e.image.close())}},v=async t=>{if(t.disposed)return;t.disposed=!0,clearTimeout(t.idleTimer),r.get(t.key)===t&&r.delete(t.key);const e=(async()=>{t.transparent&&await t.tail,t.cancelReads(),t.input.dispose(),await y(t).catch(()=>{});for(const o of t.cache.values())p.delete(o),d-=o.bytes,o.image.close();t.cache.clear(),t.canvas.width=t.canvas.height=0})();return t.transparent?new Promise((o,n)=>{const s=setTimeout(()=>{t.cancelReads(),o()},$);e.then(o,n).finally(()=>clearTimeout(s))}):e},P=t=>{clearTimeout(t.idleTimer),!(t.disposed||t.users>0||[...t.cache.values()].some(e=>e.pins>0))&&(t.idleTimer=setTimeout(()=>{t.users>0||[...t.cache.values()].some(e=>e.pins>0)||r.get(t.key)===t&&(i.delete(t.key),v(t))},1e4))},D=async t=>{const e=V("thumbnail"),o=new G({source:new Q(t,e),formats:K});l.set(o,e.cancelReads);try{const n=await o.getPrimaryVideoTrack();if(!n||f)throw new Error("Preview video unavailable");const[s,a,u,c,m,S,F,B,j]=await Promise.all([n.getDisplayWidth(),n.getDisplayHeight(),n.getFirstTimestamp(),n.getTimeResolution(),n.getSquarePixelWidth(),n.getSquarePixelHeight(),n.getRotation(),n.getFlip(),n.canBeTransparent()]),b=document.createElement("canvas");b.width=Math.max(1,Math.ceil(s));const z=F%180===0?m/S:S/m;return b.height=Math.max(1,Math.round(b.width/z)),{key:t,input:o,cancelReads:e.cancelReads,sink:new X(n),canvas:b,rotation:F,flip:B,width:s,height:a,lead:u,ticks:c,transparent:j,tail:Promise.resolve(),iterator:null,iteratorEnd:0,lastTime:-1/0,cache:new Map,users:0,disposed:!1}}catch(n){throw o.dispose(),e.cancelReads(),n}finally{l.delete(o)}},I=()=>{for(const[t]of i){if(i.size<M)break;const e=r.get(t);e&&e.users===0&&![...e.cache.values()].some(o=>o.pins>0)&&(i.delete(t),v(e))}if(i.size>=M)throw new Error("Preview decoder budget reached")},L=async t=>{const e=t;if((w.get(e)??0)>performance.now())throw new Error("Preview decoder cooling down");let o=i.get(e);o||(I(),o=D(t),i.set(e,o)),i.delete(e),i.set(e,o);let n;try{n=await o}catch(s){throw i.get(e)===o&&(i.delete(e),w.set(e,performance.now()+5e3)),s}if(f||n.disposed)throw new DOMException("Preview disposed","AbortError");return r.set(e,n),n.users++,clearTimeout(n.idleTimer),n},y=async t=>{const e=t.iterator;t.iterator=null,await(e==null?void 0:e.return())},R=(t,e)=>{if(e.throwIfAborted(),f||t.disposed)throw new Error("Preview disposed")},O=async(t,e,o)=>{for(t.iterator||(t.iteratorEnd=e+8,t.iterator=t.sink.samples(e,t.iteratorEnd));;){R(t,o);const n=await t.iterator.next();if(n.done)return null;const s=n.value;let a=!1;try{if(R(t,o),s.timestamp>e+1e-6)return null;if(a=s.timestamp+s.duration>e+1e-6,a)return s}finally{a||s.close()}}},A=(t,e)=>(e.pins++,p.delete(e),p.set(e,t),e),W=async(t,e,o,n,s)=>{const a=t.canvas.getContext("2d",{alpha:!0});if(!a)throw new Error("Preview canvas unavailable");a.clearRect(0,0,t.canvas.width,t.canvas.height),a.imageSmoothingQuality="high",e.drawWithFit(a,{fit:"fill",rotation:t.rotation,flip:t.flip});const u=await createImageBitmap(t.canvas);if(s.aborted||f||t.disposed)throw u.close(),s.throwIfAborted(),new Error("Preview disposed");const c={image:u,...J(e.timestamp,o,n),bytes:u.width*u.height*4,pins:1},m=t.cache.get(c.timestamp);if(m)return m.duration=Math.max(m.duration,c.duration),u.close(),A(t,m);if(g(E-c.bytes),d+c.bytes>E)throw u.close(),new Error("Preview frame budget reached");return t.cache.set(c.timestamp,c),p.set(c,t),d+=c.bytes,c},H=(t,e,o)=>!t.transparent&&!o.variableFrameRate&&(o.frameRate??0)>0&&e>t.lastTime+1e-6&&e-t.lastTime<=Z,N=async(t,e,o,n)=>{R(t,n);const s=[...t.cache.values()].find(m=>e>=m.timestamp-1e-6&&e<m.timestamp+m.duration-1e-6);if(s)return A(t,s);const a=Y(e,o),u=H(t,e,o);let c=null;try{if((!u||a>=t.iteratorEnd)&&await y(t),c=u?await O(t,a,n):null,c||(await y(t),c=await q(t,a)),!c)throw new Error("No preview frame at requested time");return R(t,n),t.lastTime=e,await W(t,c,e,o,n)}finally{c==null||c.close(),(n.aborted||f)&&await y(t).catch(()=>{})}},U=(t,e)=>{const o=_(t.source);return{frameRate:o==null?void 0:o.frameRate,variableFrameRate:o==null?void 0:o.variableFrameRate,sourceLead:e.lead,inputLead:e.lead,timeResolution:e.ticks}},C=async(t,e)=>{e.throwIfAborted();const o=t.source;if(!o)throw new Error("Preview source unavailable");const n=await L(o);try{const s=U(t,n),a=n.tail.then(()=>N(n,t.time,s,e));n.tail=a.then(()=>{},()=>{});const u=await a;let c=!1;return g(),{source:u.image,timestamp:u.timestamp,duration:u.duration,width:n.width,height:n.height,release(){c||(c=!0,u.pins--,g(),P(n))}}}finally{n.users--,P(n)}};return{async decode(t,e){if(f)throw new DOMException("Preview disposed","AbortError");if(new Set(t.map(({source:a})=>a)).size>M)throw new Error("Preview decoder budget reached");const o=await Promise.allSettled(t.map(a=>C(a,e))),n=o.find(a=>a.status==="rejected"),s=o.flatMap(a=>a.status==="fulfilled"?[a.value]:[]);if(n||f||e.aborted){for(const a of s)a.release();throw n?n.reason:new DOMException("Preview cancelled","AbortError")}return s},async suspend(){const t=[...i.values()].map(e=>e.then(v).catch(()=>{}));i.clear();for(const[e,o]of l)o(),e.dispose();await Promise.all(t)},dispose(){if(!f){f=!0;for(const[t,e]of l)e(),t.dispose();for(const t of i.values())t.then(v).catch(()=>{});i.clear(),w.clear()}}}}export{ot as createPausedVideoDecoder};
1
+ import{l as V}from"./index-Ob53qo6K.js";import{bw as G,bN as K,cH as Q,bE as X}from"./codec-DXM4vA6G.js";const x=1e-5,k=1e-9,T=h=>!h.variableFrameRate&&(h.frameRate??0)>0;function Y(h,i){const{sourceLead:r,inputLead:l,timeResolution:w,frameRate:p=0}=i;if(!T(i))return Math.max(l,h-r+l)+k;const d=Math.max(0,Math.floor((h-r)*p+k)),f=l+d/p;return(w>0?Math.round(f*w)/w:f)+x}function J(h,i,r){const{frameRate:l=0,sourceLead:w,inputLead:p}=r,d=T(r)?Math.round((h-p)*l)/l+w:h-p+w,f=Math.min(i,d);return{timestamp:f,duration:Math.max(T(r)?1/l:0,i-f+x)}}const E=64*1024*1024,M=4,Z=.5,$=2e3;async function q(h,i){if(!h.transparent)return h.sink.getSample(i);let r=null;try{for await(const l of h.sink.samplesAtTimestamps([i]))r==null||r.close(),r=l;return r}catch(l){throw r==null||r.close(),l}}function ot(h){const i=new Map,r=new Map,l=new Map,w=new Map,p=new Map;let d=0,f=!1;const _=t=>{var o,n;let e=new URL(t,location.href).pathname;try{e=decodeURIComponent(e)}catch{}return(n=Object.entries(((o=h.contentWindow)==null?void 0:o.__HF_MEDIA_SOURCE_FACTS__)??{}).filter(([s])=>e.endsWith(s)).sort(([s],[a])=>a.length-s.length)[0])==null?void 0:n[1]},g=(t=E)=>{for(const[e,o]of p){if(d<=t)break;e.pins>0||(p.delete(e),o.cache.delete(e.timestamp),d-=e.bytes,e.image.close())}},v=async t=>{if(t.disposed)return;t.disposed=!0,clearTimeout(t.idleTimer),r.get(t.key)===t&&r.delete(t.key);const e=(async()=>{t.transparent&&await t.tail,t.cancelReads(),t.input.dispose(),await y(t).catch(()=>{});for(const o of t.cache.values())p.delete(o),d-=o.bytes,o.image.close();t.cache.clear(),t.canvas.width=t.canvas.height=0})();return t.transparent?new Promise((o,n)=>{const s=setTimeout(()=>{t.cancelReads(),o()},$);e.then(o,n).finally(()=>clearTimeout(s))}):e},P=t=>{clearTimeout(t.idleTimer),!(t.disposed||t.users>0||[...t.cache.values()].some(e=>e.pins>0))&&(t.idleTimer=setTimeout(()=>{t.users>0||[...t.cache.values()].some(e=>e.pins>0)||r.get(t.key)===t&&(i.delete(t.key),v(t))},1e4))},D=async t=>{const e=V("thumbnail"),o=new G({source:new Q(t,e),formats:K});l.set(o,e.cancelReads);try{const n=await o.getPrimaryVideoTrack();if(!n||f)throw new Error("Preview video unavailable");const[s,a,u,c,m,S,F,B,j]=await Promise.all([n.getDisplayWidth(),n.getDisplayHeight(),n.getFirstTimestamp(),n.getTimeResolution(),n.getSquarePixelWidth(),n.getSquarePixelHeight(),n.getRotation(),n.getFlip(),n.canBeTransparent()]),b=document.createElement("canvas");b.width=Math.max(1,Math.ceil(s));const z=F%180===0?m/S:S/m;return b.height=Math.max(1,Math.round(b.width/z)),{key:t,input:o,cancelReads:e.cancelReads,sink:new X(n),canvas:b,rotation:F,flip:B,width:s,height:a,lead:u,ticks:c,transparent:j,tail:Promise.resolve(),iterator:null,iteratorEnd:0,lastTime:-1/0,cache:new Map,users:0,disposed:!1}}catch(n){throw o.dispose(),e.cancelReads(),n}finally{l.delete(o)}},I=()=>{for(const[t]of i){if(i.size<M)break;const e=r.get(t);e&&e.users===0&&![...e.cache.values()].some(o=>o.pins>0)&&(i.delete(t),v(e))}if(i.size>=M)throw new Error("Preview decoder budget reached")},L=async t=>{const e=t;if((w.get(e)??0)>performance.now())throw new Error("Preview decoder cooling down");let o=i.get(e);o||(I(),o=D(t),i.set(e,o)),i.delete(e),i.set(e,o);let n;try{n=await o}catch(s){throw i.get(e)===o&&(i.delete(e),w.set(e,performance.now()+5e3)),s}if(f||n.disposed)throw new DOMException("Preview disposed","AbortError");return r.set(e,n),n.users++,clearTimeout(n.idleTimer),n},y=async t=>{const e=t.iterator;t.iterator=null,await(e==null?void 0:e.return())},R=(t,e)=>{if(e.throwIfAborted(),f||t.disposed)throw new Error("Preview disposed")},O=async(t,e,o)=>{for(t.iterator||(t.iteratorEnd=e+8,t.iterator=t.sink.samples(e,t.iteratorEnd));;){R(t,o);const n=await t.iterator.next();if(n.done)return null;const s=n.value;let a=!1;try{if(R(t,o),s.timestamp>e+1e-6)return null;if(a=s.timestamp+s.duration>e+1e-6,a)return s}finally{a||s.close()}}},A=(t,e)=>(e.pins++,p.delete(e),p.set(e,t),e),W=async(t,e,o,n,s)=>{const a=t.canvas.getContext("2d",{alpha:!0});if(!a)throw new Error("Preview canvas unavailable");a.clearRect(0,0,t.canvas.width,t.canvas.height),a.imageSmoothingQuality="high",e.drawWithFit(a,{fit:"fill",rotation:t.rotation,flip:t.flip});const u=await createImageBitmap(t.canvas);if(s.aborted||f||t.disposed)throw u.close(),s.throwIfAborted(),new Error("Preview disposed");const c={image:u,...J(e.timestamp,o,n),bytes:u.width*u.height*4,pins:1},m=t.cache.get(c.timestamp);if(m)return m.duration=Math.max(m.duration,c.duration),u.close(),A(t,m);if(g(E-c.bytes),d+c.bytes>E)throw u.close(),new Error("Preview frame budget reached");return t.cache.set(c.timestamp,c),p.set(c,t),d+=c.bytes,c},H=(t,e,o)=>!t.transparent&&!o.variableFrameRate&&(o.frameRate??0)>0&&e>t.lastTime+1e-6&&e-t.lastTime<=Z,N=async(t,e,o,n)=>{R(t,n);const s=[...t.cache.values()].find(m=>e>=m.timestamp-1e-6&&e<m.timestamp+m.duration-1e-6);if(s)return A(t,s);const a=Y(e,o),u=H(t,e,o);let c=null;try{if((!u||a>=t.iteratorEnd)&&await y(t),c=u?await O(t,a,n):null,c||(await y(t),c=await q(t,a)),!c)throw new Error("No preview frame at requested time");return R(t,n),t.lastTime=e,await W(t,c,e,o,n)}finally{c==null||c.close(),(n.aborted||f)&&await y(t).catch(()=>{})}},U=(t,e)=>{const o=_(t.source);return{frameRate:o==null?void 0:o.frameRate,variableFrameRate:o==null?void 0:o.variableFrameRate,sourceLead:e.lead,inputLead:e.lead,timeResolution:e.ticks}},C=async(t,e)=>{e.throwIfAborted();const o=t.source;if(!o)throw new Error("Preview source unavailable");const n=await L(o);try{const s=U(t,n),a=n.tail.then(()=>N(n,t.time,s,e));n.tail=a.then(()=>{},()=>{});const u=await a;let c=!1;return g(),{source:u.image,timestamp:u.timestamp,duration:u.duration,width:n.width,height:n.height,release(){c||(c=!0,u.pins--,g(),P(n))}}}finally{n.users--,P(n)}};return{async decode(t,e){if(f)throw new DOMException("Preview disposed","AbortError");if(new Set(t.map(({source:a})=>a)).size>M)throw new Error("Preview decoder budget reached");const o=await Promise.allSettled(t.map(a=>C(a,e))),n=o.find(a=>a.status==="rejected"),s=o.flatMap(a=>a.status==="fulfilled"?[a.value]:[]);if(n||f||e.aborted){for(const a of s)a.release();throw n?n.reason:new DOMException("Preview cancelled","AbortError")}return s},async suspend(){const t=[...i.values()].map(e=>e.then(v).catch(()=>{}));i.clear();for(const[e,o]of l)o(),e.dispose();await Promise.all(t)},dispose(){if(!f){f=!0;for(const[t,e]of l)e(),t.dispose();for(const t of i.values())t.then(v).catch(()=>{});i.clear(),w.clear()}}}}export{ot as createPausedVideoDecoder};
package/dist/index.html CHANGED
@@ -14,7 +14,7 @@
14
14
  document.documentElement.dataset.theme = "paper";
15
15
  }
16
16
  </script>
17
- <script type="module" crossorigin src="/assets/index-D3lR9-ik.js"></script>
17
+ <script type="module" crossorigin src="/assets/index-Ob53qo6K.js"></script>
18
18
  <link rel="stylesheet" crossorigin href="/assets/index-dsfjBidg.css">
19
19
  </head>
20
20
  <body>
package/dist/index.js CHANGED
@@ -78394,6 +78394,11 @@ function useFreezeFrame(options) {
78394
78394
  }, []);
78395
78395
  }
78396
78396
 
78397
+ // src/utils/countOf.ts
78398
+ function countOf(n, word) {
78399
+ return `${n} ${n === 1 ? word : `${word}s`}`;
78400
+ }
78401
+
78397
78402
  // src/hooks/useRazorSplit.ts
78398
78403
  function useRazorSplit({
78399
78404
  projectId,
@@ -78502,7 +78507,10 @@ function useRazorSplit({
78502
78507
  const result = await runCut(splittable, splitTime, "all");
78503
78508
  if (!result) return;
78504
78509
  if (result.syncFailed) return;
78505
- showToast(`Split ${result.splitCount} clips at ${splitTime.toFixed(2)}s`, "info");
78510
+ showToast(
78511
+ `Split ${countOf(result.splitCount, "clip")} at ${splitTime.toFixed(2)}s`,
78512
+ "info"
78513
+ );
78506
78514
  } catch (error) {
78507
78515
  const message = error instanceof Error ? error.message : "Failed to split clips";
78508
78516
  showToast(message, "error");
@@ -79553,7 +79561,9 @@ function useTimelineDeleteOps({
79553
79561
  }
79554
79562
  );
79555
79563
  if (!removeResponse.ok) {
79556
- throw new Error(`Failed to delete ${sameFile.length} clips from ${targetPath}`);
79564
+ throw new Error(
79565
+ `Failed to delete ${countOf(sameFile.length, "clip")} from ${targetPath}`
79566
+ );
79557
79567
  }
79558
79568
  const removeData = await removeResponse.json();
79559
79569
  const removedContent = typeof removeData.content === "string" ? removeData.content : originalContent;
@@ -80229,7 +80239,7 @@ async function createAudioGroupAndAssignMembers({
80229
80239
  pendingTimelineEditPathRef
80230
80240
  }) {
80231
80241
  if (elements.length < 2) {
80232
- throw new Error(`Cannot group ${elements.length} clip(s): a group needs at least two`);
80242
+ throw new Error(`Cannot group ${countOf(elements.length, "clip")}: a group needs at least two`);
80233
80243
  }
80234
80244
  if (!GROUP_ID_PATTERN.test(groupId)) {
80235
80245
  throw new Error(`Invalid audio group id ${JSON.stringify(groupId)}`);
@@ -92852,7 +92862,7 @@ function useGestureCommit({
92852
92862
  }
92853
92863
  trackPreviewEditResult("gesture_recording", recordingMethodRef.current, outcome.finish());
92854
92864
  }
92855
- showToast(`Recorded ${sortedPcts.length} keyframes`, "info");
92865
+ showToast(`Recorded ${countOf(sortedPcts.length, "keyframe")}`, "info");
92856
92866
  } catch (err) {
92857
92867
  console.error("[GR:error]", err);
92858
92868
  showToast(`Gesture commit failed: ${err}`, "error");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.9.29",
3
+ "version": "0.9.31",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -60,12 +60,12 @@
60
60
  "dockview-react": "8.3.1",
61
61
  "gsap": "^3.13.0",
62
62
  "mediabunny": "^1.65.2",
63
- "@hyperframes/core": "0.9.29",
64
- "@hyperframes/player": "0.9.29",
65
- "@hyperframes/studio-server": "0.9.29",
66
- "@hyperframes/sdk": "0.9.29",
67
- "@hyperframes/shader-transitions": "0.9.29",
68
- "@hyperframes/parsers": "0.9.29"
63
+ "@hyperframes/player": "0.9.31",
64
+ "@hyperframes/sdk": "0.9.31",
65
+ "@hyperframes/shader-transitions": "0.9.31",
66
+ "@hyperframes/studio-server": "0.9.31",
67
+ "@hyperframes/parsers": "0.9.31",
68
+ "@hyperframes/core": "0.9.31"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@tailwindcss/vite": "^4.3.3",
@@ -82,7 +82,7 @@
82
82
  "vite": "^6.4.2",
83
83
  "vitest": "^4.1.11",
84
84
  "zustand": "^5.0.0",
85
- "@hyperframes/producer": "0.9.29"
85
+ "@hyperframes/producer": "0.9.31"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "react": "19",
@@ -26,6 +26,7 @@ import {
26
26
  type MutableRef,
27
27
  type UseTimelineElementVisibilityEditingInput,
28
28
  } from "./timelineTrackVisibility";
29
+ import { countOf } from "../utils/countOf";
29
30
 
30
31
  interface AudioGroupCarveInput extends UseTimelineElementVisibilityEditingInput {
31
32
  checkEditable?: (elements: readonly TimelineElement[]) => boolean;
@@ -181,7 +182,7 @@ export async function createAudioGroupAndAssignMembers({
181
182
  // then persists `sources: [groupId]` on success, so a quiet no-op leaves the
182
183
  // carve aimed at a group that does not exist.
183
184
  if (elements.length < 2) {
184
- throw new Error(`Cannot group ${elements.length} clip(s): a group needs at least two`);
185
+ throw new Error(`Cannot group ${countOf(elements.length, "clip")}: a group needs at least two`);
185
186
  }
186
187
  if (!GROUP_ID_PATTERN.test(groupId)) {
187
188
  throw new Error(`Invalid audio group id ${JSON.stringify(groupId)}`);
@@ -25,6 +25,7 @@ import {
25
25
  } from "./gsapShared";
26
26
  import { useStableHandlers } from "./useStableHandlers";
27
27
  import { progressAtTime, runEaseOf, timeAtProgress, warpsTime } from "../utils/gsapKeyframeEases";
28
+ import { countOf } from "../utils/countOf";
28
29
 
29
30
  type RecordedKeyframe = {
30
31
  percentage: number;
@@ -375,7 +376,7 @@ export function useGestureCommit({
375
376
  }
376
377
  trackPreviewEditResult("gesture_recording", recordingMethodRef.current, outcome.finish());
377
378
  }
378
- showToast(`Recorded ${sortedPcts.length} keyframes`, "info");
379
+ showToast(`Recorded ${countOf(sortedPcts.length, "keyframe")}`, "info");
379
380
  } catch (err) {
380
381
  console.error("[GR:error]", err);
381
382
  showToast(`Gesture commit failed: ${err}`, "error");
@@ -9,6 +9,7 @@ import { isLinkedSelectionOn } from "../utils/linkedClipPreferences";
9
9
  import { buildAtomicCutIntents, runAtomicCutTransaction } from "../utils/razorSplitTransaction";
10
10
  import type { RecordEditInput } from "./timelineEditingHelpers";
11
11
  import { useFreezeFrame } from "./useFreezeFrame";
12
+ import { countOf } from "../utils/countOf";
12
13
 
13
14
  interface UseRazorSplitOptions {
14
15
  projectId: string | null;
@@ -138,7 +139,10 @@ export function useRazorSplit({
138
139
  const result = await runCut(splittable, splitTime, "all");
139
140
  if (!result) return;
140
141
  if (result.syncFailed) return;
141
- showToast(`Split ${result.splitCount} clips at ${splitTime.toFixed(2)}s`, "info");
142
+ showToast(
143
+ `Split ${countOf(result.splitCount, "clip")} at ${splitTime.toFixed(2)}s`,
144
+ "info",
145
+ );
142
146
  } catch (error) {
143
147
  const message = error instanceof Error ? error.message : "Failed to split clips";
144
148
  showToast(message, "error");
@@ -156,6 +156,34 @@ describe("useTimelineDeleteOps: ripple undo label", () => {
156
156
  expect(body.targets).toHaveLength(elements.length);
157
157
  });
158
158
 
159
+ it("a refused delete names its count: 1 clip, 2 clips", async () => {
160
+ vi.stubGlobal(
161
+ "fetch",
162
+ vi.fn(async (input: RequestInfo | URL) =>
163
+ String(input).includes("/file-mutations/remove-elements/")
164
+ ? new Response("{}", { status: 500 })
165
+ : new Response(JSON.stringify({ content: html }), { status: 200 }),
166
+ ),
167
+ );
168
+ const showToast = vi.fn();
169
+ const { elements, b, getHook } = mountDeleteHarness({
170
+ handleTimelineGroupMove: vi.fn(),
171
+ showToast,
172
+ });
173
+
174
+ await act(async () => {
175
+ await getHook().handleTimelineElementDelete(b);
176
+ });
177
+ await act(async () => {
178
+ await getHook().handleTimelineElementsDelete(elements.slice(0, 2));
179
+ });
180
+
181
+ expect(showToast.mock.calls.map(([message]) => message)).toEqual([
182
+ "Failed to delete 1 clip from index.html",
183
+ "Failed to delete 2 clips from index.html",
184
+ ]);
185
+ });
186
+
159
187
  it("shows exactly one toast when a ripple fails to persist after a committed delete", async () => {
160
188
  const handleTimelineGroupMove = vi.fn().mockRejectedValue(new Error("persist failed"));
161
189
  const showToast = vi.fn();
@@ -25,6 +25,7 @@ import type {
25
25
  TimelineGroupMoveChange,
26
26
  } from "./useTimelineGroupEditing";
27
27
  import { studioApiFetch } from "../utils/studioApiFetch";
28
+ import { countOf } from "../utils/countOf";
28
29
 
29
30
  /** Apply already-resolved ripple changes to the surviving elements for the
30
31
  * optimistic store update after a delete. Pure — no IO. */
@@ -139,7 +140,9 @@ export function useTimelineDeleteOps({
139
140
  },
140
141
  );
141
142
  if (!removeResponse.ok) {
142
- throw new Error(`Failed to delete ${sameFile.length} clips from ${targetPath}`);
143
+ throw new Error(
144
+ `Failed to delete ${countOf(sameFile.length, "clip")} from ${targetPath}`,
145
+ );
143
146
  }
144
147
  const removeData = (await removeResponse.json()) as { content?: string };
145
148
  const removedContent =
@@ -0,0 +1,10 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { countOf } from "./countOf";
3
+
4
+ describe("countOf", () => {
5
+ it("names one thing in the singular and two in the plural", () => {
6
+ expect(countOf(1, "clip")).toBe("1 clip");
7
+ expect(countOf(2, "clip")).toBe("2 clips");
8
+ expect(countOf(0, "keyframe")).toBe("0 keyframes");
9
+ });
10
+ });
@@ -0,0 +1,3 @@
1
+ export function countOf(n: number, word: string): string {
2
+ return `${n} ${n === 1 ? word : `${word}s`}`;
3
+ }