@@ -560,3 +560,73 @@ describe("splitElementInHtml — id CSS rules across repeated cuts", () => {
560560 expect ( css ) . toContain ( ".clip:not(#a-cut){filter:blur(2px)}" ) ;
561561 } ) ;
562562} ) ;
563+
564+ // A clip that starts after another ("b", "b + 1") has no start of its own in the file: where it plays is where b
565+ // ends, which only the studio's resolved range knows. Read as 0, a cut inside the clip's real time was refused, and
566+ // a cut before it was accepted and rewrote the clip to start at 0.
567+ describe ( "splitElementInHtml — a start that names another clip" , ( ) => {
568+ const after = ( start : string ) =>
569+ `<html><body><div data-composition-id="root"><div id="b" class="clip" data-start="0" data-duration="3"></div><div id="a" class="clip" data-start="${ start } " data-duration="4"></div></div></body></html>` ;
570+ const halves = ( html : string ) =>
571+ [ "a" , "a-split" ] . map ( ( id ) => {
572+ const el = parseHTML ( html ) . document . getElementById ( id ) ;
573+ return [ el ?. getAttribute ( "data-start" ) , el ?. getAttribute ( "data-duration" ) ] ;
574+ } ) ;
575+
576+ it ( "cuts at the time the studio gives and keeps both halves tied to the clip they follow" , ( ) => {
577+ const { html, matched } = splitElementInHtml ( after ( "b" ) , { id : "a" } , 5 , "a-split" , {
578+ start : 3 ,
579+ duration : 4 ,
580+ } ) ;
581+ expect ( matched ) . toBe ( true ) ;
582+ expect ( halves ( html ) ) . toEqual ( [
583+ [ "b" , "2" ] ,
584+ [ "b + 2" , "2" ] ,
585+ ] ) ;
586+ } ) ;
587+
588+ it ( "keeps an offset: the second half starts the first half's length further after the clip" , ( ) => {
589+ const { html, matched } = splitElementInHtml ( after ( "b + 1" ) , { id : "a" } , 5 , "a-split" , {
590+ start : 4 ,
591+ duration : 4 ,
592+ } ) ;
593+ expect ( matched ) . toBe ( true ) ;
594+ expect ( halves ( html ) ) . toEqual ( [
595+ [ "b + 1" , "1" ] ,
596+ [ "b + 2" , "3" ] ,
597+ ] ) ;
598+ } ) ;
599+
600+ it ( "leaves the file as it was for a cut before the clip's real start, instead of rewriting it to start at 0" , ( ) => {
601+ const source = after ( "b" ) ;
602+ const result = splitElementInHtml ( source , { id : "a" } , 2 , "a-split" , { start : 3 , duration : 4 } ) ;
603+ expect ( result ) . toEqual ( { html : source , matched : false , newId : null } ) ;
604+ } ) ;
605+
606+ it ( "refuses when it cannot know where the clip plays" , ( ) => {
607+ const source = after ( "b" ) ;
608+ expect ( splitElementInHtml ( source , { id : "a" } , 5 , "a-split" ) ) . toEqual ( {
609+ html : source ,
610+ matched : false ,
611+ newId : null ,
612+ } ) ;
613+ } ) ;
614+ } ) ;
615+
616+ describe ( "splitElementInHtml — a cut the file's own timing does not allow" , ( ) => {
617+ const clip = `<html><body><div data-composition-id="root"><div id="a" class="clip" data-start="2" data-duration="4"></div></div></body></html>` ;
618+ const untouched = { html : clip , matched : false , newId : null } ;
619+
620+ it . each ( [
621+ [ "exactly at the clip's start" , 2 , { start : 2 , duration : 4 } ] ,
622+ [ "past the clip's end" , 7 , { start : 2 , duration : 4 } ] ,
623+ // The file is the truth: a studio that thinks the clip starts at 5 is out of date, and its cut at 6 is not cut.
624+ [
625+ "where the studio thinks the clip is but the file says otherwise" ,
626+ 6 ,
627+ { start : 5 , duration : 4 } ,
628+ ] ,
629+ ] ) ( "leaves the file as it was for a cut %s" , ( _name , at , range ) => {
630+ expect ( splitElementInHtml ( clip , { id : "a" } , at , "a-split" , range ) ) . toEqual ( untouched ) ;
631+ } ) ;
632+ } ) ;
0 commit comments