app-studio 0.2.1 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -770,7 +770,106 @@ const generateCssRules = (selector, styles, getColor, mediaQueries) => {
770
770
  return rules;
771
771
  };
772
772
  // Function to apply styles to a component
773
- const applyStyle = (props, getColor, mediaQueries, devices) => {
773
+ const computeStyleProps = (props, getColor, mediaQueries, devices) => {
774
+ const styleProps = {};
775
+ const keyframesList = [];
776
+ // Gestion de la taille de l'élément
777
+ const size = props.height !== undefined && props.width !== undefined && props.height === props.width ? props.height : props.size ? props.size : null;
778
+ if (size) {
779
+ styleProps.height = styleProps.width = size;
780
+ }
781
+ // Gestion du padding et de la marge
782
+ if (props.paddingHorizontal) {
783
+ styleProps.paddingLeft = props.paddingHorizontal;
784
+ styleProps.paddingRight = props.paddingHorizontal;
785
+ }
786
+ if (props.marginHorizontal) {
787
+ styleProps.marginLeft = props.marginHorizontal;
788
+ styleProps.marginRight = props.marginHorizontal;
789
+ }
790
+ if (props.paddingVertical) {
791
+ styleProps.paddingTop = props.paddingVertical;
792
+ styleProps.paddingBottom = props.paddingVertical;
793
+ }
794
+ if (props.marginVertical) {
795
+ styleProps.marginTop = props.marginVertical;
796
+ styleProps.marginBottom = props.marginVertical;
797
+ }
798
+ // Application des ombres si spécifié
799
+ if (props.shadow) {
800
+ if (typeof props.shadow === 'number' || typeof props.shadow === 'boolean') {
801
+ const shadowValue = typeof props.shadow === 'number' && Shadows[props.shadow] !== undefined ? props.shadow : 2;
802
+ if (Shadows[shadowValue]) {
803
+ const shadowColor = Color.hex.rgb(Shadows[shadowValue].shadowColor) || [];
804
+ styleProps['boxShadow'] = `${Shadows[shadowValue].shadowOffset.height}px ${Shadows[shadowValue].shadowOffset.width}px ${Shadows[shadowValue].shadowRadius}px rgba(${shadowColor.join(',')},${Shadows[shadowValue].shadowOpacity})`;
805
+ }
806
+ } else {
807
+ const shadowColor = Color.hex.rgb(props.shadow.shadowColor) || [];
808
+ styleProps['boxShadow'] = `${props.shadow.shadowOffset.height}px ${props.shadow.shadowOffset.width}px ${props.shadow.shadowRadius}px rgba(${shadowColor.join(',')},${props.shadow.shadowOpacity})`;
809
+ }
810
+ }
811
+ // Gestion des animations
812
+ if (props.animate) {
813
+ const animation = props.animate;
814
+ const {
815
+ keyframesName,
816
+ keyframes
817
+ } = generateKeyframes(animation);
818
+ if (keyframes) {
819
+ keyframesList.push(keyframes);
820
+ }
821
+ styleProps.animationName = keyframesName;
822
+ styleProps.animationDuration = animation.duration || '1s';
823
+ styleProps.animationTimingFunction = animation.timingFunction || 'ease';
824
+ styleProps.animationDelay = animation.delay || '0s';
825
+ styleProps.animationIterationCount = `${animation.iterationCount || '1'}`;
826
+ styleProps.animationDirection = animation.direction || 'normal';
827
+ styleProps.animationFillMode = animation.fillMode || 'both';
828
+ styleProps.animationPlayState = animation.playState || 'running';
829
+ }
830
+ Object.keys(props).forEach(property => {
831
+ if (property !== 'style' && (isStyleProp(property) || extraKeys.has(property))) {
832
+ const value = props[property];
833
+ if (typeof value === 'object' && value !== null) {
834
+ // For other nested styles, exclude 'on' and 'media'
835
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
836
+ const {
837
+ on,
838
+ media,
839
+ ...nestedProps
840
+ } = value;
841
+ const nestedResult = applyStyle(nestedProps, getColor, mediaQueries, devices);
842
+ styleProps[property] = nestedResult.styleProps;
843
+ keyframesList.push(...(nestedResult.keyframes || []));
844
+ } else {
845
+ // Simple style property
846
+ styleProps[property] = value;
847
+ }
848
+ }
849
+ });
850
+ return {
851
+ styleProps,
852
+ keyframes: keyframesList
853
+ };
854
+ };
855
+ // Function to apply styles to a component
856
+ const applyStyle = function (props, getColor, mediaQueries, devices, depth,
857
+ // Add a depth parameter
858
+ maxDepth // Set a maximum depth
859
+ ) {
860
+ if (depth === void 0) {
861
+ depth = 0;
862
+ }
863
+ if (maxDepth === void 0) {
864
+ maxDepth = 10;
865
+ }
866
+ if (depth > maxDepth) {
867
+ console.error('Maximum recursion depth reached in applyStyle');
868
+ return {
869
+ styleProps: {},
870
+ keyframes: []
871
+ };
872
+ }
774
873
  const styleProps = {};
775
874
  const keyframesList = [];
776
875
  // Gestion de la taille de l'élément
@@ -827,24 +926,20 @@ const applyStyle = (props, getColor, mediaQueries, devices) => {
827
926
  styleProps.animationFillMode = animation.fillMode || 'both';
828
927
  styleProps.animationPlayState = animation.playState || 'running';
829
928
  }
830
- // Traitement des propriétés de style
831
929
  Object.keys(props).forEach(property => {
832
930
  if (property !== 'style' && (isStyleProp(property) || extraKeys.has(property))) {
833
931
  const value = props[property];
834
932
  if (typeof value === 'object' && value !== null) {
835
- // Pour les propriétés comme 'on', 'media'
836
933
  if (property === 'on') {
837
- // Pseudo-sélecteurs
838
934
  for (const event in value) {
839
935
  if (!styleProps[`&:${event}`]) {
840
936
  styleProps[`&:${event}`] = {};
841
937
  }
842
- const nestedResult = applyStyle(value[event], getColor, mediaQueries, devices);
938
+ const nestedResult = computeStyleProps(value[event], getColor, mediaQueries, devices);
843
939
  Object.assign(styleProps[`&:${event}`], nestedResult.styleProps);
844
940
  keyframesList.push(...(nestedResult.keyframes || []));
845
941
  }
846
942
  } else if (property === 'media') {
847
- // Media queries
848
943
  for (const screenOrDevices in value) {
849
944
  const mediaValue = value[screenOrDevices];
850
945
  if (mediaQueries[screenOrDevices]) {
@@ -852,7 +947,7 @@ const applyStyle = (props, getColor, mediaQueries, devices) => {
852
947
  if (!styleProps[mediaQuery]) {
853
948
  styleProps[mediaQuery] = {};
854
949
  }
855
- const nestedResult = applyStyle(mediaValue, getColor, mediaQueries, devices);
950
+ const nestedResult = computeStyleProps(mediaValue, getColor, mediaQueries, devices);
856
951
  Object.assign(styleProps[mediaQuery], nestedResult.styleProps);
857
952
  keyframesList.push(...(nestedResult.keyframes || []));
858
953
  } else if (devices[screenOrDevices]) {
@@ -863,7 +958,7 @@ const applyStyle = (props, getColor, mediaQueries, devices) => {
863
958
  if (!styleProps[mediaQuery]) {
864
959
  styleProps[mediaQuery] = {};
865
960
  }
866
- const nestedResult = applyStyle(mediaValue, getColor, mediaQueries, devices);
961
+ const nestedResult = computeStyleProps(mediaValue, getColor, mediaQueries, devices);
867
962
  Object.assign(styleProps[mediaQuery], nestedResult.styleProps);
868
963
  keyframesList.push(...(nestedResult.keyframes || []));
869
964
  }
@@ -871,13 +966,19 @@ const applyStyle = (props, getColor, mediaQueries, devices) => {
871
966
  }
872
967
  }
873
968
  } else {
874
- // Styles imbriqués
875
- const nestedResult = applyStyle(value, getColor, mediaQueries, devices);
969
+ // For other nested styles, exclude 'on' and 'media'
970
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
971
+ const {
972
+ on,
973
+ media,
974
+ ...nestedProps
975
+ } = value;
976
+ const nestedResult = computeStyleProps(nestedProps, getColor, mediaQueries, devices);
876
977
  styleProps[property] = nestedResult.styleProps;
877
978
  keyframesList.push(...(nestedResult.keyframes || []));
878
979
  }
879
980
  } else {
880
- // Propriété de style simple
981
+ // Simple style property
881
982
  styleProps[property] = value;
882
983
  }
883
984
  }