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