@mochi-css/vanilla 3.0.1 → 4.0.0

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.mjs CHANGED
@@ -1,1858 +1,3 @@
1
- import clsx from "clsx";
1
+ import { C as Token, S as kebabToCamel, _ as shortHash, a as GlobalCssObject, b as cssFromProps, c as KeyframesObject, d as isMochiCSS, f as mergeMochiCss, g as numberToBase62, h as CssObjectSubBlock, i as globalCss, l as MochiCSS, m as CssObjectBlock, n as media, o as MochiKeyframes, p as CSSObject, r as supports, s as keyframes, t as container, u as css, v as MochiSelector, w as createToken, x as isAtRuleKey, y as camelToKebab } from "./src-CJmAtVxm.mjs";
2
2
 
3
- //#region src/token.ts
4
- /**
5
- * Represents a CSS custom property (design token) with type information.
6
- * Provides convenient access to both the variable name and its `var()` reference.
7
- * @template T - The expected value type of the token (for type checking)
8
- * @example
9
- * const primaryColor = new Token<string>('primary-color')
10
- * primaryColor.variable // '--primary-color'
11
- * primaryColor.value // 'var(--primary-color)'
12
- */
13
- var Token = class {
14
- /**
15
- * Creates a new CSS token.
16
- * @param name - The token name (without the `--` prefix)
17
- */
18
- constructor(name) {
19
- this.name = name;
20
- }
21
- /**
22
- * Gets the CSS custom property name (with `--` prefix).
23
- * Use this when defining the variable.
24
- */
25
- get variable() {
26
- return `--${this.name}`;
27
- }
28
- /**
29
- * Gets the CSS `var()` reference to this token.
30
- * Use this when consuming the variable value.
31
- */
32
- get value() {
33
- return `var(${this.variable})`;
34
- }
35
- /**
36
- * Returns the variable name for string coercion.
37
- */
38
- toString() {
39
- return this.variable;
40
- }
41
- };
42
- /**
43
- * Creates a new CSS design token.
44
- * @template T - The expected value type of the token
45
- * @param name - The token name (without the `--` prefix)
46
- * @returns A new Token instance
47
- * @example
48
- * const spacing = createToken<number>('spacing-md')
49
- * // Use in styles: { gap: spacing.value }
50
- */
51
- function createToken(name) {
52
- return new Token(name);
53
- }
54
-
55
- //#endregion
56
- //#region src/propertyUnits.generated.ts
57
- const propertyUnits = {
58
- animation: "ms",
59
- animationDelay: "ms",
60
- animationDuration: "ms",
61
- animationRange: "px",
62
- animationRangeCenter: "px",
63
- animationRangeEnd: "px",
64
- animationRangeStart: "px",
65
- background: "px",
66
- backgroundPosition: "px",
67
- backgroundPositionBlock: "px",
68
- backgroundPositionInline: "px",
69
- backgroundPositionX: "px",
70
- backgroundPositionY: "px",
71
- backgroundSize: "px",
72
- backgroundTbd: "px",
73
- baselineShift: "px",
74
- blockSize: "px",
75
- blockStep: "px",
76
- blockStepSize: "px",
77
- border: "px",
78
- borderBlock: "px",
79
- borderBlockClip: "px",
80
- borderBlockEnd: "px",
81
- borderBlockEndClip: "px",
82
- borderBlockEndRadius: "px",
83
- borderBlockEndWidth: "px",
84
- borderBlockStart: "px",
85
- borderBlockStartClip: "px",
86
- borderBlockStartRadius: "px",
87
- borderBlockStartWidth: "px",
88
- borderBlockWidth: "px",
89
- borderBottom: "px",
90
- borderBottomClip: "px",
91
- borderBottomLeftRadius: "px",
92
- borderBottomRadius: "px",
93
- borderBottomRightRadius: "px",
94
- borderBottomWidth: "px",
95
- borderClip: "px",
96
- borderEndEndRadius: "px",
97
- borderEndStartRadius: "px",
98
- borderImage: "%",
99
- borderImageOutset: "px",
100
- borderImageSlice: "%",
101
- borderImageWidth: "px",
102
- borderInline: "px",
103
- borderInlineClip: "px",
104
- borderInlineEnd: "px",
105
- borderInlineEndClip: "px",
106
- borderInlineEndRadius: "px",
107
- borderInlineEndWidth: "px",
108
- borderInlineStart: "px",
109
- borderInlineStartClip: "px",
110
- borderInlineStartRadius: "px",
111
- borderInlineStartWidth: "px",
112
- borderInlineWidth: "px",
113
- borderLeft: "px",
114
- borderLeftClip: "px",
115
- borderLeftRadius: "px",
116
- borderLeftWidth: "px",
117
- borderLimit: "px",
118
- borderRadius: "px",
119
- borderRight: "px",
120
- borderRightClip: "px",
121
- borderRightRadius: "px",
122
- borderRightWidth: "px",
123
- borderSpacing: "px",
124
- borderStartEndRadius: "px",
125
- borderStartStartRadius: "px",
126
- borderTop: "px",
127
- borderTopClip: "px",
128
- borderTopLeftRadius: "px",
129
- borderTopRadius: "px",
130
- borderTopRightRadius: "px",
131
- borderTopWidth: "px",
132
- borderWidth: "px",
133
- bottom: "px",
134
- boxShadow: "px",
135
- boxShadowBlur: "px",
136
- boxShadowOffset: "px",
137
- boxShadowSpread: "px",
138
- columnGap: "px",
139
- columnHeight: "px",
140
- columnRule: "px",
141
- columnRuleEdgeInset: "px",
142
- columnRuleEdgeInsetEnd: "px",
143
- columnRuleEdgeInsetStart: "px",
144
- columnRuleInset: "px",
145
- columnRuleInsetEnd: "px",
146
- columnRuleInsetStart: "px",
147
- columnRuleInteriorInset: "px",
148
- columnRuleInteriorInsetEnd: "px",
149
- columnRuleInteriorInsetStart: "px",
150
- columnRuleWidth: "px",
151
- columns: "px",
152
- columnWidth: "px",
153
- containIntrinsicBlockSize: "px",
154
- containIntrinsicHeight: "px",
155
- containIntrinsicInlineSize: "px",
156
- containIntrinsicSize: "px",
157
- containIntrinsicWidth: "px",
158
- corner: "px",
159
- cornerBlockEnd: "px",
160
- cornerBlockStart: "px",
161
- cornerBottom: "px",
162
- cornerBottomLeft: "px",
163
- cornerBottomRight: "px",
164
- cornerEndEnd: "px",
165
- cornerEndStart: "px",
166
- cornerInlineEnd: "px",
167
- cornerInlineStart: "px",
168
- cornerLeft: "px",
169
- cornerRight: "px",
170
- cornerStartEnd: "px",
171
- cornerStartStart: "px",
172
- cornerTop: "px",
173
- cornerTopLeft: "px",
174
- cornerTopRight: "px",
175
- cx: "px",
176
- cy: "px",
177
- fillOpacity: "%",
178
- fillPosition: "px",
179
- fillSize: "px",
180
- flex: "px",
181
- flexBasis: "px",
182
- floatOffset: "px",
183
- floodOpacity: "%",
184
- flowTolerance: "px",
185
- font: "deg",
186
- fontSize: "px",
187
- fontStretch: "%",
188
- fontStyle: "deg",
189
- fontWidth: "%",
190
- gap: "px",
191
- grid: "px",
192
- gridAutoColumns: "px",
193
- gridAutoRows: "px",
194
- gridColumnGap: "px",
195
- gridGap: "px",
196
- gridRowGap: "px",
197
- gridTemplate: "px",
198
- gridTemplateColumns: "px",
199
- gridTemplateRows: "px",
200
- height: "px",
201
- hyphenateLimitZone: "px",
202
- imageOrientation: "deg",
203
- imageResolution: "dppx",
204
- initialLetterWrap: "px",
205
- inlineSize: "px",
206
- inset: "px",
207
- insetBlock: "px",
208
- insetBlockEnd: "px",
209
- insetBlockStart: "px",
210
- insetInline: "px",
211
- insetInlineEnd: "px",
212
- insetInlineStart: "px",
213
- interestDelay: "ms",
214
- interestDelayEnd: "ms",
215
- interestDelayStart: "ms",
216
- left: "px",
217
- letterSpacing: "px",
218
- lineHeight: "px",
219
- lineHeightStep: "px",
220
- linePadding: "px",
221
- margin: "px",
222
- marginBlock: "px",
223
- marginBlockEnd: "px",
224
- marginBlockStart: "px",
225
- marginBottom: "px",
226
- marginInline: "px",
227
- marginInlineEnd: "px",
228
- marginInlineStart: "px",
229
- marginLeft: "px",
230
- marginRight: "px",
231
- marginTop: "px",
232
- mask: "px",
233
- maskBorder: "%",
234
- maskBorderOutset: "px",
235
- maskBorderSlice: "%",
236
- maskBorderWidth: "px",
237
- maskPosition: "px",
238
- maskSize: "px",
239
- maxBlockSize: "px",
240
- maxHeight: "px",
241
- maxInlineSize: "px",
242
- maxWidth: "px",
243
- minBlockSize: "px",
244
- minHeight: "px",
245
- minInlineSize: "px",
246
- minWidth: "px",
247
- objectPosition: "px",
248
- offset: "px",
249
- offsetAnchor: "px",
250
- offsetDistance: "px",
251
- offsetPosition: "px",
252
- offsetRotate: "deg",
253
- opacity: "%",
254
- outline: "px",
255
- outlineOffset: "px",
256
- outlineWidth: "px",
257
- overflowClipMargin: "px",
258
- overflowClipMarginBlock: "px",
259
- overflowClipMarginBlockEnd: "px",
260
- overflowClipMarginBlockStart: "px",
261
- overflowClipMarginBottom: "px",
262
- overflowClipMarginInline: "px",
263
- overflowClipMarginInlineEnd: "px",
264
- overflowClipMarginInlineStart: "px",
265
- overflowClipMarginLeft: "px",
266
- overflowClipMarginRight: "px",
267
- overflowClipMarginTop: "px",
268
- padding: "px",
269
- paddingBlock: "px",
270
- paddingBlockEnd: "px",
271
- paddingBlockStart: "px",
272
- paddingBottom: "px",
273
- paddingInline: "px",
274
- paddingInlineEnd: "px",
275
- paddingInlineStart: "px",
276
- paddingLeft: "px",
277
- paddingRight: "px",
278
- paddingTop: "px",
279
- pause: "ms",
280
- pauseAfter: "ms",
281
- pauseBefore: "ms",
282
- perspective: "px",
283
- perspectiveOrigin: "px",
284
- r: "px",
285
- rest: "ms",
286
- restAfter: "ms",
287
- restBefore: "ms",
288
- right: "px",
289
- rotate: "deg",
290
- rowGap: "px",
291
- rowRule: "px",
292
- rowRuleEdgeInset: "px",
293
- rowRuleEdgeInsetEnd: "px",
294
- rowRuleEdgeInsetStart: "px",
295
- rowRuleInset: "px",
296
- rowRuleInsetEnd: "px",
297
- rowRuleInsetStart: "px",
298
- rowRuleInteriorInset: "px",
299
- rowRuleInteriorInsetEnd: "px",
300
- rowRuleInteriorInsetStart: "px",
301
- rowRuleWidth: "px",
302
- rule: "px",
303
- ruleEdgeInset: "px",
304
- ruleInset: "px",
305
- ruleInsetEnd: "px",
306
- ruleInsetStart: "px",
307
- ruleInteriorInset: "px",
308
- ruleWidth: "px",
309
- rx: "px",
310
- ry: "px",
311
- scale: "%",
312
- scrollMargin: "px",
313
- scrollMarginBlock: "px",
314
- scrollMarginBlockEnd: "px",
315
- scrollMarginBlockStart: "px",
316
- scrollMarginBottom: "px",
317
- scrollMarginInline: "px",
318
- scrollMarginInlineEnd: "px",
319
- scrollMarginInlineStart: "px",
320
- scrollMarginLeft: "px",
321
- scrollMarginRight: "px",
322
- scrollMarginTop: "px",
323
- scrollPadding: "px",
324
- scrollPaddingBlock: "px",
325
- scrollPaddingBlockEnd: "px",
326
- scrollPaddingBlockStart: "px",
327
- scrollPaddingBottom: "px",
328
- scrollPaddingInline: "px",
329
- scrollPaddingInlineEnd: "px",
330
- scrollPaddingInlineStart: "px",
331
- scrollPaddingLeft: "px",
332
- scrollPaddingRight: "px",
333
- scrollPaddingTop: "px",
334
- shapeImageThreshold: "%",
335
- shapeMargin: "px",
336
- shapePadding: "px",
337
- stopOpacity: "%",
338
- strokeDasharray: "px",
339
- strokeDashcorner: "px",
340
- strokeDashCorner: "px",
341
- strokeDashoffset: "px",
342
- strokeOpacity: "%",
343
- strokePosition: "px",
344
- strokeSize: "px",
345
- strokeWidth: "px",
346
- tabSize: "px",
347
- textDecoration: "px",
348
- textDecorationInset: "px",
349
- textDecorationThickness: "px",
350
- textIndent: "px",
351
- textShadow: "px",
352
- textSizeAdjust: "%",
353
- textUnderlineOffset: "px",
354
- timelineTrigger: "px",
355
- timelineTriggerActivationRange: "px",
356
- timelineTriggerActivationRangeEnd: "px",
357
- timelineTriggerActivationRangeStart: "px",
358
- timelineTriggerActiveRange: "px",
359
- timelineTriggerActiveRangeEnd: "px",
360
- timelineTriggerActiveRangeStart: "px",
361
- top: "px",
362
- transformOrigin: "px",
363
- transition: "ms",
364
- transitionDelay: "ms",
365
- transitionDuration: "ms",
366
- translate: "px",
367
- verticalAlign: "px",
368
- viewTimeline: "px",
369
- viewTimelineInset: "px",
370
- voiceDuration: "ms",
371
- voicePitch: "Hz",
372
- voiceRange: "Hz",
373
- voiceRate: "%",
374
- width: "px",
375
- wordSpacing: "px",
376
- x: "px",
377
- y: "px",
378
- zoom: "%"
379
- };
380
-
381
- //#endregion
382
- //#region src/knownProperties.generated.ts
383
- const knownPropertyNames = new Set([
384
- "accentColor",
385
- "alignContent",
386
- "alignItems",
387
- "alignSelf",
388
- "alignmentBaseline",
389
- "all",
390
- "anchorName",
391
- "anchorScope",
392
- "animation",
393
- "animationComposition",
394
- "animationDelay",
395
- "animationDirection",
396
- "animationDuration",
397
- "animationFillMode",
398
- "animationIterationCount",
399
- "animationName",
400
- "animationPlayState",
401
- "animationRange",
402
- "animationRangeCenter",
403
- "animationRangeEnd",
404
- "animationRangeStart",
405
- "animationTimeline",
406
- "animationTimingFunction",
407
- "animationTrigger",
408
- "appearance",
409
- "aspectRatio",
410
- "backdropFilter",
411
- "backfaceVisibility",
412
- "background",
413
- "backgroundAttachment",
414
- "backgroundBlendMode",
415
- "backgroundClip",
416
- "backgroundColor",
417
- "backgroundImage",
418
- "backgroundOrigin",
419
- "backgroundPosition",
420
- "backgroundPositionBlock",
421
- "backgroundPositionInline",
422
- "backgroundPositionX",
423
- "backgroundPositionY",
424
- "backgroundRepeat",
425
- "backgroundRepeatBlock",
426
- "backgroundRepeatInline",
427
- "backgroundRepeatX",
428
- "backgroundRepeatY",
429
- "backgroundSize",
430
- "backgroundTbd",
431
- "baselineShift",
432
- "baselineSource",
433
- "blockEllipsis",
434
- "blockSize",
435
- "blockStep",
436
- "blockStepAlign",
437
- "blockStepInsert",
438
- "blockStepRound",
439
- "blockStepSize",
440
- "bookmarkLabel",
441
- "bookmarkLevel",
442
- "bookmarkState",
443
- "border",
444
- "borderBlock",
445
- "borderBlockClip",
446
- "borderBlockColor",
447
- "borderBlockEnd",
448
- "borderBlockEndClip",
449
- "borderBlockEndColor",
450
- "borderBlockEndRadius",
451
- "borderBlockEndStyle",
452
- "borderBlockEndWidth",
453
- "borderBlockStart",
454
- "borderBlockStartClip",
455
- "borderBlockStartColor",
456
- "borderBlockStartRadius",
457
- "borderBlockStartStyle",
458
- "borderBlockStartWidth",
459
- "borderBlockStyle",
460
- "borderBlockWidth",
461
- "borderBottom",
462
- "borderBottomClip",
463
- "borderBottomColor",
464
- "borderBottomLeftRadius",
465
- "borderBottomRadius",
466
- "borderBottomRightRadius",
467
- "borderBottomStyle",
468
- "borderBottomWidth",
469
- "borderBoundary",
470
- "borderClip",
471
- "borderCollapse",
472
- "borderColor",
473
- "borderEndEndRadius",
474
- "borderEndStartRadius",
475
- "borderImage",
476
- "borderImageOutset",
477
- "borderImageRepeat",
478
- "borderImageSlice",
479
- "borderImageSource",
480
- "borderImageWidth",
481
- "borderInline",
482
- "borderInlineClip",
483
- "borderInlineColor",
484
- "borderInlineEnd",
485
- "borderInlineEndClip",
486
- "borderInlineEndColor",
487
- "borderInlineEndRadius",
488
- "borderInlineEndStyle",
489
- "borderInlineEndWidth",
490
- "borderInlineStart",
491
- "borderInlineStartClip",
492
- "borderInlineStartColor",
493
- "borderInlineStartRadius",
494
- "borderInlineStartStyle",
495
- "borderInlineStartWidth",
496
- "borderInlineStyle",
497
- "borderInlineWidth",
498
- "borderLeft",
499
- "borderLeftClip",
500
- "borderLeftColor",
501
- "borderLeftRadius",
502
- "borderLeftStyle",
503
- "borderLeftWidth",
504
- "borderLimit",
505
- "borderRadius",
506
- "borderRight",
507
- "borderRightClip",
508
- "borderRightColor",
509
- "borderRightRadius",
510
- "borderRightStyle",
511
- "borderRightWidth",
512
- "borderShape",
513
- "borderSpacing",
514
- "borderStartEndRadius",
515
- "borderStartStartRadius",
516
- "borderStyle",
517
- "borderTop",
518
- "borderTopClip",
519
- "borderTopColor",
520
- "borderTopLeftRadius",
521
- "borderTopRadius",
522
- "borderTopRightRadius",
523
- "borderTopStyle",
524
- "borderTopWidth",
525
- "borderWidth",
526
- "bottom",
527
- "boxDecorationBreak",
528
- "boxShadow",
529
- "boxShadowBlur",
530
- "boxShadowColor",
531
- "boxShadowOffset",
532
- "boxShadowPosition",
533
- "boxShadowSpread",
534
- "boxSizing",
535
- "boxSnap",
536
- "breakAfter",
537
- "breakBefore",
538
- "breakInside",
539
- "captionSide",
540
- "caret",
541
- "caretAnimation",
542
- "caretColor",
543
- "caretShape",
544
- "clear",
545
- "clip",
546
- "clipPath",
547
- "clipRule",
548
- "color",
549
- "colorAdjust",
550
- "colorInterpolation",
551
- "colorInterpolationFilters",
552
- "colorScheme",
553
- "columnCount",
554
- "columnFill",
555
- "columnGap",
556
- "columnHeight",
557
- "columnRule",
558
- "columnRuleBreak",
559
- "columnRuleColor",
560
- "columnRuleEdgeInset",
561
- "columnRuleEdgeInsetEnd",
562
- "columnRuleEdgeInsetStart",
563
- "columnRuleInset",
564
- "columnRuleInsetEnd",
565
- "columnRuleInsetStart",
566
- "columnRuleInteriorInset",
567
- "columnRuleInteriorInsetEnd",
568
- "columnRuleInteriorInsetStart",
569
- "columnRuleStyle",
570
- "columnRuleVisibilityItems",
571
- "columnRuleWidth",
572
- "columnSpan",
573
- "columnWidth",
574
- "columnWrap",
575
- "columns",
576
- "contain",
577
- "containIntrinsicBlockSize",
578
- "containIntrinsicHeight",
579
- "containIntrinsicInlineSize",
580
- "containIntrinsicSize",
581
- "containIntrinsicWidth",
582
- "container",
583
- "containerName",
584
- "containerType",
585
- "content",
586
- "contentVisibility",
587
- "continue",
588
- "copyInto",
589
- "corner",
590
- "cornerBlockEnd",
591
- "cornerBlockEndShape",
592
- "cornerBlockStart",
593
- "cornerBlockStartShape",
594
- "cornerBottom",
595
- "cornerBottomLeft",
596
- "cornerBottomLeftShape",
597
- "cornerBottomRight",
598
- "cornerBottomRightShape",
599
- "cornerBottomShape",
600
- "cornerEndEnd",
601
- "cornerEndEndShape",
602
- "cornerEndStart",
603
- "cornerEndStartShape",
604
- "cornerInlineEnd",
605
- "cornerInlineEndShape",
606
- "cornerInlineStart",
607
- "cornerInlineStartShape",
608
- "cornerLeft",
609
- "cornerLeftShape",
610
- "cornerRight",
611
- "cornerRightShape",
612
- "cornerShape",
613
- "cornerStartEnd",
614
- "cornerStartEndShape",
615
- "cornerStartStart",
616
- "cornerStartStartShape",
617
- "cornerTop",
618
- "cornerTopLeft",
619
- "cornerTopLeftShape",
620
- "cornerTopRight",
621
- "cornerTopRightShape",
622
- "cornerTopShape",
623
- "counterIncrement",
624
- "counterReset",
625
- "counterSet",
626
- "cue",
627
- "cueAfter",
628
- "cueBefore",
629
- "cursor",
630
- "cx",
631
- "cy",
632
- "d",
633
- "direction",
634
- "display",
635
- "dominantBaseline",
636
- "dynamicRangeLimit",
637
- "emptyCells",
638
- "eventTrigger",
639
- "eventTriggerName",
640
- "eventTriggerSource",
641
- "fieldSizing",
642
- "fill",
643
- "fillBreak",
644
- "fillColor",
645
- "fillImage",
646
- "fillOpacity",
647
- "fillOrigin",
648
- "fillPosition",
649
- "fillRepeat",
650
- "fillRule",
651
- "fillSize",
652
- "filter",
653
- "flex",
654
- "flexBasis",
655
- "flexDirection",
656
- "flexFlow",
657
- "flexGrow",
658
- "flexShrink",
659
- "flexWrap",
660
- "float",
661
- "floatDefer",
662
- "floatOffset",
663
- "floatReference",
664
- "floodColor",
665
- "floodOpacity",
666
- "flowFrom",
667
- "flowInto",
668
- "flowTolerance",
669
- "font",
670
- "fontFamily",
671
- "fontFeatureSettings",
672
- "fontKerning",
673
- "fontLanguageOverride",
674
- "fontOpticalSizing",
675
- "fontPalette",
676
- "fontSize",
677
- "fontSizeAdjust",
678
- "fontStretch",
679
- "fontStyle",
680
- "fontSynthesis",
681
- "fontSynthesisPosition",
682
- "fontSynthesisSmallCaps",
683
- "fontSynthesisStyle",
684
- "fontSynthesisWeight",
685
- "fontVariant",
686
- "fontVariantAlternates",
687
- "fontVariantCaps",
688
- "fontVariantEastAsian",
689
- "fontVariantEmoji",
690
- "fontVariantLigatures",
691
- "fontVariantNumeric",
692
- "fontVariantPosition",
693
- "fontVariationSettings",
694
- "fontWeight",
695
- "fontWidth",
696
- "footnoteDisplay",
697
- "footnotePolicy",
698
- "forcedColorAdjust",
699
- "gap",
700
- "glyphOrientationVertical",
701
- "grid",
702
- "gridArea",
703
- "gridAutoColumns",
704
- "gridAutoFlow",
705
- "gridAutoRows",
706
- "gridColumn",
707
- "gridColumnEnd",
708
- "gridColumnGap",
709
- "gridColumnStart",
710
- "gridGap",
711
- "gridRow",
712
- "gridRowEnd",
713
- "gridRowGap",
714
- "gridRowStart",
715
- "gridTemplate",
716
- "gridTemplateAreas",
717
- "gridTemplateColumns",
718
- "gridTemplateRows",
719
- "hangingPunctuation",
720
- "height",
721
- "hyphenateCharacter",
722
- "hyphenateLimitChars",
723
- "hyphenateLimitLast",
724
- "hyphenateLimitLines",
725
- "hyphenateLimitZone",
726
- "hyphens",
727
- "imageAnimation",
728
- "imageOrientation",
729
- "imageRendering",
730
- "imageResolution",
731
- "initialLetter",
732
- "initialLetterAlign",
733
- "initialLetterWrap",
734
- "inlineSize",
735
- "inlineSizing",
736
- "inputSecurity",
737
- "inset",
738
- "insetBlock",
739
- "insetBlockEnd",
740
- "insetBlockStart",
741
- "insetInline",
742
- "insetInlineEnd",
743
- "insetInlineStart",
744
- "interactivity",
745
- "interestDelay",
746
- "interestDelayEnd",
747
- "interestDelayStart",
748
- "interpolateSize",
749
- "isolation",
750
- "justifyContent",
751
- "justifyItems",
752
- "justifySelf",
753
- "left",
754
- "letterSpacing",
755
- "lightingColor",
756
- "lineBreak",
757
- "lineClamp",
758
- "lineFitEdge",
759
- "lineGrid",
760
- "lineHeight",
761
- "lineHeightStep",
762
- "linePadding",
763
- "lineSnap",
764
- "linkParameters",
765
- "listStyle",
766
- "listStyleImage",
767
- "listStylePosition",
768
- "listStyleType",
769
- "margin",
770
- "marginBlock",
771
- "marginBlockEnd",
772
- "marginBlockStart",
773
- "marginBottom",
774
- "marginBreak",
775
- "marginInline",
776
- "marginInlineEnd",
777
- "marginInlineStart",
778
- "marginLeft",
779
- "marginRight",
780
- "marginTop",
781
- "marginTrim",
782
- "marker",
783
- "markerEnd",
784
- "markerMid",
785
- "markerSide",
786
- "markerStart",
787
- "mask",
788
- "maskBorder",
789
- "maskBorderMode",
790
- "maskBorderOutset",
791
- "maskBorderRepeat",
792
- "maskBorderSlice",
793
- "maskBorderSource",
794
- "maskBorderWidth",
795
- "maskClip",
796
- "maskComposite",
797
- "maskImage",
798
- "maskMode",
799
- "maskOrigin",
800
- "maskPosition",
801
- "maskRepeat",
802
- "maskSize",
803
- "maskType",
804
- "mathDepth",
805
- "mathShift",
806
- "mathStyle",
807
- "maxBlockSize",
808
- "maxHeight",
809
- "maxInlineSize",
810
- "maxLines",
811
- "maxWidth",
812
- "minBlockSize",
813
- "minHeight",
814
- "minInlineSize",
815
- "minIntrinsicSizing",
816
- "minWidth",
817
- "mixBlendMode",
818
- "navDown",
819
- "navLeft",
820
- "navRight",
821
- "navUp",
822
- "objectFit",
823
- "objectPosition",
824
- "objectViewBox",
825
- "offset",
826
- "offsetAnchor",
827
- "offsetDistance",
828
- "offsetPath",
829
- "offsetPosition",
830
- "offsetRotate",
831
- "opacity",
832
- "order",
833
- "orphans",
834
- "outline",
835
- "outlineColor",
836
- "outlineOffset",
837
- "outlineStyle",
838
- "outlineWidth",
839
- "overflow",
840
- "overflowAnchor",
841
- "overflowBlock",
842
- "overflowClipMargin",
843
- "overflowClipMarginBlock",
844
- "overflowClipMarginBlockEnd",
845
- "overflowClipMarginBlockStart",
846
- "overflowClipMarginBottom",
847
- "overflowClipMarginInline",
848
- "overflowClipMarginInlineEnd",
849
- "overflowClipMarginInlineStart",
850
- "overflowClipMarginLeft",
851
- "overflowClipMarginRight",
852
- "overflowClipMarginTop",
853
- "overflowInline",
854
- "overflowWrap",
855
- "overflowX",
856
- "overflowY",
857
- "overlay",
858
- "overscrollBehavior",
859
- "overscrollBehaviorBlock",
860
- "overscrollBehaviorInline",
861
- "overscrollBehaviorX",
862
- "overscrollBehaviorY",
863
- "padding",
864
- "paddingBlock",
865
- "paddingBlockEnd",
866
- "paddingBlockStart",
867
- "paddingBottom",
868
- "paddingInline",
869
- "paddingInlineEnd",
870
- "paddingInlineStart",
871
- "paddingLeft",
872
- "paddingRight",
873
- "paddingTop",
874
- "page",
875
- "pageBreakAfter",
876
- "pageBreakBefore",
877
- "pageBreakInside",
878
- "paintOrder",
879
- "pause",
880
- "pauseAfter",
881
- "pauseBefore",
882
- "perspective",
883
- "perspectiveOrigin",
884
- "placeContent",
885
- "placeItems",
886
- "placeSelf",
887
- "pointerEvents",
888
- "pointerTimeline",
889
- "pointerTimelineAxis",
890
- "pointerTimelineName",
891
- "position",
892
- "positionAnchor",
893
- "positionArea",
894
- "positionTry",
895
- "positionTryFallbacks",
896
- "positionTryOrder",
897
- "positionVisibility",
898
- "printColorAdjust",
899
- "quotes",
900
- "r",
901
- "readingFlow",
902
- "readingOrder",
903
- "regionFragment",
904
- "resize",
905
- "rest",
906
- "restAfter",
907
- "restBefore",
908
- "right",
909
- "rotate",
910
- "rowGap",
911
- "rowRule",
912
- "rowRuleBreak",
913
- "rowRuleColor",
914
- "rowRuleEdgeInset",
915
- "rowRuleEdgeInsetEnd",
916
- "rowRuleEdgeInsetStart",
917
- "rowRuleInset",
918
- "rowRuleInsetEnd",
919
- "rowRuleInsetStart",
920
- "rowRuleInteriorInset",
921
- "rowRuleInteriorInsetEnd",
922
- "rowRuleInteriorInsetStart",
923
- "rowRuleStyle",
924
- "rowRuleVisibilityItems",
925
- "rowRuleWidth",
926
- "rubyAlign",
927
- "rubyMerge",
928
- "rubyOverhang",
929
- "rubyPosition",
930
- "rule",
931
- "ruleBreak",
932
- "ruleColor",
933
- "ruleEdgeInset",
934
- "ruleInset",
935
- "ruleInsetEnd",
936
- "ruleInsetStart",
937
- "ruleInteriorInset",
938
- "ruleOverlap",
939
- "ruleStyle",
940
- "ruleVisibilityItems",
941
- "ruleWidth",
942
- "rx",
943
- "ry",
944
- "scale",
945
- "scrollBehavior",
946
- "scrollInitialTarget",
947
- "scrollMargin",
948
- "scrollMarginBlock",
949
- "scrollMarginBlockEnd",
950
- "scrollMarginBlockStart",
951
- "scrollMarginBottom",
952
- "scrollMarginInline",
953
- "scrollMarginInlineEnd",
954
- "scrollMarginInlineStart",
955
- "scrollMarginLeft",
956
- "scrollMarginRight",
957
- "scrollMarginTop",
958
- "scrollMarkerGroup",
959
- "scrollPadding",
960
- "scrollPaddingBlock",
961
- "scrollPaddingBlockEnd",
962
- "scrollPaddingBlockStart",
963
- "scrollPaddingBottom",
964
- "scrollPaddingInline",
965
- "scrollPaddingInlineEnd",
966
- "scrollPaddingInlineStart",
967
- "scrollPaddingLeft",
968
- "scrollPaddingRight",
969
- "scrollPaddingTop",
970
- "scrollSnapAlign",
971
- "scrollSnapStop",
972
- "scrollSnapType",
973
- "scrollTargetGroup",
974
- "scrollTimeline",
975
- "scrollTimelineAxis",
976
- "scrollTimelineName",
977
- "scrollbarColor",
978
- "scrollbarGutter",
979
- "scrollbarWidth",
980
- "shapeImageThreshold",
981
- "shapeInside",
982
- "shapeMargin",
983
- "shapeOutside",
984
- "shapePadding",
985
- "shapeRendering",
986
- "shapeSubtract",
987
- "sliderOrientation",
988
- "spatialNavigationAction",
989
- "spatialNavigationContain",
990
- "spatialNavigationFunction",
991
- "speak",
992
- "speakAs",
993
- "stopColor",
994
- "stopOpacity",
995
- "stringSet",
996
- "stroke",
997
- "strokeAlign",
998
- "strokeAlignment",
999
- "strokeBreak",
1000
- "strokeColor",
1001
- "strokeDashCorner",
1002
- "strokeDashJustify",
1003
- "strokeDashadjust",
1004
- "strokeDasharray",
1005
- "strokeDashcorner",
1006
- "strokeDashoffset",
1007
- "strokeImage",
1008
- "strokeLinecap",
1009
- "strokeLinejoin",
1010
- "strokeMiterlimit",
1011
- "strokeOpacity",
1012
- "strokeOrigin",
1013
- "strokePosition",
1014
- "strokeRepeat",
1015
- "strokeSize",
1016
- "strokeWidth",
1017
- "tabSize",
1018
- "tableLayout",
1019
- "textAlign",
1020
- "textAlignAll",
1021
- "textAlignLast",
1022
- "textAnchor",
1023
- "textAutospace",
1024
- "textBox",
1025
- "textBoxEdge",
1026
- "textBoxTrim",
1027
- "textCombineUpright",
1028
- "textDecoration",
1029
- "textDecorationColor",
1030
- "textDecorationInset",
1031
- "textDecorationLine",
1032
- "textDecorationSkip",
1033
- "textDecorationSkipBox",
1034
- "textDecorationSkipInk",
1035
- "textDecorationSkipSelf",
1036
- "textDecorationSkipSpaces",
1037
- "textDecorationStyle",
1038
- "textDecorationThickness",
1039
- "textEmphasis",
1040
- "textEmphasisColor",
1041
- "textEmphasisPosition",
1042
- "textEmphasisSkip",
1043
- "textEmphasisStyle",
1044
- "textGroupAlign",
1045
- "textIndent",
1046
- "textJustify",
1047
- "textOrientation",
1048
- "textOverflow",
1049
- "textRendering",
1050
- "textShadow",
1051
- "textSizeAdjust",
1052
- "textSpacing",
1053
- "textSpacingTrim",
1054
- "textTransform",
1055
- "textUnderlineOffset",
1056
- "textUnderlinePosition",
1057
- "textWrap",
1058
- "textWrapMode",
1059
- "textWrapStyle",
1060
- "timelineScope",
1061
- "timelineTrigger",
1062
- "timelineTriggerActivationRange",
1063
- "timelineTriggerActivationRangeEnd",
1064
- "timelineTriggerActivationRangeStart",
1065
- "timelineTriggerActiveRange",
1066
- "timelineTriggerActiveRangeEnd",
1067
- "timelineTriggerActiveRangeStart",
1068
- "timelineTriggerName",
1069
- "timelineTriggerSource",
1070
- "top",
1071
- "touchAction",
1072
- "transform",
1073
- "transformBox",
1074
- "transformOrigin",
1075
- "transformStyle",
1076
- "transition",
1077
- "transitionBehavior",
1078
- "transitionDelay",
1079
- "transitionDuration",
1080
- "transitionProperty",
1081
- "transitionTimingFunction",
1082
- "translate",
1083
- "triggerScope",
1084
- "unicodeBidi",
1085
- "userSelect",
1086
- "vectorEffect",
1087
- "verticalAlign",
1088
- "viewTimeline",
1089
- "viewTimelineAxis",
1090
- "viewTimelineInset",
1091
- "viewTimelineName",
1092
- "viewTransitionClass",
1093
- "viewTransitionGroup",
1094
- "viewTransitionName",
1095
- "viewTransitionScope",
1096
- "visibility",
1097
- "voiceBalance",
1098
- "voiceDuration",
1099
- "voiceFamily",
1100
- "voicePitch",
1101
- "voiceRange",
1102
- "voiceRate",
1103
- "voiceStress",
1104
- "voiceVolume",
1105
- "whiteSpace",
1106
- "whiteSpaceCollapse",
1107
- "whiteSpaceTrim",
1108
- "widows",
1109
- "width",
1110
- "willChange",
1111
- "wordBreak",
1112
- "wordSpaceTransform",
1113
- "wordSpacing",
1114
- "wordWrap",
1115
- "wrapAfter",
1116
- "wrapBefore",
1117
- "wrapFlow",
1118
- "wrapInside",
1119
- "wrapThrough",
1120
- "writingMode",
1121
- "x",
1122
- "y",
1123
- "zIndex",
1124
- "zoom"
1125
- ]);
1126
-
1127
- //#endregion
1128
- //#region src/props.ts
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
- /**
1136
- * Converts a camelCase string to kebab-case.
1137
- */
1138
- function camelToKebab(str) {
1139
- return str.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
1140
- }
1141
- function getUnitForProperty(propertyName) {
1142
- return propertyName in propertyUnits ? propertyUnits[propertyName] : void 0;
1143
- }
1144
- /**
1145
- * Converts a CSS-like value to its string representation.
1146
- * For properties with known units, numbers are automatically suffixed.
1147
- */
1148
- function formatValue(value, propertyName, maxDepth = 10) {
1149
- if (maxDepth <= 0) return "";
1150
- if (typeof value === "string") return value;
1151
- if (typeof value === "number") {
1152
- const unit = getUnitForProperty(propertyName);
1153
- if (unit === "%") return `${value * 100}${unit}`;
1154
- if (value === 0) return "0";
1155
- return unit ? `${value}${unit}` : value.toString();
1156
- }
1157
- return formatValue(value.value, propertyName, maxDepth - 1);
1158
- }
1159
- /**
1160
- * Checks if a property name is a CSS custom property (variable).
1161
- */
1162
- function isCssVariableName(key) {
1163
- return key.startsWith("--");
1164
- }
1165
- /**
1166
- * Converts a CSS-like value to a string for use as a CSS variable value.
1167
- * @param value - The value to convert (string, number, or wrapped value)
1168
- * @param maxDepth - Maximum recursion depth for evaluating the value
1169
- * @returns The string representation
1170
- */
1171
- function asVar(value, maxDepth = 10) {
1172
- if (maxDepth <= 0) return "";
1173
- switch (typeof value) {
1174
- case "string": return value;
1175
- case "number": return value.toString();
1176
- default: return asVar(value.value, maxDepth - 1);
1177
- }
1178
- }
1179
- /**
1180
- * Checks if a property name is a known CSS property.
1181
- */
1182
- function isKnownPropertyName(key) {
1183
- return knownPropertyNames.has(key);
1184
- }
1185
- /**
1186
- * Converts a value to a CSS property string.
1187
- * Automatically appends units to numeric values for properties that require them.
1188
- * @param value - The value to convert
1189
- * @param key - The CSS property name
1190
- * @returns The formatted CSS value string
1191
- */
1192
- function asKnownProp(value, key) {
1193
- return formatValue(value, key);
1194
- }
1195
- /**
1196
- * Checks if a key represents a nested CSS selector.
1197
- */
1198
- function isNestedSelector(key) {
1199
- return key.includes("&");
1200
- }
1201
- /** Known at-rule prefixes that mochi-css recognizes */
1202
- const AT_RULE_PREFIXES = [
1203
- "@media ",
1204
- "@container ",
1205
- "@supports ",
1206
- "@layer "
1207
- ];
1208
- /**
1209
- * Checks if a key represents a CSS at-rule (media, container, supports, layer).
1210
- */
1211
- function isAtRuleKey(key) {
1212
- return AT_RULE_PREFIXES.some((p) => key.startsWith(p));
1213
- }
1214
- /**
1215
- * Converts a SimpleStyleProps object to a CSS properties record.
1216
- * Transforms camelCase property names to kebab-case and applies value converters.
1217
- * @param props - The style properties object
1218
- * @returns A record of CSS property names (kebab-case) to string values
1219
- * @example
1220
- * cssFromProps({ backgroundColor: 'blue', padding: 16 })
1221
- * // { 'background-color': 'blue', 'padding': '16px' }
1222
- */
1223
- function cssFromProps(props) {
1224
- return Object.fromEntries(Object.entries(props).map(([key, value]) => {
1225
- if (value === void 0) return void 0;
1226
- if (isCssVariableName(key)) return [key, asVar(value)];
1227
- if (isKnownPropertyName(key)) return [camelToKebab(key), asKnownProp(value, key)];
1228
- }).filter((v) => v !== void 0));
1229
- }
1230
-
1231
- //#endregion
1232
- //#region src/selector.ts
1233
- /**
1234
- * Immutable CSS selector builder that handles nested selectors and CSS at-rules.
1235
- * Uses the `&` character as a placeholder for parent selector substitution.
1236
- *
1237
- * @example
1238
- * const selector = new MochiSelector(['.button'])
1239
- * selector.extend('&:hover').cssSelector // '.button:hover'
1240
- * selector.wrap('@media (min-width: 768px)').atRules // ['@media (min-width: 768px)']
1241
- */
1242
- var MochiSelector = class MochiSelector {
1243
- /**
1244
- * Creates a new MochiSelector instance.
1245
- * @param cssSelectors - Array of CSS selectors (may contain `&` placeholders)
1246
- * @param atRules - Array of full CSS at-rule strings e.g. `"@media (min-width: 768px)"`
1247
- */
1248
- constructor(cssSelectors = [], atRules = []) {
1249
- this.cssSelectors = cssSelectors;
1250
- this.atRules = atRules;
1251
- }
1252
- /**
1253
- * Gets the combined CSS selector string.
1254
- * Multiple selectors are joined with commas.
1255
- * @returns The CSS selector, or "*" if no selectors are defined
1256
- */
1257
- get cssSelector() {
1258
- if (this.cssSelectors.length === 0) return "*";
1259
- return this.cssSelectors.join(", ");
1260
- }
1261
- /**
1262
- * Substitutes all `&` placeholders with the given root selector.
1263
- * @param root - The selector to replace `&` with
1264
- * @returns A new MochiSelector with substituted selectors
1265
- */
1266
- substitute(root) {
1267
- return new MochiSelector(this.cssSelectors.map((selector) => selector.replace(/&/g, root)), this.atRules);
1268
- }
1269
- /**
1270
- * Extends this selector by nesting a child selector.
1271
- * The `&` in the child selector is replaced with each parent selector.
1272
- * @param child - The child selector pattern (must contain `&`)
1273
- * @returns A new MochiSelector with the extended selectors
1274
- * @example
1275
- * new MochiSelector(['.btn']).extend('&:hover') // '.btn:hover'
1276
- * new MochiSelector(['.btn']).extend('& .icon') // '.btn .icon'
1277
- */
1278
- extend(child) {
1279
- if (!isNestedSelector(child)) return this;
1280
- const children = MochiSelector.split(child);
1281
- return new MochiSelector(this.cssSelectors.flatMap((parentSelector) => children.map((childSelector) => {
1282
- return childSelector.replace(/&/g, parentSelector);
1283
- })), this.atRules);
1284
- }
1285
- /**
1286
- * Wraps this selector with a CSS at-rule.
1287
- * @param atRule - The full at-rule string (e.g. `"@media (min-width: 768px)"`)
1288
- * @returns A new MochiSelector with the added at-rule, or unchanged if not a known at-rule
1289
- * @example
1290
- * selector.wrap('@media (min-width: 768px)') // Adds media query
1291
- * selector.wrap('@container sidebar (min-width: 300px)') // Adds container query
1292
- */
1293
- wrap(atRule) {
1294
- if (!isAtRuleKey(atRule)) return this;
1295
- return new MochiSelector(this.cssSelectors, [...this.atRules, atRule]);
1296
- }
1297
- /**
1298
- * Splits a comma-separated selector string into individual selectors.
1299
- * @param selector - The selector string to split
1300
- * @returns Array of individual selector strings
1301
- */
1302
- static split(selector) {
1303
- return [selector];
1304
- }
1305
- };
1306
-
1307
- //#endregion
1308
- //#region src/hash.ts
1309
- /**
1310
- * Hashing utilities for generating short, deterministic class names.
1311
- * Uses djb2 algorithm for fast string hashing.
1312
- * @module hash
1313
- */
1314
- /** Characters used for base-62 encoding (css-name safe variant of base-64) */
1315
- const hashBase = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_";
1316
- const base = 64;
1317
- /**
1318
- * Converts a number to a base-62 string representation.
1319
- * @param num - The number to convert
1320
- * @param maxLength - Optional maximum length of the output string
1321
- * @returns Base-62 encoded string representation of the number
1322
- */
1323
- function numberToBase62(num, maxLength) {
1324
- let out = "";
1325
- while (num > 0 && out.length < (maxLength ?? Infinity)) {
1326
- out = hashBase[num % base] + out;
1327
- num = Math.floor(num / base);
1328
- }
1329
- return out.length > 0 ? out : "0";
1330
- }
1331
- /**
1332
- * Generates a short hash string from input using the djb2 algorithm.
1333
- * Used to create unique, deterministic CSS class names from style content.
1334
- * @param input - The string to hash
1335
- * @param length - Maximum length of the hash output (default: 8)
1336
- * @returns A short, css-safe hash string
1337
- * @example
1338
- * shortHash("color: red;") // Returns something like "A1b2C3d4"
1339
- */
1340
- function shortHash(input, length = 8) {
1341
- let h = 5381;
1342
- for (let i = 0; i < input.length; i++) h = h * 33 ^ input.charCodeAt(i);
1343
- h >>>= 0;
1344
- return numberToBase62(h, length);
1345
- }
1346
-
1347
- //#endregion
1348
- //#region src/compare.ts
1349
- /**
1350
- * String comparison utilities for deterministic sorting.
1351
- * Used internally to ensure consistent CSS output order.
1352
- * @module compare
1353
- */
1354
- /**
1355
- * Compares two strings lexicographically.
1356
- */
1357
- function compareString(a, b) {
1358
- return a < b ? -1 : a === b ? 0 : 1;
1359
- }
1360
- /**
1361
- * Compares two tuples by their first element (string key).
1362
- * Useful for sorting Object.entries() results.
1363
- */
1364
- function compareStringKey(a, b) {
1365
- return compareString(a[0], b[0]);
1366
- }
1367
- /**
1368
- * Creates a comparator function for objects with a specific string property.
1369
- * @param name - The property name to compare by
1370
- * @returns A comparator function that compares objects by the specified property
1371
- * @example
1372
- * const items = [{ key: 'b' }, { key: 'a' }]
1373
- * items.sort(stringPropComparator('key')) // [{ key: 'a' }, { key: 'b' }]
1374
- */
1375
- function stringPropComparator(name) {
1376
- return (a, b) => compareString(a[name], b[name]);
1377
- }
1378
-
1379
- //#endregion
1380
- //#region src/cssObject.ts
1381
- /**
1382
- * Represents a single CSS rule block with properties and a selector.
1383
- * Handles conversion to CSS string format and hash generation.
1384
- */
1385
- var CssObjectSubBlock = class CssObjectSubBlock {
1386
- /**
1387
- * Creates a new CSS sub-block.
1388
- * @param cssProps - Map of CSS property names (kebab-case) to values
1389
- * @param selector - The selector this block applies to
1390
- */
1391
- constructor(cssProps, selector) {
1392
- this.cssProps = cssProps;
1393
- this.selector = selector;
1394
- }
1395
- /**
1396
- * Computes a deterministic hash of this block's CSS content.
1397
- * Used for generating unique class names.
1398
- */
1399
- get hash() {
1400
- return shortHash(this.asCssString("&"));
1401
- }
1402
- /**
1403
- * Converts this block to a CSS string.
1404
- * Handles at-rule wrapping (media, container, supports, layer) if present.
1405
- * Multiple at-rules are nested in order.
1406
- * @param root - The root selector to substitute for `&`
1407
- * @returns Formatted CSS string
1408
- */
1409
- asCssString(root) {
1410
- const selector = this.selector.substitute(root);
1411
- const atRules = selector.atRules;
1412
- const innerIndent = " ".repeat(atRules.length);
1413
- const props = Object.entries(this.cssProps).toSorted(compareStringKey).map(([k, v]) => `${innerIndent} ${k}: ${v};\n`).join("");
1414
- let result = `${innerIndent}${selector.cssSelector} {\n${props}${innerIndent}}`;
1415
- for (let i = atRules.length - 1; i >= 0; i--) {
1416
- const outerIndent = " ".repeat(i);
1417
- result = `${outerIndent}${atRules[i]} {\n${result}\n${outerIndent}}`;
1418
- }
1419
- return result;
1420
- }
1421
- /**
1422
- * Parses StyleProps into an array of CSS sub-blocks.
1423
- * Recursively processes nested selectors and media queries.
1424
- * Output order is deterministic for consistent hash generation.
1425
- *
1426
- * @param props - The style properties to parse
1427
- * @param selector - The parent selector context (defaults to `&`)
1428
- * @returns Non-empty array of sub-blocks (main block first, then nested)
1429
- */
1430
- static fromProps(props, selector) {
1431
- selector ??= new MochiSelector(["&"]);
1432
- const cssProps = {};
1433
- const propsToProcess = [];
1434
- for (const [key, value] of Object.entries(props)) {
1435
- if (value === void 0) continue;
1436
- if (isCssVariableName(key)) {
1437
- cssProps[key] = asVar(value);
1438
- continue;
1439
- }
1440
- if (isKnownPropertyName(key)) {
1441
- cssProps[camelToKebab(key)] = asKnownProp(value, key);
1442
- continue;
1443
- }
1444
- if (isNestedSelector(key)) {
1445
- propsToProcess.push({
1446
- key,
1447
- props: value,
1448
- selector: selector.extend(key)
1449
- });
1450
- continue;
1451
- }
1452
- if (isAtRuleKey(key)) {
1453
- propsToProcess.push({
1454
- key,
1455
- props: value,
1456
- selector: selector.wrap(key)
1457
- });
1458
- continue;
1459
- }
1460
- if (process.env["NODE_ENV"] !== "production") console.warn(`[mochi-css] Unknown style property "${key}" will be ignored`);
1461
- }
1462
- return [new CssObjectSubBlock(cssProps, selector), ...propsToProcess.toSorted(stringPropComparator("key")).flatMap(({ props: props$1, selector: selector$1 }) => CssObjectSubBlock.fromProps(props$1, selector$1))];
1463
- }
1464
- };
1465
- /**
1466
- * Represents an abstract CSS block definition.
1467
- * Contains one or more sub-blocks for nested selectors and media queries.
1468
- */
1469
- var CssObjectBlock = class {
1470
- /** The generated unique class name for this block */
1471
- className;
1472
- /** All sub-blocks (main styles and nested/media rules) */
1473
- subBlocks = [];
1474
- /**
1475
- * Creates a new CSS block from style properties.
1476
- * Generates a unique class name based on the content hash, or uses the provided class name.
1477
- * @param styles - The style properties to compile
1478
- * @param className - Optional stable class name; if omitted, a content-hash-based name is generated
1479
- */
1480
- constructor(styles, className) {
1481
- const blocks = CssObjectSubBlock.fromProps(styles);
1482
- this.className = className ?? "c" + shortHash(blocks.map((b) => b.hash).join("+"));
1483
- this.subBlocks = blocks;
1484
- }
1485
- /**
1486
- * Gets the CSS class selector for this block.
1487
- */
1488
- get selector() {
1489
- return `.${this.className}`;
1490
- }
1491
- /**
1492
- * Converts style block to a CSS string.
1493
- * @param root - The root selector to scope styles to
1494
- * @returns Complete CSS string for this block
1495
- */
1496
- asCssString(root) {
1497
- return this.subBlocks.map((b) => b.asCssString(new MochiSelector([root]).extend(`&.${this.className}`).cssSelector)).join("\n\n");
1498
- }
1499
- };
1500
- /**
1501
- * Complete CSS object representation with main and variant styles.
1502
- *
1503
- * @template V - The variant definitions type
1504
- *
1505
- * @example
1506
- * const obj = new CSSObject({
1507
- * color: 'blue',
1508
- * variants: {
1509
- * size: {
1510
- * small: { fontSize: 12 },
1511
- * large: { fontSize: 18 }
1512
- * }
1513
- * },
1514
- * defaultVariants: { size: 'small' }
1515
- * })
1516
- * obj.asCssString() // Returns complete CSS with all variants
1517
- */
1518
- var CSSObject = class {
1519
- /** The main style block (non-variant styles) */
1520
- mainBlock;
1521
- /** Compiled blocks for each variant option */
1522
- variantBlocks;
1523
- /** Default variant selections */
1524
- variantDefaults;
1525
- /** Compound variant conditions and their parsed sub-blocks */
1526
- compoundVariants;
1527
- /**
1528
- * Creates a new CSSObject from style props.
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
1535
- */
1536
- constructor({ variants, defaultVariants, compoundVariants,...props }, className) {
1537
- this.mainBlock = new CssObjectBlock(props, className);
1538
- this.variantBlocks = {};
1539
- this.variantDefaults = defaultVariants ?? {};
1540
- this.compoundVariants = [];
1541
- if (variants) for (const variantGroupName in variants) {
1542
- this.variantBlocks[variantGroupName] = {};
1543
- const variantGroup = variants[variantGroupName];
1544
- for (const variantItemName in variantGroup) this.variantBlocks[variantGroupName][variantItemName] = new CssObjectBlock(variantGroup[variantItemName] ?? {});
1545
- }
1546
- if (compoundVariants) for (const compound of compoundVariants) {
1547
- const { css: styles,...conditions } = compound;
1548
- this.compoundVariants.push({
1549
- conditions,
1550
- subBlocks: CssObjectSubBlock.fromProps(styles)
1551
- });
1552
- }
1553
- }
1554
- /**
1555
- * Serializes the entire CSS object to a CSS string.
1556
- * Outputs main block first, then all variant blocks in sorted order.
1557
- * @returns Complete CSS string ready for injection into a stylesheet
1558
- */
1559
- asCssString() {
1560
- return [
1561
- this.mainBlock.asCssString(this.mainBlock.selector),
1562
- ...Object.entries(this.variantBlocks).toSorted(compareStringKey).flatMap(([_, b]) => Object.entries(b).toSorted(compareStringKey)).map(([_, b]) => b.asCssString(this.mainBlock.selector)),
1563
- ...this.compoundVariants.flatMap(({ conditions, subBlocks }) => {
1564
- const selectorParts = [];
1565
- for (const [variantName, optionName] of Object.entries(conditions).toSorted(compareStringKey)) {
1566
- const selector = this.variantBlocks[variantName]?.[optionName]?.selector;
1567
- if (selector === void 0) return [];
1568
- selectorParts.push(selector);
1569
- }
1570
- const combinedSelector = `${this.mainBlock.selector}${selectorParts.join("")}`;
1571
- return subBlocks.map((b) => b.asCssString(combinedSelector));
1572
- })
1573
- ].join("\n\n");
1574
- }
1575
- };
1576
-
1577
- //#endregion
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
- }
1583
- /**
1584
- * Runtime representation of a CSS style definition with variant support.
1585
- * Holds generated class names and provides methods to compute the final
1586
- * className string based on selected variants.
1587
- *
1588
- * @template V - The variant definitions type mapping variant names to their options
1589
- *
1590
- * @example
1591
- * const styles = MochiCSS.from(new CSSObject({
1592
- * color: 'blue',
1593
- * variants: { size: { small: { fontSize: 12 }, large: { fontSize: 18 } } }
1594
- * }))
1595
- * styles.variant({ size: 'large' }) // Returns combined class names
1596
- */
1597
- var MochiCSS = class MochiCSS {
1598
- $$typeof = MOCHI_CSS_TYPEOF;
1599
- /**
1600
- * Creates a new MochiCSS instance.
1601
- * @param classNames - Base class names to always include
1602
- * @param variantClassNames - Mapping of variant names to option class names
1603
- * @param defaultVariants - Default variant selections when not specified
1604
- */
1605
- constructor(classNames, variantClassNames, defaultVariants) {
1606
- this.classNames = classNames;
1607
- this.variantClassNames = variantClassNames;
1608
- this.defaultVariants = defaultVariants;
1609
- }
1610
- /**
1611
- * Computes the final className string based on variant selections.
1612
- * Compound variants are handled purely via CSS combined selectors,
1613
- * so no runtime matching is needed here.
1614
- * @param props - Variant selections
1615
- * @returns Combined className string for use in components
1616
- */
1617
- variant(props) {
1618
- const keys = new Set([...Object.keys(props), ...Object.keys(this.defaultVariants)].filter((k) => k in this.variantClassNames));
1619
- return clsx(this.classNames, ...keys.values().map((k) => {
1620
- const variantGroup = this.variantClassNames[k];
1621
- if (!variantGroup) return false;
1622
- const variantKey = ((k in props ? props[k] : void 0) ?? this.defaultVariants[k])?.toString();
1623
- if (variantKey == null) return false;
1624
- const selectedClassname = variantGroup[variantKey];
1625
- if (selectedClassname !== void 0) return selectedClassname;
1626
- const defaultKey = this.defaultVariants[k];
1627
- if (defaultKey == null) return false;
1628
- return variantGroup[defaultKey.toString()];
1629
- }));
1630
- }
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
- /**
1642
- * Creates a MochiCSS instance from a CSSObject.
1643
- * Extracts class names from the compiled CSS blocks.
1644
- * @template V - The variant definitions type
1645
- * @param object - The compiled CSSObject to extract from
1646
- * @returns A new MochiCSS instance with the extracted class names
1647
- */
1648
- static from(object) {
1649
- return new MochiCSS([object.mainBlock.className], Object.fromEntries(Object.entries(object.variantBlocks).map(([key, variantOptions]) => {
1650
- return [key, Object.fromEntries(Object.entries(variantOptions).map(([optionKey, block]) => {
1651
- return [optionKey, block.className];
1652
- }))];
1653
- })), object.variantDefaults);
1654
- }
1655
- };
1656
- /**
1657
- * Creates a CSS style definition.
1658
- * The primary API for defining styles in Mochi-CSS.
1659
- *
1660
- * @template V - Tuple of variant definition types
1661
- * @param props - One or more style objects or existing MochiCSS instances to merge
1662
- * @returns A MochiCSS instance with all styles and variants combined
1663
- *
1664
- * @example
1665
- * // Simple usage
1666
- * const button = css({ padding: 8, borderRadius: 4 })
1667
- *
1668
- * @example
1669
- * // With variants
1670
- * const button = css({
1671
- * padding: 8,
1672
- * variants: {
1673
- * size: {
1674
- * small: { padding: 4 },
1675
- * large: { padding: 16 }
1676
- * }
1677
- * },
1678
- * defaultVariants: { size: 'small' }
1679
- * })
1680
- * button.variant({ size: 'large' }) // Get class names for large size
1681
- *
1682
- * @example
1683
- * // Merging multiple styles
1684
- * const combined = css(baseStyles, additionalStyles)
1685
- */
1686
- const emptyMochiCSS = new MochiCSS([], {}, {});
1687
- /**
1688
- * Merges multiple MochiCSS instances into a single one, combining their
1689
- * class names, variant class names, and default variants.
1690
- * @param instances - The MochiCSS instances to merge
1691
- * @returns A new MochiCSS instance with all styles combined
1692
- */
1693
- function mergeMochiCss(instances) {
1694
- if (instances.length === 0) return emptyMochiCSS;
1695
- return new MochiCSS(instances.flatMap((c) => c.classNames), instances.reduce((a, b) => Object.assign(a, b.variantClassNames), {}), instances.reduce((a, b) => Object.assign(a, b.defaultVariants), {}));
1696
- }
1697
- function css(...props) {
1698
- const cssToMerge = [];
1699
- for (const p of props) {
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;
1706
- if (p instanceof MochiCSS) cssToMerge.push(p);
1707
- else cssToMerge.push(MochiCSS.from(new CSSObject(p)));
1708
- }
1709
- return mergeMochiCss(cssToMerge);
1710
- }
1711
-
1712
- //#endregion
1713
- //#region src/keyframesObject.ts
1714
- var KeyframesObject = class KeyframesObject {
1715
- name;
1716
- body;
1717
- constructor(stops) {
1718
- this.body = KeyframesObject.generateBody(stops);
1719
- this.name = "kf" + shortHash(this.body);
1720
- }
1721
- asCssString() {
1722
- return `@keyframes ${this.name} {\n${this.body}\n}`;
1723
- }
1724
- static generateBody(stops) {
1725
- return Object.entries(stops).toSorted(compareStringKey).map(([stopKey, props]) => {
1726
- const cssProps = cssFromProps(props);
1727
- return ` ${stopKey} {\n${Object.entries(cssProps).toSorted(compareStringKey).map(([k, v]) => ` ${k}: ${v};`).join("\n")}\n }`;
1728
- }).join("\n\n");
1729
- }
1730
- };
1731
-
1732
- //#endregion
1733
- //#region src/keyframes.ts
1734
- var MochiKeyframes = class MochiKeyframes {
1735
- constructor(name) {
1736
- this.name = name;
1737
- }
1738
- toString() {
1739
- return this.name;
1740
- }
1741
- get value() {
1742
- return this.name;
1743
- }
1744
- static from(object) {
1745
- return new MochiKeyframes(object.name);
1746
- }
1747
- };
1748
- function keyframes(stops) {
1749
- return MochiKeyframes.from(new KeyframesObject(stops));
1750
- }
1751
-
1752
- //#endregion
1753
- //#region src/globalCssObject.ts
1754
- /**
1755
- * CSS object model for global (non-scoped) styles.
1756
- * Accepts a map of CSS selectors to style objects and serializes them
1757
- * as plain CSS rules without class name scoping.
1758
- *
1759
- * @example
1760
- * const obj = new GlobalCssObject({
1761
- * body: { margin: 0 },
1762
- * 'h1': { fontSize: 32 },
1763
- * })
1764
- * obj.asCssString() // "body {\n margin: 0;\n}\n\nh1 {\n font-size: 32px;\n}"
1765
- */
1766
- var GlobalCssObject = class {
1767
- rules;
1768
- constructor(styles) {
1769
- this.rules = Object.entries(styles).toSorted(compareStringKey).map(([selector, props]) => ({
1770
- selector,
1771
- subBlocks: [...CssObjectSubBlock.fromProps(props)]
1772
- }));
1773
- }
1774
- asCssString() {
1775
- return this.rules.flatMap(({ selector, subBlocks }) => subBlocks.map((b) => b.asCssString(selector))).join("\n\n");
1776
- }
1777
- };
1778
-
1779
- //#endregion
1780
- //#region src/globalCss.ts
1781
- /**
1782
- * Creates a global CSS definition.
1783
- * Styles are not scoped to any class — they apply to all matching elements.
1784
- *
1785
- * @param styles - Map of CSS selectors to style objects
1786
- *
1787
- * @example
1788
- * globalCss({
1789
- * 'body': { margin: 0, padding: 0 },
1790
- * '*, *::before, *::after': { boxSizing: 'border-box' },
1791
- * })
1792
- */
1793
- function globalCss(styles) {}
1794
-
1795
- //#endregion
1796
- //#region src/query.ts
1797
- /**
1798
- * Wraps a condition in parentheses if not already wrapped.
1799
- */
1800
- function wrapParens(condition) {
1801
- const trimmed = condition.trim();
1802
- if (trimmed.startsWith("(") && trimmed.endsWith(")")) return trimmed;
1803
- return `(${trimmed})`;
1804
- }
1805
- function mediaFn(condition) {
1806
- return `@media ${wrapParens(condition)}`;
1807
- }
1808
- mediaFn.and = function(...conditions) {
1809
- return `@media ${conditions.map(wrapParens).join(" and ")}`;
1810
- };
1811
- mediaFn.or = function(...conditions) {
1812
- return `@media ${conditions.map(wrapParens).join(", ")}`;
1813
- };
1814
- Object.defineProperties(mediaFn, {
1815
- dark: {
1816
- get: () => "@media (prefers-color-scheme: dark)",
1817
- enumerable: true
1818
- },
1819
- light: {
1820
- get: () => "@media (prefers-color-scheme: light)",
1821
- enumerable: true
1822
- },
1823
- motion: {
1824
- get: () => "@media (prefers-reduced-motion: no-preference)",
1825
- enumerable: true
1826
- },
1827
- print: {
1828
- get: () => "@media print",
1829
- enumerable: true
1830
- }
1831
- });
1832
- /** Helper for constructing `@media` at-rule keys. */
1833
- const media = mediaFn;
1834
- function containerFn(condition) {
1835
- return `@container ${wrapParens(condition)}`;
1836
- }
1837
- containerFn.named = function(name, condition) {
1838
- return `@container ${name} ${wrapParens(condition)}`;
1839
- };
1840
- /** Helper for constructing `@container` at-rule keys. */
1841
- const container = containerFn;
1842
- function supportsFn(condition) {
1843
- return `@supports ${wrapParens(condition)}`;
1844
- }
1845
- supportsFn.not = function(condition) {
1846
- return `@supports not ${wrapParens(condition)}`;
1847
- };
1848
- supportsFn.and = function(...conditions) {
1849
- return `@supports ${conditions.map(wrapParens).join(" and ")}`;
1850
- };
1851
- supportsFn.or = function(...conditions) {
1852
- return `@supports ${conditions.map(wrapParens).join(" or ")}`;
1853
- };
1854
- /** Helper for constructing `@supports` at-rule keys. */
1855
- const supports = supportsFn;
1856
-
1857
- //#endregion
1858
3
  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 };