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