@react-hive/honey-style 1.7.0 → 1.8.1

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.
@@ -1975,7 +1975,9 @@ __webpack_require__.r(__webpack_exports__);
1975
1975
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
1976
1976
  /* harmony export */ assert: () => (/* binding */ assert),
1977
1977
  /* harmony export */ boolFilter: () => (/* binding */ boolFilter),
1978
+ /* harmony export */ checkIsThemeColorValue: () => (/* binding */ checkIsThemeColorValue),
1978
1979
  /* harmony export */ combineClassNames: () => (/* binding */ combineClassNames),
1980
+ /* harmony export */ convertHexToHexWithAlpha: () => (/* binding */ convertHexToHexWithAlpha),
1979
1981
  /* harmony export */ filterNonHtmlAttrs: () => (/* binding */ filterNonHtmlAttrs),
1980
1982
  /* harmony export */ generateId: () => (/* binding */ generateId),
1981
1983
  /* harmony export */ isFunction: () => (/* binding */ isFunction),
@@ -1984,12 +1986,18 @@ __webpack_require__.r(__webpack_exports__);
1984
1986
  /* harmony export */ isString: () => (/* binding */ isString),
1985
1987
  /* harmony export */ isStyledComponent: () => (/* binding */ isStyledComponent),
1986
1988
  /* harmony export */ processCss: () => (/* binding */ processCss),
1989
+ /* harmony export */ pxToRem: () => (/* binding */ pxToRem),
1987
1990
  /* harmony export */ resolveClassName: () => (/* binding */ resolveClassName),
1991
+ /* harmony export */ resolveColor: () => (/* binding */ resolveColor),
1992
+ /* harmony export */ resolveDimension: () => (/* binding */ resolveDimension),
1993
+ /* harmony export */ resolveFont: () => (/* binding */ resolveFont),
1988
1994
  /* harmony export */ toKebabCase: () => (/* binding */ toKebabCase)
1989
1995
  /* harmony export */ });
1990
- /* harmony import */ var stylis__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! stylis */ "./node_modules/stylis/src/Serializer.js");
1991
- /* harmony import */ var stylis__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! stylis */ "./node_modules/stylis/src/Parser.js");
1996
+ /* harmony import */ var stylis__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! stylis */ "./node_modules/stylis/src/Serializer.js");
1997
+ /* harmony import */ var stylis__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! stylis */ "./node_modules/stylis/src/Parser.js");
1992
1998
  /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
1999
+ /* harmony import */ var _css__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./css */ "./src/css.ts");
2000
+
1993
2001
 
1994
2002
 
