@@ -359,19 +359,15 @@ export class Twind {
359359 for ( const parsed of parse ( rule ) ) {
360360 if ( / \$ { x* } / . test ( parsed . name ) ) continue
361361
362- const [ , arbitrayValue ] = parsed . name . match ( / - ( \[ [ ^ \] ] + ] ) / ) || [ ]
362+ const hasArbitrayValue = / - ( \[ [ ^ \] ] + ] ) / . test ( parsed . name )
363363
364364 const utilitiyExists =
365365 ! parsed . name ||
366366 completions . tokens . some ( ( completion ) => {
367367 if ( completion . kind != 'utility' ) return false
368368
369- if ( arbitrayValue ) {
370- return (
371- completion . theme &&
372- completion . raw . replace ( `{{theme(${ completion . theme ?. section } )}}` , arbitrayValue ) ===
373- parsed . name
374- )
369+ if ( hasArbitrayValue ) {
370+ return parsed . name . startsWith ( completion . value ) && parsed . name != completion . value
375371 }
376372
377373 switch ( completion . interpolation ) {
@@ -536,6 +532,7 @@ export class Twind {
536532 // | `nonzero` // PositiveNumber
537533 if ( value . startsWith ( 'theme(' ) && value . endsWith ( ')' ) ) {
538534 const sectionKey = value . slice ( 6 , - 1 )
535+
539536 const section = theme ( sectionKey as keyof Theme ) ( context )
540537
541538 Object . keys ( section )
@@ -547,6 +544,7 @@ export class Twind {
547544
548545 // Is this the base object for nested values
549546 const value = section [ key ]
547+
550548 if (
551549 typeof value === 'object' &&
552550 Object . keys ( value ) . every ( ( nestedKey ) => keys . includes ( `${ key } -${ nestedKey } ` ) )
@@ -556,22 +554,33 @@ export class Twind {
556554
557555 return true
558556 } )
557+ // Add marker for arbitrary value
558+ . concat ( '[' )
559559 . forEach ( ( key ) => {
560+ if ( key == '[' && suffix ) {
561+ return
562+ }
563+
560564 let className = prefix
561565 if ( key && key != 'DEFAULT' ) {
562566 className += key
563567 }
564568 if ( className . endsWith ( '-' ) ) {
565569 className = className . slice ( 0 , - 1 )
566570 }
571+
567572 className += suffix
568573
569574 completionTokens . set (
570575 className ,
571576 createCompletionToken ( className , {
572577 kind : screens . has ( className ) ? 'screen' : undefined ,
573578 raw : directive ,
574- theme : { section : sectionKey as keyof Theme , key, value : section [ key ] } ,
579+ detail : key == '[' ? 'arbitrary value' : undefined ,
580+ theme :
581+ key == '['
582+ ? { section : sectionKey as keyof Theme , key : '' , value : '' }
583+ : { section : sectionKey as keyof Theme , key, value : section [ key ] } ,
575584 } ) ,
576585 )
577586 } )
0 commit comments