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