1995
2003
  function assert(condition, message) {
@@ -2064,7 +2072,7 @@ const resolveClassName = (css) => `hscn-${hashString(css)}`;
2064
2072
  const isStyledComponent = (component) => _constants__WEBPACK_IMPORTED_MODULE_0__.HONEY_STYLED_COMPONENT_ID_PROP in component;
2065
2073
  const processCss = (rawCss, selector) => {
2066
2074
  const scopedCss = selector ? `${selector}{${rawCss}}` : rawCss;
2067
- return (0,stylis__WEBPACK_IMPORTED_MODULE_1__.serialize)((0,stylis__WEBPACK_IMPORTED_MODULE_2__.compile)(scopedCss), stylis__WEBPACK_IMPORTED_MODULE_1__.stringify);
2075
+ return (0,stylis__WEBPACK_IMPORTED_MODULE_2__.serialize)((0,stylis__WEBPACK_IMPORTED_MODULE_3__.compile)(scopedCss), stylis__WEBPACK_IMPORTED_MODULE_2__.stringify);
2068
2076
  };
2069
2077
  /**
2070
2078
  * Filters out non-standard HTML attributes from a props object intended for a native HTML element.
@@ -2089,6 +2097,107 @@ const filterNonHtmlAttrs = (attrs) => Object.entries(attrs).reduce((allowedAttrs
2089
2097
  }
2090
2098
  return allowedAttrs;
2091
2099
  }, {});
2100
+ /**
2101
+ * Converts a pixel value to rem.
2102
+ *
2103
+ * @param px - The pixel value to be converted to rem.
2104
+ * @param base - The base value for conversion. Default is 16, which is the typical root font size.
2105
+ *
2106
+ * @returns The value in rem as a string.
2107
+ */
2108
+ const pxToRem = (px, base = 16) => `${px / base}rem`;
2109
+ /**
2110
+ * Type guard function to check if a string value follows the pattern of a theme color value.
2111
+ *
2112
+ * A theme color value is assumed to be a string containing exactly one dot (e.g., 'primary.main').
2113
+ *
2114
+ * @param propertyValue - The string value to check.
2115
+ *
2116
+ * @returns True if the string value is a theme color value, false otherwise.
2117
+ */
2118
+ const checkIsThemeColorValue = (propertyValue) => propertyValue.split('.').length === 2;
2119
+ /**
2120
+ * Resolves the font styles based on the provided font name from the theme.
2121
+ *
2122
+ * @param fontName - The name of the font to be resolved from the theme.
2123
+ *
2124
+ * @returns A style function that takes a theme object and returns the CSS styles for the specified font.
2125
+ */
2126
+ const resolveFont = (fontName) => ({ theme }) => {
2127
+ const font = theme.fonts[fontName];
2128
+ return (0,_css__WEBPACK_IMPORTED_MODULE_1__.css) `
2129
+ font-family: ${font.family};
2130
+ font-size: ${pxToRem(font.size)};
2131
+ font-weight: ${font.weight};
2132
+ line-height: ${font.lineHeight !== undefined && pxToRem(font.lineHeight)};
2133
+ letter-spacing: ${font.letterSpacing !== undefined && pxToRem(font.letterSpacing)};
2134
+ `;
2135
+ };
2136
+ /**
2137
+ * Converts a 3-character or 6-character HEX color code to an 8-character HEX with alpha (RRGGBBAA) format.
2138
+ *
2139
+ * @param hex - The 3-character or 6-character HEX color code (e.g., "#RGB" or "#RRGGBB" or "RGB" or "RRGGBB").
2140
+ * @param alpha - The alpha transparency value between 0 (fully transparent) and 1 (fully opaque).
2141
+ *
2142
+ * @throws {Error} If alpha value is not between 0 and 1, or if the hex code is invalid.
2143
+ *
2144
+ * @returns The 8-character HEX with alpha (RRGGBBAA) format color code, or null if input is invalid.
2145
+ */
2146
+ const convertHexToHexWithAlpha = (hex, alpha) => {
2147
+ if (alpha < 0 || alpha > 1) {
2148
+ throw new Error(`[honey-layout]: Alpha "${alpha}" is not a valid hex format.`);
2149
+ }
2150
+ const hexRegex = /^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;
2151
+ const match = hex.match(hexRegex);
2152
+ if (!match) {
2153
+ throw new Error(`[honey-layout]: Invalid hex format.`);
2154
+ }
2155
+ const cleanHex = match[1];
2156
+ // Expand 3-character hex to 6-character hex if necessary
2157
+ const fullHex = cleanHex.length === 3
2158
+ ? cleanHex[0] + cleanHex[0] + cleanHex[1] + cleanHex[1] + cleanHex[2] + cleanHex[2]
2159
+ : cleanHex;
2160
+ // Convert to 8-character hex with alpha
2161
+ const alphaHex = Math.round(alpha * 255)
2162
+ .toString(16)
2163
+ .toUpperCase()
2164
+ .padStart(2, '0');
2165
+ return `#${fullHex + alphaHex}`;
2166
+ };
2167
+ /**
2168
+ * Resolves a color value from the theme or returns the input color directly if it's a standalone color name or HEX value.
2169
+ *
2170
+ * @param colorInput - A string representing the color to resolve.
2171
+ * This can be:
2172
+ * - A theme key in the format 'colorType.colorName'.
2173
+ * - A standalone color name (e.g., "red", "blue").
2174
+ * - A HEX color value (e.g., "#RRGGBB").
2175
+ * @param [alpha] - The alpha transparency value between 0 (fully transparent) and 1 (fully opaque).
2176
+ * Default to `undefined`.
2177
+ *
2178
+ * @returns A function that takes an `ExecutionContext` with a `theme` and resolves the color value:
2179
+ * - A HEX color string from the theme (e.g., "#RRGGBB").
2180
+ * - A HEX color string with alpha (e.g., "#RRGGBBAA") if `alpha` is provided.
2181
+ * - The input `colorKey` value directly if it's a standalone color name or HEX value.
2182
+ *
2183
+ * @throws Will throw an error if the provided alpha value is not within the valid range (0 to 1).
2184
+ * @throws Will throw an error if the color format is invalid.
2185
+ */
2186
+ const resolveColor = (colorInput, alpha) => ({ theme }) => {
2187
+ const [colorType, colorName] = colorInput.split('.');
2188
+ const color = colorName
2189
+ ? theme.colors[colorType][colorName]
2190
+ : colorType;
2191
+ return alpha === undefined ? color : convertHexToHexWithAlpha(color, alpha);
2192
+ };
2193
+ /**
2194
+ * Resolves a specific dimension value from the theme configuration.
2195
+ *
2196
+ * @param dimensionName - The name of the dimension to resolve.
2197
+ *
2198
+ * @returns A style function that takes the theme and returns the resolved dimension value from the theme.
2199
+ */
2200
+ const resolveDimension = (dimensionName) => ({ theme }) => theme.dimensions[dimensionName];
2092
2201
 
2093
2202
 
2094
2203
  /***/ }),
