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.
- package/dist/appstudio.cjs.development.js +464 -412
- package/dist/appstudio.cjs.development.js.map +1 -1
- package/dist/appstudio.cjs.production.min.js +1 -1
- package/dist/appstudio.cjs.production.min.js.map +1 -1
- package/dist/appstudio.esm.js +464 -412
- package/dist/appstudio.esm.js.map +1 -1
- package/dist/appstudio.umd.development.js +464 -412
- package/dist/appstudio.umd.development.js.map +1 -1
- package/dist/appstudio.umd.production.min.js +1 -1
- package/dist/appstudio.umd.production.min.js.map +1 -1
- package/dist/components/Element.d.ts +1 -0
- package/dist/providers/Responsive.d.ts +1 -6
- package/dist/utils/cssClass.d.ts +2 -0
- package/dist/utils/cssProperties.d.ts +2 -0
- package/dist/utils/style.d.ts +3 -2
- package/package.json +4 -2
|
@@ -9,6 +9,30 @@ var React__default = _interopDefault(React);
|
|
|
9
9
|
var Color = _interopDefault(require('color-convert'));
|
|
10
10
|
|
|
11
11
|
const palette = {
|
|
12
|
+
whiteAlpha: {
|
|
13
|
+
50: 'rgba(255, 255, 255, 0.04)',
|
|
14
|
+
100: 'rgba(255, 255, 255, 0.06)',
|
|
15
|
+
200: 'rgba(255, 255, 255, 0.08)',
|
|
16
|
+
300: 'rgba(255, 255, 255, 0.16)',
|
|
17
|
+
400: 'rgba(255, 255, 255, 0.24)',
|
|
18
|
+
500: 'rgba(255, 255, 255, 0.36)',
|
|
19
|
+
600: 'rgba(255, 255, 255, 0.48)',
|
|
20
|
+
700: 'rgba(255, 255, 255, 0.64)',
|
|
21
|
+
800: 'rgba(255, 255, 255, 0.80)',
|
|
22
|
+
900: 'rgba(255, 255, 255, 0.92)'
|
|
23
|
+
},
|
|
24
|
+
blackAlpha: {
|
|
25
|
+
50: 'rgba(0, 0, 0, 0.04)',
|
|
26
|
+
100: 'rgba(0, 0, 0, 0.06)',
|
|
27
|
+
200: 'rgba(0, 0, 0, 0.08)',
|
|
28
|
+
300: 'rgba(0, 0, 0, 0.16)',
|
|
29
|
+
400: 'rgba(0, 0, 0, 0.24)',
|
|
30
|
+
500: 'rgba(0, 0, 0, 0.36)',
|
|
31
|
+
600: 'rgba(0, 0, 0, 0.48)',
|
|
32
|
+
700: 'rgba(0, 0, 0, 0.64)',
|
|
33
|
+
800: 'rgba(0, 0, 0, 0.80)',
|
|
34
|
+
900: 'rgba(0, 0, 0, 0.92)'
|
|
35
|
+
},
|
|
12
36
|
white: {
|
|
13
37
|
50: 'rgba(255, 255, 255, 0.04)',
|
|
14
38
|
100: 'rgba(255, 255, 255, 0.08)',
|
|
@@ -471,6 +495,7 @@ const ThemeProvider = _ref => {
|
|
|
471
495
|
}, children);
|
|
472
496
|
};
|
|
473
497
|
|
|
498
|
+
// ResponsiveContext.tsx
|
|
474
499
|
const defaultBreakpointsConfig = {
|
|
475
500
|
xs: 0,
|
|
476
501
|
sm: 340,
|
|
@@ -478,37 +503,41 @@ const defaultBreakpointsConfig = {
|
|
|
478
503
|
lg: 1080,
|
|
479
504
|
xl: 1300
|
|
480
505
|
};
|
|
481
|
-
|
|
482
|
-
mobile: ['xs', 'sm'],
|
|
483
|
-
tablet: ['md', 'lg'],
|
|
484
|
-
desktop: ['lg', 'xl']
|
|
485
|
-
};
|
|
506
|
+
// Inclure la fonction corrigée getMediaQueries ici
|
|
486
507
|
const getMediaQueries = b => {
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
if (b) a.max = b.min;
|
|
498
|
-
return b;
|
|
499
|
-
});
|
|
508
|
+
const sortedBreakpoints = Object.keys(b).map(key => ({
|
|
509
|
+
breakpoint: key,
|
|
510
|
+
min: b[key],
|
|
511
|
+
max: 0
|
|
512
|
+
})).sort((a, b) => a.min - b.min);
|
|
513
|
+
// Définir les valeurs max pour chaque breakpoint sauf le dernier
|
|
514
|
+
for (let i = 0; i < sortedBreakpoints.length - 1; i++) {
|
|
515
|
+
sortedBreakpoints[i].max = sortedBreakpoints[i + 1].min - 1;
|
|
516
|
+
}
|
|
517
|
+
// Le dernier breakpoint n'a pas de max
|
|
500
518
|
const query = {};
|
|
501
|
-
|
|
502
|
-
|
|
519
|
+
sortedBreakpoints.forEach(sizeScreen => {
|
|
520
|
+
let mediaQuery = 'only screen';
|
|
521
|
+
if (sizeScreen.min !== undefined && sizeScreen.min >= 0) {
|
|
522
|
+
mediaQuery += ` and (min-width: ${sizeScreen.min}px)`;
|
|
523
|
+
}
|
|
524
|
+
if (sizeScreen.max !== undefined && sizeScreen.max > 0) {
|
|
525
|
+
mediaQuery += ` and (max-width: ${sizeScreen.max}px)`;
|
|
526
|
+
}
|
|
527
|
+
query[sizeScreen.breakpoint] = mediaQuery.trim();
|
|
503
528
|
});
|
|
504
529
|
return query;
|
|
505
530
|
};
|
|
506
|
-
const
|
|
531
|
+
const defaultDeviceConfig = {
|
|
532
|
+
mobile: ['xs', 'sm'],
|
|
533
|
+
tablet: ['md', 'lg'],
|
|
534
|
+
desktop: ['lg', 'xl']
|
|
535
|
+
};
|
|
536
|
+
const ResponsiveContext = /*#__PURE__*/React.createContext({
|
|
507
537
|
breakpoints: defaultBreakpointsConfig,
|
|
508
538
|
devices: defaultDeviceConfig,
|
|
509
539
|
mediaQueries: /*#__PURE__*/getMediaQueries(defaultBreakpointsConfig)
|
|
510
|
-
};
|
|
511
|
-
const ResponsiveContext = /*#__PURE__*/React.createContext(defaultScreenConfig);
|
|
540
|
+
});
|
|
512
541
|
const useResponsiveContext = () => React.useContext(ResponsiveContext);
|
|
513
542
|
const ResponsiveProvider = _ref => {
|
|
514
543
|
let {
|
|
@@ -526,7 +555,6 @@ const ResponsiveProvider = _ref => {
|
|
|
526
555
|
};
|
|
527
556
|
|
|
528
557
|
// List of numeric properties that don't need 'px' suffix
|
|
529
|
-
const NumberProps = /*#__PURE__*/new Set(['numberOfLines', 'fontWeight', 'timeStamp', 'flex', 'flexGrow', 'flexShrink', 'order', 'zIndex', 'aspectRatio', 'shadowOpacity', 'shadowRadius', 'scale', 'opacity', 'min', 'max', 'now']);
|
|
530
558
|
// Keys to exclude when passing props to the component
|
|
531
559
|
const excludedKeys = /*#__PURE__*/new Set(['on', 'shadow', 'only', 'media', 'css', 'size', 'paddingHorizontal', 'paddingVertical', 'marginHorizontal', 'marginVertical', 'animate']);
|
|
532
560
|
// Keys to exclude when passing props to the component
|
|
@@ -534,10 +562,6 @@ const extraKeys = /*#__PURE__*/new Set(['on', 'shadow', 'only', 'media', 'css'])
|
|
|
534
562
|
const includeKeys = /*#__PURE__*/new Set(['src', 'alt', 'style', 'as']);
|
|
535
563
|
|
|
536
564
|
// styleHelpers.ts
|
|
537
|
-
// Excluded keys imported from constants.ts
|
|
538
|
-
// import { excludedKeys } from './constants';
|
|
539
|
-
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']);
|
|
540
|
-
const nonStyleAttributes = /*#__PURE__*/new Set(['length', 'parentRule', 'src']);
|
|
541
565
|
// Function to convert style object to CSS string
|
|
542
566
|
const styleObjectToCss = styleObj => {
|
|
543
567
|
return Object.entries(styleObj).map(_ref => {
|
|
@@ -553,71 +577,17 @@ const toKebabCase = str => str.replace(/([A-Z])/g, match => '-' + match.toLowerC
|
|
|
553
577
|
// // For simplicity, we assume all props not in excludedKeys are style props
|
|
554
578
|
// return !excludedKeys.has(prop);
|
|
555
579
|
// };
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
|
|
570
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
571
|
-
let keyframesCounter = 0;
|
|
572
|
-
const keyframesCache = /*#__PURE__*/new Map();
|
|
573
|
-
const generateKeyframes = animation => {
|
|
574
|
-
// Exclure les propriétés qui ne font pas partie des keyframes
|
|
575
|
-
const {
|
|
576
|
-
duration,
|
|
577
|
-
timingFunction,
|
|
578
|
-
delay,
|
|
579
|
-
iterationCount,
|
|
580
|
-
direction,
|
|
581
|
-
fillMode,
|
|
582
|
-
playState,
|
|
583
|
-
...keyframesDef
|
|
584
|
-
} = animation;
|
|
585
|
-
// Générer une clé pour le cache basée sur les keyframes
|
|
586
|
-
const animationConfigString = JSON.stringify(keyframesDef);
|
|
587
|
-
if (keyframesCache.has(animationConfigString)) {
|
|
588
|
-
const keyframesName = keyframesCache.get(animationConfigString);
|
|
589
|
-
return {
|
|
590
|
-
keyframesName,
|
|
591
|
-
keyframes: ''
|
|
592
|
-
}; // Les keyframes existent déjà
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
const keyframesName = `animation-${keyframesCounter++}`;
|
|
596
|
-
keyframesCache.set(animationConfigString, keyframesName);
|
|
597
|
-
const keyframesContent = [];
|
|
598
|
-
// Trier les clés pour assurer un ordre cohérent
|
|
599
|
-
const keyframeKeys = Object.keys(keyframesDef).sort((a, b) => {
|
|
600
|
-
const getPercentage = key => {
|
|
601
|
-
if (key === 'from') return 0;
|
|
602
|
-
if (key === 'to' || key === 'enter') return 100;
|
|
603
|
-
return parseInt(key.replace('%', ''), 10);
|
|
604
|
-
};
|
|
605
|
-
return getPercentage(a) - getPercentage(b);
|
|
606
|
-
});
|
|
607
|
-
keyframeKeys.forEach(key => {
|
|
608
|
-
const cssKey = key === 'enter' ? 'to' : key; // Remplacer 'enter' par 'to'
|
|
609
|
-
const styles = keyframesDef[key];
|
|
610
|
-
keyframesContent.push(`${cssKey} { ${styleObjectToCss(styles)} }`);
|
|
611
|
-
});
|
|
612
|
-
const keyframes = `
|
|
613
|
-
@keyframes ${keyframesName} {
|
|
614
|
-
${keyframesContent.join('\n')}
|
|
615
|
-
}
|
|
616
|
-
`;
|
|
617
|
-
return {
|
|
618
|
-
keyframesName,
|
|
619
|
-
keyframes
|
|
620
|
-
};
|
|
580
|
+
//const cssExtraProps: Array<keyof CSSProperties> = [
|
|
581
|
+
const cssExtraProps = ['textJustify', 'lineClamp'];
|
|
582
|
+
// Create a set of all valid CSS properties
|
|
583
|
+
const StyleProps = [... /*#__PURE__*/Object.keys( /*#__PURE__*/document.createElement('div').style), ...cssExtraProps];
|
|
584
|
+
// Create a set of all valid CSS properties
|
|
585
|
+
const StyledProps = /*#__PURE__*/new Set(StyleProps);
|
|
586
|
+
// console.log({
|
|
587
|
+
// props: JSON.stringify(StyleProps.filter((prop) => !cssProperties.has(prop))),
|
|
588
|
+
// });
|
|
589
|
+
const isStyleProp = prop => {
|
|
590
|
+
return (StyledProps.has(prop) || extraKeys.has(prop)) && !includeKeys.has(prop);
|
|
621
591
|
};
|
|
622
592
|
|
|
623
593
|
const Shadows = {
|
|
@@ -713,254 +683,314 @@ const Shadows = {
|
|
|
713
683
|
}
|
|
714
684
|
};
|
|
715
685
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
const
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
// Pour éviter les dépassements, on utilise l'opérateur >>> 0
|
|
740
|
-
hash = hash >>> 0;
|
|
741
|
-
}
|
|
742
|
-
return hash;
|
|
743
|
-
};
|
|
744
|
-
/**
|
|
745
|
-
* Fonction pour hacher un objet en utilisant JSON.stringify et hashString.
|
|
746
|
-
* @param {Object} obj - L'objet à hacher.
|
|
747
|
-
* @returns {number} - Le hachage de l'objet.
|
|
748
|
-
*/
|
|
749
|
-
const hashObject = obj => {
|
|
750
|
-
const str = JSON.stringify(obj);
|
|
751
|
-
return hashString(str).toString();
|
|
752
|
-
};
|
|
753
|
-
const classCache = /*#__PURE__*/new Map();
|
|
754
|
-
const cssRulesCache = /*#__PURE__*/new Map();
|
|
755
|
-
let classNameCounter = 0;
|
|
756
|
-
const generateClassName = styleProps => {
|
|
757
|
-
// Extract only relevant, primitive style properties
|
|
758
|
-
// Generate a unique hash based on relevantProps
|
|
759
|
-
const hash = hashObject(styleProps);
|
|
760
|
-
if (classCache.has(hash)) {
|
|
761
|
-
return classCache.get(hash);
|
|
762
|
-
} else {
|
|
763
|
-
const className = 'clz-' + classNameCounter++;
|
|
764
|
-
classCache.set(hash, className);
|
|
765
|
-
return className;
|
|
686
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
687
|
+
let keyframesCounter = 0;
|
|
688
|
+
const keyframesCache = /*#__PURE__*/new Map();
|
|
689
|
+
const generateKeyframes = animation => {
|
|
690
|
+
// Exclure les propriétés qui ne font pas partie des keyframes
|
|
691
|
+
const {
|
|
692
|
+
duration,
|
|
693
|
+
timingFunction,
|
|
694
|
+
delay,
|
|
695
|
+
iterationCount,
|
|
696
|
+
direction,
|
|
697
|
+
fillMode,
|
|
698
|
+
playState,
|
|
699
|
+
...keyframesDef
|
|
700
|
+
} = animation;
|
|
701
|
+
// Générer une clé pour le cache basée sur les keyframes
|
|
702
|
+
const animationConfigString = JSON.stringify(keyframesDef);
|
|
703
|
+
if (keyframesCache.has(animationConfigString)) {
|
|
704
|
+
const keyframesName = keyframesCache.get(animationConfigString);
|
|
705
|
+
return {
|
|
706
|
+
keyframesName,
|
|
707
|
+
keyframes: ''
|
|
708
|
+
}; // Les keyframes existent déjà
|
|
766
709
|
}
|
|
767
|
-
};
|
|
768
|
-
const useDynamicStyles = cssRules => {
|
|
769
|
-
React.useEffect(() => {
|
|
770
|
-
if (!styleSheet) return;
|
|
771
|
-
cssRules.forEach(rule => {
|
|
772
|
-
try {
|
|
773
|
-
if (Array.from(styleSheet.cssRules).some(cssRule => cssRule.cssText === rule)) {
|
|
774
|
-
return;
|
|
775
|
-
}
|
|
776
|
-
styleSheet.insertRule(rule, styleSheet.cssRules.length);
|
|
777
|
-
} catch (error) {
|
|
778
|
-
console.error('Error inserting CSS rule:', rule, error);
|
|
779
|
-
}
|
|
780
|
-
});
|
|
781
|
-
}, [cssRules]);
|
|
782
|
-
};
|
|
783
|
-
const generateCssRules = (selector, styles, getColor, mediaQueries) => {
|
|
784
|
-
const rules = [];
|
|
785
|
-
const mainStyles = {};
|
|
786
|
-
const nestedMediaQueries = {};
|
|
787
|
-
Object.keys(styles).forEach(key => {
|
|
788
|
-
const value = styles[key];
|
|
789
|
-
if (key.startsWith('@media ')) {
|
|
790
|
-
const mediaQuery = key;
|
|
791
|
-
if (!nestedMediaQueries[mediaQuery]) {
|
|
792
|
-
nestedMediaQueries[mediaQuery] = {};
|
|
793
|
-
}
|
|
794
|
-
Object.assign(nestedMediaQueries[mediaQuery], value);
|
|
795
|
-
} else if (key.startsWith('&:')) {
|
|
796
|
-
const pseudoSelector = key.slice(1);
|
|
797
|
-
const nestedStyles = styles[key];
|
|
798
|
-
const nestedRules = generateCssRules(`${selector}${pseudoSelector}`, nestedStyles, getColor
|
|
799
|
-
// Ne pas passer mediaQueries ici
|
|
800
|
-
);
|
|
801
710
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
711
|
+
const keyframesName = `animation-${keyframesCounter++}`;
|
|
712
|
+
keyframesCache.set(animationConfigString, keyframesName);
|
|
713
|
+
const keyframesContent = [];
|
|
714
|
+
// Trier les clés pour assurer un ordre cohérent
|
|
715
|
+
const keyframeKeys = Object.keys(keyframesDef).sort((a, b) => {
|
|
716
|
+
const getPercentage = key => {
|
|
717
|
+
if (key === 'from') return 0;
|
|
718
|
+
if (key === 'to' || key === 'enter') return 100;
|
|
719
|
+
return parseInt(key.replace('%', ''), 10);
|
|
720
|
+
};
|
|
721
|
+
return getPercentage(a) - getPercentage(b);
|
|
722
|
+
});
|
|
723
|
+
keyframeKeys.forEach(key => {
|
|
724
|
+
const cssKey = key === 'enter' ? 'to' : key; // Remplacer 'enter' par 'to'
|
|
725
|
+
const styles = keyframesDef[key];
|
|
726
|
+
keyframesContent.push(`${cssKey} { ${styleObjectToCss(styles)} }`);
|
|
806
727
|
});
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
if (mediaQueries) {
|
|
811
|
-
for (const query in mediaQueries) {
|
|
812
|
-
const queries = mediaQueries[query].trim();
|
|
813
|
-
mediaBreakpoints['@media ' + queries] = query;
|
|
728
|
+
const keyframes = `
|
|
729
|
+
@keyframes ${keyframesName} {
|
|
730
|
+
${keyframesContent.join('\n')}
|
|
814
731
|
}
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
732
|
+
`;
|
|
733
|
+
return {
|
|
734
|
+
keyframesName,
|
|
735
|
+
keyframes
|
|
736
|
+
};
|
|
737
|
+
};
|
|
738
|
+
|
|
739
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
740
|
+
class UtilityClassManager {
|
|
741
|
+
constructor(propertyShorthand, maxCacheSize) {
|
|
742
|
+
if (maxCacheSize === void 0) {
|
|
743
|
+
maxCacheSize = 10000;
|
|
820
744
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
const breakpoint = mediaBreakpoints[mediaQuery];
|
|
835
|
-
const bpRule = `.${breakpoint} ${selector} { ${cssProperties} }`;
|
|
836
|
-
rules.push(bpRule);
|
|
745
|
+
this.styleSheet = null;
|
|
746
|
+
this.classCache = new Map();
|
|
747
|
+
this.propertyShorthand = propertyShorthand;
|
|
748
|
+
this.maxCacheSize = maxCacheSize;
|
|
749
|
+
this.initStyleSheet();
|
|
750
|
+
}
|
|
751
|
+
initStyleSheet() {
|
|
752
|
+
if (typeof document !== 'undefined') {
|
|
753
|
+
let styleTag = document.getElementById('utility-classes');
|
|
754
|
+
if (!styleTag) {
|
|
755
|
+
styleTag = document.createElement('style');
|
|
756
|
+
styleTag.id = 'utility-classes';
|
|
757
|
+
document.head.appendChild(styleTag);
|
|
837
758
|
}
|
|
759
|
+
this.styleSheet = styleTag.sheet;
|
|
838
760
|
}
|
|
839
761
|
}
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
// Function to apply styles to a component
|
|
843
|
-
const computeStyleProps = props => {
|
|
844
|
-
const styleProps = {};
|
|
845
|
-
const keyframesList = [];
|
|
846
|
-
// Gestion de la taille de l'élément
|
|
847
|
-
const size = props.height !== undefined && props.width !== undefined && props.height === props.width ? props.height : props.size ? props.size : null;
|
|
848
|
-
if (size) {
|
|
849
|
-
styleProps.height = styleProps.width = size;
|
|
850
|
-
}
|
|
851
|
-
// Gestion du padding et de la marge
|
|
852
|
-
if (props.paddingHorizontal) {
|
|
853
|
-
styleProps.paddingLeft = props.paddingHorizontal;
|
|
854
|
-
styleProps.paddingRight = props.paddingHorizontal;
|
|
855
|
-
}
|
|
856
|
-
if (props.marginHorizontal) {
|
|
857
|
-
styleProps.marginLeft = props.marginHorizontal;
|
|
858
|
-
styleProps.marginRight = props.marginHorizontal;
|
|
762
|
+
escapeClassName(className) {
|
|
763
|
+
return className.replace(/:/g, '\\:');
|
|
859
764
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
if (props.shadow) {
|
|
870
|
-
if (typeof props.shadow === 'number' || typeof props.shadow === 'boolean') {
|
|
871
|
-
const shadowValue = typeof props.shadow === 'number' && Shadows[props.shadow] !== undefined ? props.shadow : 2;
|
|
872
|
-
if (Shadows[shadowValue]) {
|
|
873
|
-
const shadowColor = Color.hex.rgb(Shadows[shadowValue].shadowColor) || [];
|
|
874
|
-
styleProps['boxShadow'] = `${Shadows[shadowValue].shadowOffset.height}px ${Shadows[shadowValue].shadowOffset.width}px ${Shadows[shadowValue].shadowRadius}px rgba(${shadowColor.join(',')},${Shadows[shadowValue].shadowOpacity})`;
|
|
765
|
+
injectRule(cssRule) {
|
|
766
|
+
if (this.styleSheet) {
|
|
767
|
+
try {
|
|
768
|
+
const existingRules = Array.from(this.styleSheet.cssRules).map(rule => rule.cssText);
|
|
769
|
+
if (!existingRules.includes(cssRule)) {
|
|
770
|
+
this.styleSheet.insertRule(cssRule, this.styleSheet.cssRules.length);
|
|
771
|
+
}
|
|
772
|
+
} catch (e) {
|
|
773
|
+
console.error(`Erreur lors de l'insertion de la règle CSS: "${cssRule}"`, e);
|
|
875
774
|
}
|
|
876
|
-
} else {
|
|
877
|
-
const shadowColor = Color.hex.rgb(props.shadow.shadowColor) || [];
|
|
878
|
-
styleProps['boxShadow'] = `${props.shadow.shadowOffset.height}px ${props.shadow.shadowOffset.width}px ${props.shadow.shadowRadius}px rgba(${shadowColor.join(',')},${props.shadow.shadowOpacity})`;
|
|
879
775
|
}
|
|
880
776
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
keyframesName,
|
|
886
|
-
keyframes
|
|
887
|
-
} = generateKeyframes(animation);
|
|
888
|
-
if (keyframes) {
|
|
889
|
-
keyframesList.push(keyframes);
|
|
777
|
+
addToCache(key, className) {
|
|
778
|
+
if (this.classCache.size >= this.maxCacheSize) {
|
|
779
|
+
const firstKey = this.classCache.keys().next().value;
|
|
780
|
+
this.classCache.delete(firstKey);
|
|
890
781
|
}
|
|
891
|
-
|
|
892
|
-
styleProps.animationDuration = animation.duration || '1s';
|
|
893
|
-
styleProps.animationTimingFunction = animation.timingFunction || 'ease';
|
|
894
|
-
styleProps.animationDelay = animation.delay || '0s';
|
|
895
|
-
styleProps.animationIterationCount = `${animation.iterationCount || '1'}`;
|
|
896
|
-
styleProps.animationDirection = animation.direction || 'normal';
|
|
897
|
-
styleProps.animationFillMode = animation.fillMode || 'both';
|
|
898
|
-
styleProps.animationPlayState = animation.playState || 'running';
|
|
782
|
+
this.classCache.set(key, className);
|
|
899
783
|
}
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
784
|
+
/**
|
|
785
|
+
* Génère un ou plusieurs noms de classes pour une propriété et une valeur donnée.
|
|
786
|
+
* @param property La propriété CSS (ex: 'padding', 'color').
|
|
787
|
+
* @param value La valeur de la propriété (ex: '10px', '#fff').
|
|
788
|
+
* @param context Le contexte de la classe ('base', 'pseudo', 'media').
|
|
789
|
+
* @param modifier Le modificateur pour les pseudo-classes ou media queries (ex: 'hover', 'sm').
|
|
790
|
+
* @param getColor Fonction pour convertir les couleurs si nécessaire.
|
|
791
|
+
* @param mediaQueries Un tableau de media queries associées (utilisé uniquement pour le contexte 'media').
|
|
792
|
+
* @returns Un tableau de noms de classes générés.
|
|
793
|
+
*/
|
|
794
|
+
getClassNames(property, value, context, modifier, getColor, mediaQueries) {
|
|
795
|
+
if (context === void 0) {
|
|
796
|
+
context = 'base';
|
|
904
797
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
798
|
+
if (modifier === void 0) {
|
|
799
|
+
modifier = '';
|
|
800
|
+
}
|
|
801
|
+
if (getColor === void 0) {
|
|
802
|
+
getColor = color => color;
|
|
803
|
+
}
|
|
804
|
+
if (mediaQueries === void 0) {
|
|
805
|
+
mediaQueries = [];
|
|
806
|
+
}
|
|
807
|
+
let processedValue = value;
|
|
808
|
+
// Si la propriété est une couleur, la convertir en valeur hexadécimale ou RGB
|
|
809
|
+
if (property.toLowerCase().includes('color')) {
|
|
810
|
+
processedValue = getColor(value);
|
|
811
|
+
}
|
|
812
|
+
let key = `${property}:${processedValue}`;
|
|
813
|
+
if (modifier) {
|
|
814
|
+
key = `${property}:${processedValue}|${modifier}`;
|
|
815
|
+
}
|
|
816
|
+
if (this.classCache.has(key)) {
|
|
817
|
+
return [this.classCache.get(key)];
|
|
818
|
+
}
|
|
819
|
+
// Générer un nom de classe unique avec le modificateur
|
|
820
|
+
let shorthand = this.propertyShorthand[property];
|
|
821
|
+
if (!shorthand) {
|
|
822
|
+
shorthand = property.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
823
|
+
}
|
|
824
|
+
// console.log({ shorthand, property, processedValue });
|
|
825
|
+
// Normaliser la valeur pour le nom de classe
|
|
826
|
+
let normalizedValue = processedValue.toString().replace(/\./g, 'p') // Remplacer les points par 'p'
|
|
827
|
+
.replace(/\s+/g, '-') // Remplacer les espaces par '-'
|
|
828
|
+
.replace(/[^a-zA-Z0-9\-]/g, ''); // Supprimer les autres caractères spéciaux
|
|
829
|
+
let baseClassName = `${shorthand}-${normalizedValue}`;
|
|
830
|
+
// Préfixer les noms de classe pour les pseudo-classes et media queries
|
|
831
|
+
let classNames = [];
|
|
832
|
+
if (context === 'pseudo' && modifier) {
|
|
833
|
+
// Pseudo-class : ajouter '-modifier' suffix
|
|
834
|
+
const pseudoClassName = `${baseClassName}-${modifier}`;
|
|
835
|
+
classNames.push(pseudoClassName);
|
|
836
|
+
} else if (context === 'media' && modifier) {
|
|
837
|
+
// Media query : générer une classe pour chaque media query associée
|
|
838
|
+
mediaQueries.forEach(() => {
|
|
839
|
+
const mediaClassName = `${modifier}:${baseClassName}`;
|
|
840
|
+
classNames.push(mediaClassName);
|
|
841
|
+
});
|
|
842
|
+
} else {
|
|
843
|
+
classNames.push(baseClassName);
|
|
844
|
+
}
|
|
845
|
+
// Convertir camelCase en kebab-case
|
|
846
|
+
const cssProperty = property.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
847
|
+
let valueForCss = processedValue;
|
|
848
|
+
// Ajouter des unités si nécessaire
|
|
849
|
+
if (typeof valueForCss === 'number') {
|
|
850
|
+
const propertiesWithUnits = ['width', 'height', 'padding', 'margin', 'padding-left', 'padding-right', 'padding-top', 'padding-bottom', 'margin-left', 'margin-right', 'margin-top', 'margin-bottom', 'transform', 'transition'];
|
|
851
|
+
if (propertiesWithUnits.includes(cssProperty)) {
|
|
852
|
+
valueForCss = `${valueForCss}px`;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
// Construire les règles CSS pour chaque classe générée
|
|
856
|
+
classNames.forEach(className => {
|
|
857
|
+
const escapedClassName = this.escapeClassName(className);
|
|
858
|
+
let cssRules = [];
|
|
859
|
+
switch (context) {
|
|
860
|
+
case 'base':
|
|
861
|
+
cssRules.push(`.${escapedClassName} { ${cssProperty}: ${valueForCss}; }`);
|
|
862
|
+
break;
|
|
863
|
+
case 'pseudo':
|
|
864
|
+
// Appliquer la pseudo-classe directement à la classe principale
|
|
865
|
+
cssRules.push(`.${escapedClassName} { ${cssProperty}: ${valueForCss}; }`);
|
|
866
|
+
break;
|
|
867
|
+
case 'media':
|
|
868
|
+
// Les media queries sont gérées séparément
|
|
869
|
+
mediaQueries.forEach(mq => {
|
|
870
|
+
cssRules.push(`@media ${mq} { .${escapedClassName} { ${cssProperty}: ${valueForCss}; } }`);
|
|
871
|
+
if (window.isResponsive === true) {
|
|
872
|
+
cssRules.push(`.${modifier} { .${escapedClassName} { ${cssProperty}: ${valueForCss}; } }`);
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
break;
|
|
876
|
+
default:
|
|
877
|
+
cssRules.push(`.${escapedClassName} { ${cssProperty}: ${valueForCss}; }`);
|
|
878
|
+
}
|
|
879
|
+
console.log({
|
|
880
|
+
mediaQueries,
|
|
881
|
+
cssRules,
|
|
882
|
+
modifier
|
|
883
|
+
});
|
|
884
|
+
// Injecter les règles CSS
|
|
885
|
+
cssRules.forEach(rule => this.injectRule(rule));
|
|
886
|
+
// Ajouter au cache
|
|
887
|
+
this.addToCache(key, className);
|
|
888
|
+
});
|
|
889
|
+
return classNames;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
/**
|
|
893
|
+
* Mappe un événement React à une pseudo-classe CSS.
|
|
894
|
+
* @param event L'événement React (ex: 'hover', 'active')
|
|
895
|
+
* @returns La pseudo-classe CSS correspondante ou null si non supporté.
|
|
896
|
+
*/
|
|
897
|
+
const mapEventToPseudo = event => {
|
|
898
|
+
const eventMap = {
|
|
899
|
+
hover: 'hover',
|
|
900
|
+
active: 'active',
|
|
901
|
+
focus: 'focus',
|
|
902
|
+
visited: 'visited'
|
|
909
903
|
};
|
|
904
|
+
return eventMap[event] || null;
|
|
910
905
|
};
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
906
|
+
/**
|
|
907
|
+
* Génère des abréviations pour les propriétés CSS.
|
|
908
|
+
* @param styledProps Tableau des propriétés CSS à abréger.
|
|
909
|
+
* @returns Un objet mappant chaque propriété CSS à son abréviation.
|
|
910
|
+
*/
|
|
911
|
+
function generatePropertyShorthand(styledProps) {
|
|
912
|
+
const propertyShorthand = {};
|
|
913
|
+
const usedAbbreviations = new Set();
|
|
914
|
+
/**
|
|
915
|
+
* Génère une abréviation unique pour une propriété CSS donnée.
|
|
916
|
+
* @param prop La propriété CSS à abréger.
|
|
917
|
+
* @returns L'abréviation unique générée.
|
|
918
|
+
*/
|
|
919
|
+
function generateAbbreviation(prop) {
|
|
920
|
+
const first = prop[0].toLowerCase();
|
|
921
|
+
const last = prop[prop.length - 1].toLowerCase();
|
|
922
|
+
const middle = prop.slice(1, -1).replace(/[a-z]/g, '').toLowerCase();
|
|
923
|
+
let abbr = first + middle + last;
|
|
924
|
+
if (abbr.length < 2) {
|
|
925
|
+
abbr = prop.slice(0, 2).toLowerCase();
|
|
926
|
+
}
|
|
927
|
+
let i = 0;
|
|
928
|
+
let uniqueAbbr = abbr;
|
|
929
|
+
while (usedAbbreviations.has(uniqueAbbr)) {
|
|
930
|
+
i++;
|
|
931
|
+
uniqueAbbr = abbr + prop.slice(-i, prop.length).toLowerCase();
|
|
932
|
+
}
|
|
933
|
+
usedAbbreviations.add(uniqueAbbr);
|
|
934
|
+
return uniqueAbbr;
|
|
935
|
+
}
|
|
936
|
+
for (const prop of styledProps) {
|
|
937
|
+
propertyShorthand[prop] = generateAbbreviation(prop);
|
|
928
938
|
}
|
|
929
|
-
|
|
930
|
-
|
|
939
|
+
return propertyShorthand;
|
|
940
|
+
}
|
|
941
|
+
const propertyShorthand = /*#__PURE__*/generatePropertyShorthand(StyleProps);
|
|
942
|
+
const utilityClassManager = /*#__PURE__*/new UtilityClassManager(propertyShorthand);
|
|
943
|
+
const extractUtilityClasses = (props, getColor, mediaQueries, devices) => {
|
|
944
|
+
const classes = [];
|
|
945
|
+
// Styles calculés basés sur les props
|
|
946
|
+
const computedStyles = {};
|
|
931
947
|
// Gestion de la taille de l'élément
|
|
932
948
|
const size = props.height !== undefined && props.width !== undefined && props.height === props.width ? props.height : props.size ? props.size : null;
|
|
933
949
|
if (size) {
|
|
934
|
-
|
|
950
|
+
const sizeValue = typeof size === 'number' ? `${size}px` : size;
|
|
951
|
+
computedStyles.width = sizeValue;
|
|
952
|
+
computedStyles.height = sizeValue;
|
|
935
953
|
}
|
|
936
954
|
// Gestion du padding et de la marge
|
|
937
955
|
if (props.paddingHorizontal) {
|
|
938
|
-
|
|
939
|
-
|
|
956
|
+
const paddingH = typeof props.paddingHorizontal === 'number' ? `${props.paddingHorizontal}px` : props.paddingHorizontal;
|
|
957
|
+
computedStyles.paddingLeft = paddingH;
|
|
958
|
+
computedStyles.paddingRight = paddingH;
|
|
940
959
|
}
|
|
941
960
|
if (props.marginHorizontal) {
|
|
942
|
-
|
|
943
|
-
|
|
961
|
+
const marginH = typeof props.marginHorizontal === 'number' ? `${props.marginHorizontal}px` : props.marginHorizontal;
|
|
962
|
+
computedStyles.marginLeft = marginH;
|
|
963
|
+
computedStyles.marginRight = marginH;
|
|
944
964
|
}
|
|
945
965
|
if (props.paddingVertical) {
|
|
946
|
-
|
|
947
|
-
|
|
966
|
+
const paddingV = typeof props.paddingVertical === 'number' ? `${props.paddingVertical}px` : props.paddingVertical;
|
|
967
|
+
computedStyles.paddingTop = paddingV;
|
|
968
|
+
computedStyles.paddingBottom = paddingV;
|
|
948
969
|
}
|
|
949
970
|
if (props.marginVertical) {
|
|
950
|
-
|
|
951
|
-
|
|
971
|
+
const marginV = typeof props.marginVertical === 'number' ? `${props.marginVertical}px` : props.marginVertical;
|
|
972
|
+
computedStyles.marginTop = marginV;
|
|
973
|
+
computedStyles.marginBottom = marginV;
|
|
952
974
|
}
|
|
953
975
|
// Application des ombres si spécifié
|
|
954
976
|
if (props.shadow) {
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
}
|
|
977
|
+
let shadowValue;
|
|
978
|
+
if (typeof props.shadow === 'number' && Shadows[props.shadow] !== undefined) {
|
|
979
|
+
shadowValue = props.shadow;
|
|
980
|
+
} else if (typeof props.shadow === 'boolean') {
|
|
981
|
+
shadowValue = props.shadow ? 2 : 0;
|
|
961
982
|
} else {
|
|
962
|
-
|
|
963
|
-
|
|
983
|
+
shadowValue = 2;
|
|
984
|
+
}
|
|
985
|
+
if (Shadows[shadowValue]) {
|
|
986
|
+
const shadowColor = Shadows[shadowValue].shadowColor;
|
|
987
|
+
const shadowOpacity = Shadows[shadowValue].shadowOpacity;
|
|
988
|
+
const shadowOffset = Shadows[shadowValue].shadowOffset;
|
|
989
|
+
const shadowRadius = Shadows[shadowValue].shadowRadius;
|
|
990
|
+
// Convertir la couleur en rgba
|
|
991
|
+
const rgb = Color.hex.rgb(shadowColor);
|
|
992
|
+
const rgbaColor = `rgba(${rgb.join(',')}, ${shadowOpacity})`;
|
|
993
|
+
computedStyles.boxShadow = `${shadowOffset.height}px ${shadowOffset.width}px ${shadowRadius}px ${rgbaColor}`;
|
|
964
994
|
}
|
|
965
995
|
}
|
|
966
996
|
// Gestion des animations
|
|
@@ -970,119 +1000,119 @@ maxDepth // Set a maximum depth
|
|
|
970
1000
|
keyframesName,
|
|
971
1001
|
keyframes
|
|
972
1002
|
} = generateKeyframes(animation);
|
|
973
|
-
if (keyframes) {
|
|
974
|
-
|
|
1003
|
+
if (keyframes && typeof document !== 'undefined') {
|
|
1004
|
+
utilityClassManager.injectRule(keyframes);
|
|
975
1005
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
1006
|
+
computedStyles.animationName = keyframesName;
|
|
1007
|
+
if (animation.duration) computedStyles.animationDuration = animation.duration;
|
|
1008
|
+
if (animation.timingFunction) computedStyles.animationTimingFunction = animation.timingFunction;
|
|
1009
|
+
if (animation.delay) computedStyles.animationDelay = animation.delay;
|
|
1010
|
+
if (animation.iterationCount !== undefined) computedStyles.animationIterationCount = `${animation.iterationCount}`;
|
|
1011
|
+
if (animation.direction) computedStyles.animationDirection = animation.direction;
|
|
1012
|
+
if (animation.fillMode) computedStyles.animationFillMode = animation.fillMode;
|
|
1013
|
+
if (animation.playState) computedStyles.animationPlayState = animation.playState;
|
|
984
1014
|
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Génère des classes utilitaires pour un ensemble de styles.
|
|
1017
|
+
* @param styles Les styles à transformer en classes utilitaires.
|
|
1018
|
+
* @param context Le contexte des styles ('base', 'pseudo', 'media').
|
|
1019
|
+
* @param modifier Le modificateur pour les pseudo-classes ou media queries.
|
|
1020
|
+
*/
|
|
1021
|
+
const generateUtilityClasses = function (styles, context, modifier) {
|
|
1022
|
+
if (context === void 0) {
|
|
1023
|
+
context = 'base';
|
|
1024
|
+
}
|
|
1025
|
+
if (modifier === void 0) {
|
|
1026
|
+
modifier = '';
|
|
1027
|
+
}
|
|
1028
|
+
console.log({
|
|
1029
|
+
styles
|
|
1030
|
+
});
|
|
1031
|
+
Object.keys(styles).forEach(property => {
|
|
1032
|
+
const value = styles[property];
|
|
1033
|
+
let mediaQueriesForClass = [];
|
|
1034
|
+
if (context === 'media') {
|
|
1035
|
+
// 'modifier' peut être un breakpoint ou un dispositif
|
|
1036
|
+
if (mediaQueries[modifier]) {
|
|
1037
|
+
mediaQueriesForClass = [mediaQueries[modifier]];
|
|
1038
|
+
} else if (devices[modifier]) {
|
|
1039
|
+
mediaQueriesForClass = devices[modifier].map(mq => mediaQueries[mq]).filter(mq => mq); // Filtrer les media queries valides
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
if (value !== undefined) {
|
|
1044
|
+
const classNames = utilityClassManager.getClassNames(property, value, context, modifier, getColor, mediaQueriesForClass);
|
|
1045
|
+
classes.push(...classNames);
|
|
1046
|
+
} else {
|
|
1047
|
+
console.error({
|
|
1048
|
+
styles,
|
|
1049
|
+
value,
|
|
1050
|
+
property
|
|
1051
|
+
});
|
|
1052
|
+
debugger;
|
|
1053
|
+
}
|
|
1054
|
+
});
|
|
1055
|
+
};
|
|
1056
|
+
// Générer des classes utilitaires pour les styles calculés
|
|
1057
|
+
generateUtilityClasses(computedStyles, 'base');
|
|
1058
|
+
// Parcourir toutes les propriétés de style et générer des classes utilitaires
|
|
985
1059
|
Object.keys(props).forEach(property => {
|
|
986
|
-
if (property !== 'style' && (isStyleProp(property) ||
|
|
1060
|
+
if (property !== 'style' && (isStyleProp(property) || ['on', 'media'].includes(property))) {
|
|
987
1061
|
const value = props[property];
|
|
988
1062
|
if (typeof value === 'object' && value !== null) {
|
|
989
1063
|
if (property === 'on') {
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
1064
|
+
// Styles liés aux événements (pseudo-classes)
|
|
1065
|
+
Object.keys(value).forEach(event => {
|
|
1066
|
+
const eventStyles = value[event];
|
|
1067
|
+
// Séparer les propriétés de transition et les autres propriétés
|
|
1068
|
+
const transitionStyles = {};
|
|
1069
|
+
const nonTransitionStyles = {};
|
|
1070
|
+
Object.keys(eventStyles).forEach(prop => {
|
|
1071
|
+
if (prop === 'transition') {
|
|
1072
|
+
transitionStyles[prop] = eventStyles[prop];
|
|
1073
|
+
} else {
|
|
1074
|
+
nonTransitionStyles[prop] = eventStyles[prop];
|
|
1075
|
+
}
|
|
1076
|
+
});
|
|
1077
|
+
// Appliquer les transitions aux styles de base
|
|
1078
|
+
if (Object.keys(transitionStyles).length > 0) {
|
|
1079
|
+
generateUtilityClasses(transitionStyles, 'base');
|
|
993
1080
|
}
|
|
994
|
-
|
|
995
|
-
Object.
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
for (const screenOrDevices in value) {
|
|
1000
|
-
const mediaValue = value[screenOrDevices];
|
|
1001
|
-
if (mediaQueries[screenOrDevices]) {
|
|
1002
|
-
const mediaQuery = '@media ' + mediaQueries[screenOrDevices];
|
|
1003
|
-
if (!styleProps[mediaQuery]) {
|
|
1004
|
-
styleProps[mediaQuery] = {};
|
|
1081
|
+
// Générer les classes pour les pseudo-classes
|
|
1082
|
+
if (Object.keys(nonTransitionStyles).length > 0) {
|
|
1083
|
+
const pseudo = mapEventToPseudo(event);
|
|
1084
|
+
if (pseudo) {
|
|
1085
|
+
generateUtilityClasses(nonTransitionStyles, 'pseudo', pseudo);
|
|
1005
1086
|
}
|
|
1006
|
-
const nestedResult = computeStyleProps(mediaValue);
|
|
1007
|
-
Object.assign(styleProps[mediaQuery], nestedResult.styleProps);
|
|
1008
|
-
keyframesList.push(...(nestedResult.keyframes || []));
|
|
1009
|
-
} else if (devices[screenOrDevices]) {
|
|
1010
|
-
const deviceScreens = devices[screenOrDevices];
|
|
1011
|
-
deviceScreens.forEach(screen => {
|
|
1012
|
-
if (mediaQueries[screen]) {
|
|
1013
|
-
const mediaQuery = '@media ' + mediaQueries[screen];
|
|
1014
|
-
if (!styleProps[mediaQuery]) {
|
|
1015
|
-
styleProps[mediaQuery] = {};
|
|
1016
|
-
}
|
|
1017
|
-
const nestedResult = computeStyleProps(mediaValue);
|
|
1018
|
-
Object.assign(styleProps[mediaQuery], nestedResult.styleProps);
|
|
1019
|
-
keyframesList.push(...(nestedResult.keyframes || []));
|
|
1020
|
-
}
|
|
1021
|
-
});
|
|
1022
1087
|
}
|
|
1023
|
-
}
|
|
1024
|
-
} else {
|
|
1025
|
-
//
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
...nestedProps
|
|
1031
|
-
} = value;
|
|
1032
|
-
const nestedResult = computeStyleProps(nestedProps);
|
|
1033
|
-
styleProps[property] = nestedResult.styleProps;
|
|
1034
|
-
keyframesList.push(...(nestedResult.keyframes || []));
|
|
1088
|
+
});
|
|
1089
|
+
} else if (property === 'media') {
|
|
1090
|
+
// Styles conditionnels basés sur les media queries ou devices
|
|
1091
|
+
Object.keys(value).forEach(screenOrDevice => {
|
|
1092
|
+
const mediaStyles = value[screenOrDevice];
|
|
1093
|
+
generateUtilityClasses(mediaStyles, 'media', screenOrDevice);
|
|
1094
|
+
});
|
|
1035
1095
|
}
|
|
1036
1096
|
} else {
|
|
1037
|
-
//
|
|
1038
|
-
|
|
1097
|
+
// Générer une classe utilitaire pour cette propriété et valeur
|
|
1098
|
+
if (value !== undefined) {
|
|
1099
|
+
const classNames = utilityClassManager.getClassNames(property, value, 'base', '', getColor);
|
|
1100
|
+
classes.push(...classNames);
|
|
1101
|
+
} else {
|
|
1102
|
+
console.error({
|
|
1103
|
+
value,
|
|
1104
|
+
property
|
|
1105
|
+
});
|
|
1106
|
+
debugger;
|
|
1107
|
+
}
|
|
1039
1108
|
}
|
|
1040
1109
|
}
|
|
1041
1110
|
});
|
|
1042
|
-
return
|
|
1043
|
-
styleProps,
|
|
1044
|
-
keyframes: keyframesList
|
|
1045
|
-
};
|
|
1046
|
-
};
|
|
1047
|
-
const getStyledProps = (props, getColor, mediaQueries, devices) => {
|
|
1048
|
-
const {
|
|
1049
|
-
styleProps,
|
|
1050
|
-
keyframes
|
|
1051
|
-
} = applyStyle(props, mediaQueries, devices);
|
|
1052
|
-
const className = generateClassName(styleProps);
|
|
1053
|
-
let cssRules = [];
|
|
1054
|
-
if (cssRulesCache.has(className)) {
|
|
1055
|
-
cssRules = cssRulesCache.get(className);
|
|
1056
|
-
} else {
|
|
1057
|
-
cssRules = generateCssRules(`.${className}`, styleProps, getColor, mediaQueries);
|
|
1058
|
-
if (keyframes && keyframes.length > 0) {
|
|
1059
|
-
cssRules = keyframes.concat(cssRules);
|
|
1060
|
-
}
|
|
1061
|
-
cssRulesCache.set(className, cssRules);
|
|
1062
|
-
}
|
|
1063
|
-
const {
|
|
1064
|
-
style,
|
|
1065
|
-
...restProps
|
|
1066
|
-
} = props;
|
|
1067
|
-
const newProps = Object.keys(restProps).reduce((acc, key) => {
|
|
1068
|
-
if (!excludedKeys.has(key) && !isStyleProp(key) || includeKeys.has(key)) {
|
|
1069
|
-
acc[key] = restProps[key];
|
|
1070
|
-
}
|
|
1071
|
-
return acc;
|
|
1072
|
-
}, {});
|
|
1073
|
-
if (className) {
|
|
1074
|
-
newProps.className = className;
|
|
1075
|
-
}
|
|
1076
|
-
if (style) {
|
|
1077
|
-
newProps.style = style;
|
|
1078
|
-
}
|
|
1079
|
-
return {
|
|
1080
|
-
newProps,
|
|
1081
|
-
className,
|
|
1082
|
-
cssRules
|
|
1083
|
-
};
|
|
1111
|
+
return classes;
|
|
1084
1112
|
};
|
|
1085
|
-
|
|
1113
|
+
|
|
1114
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
1115
|
+
const Element = /*#__PURE__*/React__default.memo(props => {
|
|
1086
1116
|
const {
|
|
1087
1117
|
onPress,
|
|
1088
1118
|
...rest
|
|
@@ -1094,18 +1124,40 @@ const Element = props => {
|
|
|
1094
1124
|
mediaQueries,
|
|
1095
1125
|
devices
|
|
1096
1126
|
} = useResponsiveContext();
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1127
|
+
console.log({
|
|
1128
|
+
rest
|
|
1129
|
+
});
|
|
1130
|
+
// Extraire les classes utilitaires
|
|
1131
|
+
const utilityClasses = React.useMemo(() => extractUtilityClasses(rest, getColor, mediaQueries, devices), [rest, getColor, mediaQueries, devices]);
|
|
1132
|
+
// Gérer les événements
|
|
1133
|
+
const newProps = {};
|
|
1101
1134
|
if (onPress) {
|
|
1102
1135
|
newProps.onClick = onPress;
|
|
1103
1136
|
}
|
|
1104
|
-
|
|
1137
|
+
// Ajouter les classes utilitaires
|
|
1138
|
+
if (utilityClasses.length > 0) {
|
|
1139
|
+
newProps.className = utilityClasses.join(' ');
|
|
1140
|
+
}
|
|
1141
|
+
// Ajouter le reste des props qui ne sont pas des styles
|
|
1142
|
+
const {
|
|
1143
|
+
style,
|
|
1144
|
+
children,
|
|
1145
|
+
...otherProps
|
|
1146
|
+
} = rest;
|
|
1147
|
+
Object.keys(otherProps).forEach(key => {
|
|
1148
|
+
if (!excludedKeys.has(key) && !isStyleProp(key) || includeKeys.has(key)) {
|
|
1149
|
+
newProps[key] = otherProps[key];
|
|
1150
|
+
}
|
|
1151
|
+
});
|
|
1152
|
+
// Ajouter les styles inline s'il y en a
|
|
1153
|
+
if (style) {
|
|
1154
|
+
newProps.style = style;
|
|
1155
|
+
}
|
|
1156
|
+
// Définir le composant HTML
|
|
1105
1157
|
const Component = newProps.as || 'div';
|
|
1106
1158
|
delete newProps.as;
|
|
1107
|
-
return /*#__PURE__*/React__default.createElement(Component, Object.assign({}, newProps),
|
|
1108
|
-
};
|
|
1159
|
+
return /*#__PURE__*/React__default.createElement(Component, Object.assign({}, newProps), children);
|
|
1160
|
+
});
|
|
1109
1161
|
|
|
1110
1162
|
const View = /*#__PURE__*/React__default.memo(props => /*#__PURE__*/React__default.createElement(Element, Object.assign({}, props)));
|
|
1111
1163
|
const Div = View;
|