@@ -318,16 +318,17 @@ const PATH_ARGUMENTS: Record<string, number> = { M: 2, L: 2, C: 6, Z: 0, E: 0 };
318318const MotionPath = type ( "string" ) . narrow ( ( path , ctx ) => {
319319 const tokens = path . trim ( ) . split ( / [ \s , ] + / ) ;
320320 if ( tokens [ 0 ] !== "M" ) return ctx . mustBe ( "a path starting with M" ) ;
321- for ( let at = 0 ; at < tokens . length ; ) {
322- const count = PATH_ARGUMENTS [ tokens [ at ] ?? "" ] ;
321+ let at = 0 ;
322+ for ( let command = tokens [ at ] ; command !== undefined ; command = tokens [ at ] ) {
323+ const count = PATH_ARGUMENTS [ command ] ;
323324 if ( count === undefined )
324325 return ctx . mustBe ( "a path of M, L, C, Z and E commands with numbers" ) ;
325326 const numbers = tokens . slice ( at + 1 , at + 1 + count ) ;
326327 if (
327328 numbers . length < count ||
328329 numbers . some ( ( n ) => ! Number . isFinite ( Number ( n ) ) )
329330 )
330- return ctx . mustBe ( `a path whose ${ tokens [ at ] } has ${ count } numbers` ) ;
331+ return ctx . mustBe ( `a path whose ${ command } has ${ count } numbers` ) ;
331332 at += 1 + count ;
332333 }
333334 return true ;
@@ -499,14 +500,16 @@ const NESTING = [
499500 } ,
500501] as const ;
501502
503+ type Depths = Record < ( typeof NESTING ) [ number ] [ "key" ] , number > ;
504+
502505/** Lists and groups nested past their limits, found without recursion before the schema's own recursion can overflow. */
503506function deepNesting ( input : unknown ) : DeckIssue [ ] {
504507 const issues : DeckIssue [ ] = [ ] ;
505508 const pending = [
506509 {
507510 value : isObject ( input ) ? input . slides : undefined ,
508511 path : [ "slides" ] as Path ,
509- depths : NESTING . map ( ( ) => 0 ) ,
512+ depths : { items : 0 , children : 0 } satisfies Depths ,
510513 } ,
511514 ] ;
512515 for ( let next = pending . pop ( ) ; next ; next = pending . pop ( ) ) {
@@ -515,22 +518,18 @@ function deepNesting(input: unknown): DeckIssue[] {
515518 const entries = Object . entries ( value ) . reverse ( ) ;
516519 for ( const [ key , child ] of entries ) {
517520 const childPath = [ ...path , Array . isArray ( value ) ? Number ( key ) : key ] ;
518- const level = NESTING . findIndex (
519- ( nesting , index ) =>
520- key === nesting . key &&
521+ const nesting = NESTING . find (
522+ ( each ) =>
523+ key === each . key &&
521524 Array . isArray ( child ) &&
522- nesting . opens ( value , depths [ index ] ?? 0 ) ,
525+ each . opens ( value , depths [ each . key ] ) ,
523526 ) ;
524- const nesting = NESTING [ level ] ;
525- const depth = depths [ level ] ?? 0 ;
526527 if ( ! nesting ) pending . push ( { value : child , path : childPath , depths } ) ;
527- else if ( depth < nesting . limit )
528+ else if ( depths [ nesting . key ] < nesting . limit )
528529 pending . push ( {
529530 value : child ,
530531 path : childPath ,
531- depths : depths . map ( ( each , index ) =>
532- index === level ? each + 1 : each ,
533- ) ,
532+ depths : { ...depths , [ nesting . key ] : depths [ nesting . key ] + 1 } ,
534533 } ) ;
535534 else
536535 issues . push (
@@ -654,8 +653,9 @@ function freeSlideIssues(slide: Slide, index: number): DeckIssue[] {
654653 ) ,
655654 ) ;
656655 }
656+ if ( ! slide . animations ) return issues ;
657657 let endless = false ;
658- for ( const [ position , animation ] of ( slide . animations ?? [ ] ) . entries ( ) ) {
658+ for ( const [ position , animation ] of slide . animations . entries ( ) ) {
659659 const path = [ "slides" , index , "animations" , position ] ;
660660 if ( ! ids . has ( animation . target ) )
661661 issues . push (
0 commit comments