@front10/helpers 2.0.26 → 2.0.27

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.
@@ -790,9 +790,127 @@ var buildClass = function buildClass(props) {
790
790
 
791
791
  if (props["cmp-styles"] && _typeof(props["cmp-styles"]) === "object" && props["cmp-styles"].constructor === Object) {
792
792
  var styles = JSON.parse(JSON.stringify(props["cmp-styles"]));
793
+ /**
794
+ * Checks if a key is a CSS selector that should be treated as nested
795
+ * (excludes pseudo-selectors which are handled differently at root level)
796
+ */
797
+
798
+ var isNestedSelector = function isNestedSelector(key) {
799
+ return /^[.#\[>~+]/.test(key) || /^[a-z]+$/i.test(key) && !key.startsWith("@") && !key.includes(":") || key.startsWith("--point--") || key.startsWith("--hashtag--") || key.startsWith("--tilde--") || key.startsWith("--plus--");
800
+ };
801
+ /**
802
+ * Resolves theme/palette values from a string value
803
+ */
804
+
805
+
806
+ var resolveValue = function resolveValue(value) {
807
+ if (typeof value !== "string") return value;
808
+
809
+ if (value.startsWith("@theme:")) {
810
+ return (0, _ThemeProvider.getValueFromPath)(value, tokenTheme) || value;
811
+ }
812
+
813
+ if (value.includes("@palette:")) {
814
+ return (0, _ThemeProvider.getFromPalette)(value, tokenTheme) || value;
815
+ }
816
+
817
+ return value;
818
+ };
819
+ /**
820
+ * Builds CSS properties string from an object, handling @theme and @palette
821
+ */
822
+
823
+
824
+ var buildCssProperties = function buildCssProperties(obj) {
825
+ return Object.entries(obj).reduce(function (acc, _ref) {
826
+ var _ref2 = _slicedToArray(_ref, 2),
827
+ propName = _ref2[0],
828
+ propValue = _ref2[1];
829
+
830
+ if (propName === "@theme") {
831
+ var themes = Array.isArray(propValue) ? propValue : [propValue];
832
+ themes.forEach(function (item) {
833
+ var path = item.startsWith("@theme:") ? item : "@theme:".concat(item);
834
+ var themeValues = (0, _ThemeProvider.getValueFromPath)(path, tokenTheme) || {};
835
+ Object.entries(themeValues).forEach(function (_ref3) {
836
+ var _ref4 = _slicedToArray(_ref3, 2),
837
+ k = _ref4[0],
838
+ v = _ref4[1];
839
+
840
+ acc += "".concat(k, ":").concat(v, ";");
841
+ });
842
+ });
843
+ } else if (typeof propValue === "string") {
844
+ var resolved = resolveValue(propValue);
845
+ if (resolved) acc += "".concat(propName, ":").concat(resolved, ";");
846
+ } else if (propValue) {
847
+ acc += "".concat(propName, ":").concat(propValue, ";");
848
+ }
849
+
850
+ return acc;
851
+ }, "");
852
+ };
853
+ /**
854
+ * Recursively builds CSS content for nested selectors within media queries
855
+ * @param {string} baseSelector - The base selector (e.g., ".fr-xxx")
856
+ * @param {object} styleObj - The style object to process
857
+ * @returns {string} - CSS rules string
858
+ */
859
+
860
+
861
+ var buildNestedMediaContent = function buildNestedMediaContent(baseSelector, styleObj) {
862
+ var cssRules = "";
863
+ var directProperties = {};
864
+ var nestedSelectors = {}; // Separate direct properties from nested selectors
865
+
866
+ Object.entries(styleObj).forEach(function (_ref5) {
867
+ var _ref6 = _slicedToArray(_ref5, 2),
868
+ key = _ref6[0],
869
+ value = _ref6[1];
870
+
871
+ var new_key = key.replace(/--space--/g, " ").replace(/--point--/g, ".").replace(/--tilde--/g, "~").replace(/--plus--/g, "+").replace(/--hashtag--/g, "#");
872
+
873
+ if (_typeof(value) === "object" && value !== null && !Array.isArray(value)) {
874
+ // Check if this is a nested selector or a complex value
875
+ if (isNestedSelector(new_key) || new_key.startsWith(":")) {
876
+ nestedSelectors[new_key] = value;
877
+ } else {
878
+ // Treat as direct property with object value (shouldn't happen often)
879
+ directProperties[new_key] = value;
880
+ }
881
+ } else {
882
+ directProperties[new_key] = value;
883
+ }
884
+ }); // Build direct properties for base selector
885
+
886
+ if (Object.keys(directProperties).length > 0) {
887
+ var propsString = buildCssProperties(directProperties);
888
+
889
+ if (propsString) {
890
+ cssRules += "".concat(baseSelector, "{").concat(propsString, "}");
891
+ }
892
+ } // Build nested selectors
893
+
894
+
895
+ Object.entries(nestedSelectors).forEach(function (_ref7) {
896
+ var _ref8 = _slicedToArray(_ref7, 2),
897
+ selector = _ref8[0],
898
+ value = _ref8[1];
899
+
900
+ var new_selector = selector.replace(/--space--/g, " ").replace(/--point--/g, ".").replace(/--tilde--/g, "~").replace(/--plus--/g, "+").replace(/--hashtag--/g, "#");
901
+ var combinedSelector = new_selector.startsWith(":") ? "".concat(baseSelector).concat(new_selector) : "".concat(baseSelector, " ").concat(new_selector);
902
+
903
+ if (_typeof(value) === "object" && value !== null) {
904
+ // Recursively handle deeper nesting
905
+ cssRules += buildNestedMediaContent(combinedSelector, value);
906
+ }
907
+ });
908
+ return cssRules;
909
+ };
910
+
793
911
  Object.keys(styles).map(function (p) {
794
912
  var prop = p.replace(/--space--/g, " ").replace(/--point--/g, ".").replace(/--tilde--/g, "~").replace(/--plus--/g, "+").replace(/--hashtag--/g, "#");
795
- var content = "";
913
+ var content = ""; // Handle string values
796
914
 
797
915
  if (typeof styles[p] === "string") {
798
916
  if (prop === "@theme") {
@@ -807,7 +925,8 @@ var buildClass = function buildClass(props) {
807
925
  var valueFromPalette = (0, _ThemeProvider.getFromPalette)(styles[p], tokenTheme);
808
926
  if (valueFromPalette) content = "{".concat(prop, ":").concat(valueFromPalette, "}");else if ((0, _canI.canIExecuteClientCode)()) console.warn("Palette color ".concat(styles[p], " not found in theme."));
809
927
  } else content = "".concat(styles[p] ? "{".concat(prop, ":").concat(styles[p], "}") : "");
810
- }
928
+ } // Handle @theme array at root level
929
+
811
930
 
812
931
  if (prop === "@theme" && styles[p] && Array.isArray(styles[p])) {
813
932
  styles[p].forEach(function (item) {
@@ -821,80 +940,112 @@ var buildClass = function buildClass(props) {
821
940
  content = result;
822
941
  });
823
942
  content = "{".concat(content, "}");
824
- }
943
+ } // Handle object values
944
+
825
945
 
826
946
  if (styles[p] && _typeof(styles[p]) === "object" && styles[p].constructor === Object) {
827
- content = "{".concat(Object.entries(styles[p]).reduce(function (content, _ref) {
828
- var _ref2 = _slicedToArray(_ref, 2),
829
- propName = _ref2[0],
830
- propValue = _ref2[1];
947
+ // Check if this is a media query with nested selectors
948
+ if (prop.startsWith("@media")) {
949
+ var hasNestedSelectors = Object.keys(styles[p]).some(function (key) {
950
+ return isNestedSelector(key) || key.startsWith(":");
951
+ });
831
952
 
832
- var result = content;
953
+ if (hasNestedSelectors) {
954
+ // Will be handled specially below
955
+ content = "__NESTED_MEDIA__";
956
+ } else {
957
+ // Standard media query with direct properties
958
+ content = "{".concat(buildCssProperties(styles[p]), "}");
959
+ }
960
+ } else {
961
+ // Non-media query object handling (original logic)
962
+ content = "{".concat(Object.entries(styles[p]).reduce(function (content, _ref9) {
963
+ var _ref10 = _slicedToArray(_ref9, 2),
964
+ propName = _ref10[0],
965
+ propValue = _ref10[1];
966
+
967
+ var result = content;
968
+
969
+ if (propName === "@theme") {
970
+ if (propValue && Array.isArray(propValue)) {
971
+ propValue.forEach(function (item) {
972
+ var result = content;
973
+ var newItem = item;
974
+ newItem = (0, _ThemeProvider.getValueFromPath)("@theme:".concat(newItem), tokenTheme) || {};
975
+ Object.keys(newItem).map(function (k) {
976
+ result += "".concat(k, ":").concat(newItem[k], ";");
977
+ });
978
+ content = result;
979
+ });
980
+ result = content;
981
+ } else {
982
+ var path = propValue;
833
983
 
834
- if (propName === "@theme") {
835
- if (propValue && Array.isArray(propValue)) {
836
- propValue.forEach(function (item) {
837
- var result = content;
838
- var newItem = item;
839
- newItem = (0, _ThemeProvider.getValueFromPath)("@theme:".concat(newItem), tokenTheme) || {};
840
- Object.keys(newItem).map(function (k) {
841
- result += "".concat(k, ":").concat(newItem[k], ";");
984
+ if (!propValue.startsWith("@theme:")) {
985
+ path = "@theme:".concat(path);
986
+ }
987
+
988
+ var valueFromPath = (0, _ThemeProvider.getValueFromPath)(path, tokenTheme) || {};
989
+ Object.keys(valueFromPath).map(function (k) {
990
+ result += "".concat(k, ":").concat(valueFromPath[k], ";");
842
991
  });
843
- content = result;
844
- });
845
- result = content;
846
- } else {
847
- var path = propValue;
848
-
849
- if (!propValue.startsWith("@theme:")) {
850
- path = "@theme:".concat(path);
851
992
  }
993
+ } else if (typeof propValue === "string" && propValue.startsWith("@theme:")) {
994
+ var _valueFromPath = (0, _ThemeProvider.getValueFromPath)(propValue, tokenTheme);
852
995
 
853
- var valueFromPath = (0, _ThemeProvider.getValueFromPath)(path, tokenTheme) || {};
854
- Object.keys(valueFromPath).map(function (k) {
855
- result += "".concat(k, ":").concat(valueFromPath[k], ";");
856
- });
857
- }
858
- } else if (typeof propValue === "string" && propValue.startsWith("@theme:")) {
859
- var _valueFromPath = (0, _ThemeProvider.getValueFromPath)(propValue, tokenTheme);
996
+ if (_valueFromPath) {
997
+ result = "".concat(content).concat(propName, ":").concat(_valueFromPath, ";");
998
+ } else if ((0, _canI.canIExecuteClientCode)()) {
999
+ console.warn("Design token ".concat(propValue, " not found in theme."));
1000
+ }
1001
+ } else if (typeof propValue === "string" && propValue.includes("@palette:")) {
1002
+ var _valueFromPalette = (0, _ThemeProvider.getFromPalette)(propValue, tokenTheme);
860
1003
 
861
- if (_valueFromPath) {
862
- result = "".concat(content).concat(propName, ":").concat(_valueFromPath, ";");
863
- } else if ((0, _canI.canIExecuteClientCode)()) {
864
- console.warn("Design token ".concat(propValue, " not found in theme."));
1004
+ if (_valueFromPalette) {
1005
+ result = "".concat(content).concat(propName, ":").concat(_valueFromPalette, ";");
1006
+ } else if ((0, _canI.canIExecuteClientCode)()) {
1007
+ console.warn("Palette color ".concat(propValue, " not found in theme."));
1008
+ }
1009
+ } else if (propValue) {
1010
+ result = "".concat(content).concat(propName, ":").concat(propValue, ";");
865
1011
  }
866
- } else if (typeof propValue === "string" && propValue.includes("@palette:")) {
867
- var _valueFromPalette = (0, _ThemeProvider.getFromPalette)(propValue, tokenTheme);
868
1012
 
869
- if (_valueFromPalette) {
870
- result = "".concat(content).concat(propName, ":").concat(_valueFromPalette, ";");
871
- } else if ((0, _canI.canIExecuteClientCode)()) {
872
- console.warn("Palette color ".concat(propValue, " not found in theme."));
873
- }
874
- } else if (propValue) {
875
- result = "".concat(content).concat(propName, ":").concat(propValue, ";");
876
- }
877
-
878
- return result;
879
- }, ""), "}");
1013
+ return result;
1014
+ }, ""), "}");
1015
+ }
880
1016
  }
881
1017
 
882
1018
  content = content && content !== "{}" ? content : null;
883
1019
 
884
1020
  if (content) {
885
- if (direction === "rtl") content = buildRtl(content);
886
- var hash = "fr-".concat((0, _uuid.getUuidMin)("".concat(prop).concat(content)));
887
- var contentClass = ".".concat(hash);
888
- if (prop.startsWith(":")) contentClass += "".concat(prop).concat(content);else if (prop.startsWith(".") || prop.startsWith("#")) {
889
- contentClass += " ".concat(prop).concat(content);
890
- } else if (prop.startsWith("@media")) contentClass = "".concat(prop, "{.").concat(hash).concat(content, "}");else contentClass += content;
891
-
892
- if (!isDynamicGeneratedStyleRegistered(hash)) {
893
- appendDynamicGeneratedStyles(contentClass);
894
- registerDynamicGeneratedStyles(hash);
895
- }
1021
+ if (direction === "rtl" && content !== "__NESTED_MEDIA__") content = buildRtl(content); // Handle nested media queries specially
1022
+
1023
+ if (content === "__NESTED_MEDIA__" && prop.startsWith("@media")) {
1024
+ var hash = "fr-".concat((0, _uuid.getUuidMin)("".concat(prop).concat(JSON.stringify(styles[p]))));
1025
+ var nestedContent = buildNestedMediaContent(".".concat(hash), styles[p]);
1026
+
1027
+ if (nestedContent && !isDynamicGeneratedStyleRegistered(hash)) {
1028
+ var mediaRule = "".concat(prop, "{").concat(nestedContent, "}");
1029
+ appendDynamicGeneratedStyles(mediaRule);
1030
+ registerDynamicGeneratedStyles(hash);
1031
+ }
896
1032
 
897
- _class += !_class.includes(hash) ? " ".concat(hash) : "";
1033
+ _class += !_class.includes(hash) ? " ".concat(hash) : "";
1034
+ } else {
1035
+ var _hash = "fr-".concat((0, _uuid.getUuidMin)("".concat(prop).concat(content)));
1036
+
1037
+ var contentClass = ".".concat(_hash);
1038
+ if (prop.startsWith(":")) contentClass += "".concat(prop).concat(content);else if (prop.startsWith(".") || prop.startsWith("#")) {
1039
+ contentClass += " ".concat(prop).concat(content);
1040
+ } else if (prop.startsWith("@media")) contentClass = "".concat(prop, "{.").concat(_hash).concat(content, "}");else contentClass += content;
1041
+
1042
+ if (!isDynamicGeneratedStyleRegistered(_hash)) {
1043
+ appendDynamicGeneratedStyles(contentClass);
1044
+ registerDynamicGeneratedStyles(_hash);
1045
+ }
1046
+
1047
+ _class += !_class.includes(_hash) ? " ".concat(_hash) : "";
1048
+ }
898
1049
  }
899
1050
  });
900
1051
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@front10/helpers",
3
- "version": "2.0.26",
3
+ "version": "2.0.27",
4
4
  "description": "Helpers for front10 components",
5
5
  "source": "src/index.js",
6
6
  "main": "dist/front10-helpers.js",