@@ -32,74 +32,89 @@ const props = withDefaults(defineProps<ObjectOverlayProps>(), {
3232 tag: ' div' ,
3333});
3434
35- const attrs = computed (() => {
36- const component: Record <string , string > = {};
37- const content: Record <string , any > = {};
38-
39- const componentProperties = [
40- ' position' ,
41- ' gradient'
42- ];
43-
44- componentProperties .forEach ((property ) => {
45- const prop = props [property as keyof typeof props ];
46-
47- if (typeof prop === ' string' ) {
48- component [` data-${property } ` ] = prop ;
49- } else if (typeof prop === ' object' ) {
35+ // Helper function to process component properties (position, gradient)
36+ const processComponentProperty = (property : string , prop : any ): Record <string , string > => {
37+ const result: Record <string , string > = {};
38+
39+ try {
40+ if (typeof prop === ' string' ) {
41+ result [` data-${property } ` ] = prop ;
42+ } else if (typeof prop === ' object' && prop !== null ) {
5043 Object .entries (prop ).forEach (([mq , value ]) => {
5144 if (mq === ' xs' ) {
52- component [` data-${property } ` ] = value ;
45+ result [` data-${property } ` ] = String ( value ) ;
5346 } else {
54- component [` data-${property }-${mq } ` ] = value ;
47+ result [` data-${property }-${mq } ` ] = String ( value ) ;
5548 }
5649 });
5750 }
58- });
51+ } catch (error ) {
52+ console .error (` Error processing ${property }: ` , error );
53+ }
54+
55+ return result ;
56+ };
57+
58+ // Helper function to create CSS variable references
59+ const createCssVar = (space : string ): string => ` var(--cdr-space-${space }) ` ;
60+
61+ // Helper function to process content properties (margin, padding)
62+ const processContentProperty = (
63+ property : string ,
64+ prop : string | string [] | Record <string , string | string []>,
65+ existingStyle : Record <string , string > = {}
66+ ): Record <string , string > => {
67+ const style = { ... existingStyle };
68+
69+ try {
70+ if (typeof prop === ' string' ) {
71+ style [` --${property } ` ] = createCssVar (prop );
72+ } else if (Array .isArray (prop )) {
73+ style [` --${property } ` ] = prop .map (createCssVar ).join (' ' );
74+ } else if (typeof prop === ' object' && prop !== null ) {
75+ Object .entries (prop ).forEach (([mq , value ]) => {
76+ const val = typeof value === ' string'
77+ ? createCssVar (value )
78+ : (value as string []).map (createCssVar ).join (' ' );
5979
60- const contentProperties = [
61- ' margin' ,
62- ' padding'
63- ]
80+ style [` --${property }-${mq } ` ] = val ;
81+ });
82+ }
83+ } catch (error ) {
84+ console .error (` Error processing ${property }: ` , error );
85+ }
86+
87+ return style ;
88+ };
6489
65- contentProperties .forEach ((property ) => {
66- const prop = props [property as keyof typeof props ];
90+ const attrs = computed (() => {
91+ const component: Record <string , string > = {};
92+ const content: Record <string , any > = { style: {} };
6793
68- if (typeof prop === ' string' ) {
69- content .style = {
70- ... (content .style || {}),
71- [` --${property } ` ]: ` var(--cdr-space-${prop }) `
72- };
73- } else if (typeof prop === ' object' ) {
74- if (Array .isArray (prop )) {
75- content .style = {
76- ... content .style ,
77- [` --${property } ` ]: prop .map (
78- (val ) => ` var(--cdr-space-${val }) `
79- ).join (' ' )
80- };
81- } else {
82- Object .entries (prop ).forEach (([mq , value ]) => {
83- const val = typeof value === ' string' ?
84- ` var(--cdr-space-${value }) `
85- :
86- value .map (
87- (v : string ) => ` var(--cdr-space-${v }) `
88- ).join (' ' );
94+ // Process component properties
95+ [' position' , ' gradient' ].forEach ((property ) => {
96+ const prop = props [property as keyof typeof props ];
97+ if (prop ) {
98+ Object .assign (component , processComponentProperty (property , prop ));
99+ }
100+ });
89101
90- content .style = {
91- ... content .style ,
92- [` --${property }-${mq } ` ]: val
93- };
94- });
95- }
96- }
102+ // Process content properties
103+ [' margin' , ' padding' ].forEach ((property ) => {
104+ const prop = props [property as keyof typeof props ];
105+ if (prop ) {
106+ content .style = processContentProperty (
107+ property ,
108+ prop as string | string [] | Record <string , string | string []>,
109+ content .style
110+ );
111+ }
97112 });
98113
99114 return {
100115 component ,
101116 content
102- }
117+ };
103118});
104119
105120const styles = useCssModule ();
0 commit comments