@@ -2187,10 +2296,29 @@ __webpack_require__.r(__webpack_exports__);
2187
2296
  /* harmony export */ HoneyStyleProvider: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_2__.HoneyStyleProvider),
2188
2297
  /* harmony export */ VALID_DOM_ELEMENT_ATTRS: () => (/* reexport safe */ _constants__WEBPACK_IMPORTED_MODULE_0__.VALID_DOM_ELEMENT_ATTRS),
2189
2298
  /* harmony export */ __DEV__: () => (/* reexport safe */ _constants__WEBPACK_IMPORTED_MODULE_0__.__DEV__),
2299
+ /* harmony export */ assert: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.assert),
2300
+ /* harmony export */ boolFilter: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.boolFilter),
2301
+ /* harmony export */ checkIsThemeColorValue: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.checkIsThemeColorValue),
2302
+ /* harmony export */ combineClassNames: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.combineClassNames),
2303
+ /* harmony export */ convertHexToHexWithAlpha: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.convertHexToHexWithAlpha),
2190
2304
  /* harmony export */ createGlobalStyle: () => (/* reexport safe */ _global_style__WEBPACK_IMPORTED_MODULE_6__.createGlobalStyle),
2191
2305
  /* harmony export */ css: () => (/* reexport safe */ _css__WEBPACK_IMPORTED_MODULE_5__.css),
2306
+ /* harmony export */ filterNonHtmlAttrs: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.filterNonHtmlAttrs),
2307
+ /* harmony export */ generateId: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.generateId),
2308
+ /* harmony export */ isFunction: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.isFunction),
2309
+ /* harmony export */ isNil: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.isNil),
2310
+ /* harmony export */ isObject: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.isObject),
2311
+ /* harmony export */ isString: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.isString),
2312
+ /* harmony export */ isStyledComponent: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.isStyledComponent),
2192
2313
  /* harmony export */ mediaQuery: () => (/* reexport safe */ _at_rules__WEBPACK_IMPORTED_MODULE_8__.mediaQuery),
2314
+ /* harmony export */ processCss: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.processCss),
2315
+ /* harmony export */ pxToRem: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.pxToRem),
2316
+ /* harmony export */ resolveClassName: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.resolveClassName),
2317
+ /* harmony export */ resolveColor: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.resolveColor),
2318
+ /* harmony export */ resolveDimension: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.resolveDimension),
2319
+ /* harmony export */ resolveFont: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.resolveFont),
2193
2320
  /* harmony export */ styled: () => (/* reexport safe */ _styled__WEBPACK_IMPORTED_MODULE_7__.styled),
2321
+ /* harmony export */ toKebabCase: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_9__.toKebabCase),
2194
2322
  /* harmony export */ useHoneyStyle: () => (/* reexport safe */ _hooks__WEBPACK_IMPORTED_MODULE_3__.useHoneyStyle)
2195
2323
  /* harmony export */ });
2196
2324
  /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./constants */ "./src/constants.ts");
@@ -2202,6 +2330,8 @@ __webpack_require__.r(__webpack_exports__);
2202
2330
  /* harmony import */ var _global_style__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./global-style */ "./src/global-style.ts");
2203
2331
  /* harmony import */ var _styled__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./styled */ "./src/styled.ts");
2204
2332
  /* harmony import */ var _at_rules__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./at-rules */ "./src/at-rules/index.ts");
2333
+ /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./utils */ "./src/utils.ts");
2334
+
2205
2335
 
2206
2336
 
2207
2337