app-studio 0.2.18 → 0.2.21

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.
@@ -2,6 +2,30 @@ import React, { createContext, useContext, useMemo, useEffect, useState } from '
2
2
  import Color from 'color-convert';
3
3
 
4
4
  const palette = {
5
+ whiteAlpha: {
6
+ 50: 'rgba(255, 255, 255, 0.04)',
7
+ 100: 'rgba(255, 255, 255, 0.06)',
8
+ 200: 'rgba(255, 255, 255, 0.08)',
9
+ 300: 'rgba(255, 255, 255, 0.16)',
10
+ 400: 'rgba(255, 255, 255, 0.24)',
11
+ 500: 'rgba(255, 255, 255, 0.36)',
12
+ 600: 'rgba(255, 255, 255, 0.48)',
13
+ 700: 'rgba(255, 255, 255, 0.64)',
14
+ 800: 'rgba(255, 255, 255, 0.80)',
15
+ 900: 'rgba(255, 255, 255, 0.92)'
16
+ },
17
+ blackAlpha: {
18
+ 50: 'rgba(0, 0, 0, 0.04)',
19
+ 100: 'rgba(0, 0, 0, 0.06)',
20
+ 200: 'rgba(0, 0, 0, 0.08)',
21
+ 300: 'rgba(0, 0, 0, 0.16)',
22
+ 400: 'rgba(0, 0, 0, 0.24)',
23
+ 500: 'rgba(0, 0, 0, 0.36)',
24
+ 600: 'rgba(0, 0, 0, 0.48)',
25
+ 700: 'rgba(0, 0, 0, 0.64)',
26
+ 800: 'rgba(0, 0, 0, 0.80)',
27
+ 900: 'rgba(0, 0, 0, 0.92)'
28
+ },
5
29
  white: {
6
30
  50: 'rgba(255, 255, 255, 0.04)',
7
31
  100: 'rgba(255, 255, 255, 0.08)',
@@ -464,6 +488,7 @@ const ThemeProvider = _ref => {
464
488
  }, children);
465
489
  };
466
490
 
