@mochi-css/vanilla 2.1.0 → 3.0.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.
package/dist/index.js CHANGED
@@ -23,8 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  //#endregion
24
24
  let clsx = require("clsx");
25
25
  clsx = __toESM(clsx);
26
- let react = require("react");
27
- react = __toESM(react);
28
26
 
29
27
  //#region src/token.ts
30
28
  /**
@@ -239,7 +237,6 @@ const propertyUnits = {
239
237
  interestDelay: "ms",
240
238
  interestDelayEnd: "ms",
241
239
  interestDelayStart: "ms",
242
- itemFlow: "px",
243
240
  left: "px",
244
241
  letterSpacing: "px",
245
242
  lineHeight: "px",
@@ -379,12 +376,12 @@ const propertyUnits = {
379
376
  textSizeAdjust: "%",
380
377
  textUnderlineOffset: "px",
381
378
  timelineTrigger: "px",
382
- timelineTriggerExitRange: "px",
383
- timelineTriggerExitRangeEnd: "px",
384
- timelineTriggerExitRangeStart: "px",
385
- timelineTriggerRange: "px",
386
- timelineTriggerRangeEnd: "px",
387
- timelineTriggerRangeStart: "px",
379
+ timelineTriggerActivationRange: "px",
380
+ timelineTriggerActivationRangeEnd: "px",
381
+ timelineTriggerActivationRangeStart: "px",
382
+ timelineTriggerActiveRange: "px",
383
+ timelineTriggerActiveRangeEnd: "px",
384
+ timelineTriggerActiveRangeStart: "px",
388
385
  top: "px",
389
386
  transformOrigin: "px",
390
387
  transition: "ms",
@@ -594,6 +591,7 @@ const knownPropertyNames = new Set([
594
591
  "columnRuleInteriorInsetEnd",
595
592
  "columnRuleInteriorInsetStart",
596
593
  "columnRuleStyle",
594
+ "columnRuleVisibilityItems",
597
595
  "columnRuleWidth",
598
596
  "columnSpan",
599
597
  "columnWidth",
@@ -750,6 +748,7 @@ const knownPropertyNames = new Set([
750
748
  "hyphenateLimitLines",
751
749
  "hyphenateLimitZone",
752
750
  "hyphens",
751
+ "imageAnimation",
753
752
  "imageOrientation",
754
753
  "imageRendering",
755
754
  "imageResolution",
@@ -772,12 +771,6 @@ const knownPropertyNames = new Set([
772
771
  "interestDelayStart",
773
772
  "interpolateSize",
774
773
  "isolation",
775
- "itemCross",
776
- "itemDirection",
777
- "itemFlow",
778
- "itemPack",
779
- "itemTrack",
780
- "itemWrap",
781
774
  "justifyContent",
782
775
  "justifyItems",
783
776
  "justifySelf",
@@ -952,6 +945,7 @@ const knownPropertyNames = new Set([
952
945
  "rowRuleInteriorInsetEnd",
953
946
  "rowRuleInteriorInsetStart",
954
947
  "rowRuleStyle",
948
+ "rowRuleVisibilityItems",
955
949
  "rowRuleWidth",
956
950
  "rubyAlign",
957
951
  "rubyMerge",
@@ -967,6 +961,7 @@ const knownPropertyNames = new Set([
967
961
  "ruleInteriorInset",
968
962
  "ruleOverlap",
969
963
  "ruleStyle",
964
+ "ruleVisibilityItems",
970
965
  "ruleWidth",
971
966
  "rx",
972
967
  "ry",
@@ -1088,13 +1083,13 @@ const knownPropertyNames = new Set([
1088
1083
  "textWrapStyle",
1089
1084
  "timelineScope",
1090
1085
  "timelineTrigger",
1091
- "timelineTriggerExitRange",
1092
- "timelineTriggerExitRangeEnd",
1093
- "timelineTriggerExitRangeStart",
1086
+ "timelineTriggerActivationRange",
1087
+ "timelineTriggerActivationRangeEnd",
1088
+ "timelineTriggerActivationRangeStart",
1089
+ "timelineTriggerActiveRange",
1090
+ "timelineTriggerActiveRangeEnd",
1091
+ "timelineTriggerActiveRangeStart",
1094
1092
  "timelineTriggerName",
1095
- "timelineTriggerRange",
1096
- "timelineTriggerRangeEnd",
1097
- "timelineTriggerRangeStart",
1098
1093
  "timelineTriggerSource",
1099
1094
  "top",
1100
1095
  "touchAction",
@@ -1156,6 +1151,12 @@ const knownPropertyNames = new Set([
1156
1151
  //#endregion
1157
1152
  //#region src/props.ts
1158
1153
  /**
1154
+ * Converts a kebab-case string to camelCase.
1155
+ */
1156
+ function kebabToCamel(str) {
1157
+ return str.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
1158
+ }
1159
+ /**
1159
1160
  * Converts a camelCase string to kebab-case.
1160
1161
  */
