@@ -408,6 +408,8 @@ function resolveStyle(
408408 return result ;
409409}
410410
411+ export const __customProperties : MutableCustomProperties = { } ;
412+
411413/**
412414 * The create method shim should do initial transforms like
413415 * renaming/expanding/validating properties, essentially all the steps
@@ -433,6 +435,45 @@ function _create<S: { +[string]: { +[string]: mixed } }>(styles: S): {
433435}
434436export const create : IStyleX [ 'create' ] = _create as $FlowFixMe ;
435437
438+ const RE_CAPTURE_VAR_NAME = / ^ v a r \( - - ( .* ) \) $ / ;
439+ export const createTheme = (
440+ baseTokens : Tokens ,
441+ overrides : CustomProperties
442+ ) : CustomProperties => {
443+ const result : MutableCustomProperties = { $$theme : 'theme' } ;
444+ for ( const key in baseTokens ) {
445+ const varName : string = baseTokens [ key ] ;
446+ const normalizedKey = varName . replace ( RE_CAPTURE_VAR_NAME , '$1' ) ;
447+ result [ normalizedKey ] = overrides [ key ] ;
448+ }
449+ return result ;
450+ } ;
451+
452+ export const defineConsts = ( tokens : {
453+ [ string ] : string
454+ } ) : { [ string ] : string } = > {
455+ if ( __DEV__ ) {
456+ errorMsg ( 'css.defineConsts() is not supported.' ) ;
457+ }
458+ return tokens ;
459+ } ;
460+
461+ type Tokens = { [ string ] : string } ;
462+ let defineVarsCount = 1 ;
463+ export const defineVars = ( tokens : CustomProperties ) : Tokens => {
464+ const result : Tokens = { } ;
465+ for ( const key in tokens ) {
466+ const value = tokens [ key ] ;
467+ const customPropName = `${ key } __id__${ defineVarsCount ++ } ` ;
468+ result [ key ] = `var(--${ customPropName } )` ;
469+ // NOTE: it's generally not a good idea to mutate the default context,
470+ // but defineVars is always called before any component body is evaluated,
471+ // and so it's safe to do so here.
472+ __customProperties [ customPropName ] = value ;
473+ }
474+ return result ;
475+ } ;
476+
436477export const firstThatWorks = < T : string | number > (
437478 ...values: $ReadOnlyArray< T >
438479): T => {
@@ -442,7 +483,6 @@ export const firstThatWorks = <T: string | number>(
442483type Keyframes = {
443484 + [ key : string ] : { + [ k : string ] : string | number }
444485} ;
445-
446486function _keyframes ( k : Keyframes ) : Keyframes {
447487 if ( __DEV__ ) {
448488 errorMsg ( 'css.keyframes() is not supported.' ) ;
@@ -451,9 +491,16 @@ function _keyframes(k: Keyframes): Keyframes {
451491}
452492export const keyframes : ( Keyframes ) => string = _keyframes as $FlowFixMe ;
453493
454- /**
455- * The spread method shim
456- */
494+ type PositionTry = {
495+ + [ k : string ] : string | number
496+ } ;
497+ function _positionTry(p: PositionTry): PositionTry {
498+ if ( __DEV__ ) {
499+ errorMsg ( 'css.positionTry() is not supported.' ) ;
500+ }
501+ return p;
502+ }
503+ export const positionTry : ( PositionTry ) => string = _positionTry as $FlowFixMe ;
457504
458505export function props (
459506 this : ResolveStyleOptions ,
@@ -645,36 +692,3 @@ export function props(
645692
646693 return nativeProps;
647694}
648-
649- type Tokens = { [ string ] : string } ;
650- let count = 1;
651- const RE_CAPTURE_VAR_NAME = /^var\(--(.*)\)$/;
652-
653- export const __customProperties: MutableCustomProperties = { } ;
654-
655- export const defineVars = (tokens: CustomProperties): Tokens => {
656- const result : Tokens = { } ;
657- for ( const key in tokens ) {
658- const value = tokens [ key ] ;
659- const customPropName = `${ key } __id__${ count ++ } ` ;
660- result [ key ] = `var(--${ customPropName } )` ;
661- // NOTE: it's generally not a good idea to mutate the default context,
662- // but defineVars is always called before any component body is evaluated,
663- // and so it's safe to do so here.
664- __customProperties [ customPropName ] = value ;
665- }
666- return result ;
667- } ;
668-
669- export const createTheme = (
670- baseTokens: Tokens,
671- overrides: CustomProperties
672- ): CustomProperties => {
673- const result : MutableCustomProperties = { $$theme : 'theme' } ;
674- for ( const key in baseTokens ) {
675- const varName : string = baseTokens [ key ] ;
676- const normalizedKey = varName . replace ( RE_CAPTURE_VAR_NAME , '$1' ) ;
677- result [ normalizedKey ] = overrides [ key ] ;
678- }
679- return result ;
680- } ;
0 commit comments