491
+ // ResponsiveContext.tsx
467
492
  const defaultBreakpointsConfig = {
468
493
  xs: 0,
469
494
  sm: 340,
@@ -471,37 +496,41 @@ const defaultBreakpointsConfig = {
471
496
  lg: 1080,
472
497
  xl: 1300
473
498
  };
474
- const defaultDeviceConfig = {
475
- mobile: ['xs', 'sm'],
476
- tablet: ['md', 'lg'],
477
- desktop: ['lg', 'xl']
478
- };
499
+ // Inclure la fonction corrigée getMediaQueries ici
479
500
  const getMediaQueries = b => {
480
- const defaultKeys = Object.keys(b);
481
- const breakpointValue = defaultKeys.map(breakpoint => {
482
- const value = {
483
- breakpoint: breakpoint,
484
- min: b[breakpoint],
485
- max: 0
486
- };
487
- return value;
488
- }).sort((a, b) => a.min - b.min);
489
- breakpointValue.reduce((a, b) => {
490
- if (b) a.max = b.min;
491
- return b;
492
- });
501
+ const sortedBreakpoints = Object.keys(b).map(key => ({
502
+ breakpoint: key,
503
+ min: b[key],
504
+ max: 0
505
+ })).sort((a, b) => a.min - b.min);
506
+ // Définir les valeurs max pour chaque breakpoint sauf le dernier
507
+ for (let i = 0; i < sortedBreakpoints.length - 1; i++) {
508
+ sortedBreakpoints[i].max = sortedBreakpoints[i + 1].min - 1;
509
+ }
510
+ // Le dernier breakpoint n'a pas de max
493
511
  const query = {};
494
- breakpointValue.map(sizeScreen => {
495
- query[sizeScreen.breakpoint] = `only screen ${sizeScreen.min && sizeScreen.min >= 0 ? 'and (min-width:' + sizeScreen.min + 'px)' : ''} ${sizeScreen.max && sizeScreen.max >= 0 ? 'and (max-width:' + sizeScreen.max + 'px)' : ''}`;
512
+ sortedBreakpoints.forEach(sizeScreen => {
513
+ let mediaQuery = 'only screen';
514
+ if (sizeScreen.min !== undefined && sizeScreen.min >= 0) {
515
+ mediaQuery += ` and (min-width: ${sizeScreen.min}px)`;
516
+ }
517
+ if (sizeScreen.max !== undefined && sizeScreen.max > 0) {
518
+ mediaQuery += ` and (max-width: ${sizeScreen.max}px)`;
519
+ }
520
+ query[sizeScreen.breakpoint] = mediaQuery.trim();
496
521
  });
497
522
  return query;
498
523
  };
499
- const defaultScreenConfig = {
524
+ const defaultDeviceConfig = {
525
+ mobile: ['xs', 'sm'],
526
+ tablet: ['md', 'lg'],
527
+ desktop: ['lg', 'xl']
528
+ };
529
+ const ResponsiveContext = /*#__PURE__*/createContext({
500
530
  breakpoints: defaultBreakpointsConfig,
501
531
  devices: defaultDeviceConfig,
502
532
  mediaQueries: /*#__PURE__*/getMediaQueries(defaultBreakpointsConfig)
503
- };
504
- const ResponsiveContext = /*#__PURE__*/createContext(defaultScreenConfig);
533
+ });
505
534
  const useResponsiveContext = () => useContext(ResponsiveContext);
506
535
  const ResponsiveProvider = _ref => {
507
536
  let {
@@ -519,7 +548,6 @@ const ResponsiveProvider = _ref => {
519
548
  };
520
549
 
521
550
  // List of numeric properties that don't need 'px' suffix
522
- const NumberProps = /*#__PURE__*/new Set(['numberOfLines', 'fontWeight', 'timeStamp', 'flex', 'flexGrow', 'flexShrink', 'order', 'zIndex', 'aspectRatio', 'shadowOpacity', 'shadowRadius', 'scale', 'opacity', 'min', 'max', 'now']);
523
551
  // Keys to exclude when passing props to the component
524
552
  const excludedKeys = /*#__PURE__*/new Set(['on', 'shadow', 'only', 'media', 'css', 'size', 'paddingHorizontal', 'paddingVertical', 'marginHorizontal', 'marginVertical', 'animate']);
525
553
  // Keys to exclude when passing props to the component
@@ -527,10 +555,6 @@ const extraKeys = /*#__PURE__*/new Set(['on', 'shadow', 'only', 'media', 'css'])
527
555
  const includeKeys = /*#__PURE__*/new Set(['src', 'alt', 'style', 'as']);
528
556
 
529
557
  // styleHelpers.ts
530
- // Excluded keys imported from constants.ts
531
- // import { excludedKeys } from './constants';
532
- const StyleProps = /*#__PURE__*/new Set(['alignContent', 'alignItems', 'alignSelf', 'alignmentBaseline', 'all', 'animation', 'animationDelay', 'animationDirection', 'animationDuration', 'animationFillMode', 'animationIterationCount', 'animationName', 'animationPlayState', 'animationTimingFunction', 'appearance', 'backdropFilter', 'backfaceVisibility', 'background', 'backgroundAttachment', 'backgroundBlendMode', 'backgroundClip', 'backgroundColor', 'backgroundImage', 'backgroundOrigin', 'backgroundPosition', 'backgroundPositionX', 'backgroundPositionY', 'backgroundRepeat', 'backgroundRepeatX', 'backgroundRepeatY', 'backgroundSize', 'baselineShift', 'blockSize', 'border', 'borderBlockEnd', 'borderBlockEndColor', 'borderBlockEndStyle', 'borderBlockEndWidth', 'borderBlockStart', 'borderBlockStartColor', 'borderBlockStartStyle', 'borderBlockStartWidth', 'borderBottom', 'borderBottomColor', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'borderBottomStyle', 'borderBottomWidth', 'borderCollapse', 'borderColor', 'borderImage', 'borderImageOutset', 'borderImageRepeat', 'borderImageSlice', 'borderImageSource', 'borderImageWidth', 'borderInlineEnd', 'borderInlineEndColor', 'borderInlineEndStyle', 'borderInlineEndWidth', 'borderInlineStart', 'borderInlineStartColor', 'borderInlineStartStyle', 'borderInlineStartWidth', 'borderLeft', 'borderLeftColor', 'borderLeftStyle', 'borderLeftWidth', 'borderRadius', 'borderRight', 'borderRightColor', 'borderRightStyle', 'borderRightWidth', 'borderSpacing', 'borderStyle', 'borderTop', 'borderTopColor', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderTopStyle', 'borderTopWidth', 'borderWidth', 'bottom', 'boxShadow', 'boxSizing', 'breakAfter', 'breakBefore', 'breakInside', 'bufferedRendering', 'captionSide', 'caretColor', 'clear', 'clip', 'clipPath', 'clipRule', 'color', 'colorInterpolation', 'colorInterpolationFilters', 'colorRendering', 'columnCount', 'columnFill', 'columnGap', 'columnRule', 'columnRuleColor', 'columnRuleStyle', 'columnRuleWidth', 'columnSpan', 'columnWidth', 'columns', 'contain', 'content', 'counterIncrement', 'counterReset', 'cursor', 'cx', 'cy', 'd', 'direction', 'display', 'dominantBaseline', 'emptyCells', 'fill', 'fillOpacity', 'fillRule', 'filter', 'flex', 'flexBasis', 'flexDirection', 'flexFlow', 'flexGrow', 'flexShrink', 'flexWrap', 'float', 'floodColor', 'floodOpacity', 'font', 'fontDisplay', 'fontFamily', 'fontFeatureSettings', 'fontKerning', 'fontSize', 'fontStretch', 'fontStyle', 'fontVariant', 'fontVariantCaps', 'fontVariantEastAsian', 'fontVariantLigatures', 'fontVariantNumeric', 'fontVariationSettings', 'fontWeight', 'gap', 'grid', 'gridArea', 'gridAutoColumns', 'gridAutoFlow', 'gridAutoRows', 'gridColumn', 'gridColumnEnd', 'gridColumnGap', 'gridColumnStart', 'gridGap', 'gridRow', 'gridRowEnd', 'gridRowGap', 'gridRowStart', 'gridTemplate', 'gridTemplateAreas', 'gridTemplateColumns', 'gridTemplateRows', 'height', 'hyphens', 'imageRendering', 'inlineSize', 'isolation', 'justifyContent', 'justifyItems', 'justifySelf', 'left', 'letterSpacing', 'lightingColor', 'lineBreak', 'lineHeight', 'listStyle', 'listStyleImage', 'listStylePosition', 'listStyleType', 'margin', 'marginBlockEnd', 'marginBlockStart', 'marginBottom', 'marginInlineEnd', 'marginInlineStart', 'marginLeft', 'marginRight', 'marginTop', 'marker', 'markerEnd', 'markerMid', 'markerStart', 'mask', 'maskType', 'maxBlockSize', 'maxHeight', 'maxInlineSize', 'maxWidth', 'maxZoom', 'minBlockSize', 'minHeight', 'minInlineSize', 'minWidth', 'minZoom', 'mixBlendMode', 'objectFit', 'objectPosition', 'offset', 'offsetDistance', 'offsetPath', 'offsetRotate', 'opacity', 'order', 'orientation', 'orphans', 'outline', 'outlineColor', 'outlineOffset', 'outlineStyle', 'outlineWidth', 'overflow', 'overflowAnchor', 'overflowWrap', 'overflowX', 'overflowY', 'overscrollBehavior', 'overscrollBehaviorBlock', 'overscrollBehaviorInline', 'overscrollBehaviorX', 'overscrollBehaviorY', 'padding', 'paddingBlockEnd', 'paddingBlockStart', 'paddingBottom', 'paddingInlineEnd', 'paddingInlineStart', 'paddingLeft', 'paddingRight', 'paddingTop', 'page', 'pageBreakAfter', 'pageBreakBefore', 'pageBreakInside', 'paintOrder', 'perspective', 'perspectiveOrigin', 'placeContent', 'placeItems', 'placeSelf', 'pointerEvents', 'position', 'quotes', 'r', 'resize', 'right', 'rowGap', 'rx', 'ry', 'scrollBehavior', 'scrollMargin', 'scrollMarginBlock', 'scrollMarginBlockEnd', 'scrollMarginBlockStart', 'scrollMarginBottom', 'scrollMarginInline', 'scrollMarginInlineEnd', 'scrollMarginInlineStart', 'scrollMarginLeft', 'scrollMarginRight', 'scrollMarginTop', 'scrollPadding', 'scrollPaddingBlock', 'scrollPaddingBlockEnd', 'scrollPaddingBlockStart', 'scrollPaddingBottom', 'scrollPaddingInline', 'scrollPaddingInlineEnd', 'scrollPaddingInlineStart', 'scrollPaddingLeft', 'scrollPaddingRight', 'scrollPaddingTop', 'scrollSnapAlign', 'scrollSnapStop', 'scrollSnapType', 'shapeImageThreshold', 'shapeMargin', 'shapeOutside', 'shapeRendering', 'size', 'speak', 'src', 'stopColor', 'stopOpacity', 'stroke', 'strokeDasharray', 'strokeDashoffset', 'strokeLinecap', 'strokeLinejoin', 'strokeMiterlimit', 'strokeOpacity', 'strokeWidth', 'tabSize', 'tableLayout', 'textAlign', 'textAlignLast', 'textAnchor', 'textCombineUpright', 'textDecoration', 'textDecorationColor', 'textDecorationLine', 'textDecorationSkipInk', 'textDecorationStyle', 'textDecorationThickness', 'textEmphasis', 'textIndent', 'textOrientation', 'textOverflow', 'textRendering', 'textShadow', 'textSizeAdjust', 'textTransform', 'textUnderlinePosition', 'textJustify', 'top', 'touchAction', 'transform', 'transformBox', 'transformOrigin', 'transformStyle', 'transition', 'transitionDelay', 'transitionDuration', 'transitionProperty', 'transitionTimingFunction', 'unicodeBidi', 'unicodeRange', 'userSelect', 'userZoom', 'vectorEffect', 'verticalAlign', 'visibility', 'wrap', 'whiteSpace', 'widows', 'width', 'willChange', 'wordBreak', 'wordSpacing', 'wordWrap', 'writingMode', 'x', 'y', 'zIndex', 'zoom', 'alwaysBounceHorizontal', 'alwaysBounceVertical', 'automaticallyAdjustContentInsets', 'bounces', 'bouncesZoom', 'canCancelContentTouches', 'centerContent', 'contentLayoutStyle', 'contentInset', 'contentInsetAdjustmentBehavior', 'contentOffset', 'decelerationRate', 'directionalLockEnabled', 'disableIntervalMomentum', 'disableScrollViewPanResponder', 'endFillColor', 'fadingEdgeLength', 'horizontal', 'indicatorStyle', 'invertStickyHeaders', 'keyboardDismissMode', 'keyboardShouldPersistTaps', 'maintainVisibleContentPosition', 'maximumZoomScale', 'minimumZoomScale', 'nestedScrollEnabled', 'onContentSizeChange', 'onMomentumScrollBegin', 'onMomentumScrollEnd', 'onScroll', 'onScrollBeginDrag', 'onScrollEndDrag', 'onScrollToTop', 'overScrollMode', 'pagingEnabled', 'persistentScrollbar', 'pinchGestureEnabled', 'refreshControl', 'removeClippedSubviews', 'scrollBarThumbImage', 'scrollEnabled', 'scrollEventThrottle', 'scrollIndicatorInsets', 'scrollPerfTag', 'scrollToOverflowEnabled', 'scrollsToTop', 'DEPRECATED_sendUpdatedChildFrames', 'showsHorizontalScrollIndicator', 'showsVerticalScrollIndicator', 'snapToAlignment', 'snapToEnd', 'snapToInterval', 'snapToOffsets', 'snapToStart', 'stickyHeaderIndices', 'zoomScale', 'borderRightColor', 'backfaceVisibility', 'borderBottomColor', 'borderBottomEndRadius', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'borderBottomStartRadius', 'borderBottomWidth', 'borderColor', 'borderEndColor', 'borderLeftColor', 'borderLeftWidth', 'borderRadius', 'backgroundColor', 'borderRightWidth', 'borderStartColor', 'borderStyle', 'borderTopColor', 'borderTopEndRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderTopStartRadius', 'borderTopWidth', 'borderWidth', 'border', 'opacity', 'elevation', 'shadowColor', 'shadowOffset', 'shadowOpacity', 'shadowRadius', 'alignContent', 'alignItems', 'alignSelf', 'aspectRatio', 'borderBottomWidth', 'borderEndWidth', 'borderLeftWidth', 'borderRightWidth', 'borderStartWidth', 'borderTopWidth', 'borderWidth', 'bottom', 'direction', 'display', 'end', 'flex', 'flexBasis', 'flexDirection', 'flexGrow', 'flexShrink', 'flexWrap', 'height', 'justifyContent', 'left', 'margin', 'marginBottom', 'marginEnd', 'marginHorizontal', 'marginLeft', 'marginRight', 'marginStart', 'marginTop', 'marginVertical', 'maxHeight', 'maxWidth', 'minHeight', 'minWidth', 'overflow', 'overflowX', 'overflowY', 'padding', 'paddingBottom', 'paddingEnd', 'paddingHorizontal', 'paddingLeft', 'paddingRight', 'paddingStart', 'paddingTop', 'paddingVertical', 'position', 'right', 'start', 'top', 'width', 'zIndex', 'borderTopRightRadius', 'backfaceVisibility', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'borderColor', 'borderRadius', 'borderTopLeftRadius', 'backgroundColor', 'borderWidth', 'opacity', 'overflow', 'overflowX', 'overflowY', 'resizeMode', 'tintColor', 'overlayColor', 'transform', 'transformMatrix', 'rotation', 'scaleX', 'scaleY', 'translateX', 'translateY', 'perspective', 'rotate', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'skewX', 'skewY', 'testID', 'decomposedMatrix', 'gridRowStart', 'gridRowEnd', 'gridColumnStart', 'gridColumnEnd', 'lineClamp', 'writingMode', 'objectFit', 'objectPosition', 'placeItems', 'placeSelf']);
533
- const nonStyleAttributes = /*#__PURE__*/new Set(['length', 'parentRule', 'src']);
534
558
  // Function to convert style object to CSS string
535
559
  const styleObjectToCss = styleObj => {
536
560
  return Object.entries(styleObj).map(_ref => {
@@ -546,71 +570,17 @@ const toKebabCase = str => str.replace(/([A-Z])/g, match => '-' + match.toLowerC
546
570
  // // For simplicity, we assume all props not in excludedKeys are style props
547
571
  // return !excludedKeys.has(prop);
548
572
  // };
549
- const isStyleProp = property => {
550
- return StyleProps.has(property) || nonStyleAttributes.has(property);
551
- };
552
- // Function to process and normalize style properties
553
- const processStyleProperty = (property, value, getColor) => {
554
- if (typeof value === 'number' && !NumberProps.has(property)) {
555
- return `${value}px`;
556
- } else if (property.toLowerCase().includes('color')) {
557
- return getColor(value);
558
- } else {
559
- return value;
560
- }
561
- };
562
-
563
- /* eslint-disable @typescript-eslint/no-unused-vars */
564
- let keyframesCounter = 0;
565
- const keyframesCache = /*#__PURE__*/new Map();
566
- const generateKeyframes = animation => {
567
- // Exclure les propriétés qui ne font pas partie des keyframes
568
- const {
569
- duration,
570
- timingFunction,
571
- delay,
572
- iterationCount,
573
- direction,
574
- fillMode,
575
- playState,
576
- ...keyframesDef
577
- } = animation;
578
- // Générer une clé pour le cache basée sur les keyframes
579
- const animationConfigString = JSON.stringify(keyframesDef);
580
- if (keyframesCache.has(animationConfigString)) {
581
- const keyframesName = keyframesCache.get(animationConfigString);
582
- return {
583
- keyframesName,
584
- keyframes: ''
585
- }; // Les keyframes existent déjà
586
- }
587
-
588
- const keyframesName = `animation-${keyframesCounter++}`;
589
- keyframesCache.set(animationConfigString, keyframesName);
590
- const keyframesContent = [];
591
- // Trier les clés pour assurer un ordre cohérent
592
- const keyframeKeys = Object.keys(keyframesDef).sort((a, b) => {
593
- const getPercentage = key => {
594
- if (key === 'from') return 0;
595
- if (key === 'to' || key === 'enter') return 100;
596
- return parseInt(key.replace('%', ''), 10);
597
- };
598
- return getPercentage(a) - getPercentage(b);
599
- });
600
- keyframeKeys.forEach(key => {
601
- const cssKey = key === 'enter' ? 'to' : key; // Remplacer 'enter' par 'to'
602
- const styles = keyframesDef[key];
603
- keyframesContent.push(`${cssKey} { ${styleObjectToCss(styles)} }`);
604
- });
605
- const keyframes = `
606
- @keyframes ${keyframesName} {
607
- ${keyframesContent.join('\n')}
608
- }
609
- `;
610
- return {
611
- keyframesName,
612
- keyframes
613
- };
573
+ //const cssExtraProps: Array<keyof CSSProperties> = [
574
+ const cssExtraProps = ['textJustify', 'lineClamp'];
575
+ // Create a set of all valid CSS properties
576
+ const StyleProps = [... /*#__PURE__*/Object.keys( /*#__PURE__*/document.createElement('div').style), ...cssExtraProps];
577
+ // Create a set of all valid CSS properties
578
+ const StyledProps = /*#__PURE__*/new Set(StyleProps);
579
+ // console.log({
580
+ // props: JSON.stringify(StyleProps.filter((prop) => !cssProperties.has(prop))),
581
+ // });
582
+ const isStyleProp = prop => {
583
+ return (StyledProps.has(prop) || extraKeys.has(prop)) && !includeKeys.has(prop);
614
584
  };
615
585
 
616
586
  const Shadows = {
@@ -706,254 +676,314 @@ const Shadows = {
706
676
  }
707
677
  };
708
678
 
709
- // Element.tsx
710
- const styleSheet = /*#__PURE__*/(() => {
711
- if (typeof document !== 'undefined') {
712
- let styleTag = /*#__PURE__*/document.getElementById('dynamic-styles');
713
- if (!styleTag) {
714
- styleTag = /*#__PURE__*/document.createElement('style');
715
- styleTag.id = 'dynamic-styles';
716
- document.head.appendChild(styleTag);
717
- }
718
- return styleTag.sheet;
719
- }
720
- return null;
721
- })();
722
- /**
723
- * Fonction de hachage simple et rapide basée sur l'algorithme djb2.
724
- * @param {string} str - La chaîne de caractères à hacher.
725
- * @returns {number} - Le hachage sous forme d'entier non signé 32 bits.
726
- */
727
- const hashString = str => {
728
- let hash = 5381;
729
- for (let i = 0; i < str.length; i++) {
730
- // hash * 33 + c
731
- hash = (hash << 5) + hash + str.charCodeAt(i);
732
- // Pour éviter les dépassements, on utilise l'opérateur >>> 0
733
- hash = hash >>> 0;
734
- }
735
- return hash;
736
- };
737
- /**
738
- * Fonction pour hacher un objet en utilisant JSON.stringify et hashString.
739
- * @param {Object} obj - L'objet à hacher.
740
- * @returns {number} - Le hachage de l'objet.
741
- */
742
- const hashObject = obj => {
743
- const str = JSON.stringify(obj);
744
- return hashString(str).toString();
745
- };
746
- const classCache = /*#__PURE__*/new Map();
747
- const cssRulesCache = /*#__PURE__*/new Map();
748
- let classNameCounter = 0;
749
- const generateClassName = styleProps => {
750
- // Extract only relevant, primitive style properties
751
- // Generate a unique hash based on relevantProps
752
- const hash = hashObject(styleProps);
753
- if (classCache.has(hash)) {
754
- return classCache.get(hash);
755
- } else {
756
- const className = 'clz-' + classNameCounter++;
757
- classCache.set(hash, className);
758
- return className;
679
+ /* eslint-disable @typescript-eslint/no-unused-vars */
680
+ let keyframesCounter = 0;
681
+ const keyframesCache = /*#__PURE__*/new Map();
682
+ const generateKeyframes = animation => {
683
+ // Exclure les propriétés qui ne font pas partie des keyframes
684
+ const {
685
+ duration,
686
+ timingFunction,
687
+ delay,
688
+ iterationCount,
689
+ direction,
690
+ fillMode,
691
+ playState,
692
+ ...keyframesDef
693
+ } = animation;
694
+ // Générer une clé pour le cache basée sur les keyframes
695
+ const animationConfigString = JSON.stringify(keyframesDef);
696
+ if (keyframesCache.has(animationConfigString)) {
697
+ const keyframesName = keyframesCache.get(animationConfigString);
698
+ return {
699
+ keyframesName,
700
+ keyframes: ''
701
+ }; // Les keyframes existent déjà
759
702
  }
760
- };
761
- const useDynamicStyles = cssRules => {
762
- useEffect(() => {
763
- if (!styleSheet) return;
764
- cssRules.forEach(rule => {
765
- try {
766
- if (Array.from(styleSheet.cssRules).some(cssRule => cssRule.cssText === rule)) {
767
- return;
768
- }
769
- styleSheet.insertRule(rule, styleSheet.cssRules.length);
770
- } catch (error) {
771
- console.error('Error inserting CSS rule:', rule, error);
772
- }
773
- });
774
- }, [cssRules]);
775
- };
776
- const generateCssRules = (selector, styles, getColor, mediaQueries) => {
777
- const rules = [];
778
- const mainStyles = {};
779
- const nestedMediaQueries = {};
780
- Object.keys(styles).forEach(key => {
781
- const value = styles[key];
782
- if (key.startsWith('@media ')) {
783
- const mediaQuery = key;
784
- if (!nestedMediaQueries[mediaQuery]) {
785
- nestedMediaQueries[mediaQuery] = {};
786
- }
787
- Object.assign(nestedMediaQueries[mediaQuery], value);
788
- } else if (key.startsWith('&:')) {
789
- const pseudoSelector = key.slice(1);
790
- const nestedStyles = styles[key];
791
- const nestedRules = generateCssRules(`${selector}${pseudoSelector}`, nestedStyles, getColor
792
- // Ne pas passer mediaQueries ici
793
- );
794
703
 
795
- rules.push(...nestedRules);
796
- } else {
797
- mainStyles[key] = value;
798
- }
704
+ const keyframesName = `animation-${keyframesCounter++}`;
705
+ keyframesCache.set(animationConfigString, keyframesName);
706
+ const keyframesContent = [];
707
+ // Trier les clés pour assurer un ordre cohérent
708
+ const keyframeKeys = Object.keys(keyframesDef).sort((a, b) => {
709
+ const getPercentage = key => {
710
+ if (key === 'from') return 0;
711
+ if (key === 'to' || key === 'enter') return 100;
712
+ return parseInt(key.replace('%', ''), 10);
713
+ };
714
+ return getPercentage(a) - getPercentage(b);
715
+ });
716
+ keyframeKeys.forEach(key => {
717
+ const cssKey = key === 'enter' ? 'to' : key; // Remplacer 'enter' par 'to'
718
+ const styles = keyframesDef[key];
719
+ keyframesContent.push(`${cssKey} { ${styleObjectToCss(styles)} }`);
799
720
  });
800
- // Gestion des media queries
801
- // eslint-disable-next-line prefer-const
802
- let mediaBreakpoints = {};
803
- if (mediaQueries) {
804
- for (const query in mediaQueries) {
805
- const queries = mediaQueries[query].trim();
806
- mediaBreakpoints['@media ' + queries] = query;
721
+ const keyframes = `
722
+ @keyframes ${keyframesName} {
723
+ ${keyframesContent.join('\n')}
807
724
  }
808
- }
809
- if (Object.keys(mainStyles).length > 0 || Object.keys(nestedMediaQueries).length > 0) {
810
- const processedStyles = {};
811
- for (const property in mainStyles) {
812
- processedStyles[property] = processStyleProperty(property, mainStyles[property], getColor);
725
+ `;
726
+ return {
727
+ keyframesName,
728
+ keyframes
729
+ };
730
+ };
731
+
732
+ /* eslint-disable @typescript-eslint/no-unused-vars */
733
+ class UtilityClassManager {
734
+ constructor(propertyShorthand, maxCacheSize) {
735
+ if (maxCacheSize === void 0) {
736
+ maxCacheSize = 10000;
813
737
  }
814
- const cssRule = `${selector} { ${styleObjectToCss(processedStyles)} }`;
815
- rules.push(cssRule);
816
- for (let mediaQuery in nestedMediaQueries) {
817
- mediaQuery = mediaQuery.trim();
818
- const mediaStyles = nestedMediaQueries[mediaQuery];
819
- const processedMediaStyles = {};
820
- for (const property in mediaStyles) {
821
- processedMediaStyles[property] = processStyleProperty(property, mediaStyles[property], getColor);
822
- }
823
- const cssProperties = styleObjectToCss(processedMediaStyles);
824
- const mediaRule = `${mediaQuery} { ${selector} { ${cssProperties} } }`;
825
- rules.push(mediaRule);
826
- if (mediaBreakpoints[mediaQuery]) {
827
- const breakpoint = mediaBreakpoints[mediaQuery];
828
- const bpRule = `.${breakpoint} ${selector} { ${cssProperties} }`;
829
- rules.push(bpRule);
738
+ this.styleSheet = null;
739
+ this.classCache = new Map();
740
+ this.propertyShorthand = propertyShorthand;
741
+ this.maxCacheSize = maxCacheSize;
742
+ this.initStyleSheet();
743
+ }
744
+ initStyleSheet() {
745
+ if (typeof document !== 'undefined') {
746
+ let styleTag = document.getElementById('utility-classes');
747
+ if (!styleTag) {
748
+ styleTag = document.createElement('style');
749
+ styleTag.id = 'utility-classes';
750
+ document.head.appendChild(styleTag);
830
751
  }
752
+ this.styleSheet = styleTag.sheet;
831
753
  }
832
754
  }
833
- return rules;
834
- };
835
- // Function to apply styles to a component
836
- const computeStyleProps = props => {
837
- const styleProps = {};
838
- const keyframesList = [];
839
- // Gestion de la taille de l'élément
840
- const size = props.height !== undefined && props.width !== undefined && props.height === props.width ? props.height : props.size ? props.size : null;
841
- if (size) {
842
- styleProps.height = styleProps.width = size;
843
- }
844
- // Gestion du padding et de la marge
845
- if (props.paddingHorizontal) {
846
- styleProps.paddingLeft = props.paddingHorizontal;
847
- styleProps.paddingRight = props.paddingHorizontal;
848
- }
849
- if (props.marginHorizontal) {
850
- styleProps.marginLeft = props.marginHorizontal;
851
- styleProps.marginRight = props.marginHorizontal;
755
+ escapeClassName(className) {
756
+ return className.replace(/:/g, '\\:');
852
757
  }
853
- if (props.paddingVertical) {
854
- styleProps.paddingTop = props.paddingVertical;
855
- styleProps.paddingBottom = props.paddingVertical;
856
- }
857
- if (props.marginVertical) {
858
- styleProps.marginTop = props.marginVertical;
859
- styleProps.marginBottom = props.marginVertical;
860
- }
861
- // Application des ombres si spécifié
862
- if (props.shadow) {
863
- if (typeof props.shadow === 'number' || typeof props.shadow === 'boolean') {
864
- const shadowValue = typeof props.shadow === 'number' && Shadows[props.shadow] !== undefined ? props.shadow : 2;
865
- if (Shadows[shadowValue]) {
866
- const shadowColor = Color.hex.rgb(Shadows[shadowValue].shadowColor) || [];
867
- styleProps['boxShadow'] = `${Shadows[shadowValue].shadowOffset.height}px ${Shadows[shadowValue].shadowOffset.width}px ${Shadows[shadowValue].shadowRadius}px rgba(${shadowColor.join(',')},${Shadows[shadowValue].shadowOpacity})`;
758
+ injectRule(cssRule) {
759
+ if (this.styleSheet) {
760
+ try {
761
+ const existingRules = Array.from(this.styleSheet.cssRules).map(rule => rule.cssText);
762
+ if (!existingRules.includes(cssRule)) {
763
+ this.styleSheet.insertRule(cssRule, this.styleSheet.cssRules.length);
764
+ }
765
+ } catch (e) {
766
+ console.error(`Erreur lors de l'insertion de la règle CSS: "${cssRule}"`, e);
868
767
  }
869
- } else {
870
- const shadowColor = Color.hex.rgb(props.shadow.shadowColor) || [];
871
- styleProps['boxShadow'] = `${props.shadow.shadowOffset.height}px ${props.shadow.shadowOffset.width}px ${props.shadow.shadowRadius}px rgba(${shadowColor.join(',')},${props.shadow.shadowOpacity})`;
872
768
  }
873
769
  }
874
- // Gestion des animations
875
- if (props.animate) {
876
- const animation = props.animate;
877
- const {
878
- keyframesName,
879
- keyframes
880
- } = generateKeyframes(animation);
881
- if (keyframes) {
882
- keyframesList.push(keyframes);
770
+ addToCache(key, className) {
771
+ if (this.classCache.size >= this.maxCacheSize) {
772
+ const firstKey = this.classCache.keys().next().value;
773
+ this.classCache.delete(firstKey);
883
774
  }
884
- styleProps.animationName = keyframesName;
885
- styleProps.animationDuration = animation.duration || '1s';
886
- styleProps.animationTimingFunction = animation.timingFunction || 'ease';
887
- styleProps.animationDelay = animation.delay || '0s';
888
- styleProps.animationIterationCount = `${animation.iterationCount || '1'}`;
889
- styleProps.animationDirection = animation.direction || 'normal';
890
- styleProps.animationFillMode = animation.fillMode || 'both';
891
- styleProps.animationPlayState = animation.playState || 'running';
775
+ this.classCache.set(key, className);
892
776
  }
893
- Object.keys(props).forEach(property => {
894
- if (property !== 'style' && (isStyleProp(property) || extraKeys.has(property))) {
895
- // Simple style property
896
- styleProps[property] = props[property];
777
+ /**
778
+ * Génère un ou plusieurs noms de classes pour une propriété et une valeur donnée.
779
+ * @param property La propriété CSS (ex: 'padding', 'color').
780
+ * @param value La valeur de la propriété (ex: '10px', '#fff').
781
+ * @param context Le contexte de la classe ('base', 'pseudo', 'media').
782
+ * @param modifier Le modificateur pour les pseudo-classes ou media queries (ex: 'hover', 'sm').
783
+ * @param getColor Fonction pour convertir les couleurs si nécessaire.
784
+ * @param mediaQueries Un tableau de media queries associées (utilisé uniquement pour le contexte 'media').
785
+ * @returns Un tableau de noms de classes générés.
786
+ */
787
+ getClassNames(property, value, context, modifier, getColor, mediaQueries) {
788
+ if (context === void 0) {
789
+ context = 'base';
897
790
  }
898
- });
899
- return {
900
- styleProps,
901
- keyframes: keyframesList
791
+ if (modifier === void 0) {
792
+ modifier = '';
793
+ }
794
+ if (getColor === void 0) {
795
+ getColor = color => color;
796
+ }
797
+ if (mediaQueries === void 0) {
798
+ mediaQueries = [];
799
+ }
800
+ let processedValue = value;
801
+ // Si la propriété est une couleur, la convertir en valeur hexadécimale ou RGB
802
+ if (property.toLowerCase().includes('color')) {
803
+ processedValue = getColor(value);
804
+ }
805
+ let key = `${property}:${processedValue}`;
806
+ if (modifier) {
807
+ key = `${property}:${processedValue}|${modifier}`;
808
+ }
809
+ if (this.classCache.has(key)) {
810
+ return [this.classCache.get(key)];
811
+ }
812
+ // Générer un nom de classe unique avec le modificateur
813
+ let shorthand = this.propertyShorthand[property];
814
+ if (!shorthand) {
815
+ shorthand = property.replace(/([A-Z])/g, '-$1').toLowerCase();
816
+ }
817
+ // console.log({ shorthand, property, processedValue });
818
+ // Normaliser la valeur pour le nom de classe
819
+ let normalizedValue = processedValue.toString().replace(/\./g, 'p') // Remplacer les points par 'p'
820
+ .replace(/\s+/g, '-') // Remplacer les espaces par '-'
821
+ .replace(/[^a-zA-Z0-9\-]/g, ''); // Supprimer les autres caractères spéciaux
822
+ let baseClassName = `${shorthand}-${normalizedValue}`;
823
+ // Préfixer les noms de classe pour les pseudo-classes et media queries
824
+ let classNames = [];
825
+ if (context === 'pseudo' && modifier) {
826
+ // Pseudo-class : ajouter '-modifier' suffix
827
+ const pseudoClassName = `${baseClassName}-${modifier}`;
828
+ classNames.push(pseudoClassName);
829
+ } else if (context === 'media' && modifier) {
830
+ // Media query : générer une classe pour chaque media query associée
831
+ mediaQueries.forEach(() => {
832
+ const mediaClassName = `${modifier}:${baseClassName}`;
833
+ classNames.push(mediaClassName);
834
+ });
835
+ } else {
836
+ classNames.push(baseClassName);
837
+ }
838
+ // Convertir camelCase en kebab-case
839
+ const cssProperty = property.replace(/([A-Z])/g, '-$1').toLowerCase();
840
+ let valueForCss = processedValue;
841
+ // Ajouter des unités si nécessaire
842
+ if (typeof valueForCss === 'number') {
843
+ const propertiesWithUnits = ['width', 'height', 'padding', 'margin', 'padding-left', 'padding-right', 'padding-top', 'padding-bottom', 'margin-left', 'margin-right', 'margin-top', 'margin-bottom', 'transform', 'transition'];
844
+ if (propertiesWithUnits.includes(cssProperty)) {
845
+ valueForCss = `${valueForCss}px`;
846
+ }
847
+ }
848
+ // Construire les règles CSS pour chaque classe générée
849
+ classNames.forEach(className => {
850
+ const escapedClassName = this.escapeClassName(className);
851
+ let cssRules = [];
852
+ switch (context) {
853
+ case 'base':
854
+ cssRules.push(`.${escapedClassName} { ${cssProperty}: ${valueForCss}; }`);
855
+ break;
856
+ case 'pseudo':
857
+ // Appliquer la pseudo-classe directement à la classe principale
858
+ cssRules.push(`.${escapedClassName} { ${cssProperty}: ${valueForCss}; }`);
859
+ break;
860
+ case 'media':
861
+ // Les media queries sont gérées séparément
862
+ mediaQueries.forEach(mq => {
863
+ cssRules.push(`@media ${mq} { .${escapedClassName} { ${cssProperty}: ${valueForCss}; } }`);
864
+ if (window.isResponsive === true) {
865
+ cssRules.push(`.${modifier} { .${escapedClassName} { ${cssProperty}: ${valueForCss}; } }`);
866
+ }
867
+ });
868
+ break;
869
+ default:
870
+ cssRules.push(`.${escapedClassName} { ${cssProperty}: ${valueForCss}; }`);
871
+ }
872
+ console.log({
873
+ mediaQueries,
874
+ cssRules,
875
+ modifier
876
+ });
877
+ // Injecter les règles CSS
878
+ cssRules.forEach(rule => this.injectRule(rule));
879
+ // Ajouter au cache
880
+ this.addToCache(key, className);
881
+ });
882
+ return classNames;
883
+ }
884
+ }
885
+ /**
886
+ * Mappe un événement React à une pseudo-classe CSS.
887
+ * @param event L'événement React (ex: 'hover', 'active')
888
+ * @returns La pseudo-classe CSS correspondante ou null si non supporté.
889
+ */
890
+ const mapEventToPseudo = event => {
891
+ const eventMap = {
892
+ hover: 'hover',
893
+ active: 'active',
894
+ focus: 'focus',
895
+ visited: 'visited'
902
896
  };
897
+ return eventMap[event] || null;
903
898
  };
904
- // Function to apply styles to a component
905
- const applyStyle = function (props, mediaQueries, devices, depth,
906
- // Add a depth parameter
907
- maxDepth // Set a maximum depth
908
- ) {
909
- if (depth === void 0) {
910
- depth = 0;
911
- }
912
- if (maxDepth === void 0) {
913
- maxDepth = 10;
914
- }
915
- if (depth > maxDepth) {
916
- console.error('Maximum recursion depth reached in applyStyle');
917
- return {
918
- styleProps: {},
919
- keyframes: []
920
- };
899
+ /**
900
+ * Génère des abréviations pour les propriétés CSS.
901
+ * @param styledProps Tableau des propriétés CSS à abréger.
902
+ * @returns Un objet mappant chaque propriété CSS à son abréviation.
903
+ */
904
+ function generatePropertyShorthand(styledProps) {
905
+ const propertyShorthand = {};
906
+ const usedAbbreviations = new Set();
907
+ /**
908
+ * Génère une abréviation unique pour une propriété CSS donnée.
909
+ * @param prop La propriété CSS à abréger.
910
+ * @returns L'abréviation unique générée.
911
+ */
912
+ function generateAbbreviation(prop) {
913
+ const first = prop[0].toLowerCase();
914
+ const last = prop[prop.length - 1].toLowerCase();
915
+ const middle = prop.slice(1, -1).replace(/[a-z]/g, '').toLowerCase();
916
+ let abbr = first + middle + last;
917
+ if (abbr.length < 2) {
918
+ abbr = prop.slice(0, 2).toLowerCase();
919
+ }
920
+ let i = 0;
921
+ let uniqueAbbr = abbr;
922
+ while (usedAbbreviations.has(uniqueAbbr)) {
923
+ i++;
924
+ uniqueAbbr = abbr + prop.slice(-i, prop.length).toLowerCase();
925
+ }
926
+ usedAbbreviations.add(uniqueAbbr);
927
+ return uniqueAbbr;
928
+ }
929
+ for (const prop of styledProps) {
930
+ propertyShorthand[prop] = generateAbbreviation(prop);
921
931
  }
922
- const styleProps = {};
923
- const keyframesList = [];
932
+ return propertyShorthand;
933
+ }
934
+ const propertyShorthand = /*#__PURE__*/generatePropertyShorthand(StyleProps);
935
+ const utilityClassManager = /*#__PURE__*/new UtilityClassManager(propertyShorthand);
936
+ const extractUtilityClasses = (props, getColor, mediaQueries, devices) => {
937
+ const classes = [];
938
+ // Styles calculés basés sur les props
939
+ const computedStyles = {};
924
940
  // Gestion de la taille de l'élément
925
941
  const size = props.height !== undefined && props.width !== undefined && props.height === props.width ? props.height : props.size ? props.size : null;
926
942
  if (size) {
927
- styleProps.height = styleProps.width = size;
943
+ const sizeValue = typeof size === 'number' ? `${size}px` : size;
944
+ computedStyles.width = sizeValue;
945
+ computedStyles.height = sizeValue;
928
946
  }
929
947
  // Gestion du padding et de la marge
930
948
  if (props.paddingHorizontal) {
931
- styleProps.paddingLeft = props.paddingHorizontal;
932
- styleProps.paddingRight = props.paddingHorizontal;
949
+ const paddingH = typeof props.paddingHorizontal === 'number' ? `${props.paddingHorizontal}px` : props.paddingHorizontal;
950
+ computedStyles.paddingLeft = paddingH;
951
+ computedStyles.paddingRight = paddingH;
933
952
  }
934
953
  if (props.marginHorizontal) {
935
- styleProps.marginLeft = props.marginHorizontal;
936
- styleProps.marginRight = props.marginHorizontal;
954
+ const marginH = typeof props.marginHorizontal === 'number' ? `${props.marginHorizontal}px` : props.marginHorizontal;
955
+ computedStyles.marginLeft = marginH;
956
+ computedStyles.marginRight = marginH;
937
957
  }
938
958
  if (props.paddingVertical) {
939
- styleProps.paddingTop = props.paddingVertical;
940
- styleProps.paddingBottom = props.paddingVertical;
959
+ const paddingV = typeof props.paddingVertical === 'number' ? `${props.paddingVertical}px` : props.paddingVertical;
960
+ computedStyles.paddingTop = paddingV;
961
+ computedStyles.paddingBottom = paddingV;
941
962
  }
942
963
  if (props.marginVertical) {
943
- styleProps.marginTop = props.marginVertical;
944
- styleProps.marginBottom = props.marginVertical;
964
+ const marginV = typeof props.marginVertical === 'number' ? `${props.marginVertical}px` : props.marginVertical;
965
+ computedStyles.marginTop = marginV;
966
+ computedStyles.marginBottom = marginV;
945
967
  }
946
968
  // Application des ombres si spécifié
947
969
  if (props.shadow) {
948
- if (typeof props.shadow === 'number' || typeof props.shadow === 'boolean') {
949
- const shadowValue = typeof props.shadow === 'number' && Shadows[props.shadow] !== undefined ? props.shadow : 2;
950
- if (Shadows[shadowValue]) {
951
- const shadowColor = Color.hex.rgb(Shadows[shadowValue].shadowColor) || [];
952
- styleProps['boxShadow'] = `${Shadows[shadowValue].shadowOffset.height}px ${Shadows[shadowValue].shadowOffset.width}px ${Shadows[shadowValue].shadowRadius}px rgba(${shadowColor.join(',')},${Shadows[shadowValue].shadowOpacity})`;
953
- }
970
+ let shadowValue;
971
+ if (typeof props.shadow === 'number' && Shadows[props.shadow] !== undefined) {
972
+ shadowValue = props.shadow;
973
+ } else if (typeof props.shadow === 'boolean') {
974
+ shadowValue = props.shadow ? 2 : 0;
954
975
  } else {
955
- const shadowColor = Color.hex.rgb(props.shadow.shadowColor) || [];
956
- styleProps['boxShadow'] = `${props.shadow.shadowOffset.height}px ${props.shadow.shadowOffset.width}px ${props.shadow.shadowRadius}px rgba(${shadowColor.join(',')},${props.shadow.shadowOpacity})`;
976
+ shadowValue = 2;
977
+ }
978
+ if (Shadows[shadowValue]) {
979
+ const shadowColor = Shadows[shadowValue].shadowColor;
980
+ const shadowOpacity = Shadows[shadowValue].shadowOpacity;
981
+ const shadowOffset = Shadows[shadowValue].shadowOffset;
982
+ const shadowRadius = Shadows[shadowValue].shadowRadius;
983
+ // Convertir la couleur en rgba
984
+ const rgb = Color.hex.rgb(shadowColor);
985
+ const rgbaColor = `rgba(${rgb.join(',')}, ${shadowOpacity})`;
986
+ computedStyles.boxShadow = `${shadowOffset.height}px ${shadowOffset.width}px ${shadowRadius}px ${rgbaColor}`;
957
987
  }
958
988
  }
959
989
  // Gestion des animations
@@ -963,119 +993,119 @@ maxDepth // Set a maximum depth
963
993
  keyframesName,
964
994
  keyframes
965
995
  } = generateKeyframes(animation);
966
- if (keyframes) {
967
- keyframesList.push(keyframes);
996
+ if (keyframes && typeof document !== 'undefined') {
997
+ utilityClassManager.injectRule(keyframes);
968
998
  }
969
- styleProps.animationName = keyframesName;
970
- styleProps.animationDuration = animation.duration || '1s';
971
- styleProps.animationTimingFunction = animation.timingFunction || 'ease';
972
- styleProps.animationDelay = animation.delay || '0s';
973
- styleProps.animationIterationCount = `${animation.iterationCount || '1'}`;
974
- styleProps.animationDirection = animation.direction || 'normal';
975
- styleProps.animationFillMode = animation.fillMode || 'both';
976
- styleProps.animationPlayState = animation.playState || 'running';
999
+ computedStyles.animationName = keyframesName;
1000
+ if (animation.duration) computedStyles.animationDuration = animation.duration;
1001
+ if (animation.timingFunction) computedStyles.animationTimingFunction = animation.timingFunction;
1002
+ if (animation.delay) computedStyles.animationDelay = animation.delay;
1003
+ if (animation.iterationCount !== undefined) computedStyles.animationIterationCount = `${animation.iterationCount}`;
1004
+ if (animation.direction) computedStyles.animationDirection = animation.direction;
1005
+ if (animation.fillMode) computedStyles.animationFillMode = animation.fillMode;
1006
+ if (animation.playState) computedStyles.animationPlayState = animation.playState;
977
1007
  }
1008
+ /**
1009
+ * Génère des classes utilitaires pour un ensemble de styles.
1010
+ * @param styles Les styles à transformer en classes utilitaires.
1011
+ * @param context Le contexte des styles ('base', 'pseudo', 'media').
1012
+ * @param modifier Le modificateur pour les pseudo-classes ou media queries.
1013
+ */
1014
+ const generateUtilityClasses = function (styles, context, modifier) {
1015
+ if (context === void 0) {
1016
+ context = 'base';
1017
+ }
1018
+ if (modifier === void 0) {
1019
+ modifier = '';
1020
+ }
1021
+ console.log({
1022
+ styles
1023
+ });
1024
+ Object.keys(styles).forEach(property => {
1025
+ const value = styles[property];
1026
+ let mediaQueriesForClass = [];
1027
+ if (context === 'media') {
1028
+ // 'modifier' peut être un breakpoint ou un dispositif
1029
+ if (mediaQueries[modifier]) {
1030
+ mediaQueriesForClass = [mediaQueries[modifier]];
1031
+ } else if (devices[modifier]) {
1032
+ mediaQueriesForClass = devices[modifier].map(mq => mediaQueries[mq]).filter(mq => mq); // Filtrer les media queries valides
1033
+ }
1034
+ }
1035
+
1036
+ if (value !== undefined) {
1037
+ const classNames = utilityClassManager.getClassNames(property, value, context, modifier, getColor, mediaQueriesForClass);
1038
+ classes.push(...classNames);
1039
+ } else {
1040
+ console.error({
1041
+ styles,
1042
+ value,
1043
+ property
1044
+ });
1045
+ debugger;
1046
+ }
1047
+ });
1048
+ };
1049
+ // Générer des classes utilitaires pour les styles calculés
1050
+ generateUtilityClasses(computedStyles, 'base');
1051
+ // Parcourir toutes les propriétés de style et générer des classes utilitaires
978
1052
  Object.keys(props).forEach(property => {
979
- if (property !== 'style' && (isStyleProp(property) || extraKeys.has(property))) {
1053
+ if (property !== 'style' && (isStyleProp(property) || ['on', 'media'].includes(property))) {
980
1054
  const value = props[property];
981
1055
  if (typeof value === 'object' && value !== null) {
982
1056
  if (property === 'on') {
983
- for (const event in value) {
984
- if (!styleProps[`&:${event}`]) {
985
- styleProps[`&:${event}`] = {};
1057
+ // Styles liés aux événements (pseudo-classes)
1058
+ Object.keys(value).forEach(event => {
1059
+ const eventStyles = value[event];
1060
+ // Séparer les propriétés de transition et les autres propriétés
1061
+ const transitionStyles = {};
1062
+ const nonTransitionStyles = {};
1063
+ Object.keys(eventStyles).forEach(prop => {
1064
+ if (prop === 'transition') {
1065
+ transitionStyles[prop] = eventStyles[prop];
1066
+ } else {
1067
+ nonTransitionStyles[prop] = eventStyles[prop];
1068
+ }
1069
+ });
1070
+ // Appliquer les transitions aux styles de base
1071
+ if (Object.keys(transitionStyles).length > 0) {
1072
+ generateUtilityClasses(transitionStyles, 'base');
986
1073
  }
987
- const nestedResult = computeStyleProps(value[event]);
988
- Object.assign(styleProps[`&:${event}`], nestedResult.styleProps);
989
- keyframesList.push(...(nestedResult.keyframes || []));
990
- }
991
- } else if (property === 'media') {
992
- for (const screenOrDevices in value) {
993
- const mediaValue = value[screenOrDevices];
994
- if (mediaQueries[screenOrDevices]) {
995
- const mediaQuery = '@media ' + mediaQueries[screenOrDevices];
996
- if (!styleProps[mediaQuery]) {
997
- styleProps[mediaQuery] = {};
1074
+ // Générer les classes pour les pseudo-classes
1075
+ if (Object.keys(nonTransitionStyles).length > 0) {
1076
+ const pseudo = mapEventToPseudo(event);
1077
+ if (pseudo) {
1078
+ generateUtilityClasses(nonTransitionStyles, 'pseudo', pseudo);
998
1079
  }
999
- const nestedResult = computeStyleProps(mediaValue);
1000
- Object.assign(styleProps[mediaQuery], nestedResult.styleProps);
1001
- keyframesList.push(...(nestedResult.keyframes || []));
1002
- } else if (devices[screenOrDevices]) {
1003
- const deviceScreens = devices[screenOrDevices];
1004
- deviceScreens.forEach(screen => {
1005
- if (mediaQueries[screen]) {
1006
- const mediaQuery = '@media ' + mediaQueries[screen];
1007
- if (!styleProps[mediaQuery]) {
1008
- styleProps[mediaQuery] = {};
1009
- }
1010
- const nestedResult = computeStyleProps(mediaValue);
1011
- Object.assign(styleProps[mediaQuery], nestedResult.styleProps);
1012
- keyframesList.push(...(nestedResult.keyframes || []));
1013
- }
1014
- });
1015
1080
  }
1016
- }
1017
- } else {
1018
- // For other nested styles, exclude 'on' and 'media'
1019
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1020
- const {
1021
- on,
1022
- media,
1023
- ...nestedProps
1024
- } = value;
1025
- const nestedResult = computeStyleProps(nestedProps);
1026
- styleProps[property] = nestedResult.styleProps;
1027
- keyframesList.push(...(nestedResult.keyframes || []));
1081
+ });
1082
+ } else if (property === 'media') {
1083
+ // Styles conditionnels basés sur les media queries ou devices
1084
+ Object.keys(value).forEach(screenOrDevice => {
1085
+ const mediaStyles = value[screenOrDevice];
1086
+ generateUtilityClasses(mediaStyles, 'media', screenOrDevice);
1087
+ });
1028
1088
  }
1029
1089
  } else {
1030
- // Simple style property
1031
- styleProps[property] = value;
1090
+ // Générer une classe utilitaire pour cette propriété et valeur
1091
+ if (value !== undefined) {
1092
+ const classNames = utilityClassManager.getClassNames(property, value, 'base', '', getColor);
1093
+ classes.push(...classNames);
1094
+ } else {
1095
+ console.error({
1096
+ value,
1097
+ property
1098
+ });
1099
+ debugger;
1100
+ }
1032
1101
  }
1033
1102
  }
1034
1103
  });
1035
- return {
1036
- styleProps,
1037
- keyframes: keyframesList
1038
- };
1039
- };
1040
- const getStyledProps = (props, getColor, mediaQueries, devices) => {
1041
- const {
1042
- styleProps,
1043
- keyframes
1044
- } = applyStyle(props, mediaQueries, devices);
1045
- const className = generateClassName(styleProps);
1046
- let cssRules = [];
1047
- if (cssRulesCache.has(className)) {
1048
- cssRules = cssRulesCache.get(className);
1049
- } else {
1050
- cssRules = generateCssRules(`.${className}`, styleProps, getColor, mediaQueries);
1051
- if (keyframes && keyframes.length > 0) {
1052
- cssRules = keyframes.concat(cssRules);
1053
- }
1054
- cssRulesCache.set(className, cssRules);
1055
- }
1056
- const {
1057
- style,
1058
- ...restProps
1059
- } = props;
1060
- const newProps = Object.keys(restProps).reduce((acc, key) => {
1061
- if (!excludedKeys.has(key) && !isStyleProp(key) || includeKeys.has(key)) {
1062
- acc[key] = restProps[key];
1063
- }
1064
- return acc;
1065
- }, {});
1066
- if (className) {
1067
- newProps.className = className;
1068
- }
1069
- if (style) {
1070
- newProps.style = style;
1071
- }
1072
- return {
1073
- newProps,
1074
- className,
1075
- cssRules
1076
- };
1104
+ return classes;
1077
1105
  };
1078
- const Element = props => {
1106
+
1107
+ /* eslint-disable @typescript-eslint/no-unused-vars */
1108
+ const Element = /*#__PURE__*/React.memo(props => {
1079
1109
  const {
1080
1110
  onPress,
1081
1111
  ...rest
@@ -1087,18 +1117,40 @@ const Element = props => {
1087
1117
  mediaQueries,
1088
1118
  devices
1089
1119
  } = useResponsiveContext();
1090
- const {
1091
- newProps,
1092
- cssRules
1093
- } = useMemo(() => getStyledProps(rest, getColor, mediaQueries, devices), [rest, getColor, mediaQueries, devices]);
1120
+ console.log({
1121
+ rest
1122
+ });
1123
+ // Extraire les classes utilitaires
1124
+ const utilityClasses = useMemo(() => extractUtilityClasses(rest, getColor, mediaQueries, devices), [rest, getColor, mediaQueries, devices]);
1125
+ // Gérer les événements
1126
+ const newProps = {};
1094
1127
  if (onPress) {
1095
1128
  newProps.onClick = onPress;
1096
1129
  }
1097
- useDynamicStyles(cssRules);
1130
+ // Ajouter les classes utilitaires
1131
+ if (utilityClasses.length > 0) {
1132
+ newProps.className = utilityClasses.join(' ');
1133
+ }
1134
+ // Ajouter le reste des props qui ne sont pas des styles
1135
+ const {
1136
+ style,
1137
+ children,
1138
+ ...otherProps
1139
+ } = rest;
1140
+ Object.keys(otherProps).forEach(key => {
1141
+ if (!excludedKeys.has(key) && !isStyleProp(key) || includeKeys.has(key)) {
1142
+ newProps[key] = otherProps[key];
1143
+ }
1144
+ });
1145
+ // Ajouter les styles inline s'il y en a
1146
+ if (style) {
1147
+ newProps.style = style;
1148
+ }
1149
+ // Définir le composant HTML
1098
1150
  const Component = newProps.as || 'div';
1099
1151
  delete newProps.as;
1100
- return /*#__PURE__*/React.createElement(Component, Object.assign({}, newProps), props.children);
1101
- };
1152
+ return /*#__PURE__*/React.createElement(Component, Object.assign({}, newProps), children);
1153
+ });
1102
1154
 
1103
1155
  const View = /*#__PURE__*/React.memo(props => /*#__PURE__*/React.createElement(Element, Object.assign({}, props)));
1104
1156
  const Div = View;