@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/README.md +21 -11
- package/dist/index.d.mts +72 -55
- package/dist/index.d.ts +72 -55
- package/dist/index.js +57 -70
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -69
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -12
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import clsx from "clsx";
|
|
2
|
-
import { createElement } from "react";
|
|
3
2
|
|
|
4
3
|
//#region src/token.ts
|
|
5
4
|
/**
|
|
@@ -214,7 +213,6 @@ const propertyUnits = {
|
|
|
214
213
|
interestDelay: "ms",
|
|
215
214
|
interestDelayEnd: "ms",
|
|
216
215
|
interestDelayStart: "ms",
|
|
217
|
-
itemFlow: "px",
|
|
218
216
|
left: "px",
|
|
219
217
|
letterSpacing: "px",
|
|
220
218
|
lineHeight: "px",
|
|
@@ -354,12 +352,12 @@ const propertyUnits = {
|
|
|
354
352
|
textSizeAdjust: "%",
|
|
355
353
|
textUnderlineOffset: "px",
|
|
356
354
|
timelineTrigger: "px",
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
355
|
+
timelineTriggerActivationRange: "px",
|
|
356
|
+
timelineTriggerActivationRangeEnd: "px",
|
|
357
|
+
timelineTriggerActivationRangeStart: "px",
|
|
358
|
+
timelineTriggerActiveRange: "px",
|
|
359
|
+
timelineTriggerActiveRangeEnd: "px",
|
|
360
|
+
timelineTriggerActiveRangeStart: "px",
|
|
363
361
|
top: "px",
|
|
364
362
|
transformOrigin: "px",
|
|
365
363
|
transition: "ms",
|
|
@@ -569,6 +567,7 @@ const knownPropertyNames = new Set([
|
|
|
569
567
|
"columnRuleInteriorInsetEnd",
|
|
570
568
|
"columnRuleInteriorInsetStart",
|
|
571
569
|
"columnRuleStyle",
|
|
570
|
+
"columnRuleVisibilityItems",
|
|
572
571
|
"columnRuleWidth",
|
|
573
572
|
"columnSpan",
|
|
574
573
|
"columnWidth",
|
|
@@ -725,6 +724,7 @@ const knownPropertyNames = new Set([
|
|
|
725
724
|
"hyphenateLimitLines",
|
|
726
725
|
"hyphenateLimitZone",
|
|
727
726
|
"hyphens",
|
|
727
|
+
"imageAnimation",
|
|
728
728
|
"imageOrientation",
|
|
729
729
|
"imageRendering",
|
|
730
730
|
"imageResolution",
|
|
@@ -747,12 +747,6 @@ const knownPropertyNames = new Set([
|
|
|
747
747
|
"interestDelayStart",
|
|
748
748
|
"interpolateSize",
|
|
749
749
|
"isolation",
|
|
750
|
-
"itemCross",
|
|
751
|
-
"itemDirection",
|
|
752
|
-
"itemFlow",
|
|
753
|
-
"itemPack",
|
|
754
|
-
"itemTrack",
|
|
755
|
-
"itemWrap",
|
|
756
750
|
"justifyContent",
|
|
757
751
|
"justifyItems",
|
|
758
752
|
"justifySelf",
|
|
@@ -927,6 +921,7 @@ const knownPropertyNames = new Set([
|
|
|
927
921
|
"rowRuleInteriorInsetEnd",
|
|
928
922
|
"rowRuleInteriorInsetStart",
|
|
929
923
|
"rowRuleStyle",
|
|
924
|
+
"rowRuleVisibilityItems",
|
|
930
925
|
"rowRuleWidth",
|
|
931
926
|
"rubyAlign",
|
|
932
927
|
"rubyMerge",
|
|
@@ -942,6 +937,7 @@ const knownPropertyNames = new Set([
|
|
|
942
937
|
"ruleInteriorInset",
|
|
943
938
|
"ruleOverlap",
|
|
944
939
|
"ruleStyle",
|
|
940
|
+
"ruleVisibilityItems",
|
|
945
941
|
"ruleWidth",
|
|
946
942
|
"rx",
|
|
947
943
|
"ry",
|
|
@@ -1063,13 +1059,13 @@ const knownPropertyNames = new Set([
|
|
|
1063
1059
|
"textWrapStyle",
|
|
1064
1060
|
"timelineScope",
|
|
1065
1061
|
"timelineTrigger",
|
|
1066
|
-
"
|
|
1067
|
-
"
|
|
1068
|
-
"
|
|
1062
|
+
"timelineTriggerActivationRange",
|
|
1063
|
+
"timelineTriggerActivationRangeEnd",
|
|
1064
|
+
"timelineTriggerActivationRangeStart",
|
|
1065
|
+
"timelineTriggerActiveRange",
|
|
1066
|
+
"timelineTriggerActiveRangeEnd",
|
|
1067
|
+
"timelineTriggerActiveRangeStart",
|
|
1069
1068
|
"timelineTriggerName",
|
|
1070
|
-
"timelineTriggerRange",
|
|
1071
|
-
"timelineTriggerRangeEnd",
|
|
1072
|
-
"timelineTriggerRangeStart",
|
|
1073
1069
|
"timelineTriggerSource",
|
|
1074
1070
|
"top",
|
|
1075
1071
|
"touchAction",
|
|
@@ -1131,6 +1127,12 @@ const knownPropertyNames = new Set([
|
|
|
1131
1127
|
//#endregion
|
|
1132
1128
|
//#region src/props.ts
|
|
1133
1129
|
/**
|
|
1130
|
+
* Converts a kebab-case string to camelCase.
|
|
1131
|
+
*/
|
|
1132
|
+
function kebabToCamel(str) {
|
|
1133
|
+
return str.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1134
1136
|
* Converts a camelCase string to kebab-case.
|
|
1135
1137
|
*/
|
|
1136
1138
|
function camelToKebab(str) {
|
|
@@ -1471,12 +1473,13 @@ var CssObjectBlock = class {
|
|
|
1471
1473
|
subBlocks = [];
|
|
1472
1474
|
/**
|
|
1473
1475
|
* Creates a new CSS block from style properties.
|
|
1474
|
-
* Generates a unique class name based on the content hash.
|
|
1476
|
+
* Generates a unique class name based on the content hash, or uses the provided class name.
|
|
1475
1477
|
* @param styles - The style properties to compile
|
|
1478
|
+
* @param className - Optional stable class name; if omitted, a content-hash-based name is generated
|
|
1476
1479
|
*/
|
|
1477
|
-
constructor(styles) {
|
|
1480
|
+
constructor(styles, className) {
|
|
1478
1481
|
const blocks = CssObjectSubBlock.fromProps(styles);
|
|
1479
|
-
this.className = "c" + shortHash(blocks.map((b) => b.hash).join("+"));
|
|
1482
|
+
this.className = className ?? "c" + shortHash(blocks.map((b) => b.hash).join("+"));
|
|
1480
1483
|
this.subBlocks = blocks;
|
|
1481
1484
|
}
|
|
1482
1485
|
/**
|
|
@@ -1524,9 +1527,14 @@ var CSSObject = class {
|
|
|
1524
1527
|
/**
|
|
1525
1528
|
* Creates a new CSSObject from style props.
|
|
1526
1529
|
* Compiles main styles and all variant options into CSS blocks.
|
|
1530
|
+
* @param props - Base style props plus variant definitions
|
|
1531
|
+
* @param props.variants - Named variant groups, each mapping variant values to style props
|
|
1532
|
+
* @param props.defaultVariants - Default value for each variant when none is provided at runtime
|
|
1533
|
+
* @param props.compoundVariants - Style props applied when a specific combination of variants is active
|
|
1534
|
+
* @param className - Optional stable class name for the main block
|
|
1527
1535
|
*/
|
|
1528
|
-
constructor({ variants, defaultVariants, compoundVariants,...props }) {
|
|
1529
|
-
this.mainBlock = new CssObjectBlock(props);
|
|
1536
|
+
constructor({ variants, defaultVariants, compoundVariants,...props }, className) {
|
|
1537
|
+
this.mainBlock = new CssObjectBlock(props, className);
|
|
1530
1538
|
this.variantBlocks = {};
|
|
1531
1539
|
this.variantDefaults = defaultVariants ?? {};
|
|
1532
1540
|
this.compoundVariants = [];
|
|
@@ -1568,6 +1576,10 @@ var CSSObject = class {
|
|
|
1568
1576
|
|
|
1569
1577
|
//#endregion
|
|
1570
1578
|
//#region src/css.ts
|
|
1579
|
+
const MOCHI_CSS_TYPEOF = Symbol.for("mochi-css.MochiCSS");
|
|
1580
|
+
function isMochiCSS(value) {
|
|
1581
|
+
return typeof value === "object" && value !== null && value["$$typeof"] === MOCHI_CSS_TYPEOF;
|
|
1582
|
+
}
|
|
1571
1583
|
/**
|
|
1572
1584
|
* Runtime representation of a CSS style definition with variant support.
|
|
1573
1585
|
* Holds generated class names and provides methods to compute the final
|
|
@@ -1582,10 +1594,6 @@ var CSSObject = class {
|
|
|
1582
1594
|
* }))
|
|
1583
1595
|
* styles.variant({ size: 'large' }) // Returns combined class names
|
|
1584
1596
|
*/
|
|
1585
|
-
const MOCHI_CSS_TYPEOF = Symbol.for("mochi-css.MochiCSS");
|
|
1586
|
-
function isMochiCSS(value) {
|
|
1587
|
-
return typeof value === "object" && value !== null && value["$$typeof"] === MOCHI_CSS_TYPEOF;
|
|
1588
|
-
}
|
|
1589
1597
|
var MochiCSS = class MochiCSS {
|
|
1590
1598
|
$$typeof = MOCHI_CSS_TYPEOF;
|
|
1591
1599
|
/**
|
|
@@ -1621,6 +1629,16 @@ var MochiCSS = class MochiCSS {
|
|
|
1621
1629
|
}));
|
|
1622
1630
|
}
|
|
1623
1631
|
/**
|
|
1632
|
+
* Returns the CSS selector for this style (e.g. `.abc123`).
|
|
1633
|
+
* Useful for targeting this component from another style.
|
|
1634
|
+
*/
|
|
1635
|
+
get selector() {
|
|
1636
|
+
return this.classNames.map((n) => `.${n}`).join();
|
|
1637
|
+
}
|
|
1638
|
+
toString() {
|
|
1639
|
+
return this.selector;
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1624
1642
|
* Creates a MochiCSS instance from a CSSObject.
|
|
1625
1643
|
* Extracts class names from the compiled CSS blocks.
|
|
1626
1644
|
* @template V - The variant definitions type
|
|
@@ -1679,51 +1697,18 @@ function mergeMochiCss(instances) {
|
|
|
1679
1697
|
function css(...props) {
|
|
1680
1698
|
const cssToMerge = [];
|
|
1681
1699
|
for (const p of props) {
|
|
1682
|
-
if (p == null
|
|
1700
|
+
if (p == null) continue;
|
|
1701
|
+
if (typeof p === "string") {
|
|
1702
|
+
cssToMerge.push(new MochiCSS([p], {}, {}));
|
|
1703
|
+
continue;
|
|
1704
|
+
}
|
|
1705
|
+
if (typeof p !== "object") continue;
|
|
1683
1706
|
if (p instanceof MochiCSS) cssToMerge.push(p);
|
|
1684
1707
|
else cssToMerge.push(MochiCSS.from(new CSSObject(p)));
|
|
1685
1708
|
}
|
|
1686
1709
|
return mergeMochiCss(cssToMerge);
|
|
1687
1710
|
}
|
|
1688
1711
|
|
|
1689
|
-
//#endregion
|
|
1690
|
-
//#region src/styled.ts
|
|
1691
|
-
/**
|
|
1692
|
-
* Creates a styled React component with CSS-in-JS support and variant props.
|
|
1693
|
-
* Similar to styled-components or Stitches, but with zero runtime overhead.
|
|
1694
|
-
*
|
|
1695
|
-
* @template T - The base element type or component type
|
|
1696
|
-
* @template V - The variant definitions tuple type
|
|
1697
|
-
* @param target - The HTML element tag name or React component to style
|
|
1698
|
-
* @param props - One or more style objects with optional variants
|
|
1699
|
-
* @returns A React functional component with merged props and variant support
|
|
1700
|
-
*
|
|
1701
|
-
* @example
|
|
1702
|
-
* const Button = styled('button', {
|
|
1703
|
-
* padding: 8,
|
|
1704
|
-
* borderRadius: 4,
|
|
1705
|
-
* variants: {
|
|
1706
|
-
* size: {
|
|
1707
|
-
* small: { padding: 4 },
|
|
1708
|
-
* large: { padding: 16 }
|
|
1709
|
-
* },
|
|
1710
|
-
* variant: {
|
|
1711
|
-
* primary: { backgroundColor: 'blue' },
|
|
1712
|
-
* secondary: { backgroundColor: 'gray' }
|
|
1713
|
-
* }
|
|
1714
|
-
* }
|
|
1715
|
-
* })
|
|
1716
|
-
*
|
|
1717
|
-
* // Usage: <Button size="large" variant="primary">Click me</Button>
|
|
1718
|
-
*/
|
|
1719
|
-
function styled(target, ...props) {
|
|
1720
|
-
const styles = css(...props);
|
|
1721
|
-
return ({ className,...p }) => createElement(target, {
|
|
1722
|
-
className: clsx(styles.variant(p), className),
|
|
1723
|
-
...p
|
|
1724
|
-
});
|
|
1725
|
-
}
|
|
1726
|
-
|
|
1727
1712
|
//#endregion
|
|
1728
1713
|
//#region src/keyframesObject.ts
|
|
1729
1714
|
var KeyframesObject = class KeyframesObject {
|
|
@@ -1870,4 +1855,4 @@ supportsFn.or = function(...conditions) {
|
|
|
1870
1855
|
const supports = supportsFn;
|
|
1871
1856
|
|
|
1872
1857
|
//#endregion
|
|
1873
|
-
export { CSSObject, CssObjectBlock, CssObjectSubBlock, GlobalCssObject, KeyframesObject, MochiCSS, MochiKeyframes, MochiSelector, Token, container, createToken, css, cssFromProps, globalCss, isAtRuleKey, isMochiCSS, keyframes, media, mergeMochiCss,
|
|
1858
|
+
export { CSSObject, CssObjectBlock, CssObjectSubBlock, GlobalCssObject, KeyframesObject, MochiCSS, MochiKeyframes, MochiSelector, Token, camelToKebab, container, createToken, css, cssFromProps, globalCss, isAtRuleKey, isMochiCSS, kebabToCamel, keyframes, media, mergeMochiCss, numberToBase62, shortHash, supports };
|