1161
1162
  function camelToKebab(str) {
@@ -1496,12 +1497,13 @@ var CssObjectBlock = class {
1496
1497
  subBlocks = [];
1497
1498
  /**
1498
1499
  * Creates a new CSS block from style properties.
1499
- * Generates a unique class name based on the content hash.
1500
+ * Generates a unique class name based on the content hash, or uses the provided class name.
1500
1501
  * @param styles - The style properties to compile
1502
+ * @param className - Optional stable class name; if omitted, a content-hash-based name is generated
1501
1503
  */
1502
- constructor(styles) {
1504
+ constructor(styles, className) {
1503
1505
  const blocks = CssObjectSubBlock.fromProps(styles);
1504
- this.className = "c" + shortHash(blocks.map((b) => b.hash).join("+"));
1506
+ this.className = className ?? "c" + shortHash(blocks.map((b) => b.hash).join("+"));
1505
1507
  this.subBlocks = blocks;
1506
1508
  }
1507
1509
  /**
@@ -1549,9 +1551,14 @@ var CSSObject = class {
1549
1551
  /**
1550
1552
  * Creates a new CSSObject from style props.
1551
1553
  * Compiles main styles and all variant options into CSS blocks.
1554
+ * @param props - Base style props plus variant definitions
1555
+ * @param props.variants - Named variant groups, each mapping variant values to style props
1556
+ * @param props.defaultVariants - Default value for each variant when none is provided at runtime
1557
+ * @param props.compoundVariants - Style props applied when a specific combination of variants is active
1558
+ * @param className - Optional stable class name for the main block
1552
1559
  */
1553
- constructor({ variants, defaultVariants, compoundVariants,...props }) {
1554
- this.mainBlock = new CssObjectBlock(props);
1560
+ constructor({ variants, defaultVariants, compoundVariants,...props }, className) {
1561
+ this.mainBlock = new CssObjectBlock(props, className);
1555
1562
  this.variantBlocks = {};
1556
1563
  this.variantDefaults = defaultVariants ?? {};
1557
1564
  this.compoundVariants = [];
@@ -1593,6 +1600,10 @@ var CSSObject = class {
1593
1600
 
1594
1601
  //#endregion
1595
1602
  //#region src/css.ts
1603
+ const MOCHI_CSS_TYPEOF = Symbol.for("mochi-css.MochiCSS");
1604
+ function isMochiCSS(value) {
1605
+ return typeof value === "object" && value !== null && value["$$typeof"] === MOCHI_CSS_TYPEOF;
1606
+ }
1596
1607
  /**
1597
1608
  * Runtime representation of a CSS style definition with variant support.
1598
1609
  * Holds generated class names and provides methods to compute the final
@@ -1607,10 +1618,6 @@ var CSSObject = class {
1607
1618
  * }))
1608
1619
  * styles.variant({ size: 'large' }) // Returns combined class names
1609
1620
  */
1610
- const MOCHI_CSS_TYPEOF = Symbol.for("mochi-css.MochiCSS");
1611
- function isMochiCSS(value) {
1612
- return typeof value === "object" && value !== null && value["$$typeof"] === MOCHI_CSS_TYPEOF;
1613
- }
1614
1621
  var MochiCSS = class MochiCSS {
1615
1622
  $$typeof = MOCHI_CSS_TYPEOF;
1616
1623
  /**
@@ -1646,6 +1653,16 @@ var MochiCSS = class MochiCSS {
1646
1653
  }));
1647
1654
  }
1648
1655
  /**
1656
+ * Returns the CSS selector for this style (e.g. `.abc123`).
1657
+ * Useful for targeting this component from another style.
1658
+ */
1659
+ get selector() {
1660
+ return this.classNames.map((n) => `.${n}`).join();
1661
+ }
1662
+ toString() {
1663
+ return this.selector;
1664
+ }
1665
+ /**
1649
1666
  * Creates a MochiCSS instance from a CSSObject.
1650
1667
  * Extracts class names from the compiled CSS blocks.
1651
1668
  * @template V - The variant definitions type
@@ -1704,51 +1721,18 @@ function mergeMochiCss(instances) {
1704
1721
  function css(...props) {
1705
1722
  const cssToMerge = [];
1706
1723
  for (const p of props) {
1707
- if (p == null || typeof p !== "object") continue;
1724
+ if (p == null) continue;
1725
+ if (typeof p === "string") {
1726
+ cssToMerge.push(new MochiCSS([p], {}, {}));
1727
+ continue;
1728
+ }
1729
+ if (typeof p !== "object") continue;
1708
1730
  if (p instanceof MochiCSS) cssToMerge.push(p);
1709
1731
  else cssToMerge.push(MochiCSS.from(new CSSObject(p)));
1710
1732
  }
1711
1733
  return mergeMochiCss(cssToMerge);
1712
1734
  }
1713
1735
 
1714
- //#endregion
1715
- //#region src/styled.ts
1716
- /**
1717
- * Creates a styled React component with CSS-in-JS support and variant props.
1718
- * Similar to styled-components or Stitches, but with zero runtime overhead.
1719
- *
1720
- * @template T - The base element type or component type
1721
- * @template V - The variant definitions tuple type
1722
- * @param target - The HTML element tag name or React component to style
1723
- * @param props - One or more style objects with optional variants
1724
- * @returns A React functional component with merged props and variant support
1725
- *
1726
- * @example
1727
- * const Button = styled('button', {
1728
- * padding: 8,
1729
- * borderRadius: 4,
1730
- * variants: {
1731
- * size: {
1732
- * small: { padding: 4 },
1733
- * large: { padding: 16 }
1734
- * },
1735
- * variant: {
1736
- * primary: { backgroundColor: 'blue' },
1737
- * secondary: { backgroundColor: 'gray' }
1738
- * }
1739
- * }
1740
- * })
1741
- *
1742
- * // Usage: <Button size="large" variant="primary">Click me</Button>
1743
- */
1744
- function styled(target, ...props) {
1745
- const styles = css(...props);
1746
- return ({ className,...p }) => (0, react.createElement)(target, {
1747
- className: (0, clsx.default)(styles.variant(p), className),
1748
- ...p
1749
- });
1750
- }
1751
-
1752
1736
  //#endregion
1753
1737
  //#region src/keyframesObject.ts
1754
1738
  var KeyframesObject = class KeyframesObject {
@@ -1904,6 +1888,7 @@ exports.MochiCSS = MochiCSS;
1904
1888
  exports.MochiKeyframes = MochiKeyframes;
1905
1889
  exports.MochiSelector = MochiSelector;
1906
1890
  exports.Token = Token;
1891
+ exports.camelToKebab = camelToKebab;
1907
1892
  exports.container = container;
1908
1893
  exports.createToken = createToken;
1909
1894
  exports.css = css;
@@ -1911,9 +1896,11 @@ exports.cssFromProps = cssFromProps;
1911
1896
  exports.globalCss = globalCss;
1912
1897
  exports.isAtRuleKey = isAtRuleKey;
1913
1898
  exports.isMochiCSS = isMochiCSS;
1899
+ exports.kebabToCamel = kebabToCamel;
1914
1900
  exports.keyframes = keyframes;
1915
1901
  exports.media = media;
1916
1902
  exports.mergeMochiCss = mergeMochiCss;
1917
- exports.styled = styled;
1903
+ exports.numberToBase62 = numberToBase62;
1904
+ exports.shortHash = shortHash;
1918
1905
  exports.supports = supports;
1919
1906
  //# sourceMappingURL=index.js.map