@csszyx/runtime 0.10.10 → 0.10.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +98 -197
- package/dist/index.cjs +409 -15
- package/dist/index.d.cts +99 -5
- package/dist/index.d.mts +99 -5
- package/dist/index.mjs +408 -16
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -506,6 +506,10 @@ declare function clearHydrationErrors(): void;
|
|
|
506
506
|
/**
|
|
507
507
|
* Gets the count of aborted subtrees.
|
|
508
508
|
*
|
|
509
|
+
* Counts abort marks minus recoveries this session. Aborted elements that were
|
|
510
|
+
* garbage-collected after leaving the DOM stay counted — the number reports
|
|
511
|
+
* how many aborts happened, not how many aborted elements are still alive.
|
|
512
|
+
*
|
|
509
513
|
* @returns {number} Number of aborted subtrees
|
|
510
514
|
*/
|
|
511
515
|
declare function getAbortedSubtreeCount(): number;
|
|
@@ -630,7 +634,8 @@ declare function startHydration(): void;
|
|
|
630
634
|
declare function endHydration(): void;
|
|
631
635
|
|
|
632
636
|
/**
|
|
633
|
-
* Merge className strings with last-wins override per utility, mangle-aware
|
|
637
|
+
* Merge className strings with last-wins override per utility, mangle-aware and
|
|
638
|
+
* memoized (see the memo note above — repeated inputs return in one Map lookup).
|
|
634
639
|
*
|
|
635
640
|
* Intended for the single resolution point in a layered design-system component
|
|
636
641
|
* (typically at the leaf Box): combine the component's default classes with the
|
|
@@ -643,6 +648,63 @@ declare function endHydration(): void;
|
|
|
643
648
|
*/
|
|
644
649
|
declare function szcn(...inputs: (string | false | null | undefined)[]): string;
|
|
645
650
|
|
|
651
|
+
/**
|
|
652
|
+
* Value-set-aware conflict groups for the ambiguous utility prefixes.
|
|
653
|
+
*
|
|
654
|
+
* `szcn` merges by utility prefix, but eight prefixes span MORE than one CSS
|
|
655
|
+
* property (`text-sm` is font-size, `text-red-500` is color), so they used to
|
|
656
|
+
* be excluded from dedup entirely — a consumer's `text-sm` override after a
|
|
657
|
+
* `text-base` default kept BOTH classes and the stylesheet order, not the
|
|
658
|
+
* className order, picked the winner. This module classifies a token's VALUE
|
|
659
|
+
* into a property group (closed keyword sets + shape validators), so same-group
|
|
660
|
+
* tokens dedupe last-wins while different properties keep co-existing.
|
|
661
|
+
*
|
|
662
|
+
* Fail-safe contract (inherited from szcn): classification may only ever err
|
|
663
|
+
* toward `null` = keep-both. A value that matches no group — or matches more
|
|
664
|
+
* than one — is never merged away.
|
|
665
|
+
*
|
|
666
|
+
* Custom `@theme` tokens: the build plugin auto-registers theme token names via
|
|
667
|
+
* `registerSzcnGroups` (see `virtual:csszyx/theme-groups`); apps can call it
|
|
668
|
+
* directly for hand-written CSS classes. Registration is guarded: a name that
|
|
669
|
+
* collides with a static value keyword of an affected prefix (e.g. a color
|
|
670
|
+
* token named `cover` — `bg-cover` is background-size) or that is registered in
|
|
671
|
+
* two conflicting categories is dropped with a dev warning, falling back to
|
|
672
|
+
* keep-both rather than guessing. The ambiguity drop is remembered across
|
|
673
|
+
* registration batches, so a later batch re-registering only one side cannot
|
|
674
|
+
* resurrect the name into a single category.
|
|
675
|
+
*
|
|
676
|
+
* @module
|
|
677
|
+
*/
|
|
678
|
+
/** Custom token categories accepted by {@link registerSzcnGroups}. */
|
|
679
|
+
interface SzcnThemeGroups {
|
|
680
|
+
/** Color token names (`brand` → `text-brand`, `bg-brand`, `border-brand`, …). */
|
|
681
|
+
colors?: readonly string[];
|
|
682
|
+
/** Font-size token names (`huge` → `text-huge`). */
|
|
683
|
+
textSizes?: readonly string[];
|
|
684
|
+
/** Font-family token names (`display` → `font-display`). */
|
|
685
|
+
fontFamilies?: readonly string[];
|
|
686
|
+
/** Font-weight token names (`chunky` → `font-chunky`). */
|
|
687
|
+
fontWeights?: readonly string[];
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Register custom theme token names so szcn can dedupe classes built from them
|
|
691
|
+
* (`text-brand` + `text-accent` → last wins). Idempotent and additive; called
|
|
692
|
+
* automatically by the build plugin from the app's `@theme` blocks, or manually
|
|
693
|
+
* for hand-written CSS utilities.
|
|
694
|
+
*
|
|
695
|
+
* Guard rails (both fall back to keep-both, never a wrong merge):
|
|
696
|
+
* - a name colliding with a static utility keyword of an affected prefix is
|
|
697
|
+
* rejected (e.g. a color named `cover`);
|
|
698
|
+
* - a name registered in two conflicting categories (e.g. both a color and a
|
|
699
|
+
* text size — `text-huge` would be unclassifiable) is removed from both,
|
|
700
|
+
* and STAYS removed: later batches re-registering only one side are
|
|
701
|
+
* rejected too, so registration order can never resurrect an ambiguous
|
|
702
|
+
* name into a single category.
|
|
703
|
+
*
|
|
704
|
+
* @param groups - Custom token names per theme category.
|
|
705
|
+
*/
|
|
706
|
+
declare function registerSzcnGroups(groups: SzcnThemeGroups): void;
|
|
707
|
+
|
|
646
708
|
/** Which side of the CSS box-model border a property acts on. */
|
|
647
709
|
type BoxRole = 'outer' | 'inner';
|
|
648
710
|
|
|
@@ -837,6 +899,34 @@ declare function omitSz(sz: SzInput, selector: BoxSelector): SzObject;
|
|
|
837
899
|
*/
|
|
838
900
|
declare function stripSzProps<T extends Record<string, unknown>>(props: T): Omit<T, 'sz'>;
|
|
839
901
|
|
|
902
|
+
/**
|
|
903
|
+
* Narrow a compiled `szs` slot to the class string it becomes after build.
|
|
904
|
+
*
|
|
905
|
+
* A `Szs` slot is AUTHORED as an sz value (`szs={{ title: { text: 'lg' } }}`),
|
|
906
|
+
* but the compiler rewrites every slot to its class string before the component
|
|
907
|
+
* ever runs — so at runtime `szs?.title` IS a string, while its TYPE is still
|
|
908
|
+
* `SzPropValue`. Forwarding a slot into a `className?: string` prop therefore
|
|
909
|
+
* needed an `as string` cast in every compound component. This helper does that
|
|
910
|
+
* narrowing once, typed, and fail-safe: if a slot somehow reaches runtime
|
|
911
|
+
* uncompiled (a misconfigured build, or a dynamic value the v1 contract
|
|
912
|
+
* rejects), it returns `undefined` instead of letting an object coerce into
|
|
913
|
+
* `class="[object Object]"`.
|
|
914
|
+
*
|
|
915
|
+
* @param slot - One slot value from an `szs` prop.
|
|
916
|
+
* @returns The compiled class string, or `undefined` when the slot is absent or
|
|
917
|
+
* was not compiled to a string.
|
|
918
|
+
*
|
|
919
|
+
* @example
|
|
920
|
+
* ```tsx
|
|
921
|
+
* function Card({ szs }: { szs?: Szs<'title' | 'body'> }) {
|
|
922
|
+
* return <Box className={szcn('font-medium', szsClass(szs?.title))} />;
|
|
923
|
+
* }
|
|
924
|
+
* ```
|
|
925
|
+
*
|
|
926
|
+
* @module @csszyx/runtime/szs-class
|
|
927
|
+
*/
|
|
928
|
+
declare function szsClass(slot: unknown): string | undefined;
|
|
929
|
+
|
|
840
930
|
/**
|
|
841
931
|
* szv() — variant-based sz object factory.
|
|
842
932
|
*
|
|
@@ -857,10 +947,14 @@ type VariantSchema = Record<string, Record<string, SzObject>>;
|
|
|
857
947
|
type VariantSelection<V extends VariantSchema> = {
|
|
858
948
|
[K in keyof V]?: keyof V[K] | null | undefined;
|
|
859
949
|
};
|
|
860
|
-
/**
|
|
950
|
+
/**
|
|
951
|
+
* Configuration for a variant component: base styles, variants, and defaults.
|
|
952
|
+
* `variants` is optional — a base-only config is a legitimate way to declare
|
|
953
|
+
* one compiled-and-extracted class bundle for reuse.
|
|
954
|
+
*/
|
|
861
955
|
interface SzvConfig<V extends VariantSchema> {
|
|
862
956
|
base?: SzObject;
|
|
863
|
-
variants
|
|
957
|
+
variants?: V;
|
|
864
958
|
defaultVariants?: Partial<VariantSelection<V>>;
|
|
865
959
|
}
|
|
866
960
|
/**
|
|
@@ -992,5 +1086,5 @@ declare function isRuntimeInitialized(): boolean;
|
|
|
992
1086
|
*/
|
|
993
1087
|
declare function resetRuntime(): void;
|
|
994
1088
|
|
|
995
|
-
export { DEFAULT_RUNTIME_CONFIG, VERSION, _sz, _sz2, _sz3, _szMerge, abortHydration, attemptCSRRecovery, classify, classifySzKey, clearHydrationErrors, computeMangleChecksumAsync, disableCSRRecovery, enableCSRRecovery, endHydration, getAbortedSubtreeCount, getHydrationErrors, getRecoveryMode, getRuntimeConfig, getSSRContext, guardHydration, has, hasRecoveryToken, hasSz, initRuntime, isCSRRecoveryAllowed, isHydrating, isHydrationAborted, isRuntimeInitialized, isSSREnvironment, isValidMangleMap, isValidManifest, loadMangleMapFromDOM, loadManifestFromDOM, omit, omitSz, pick, pickSz, resetRuntime, splitBox, splitBoxSz, startHydration, stripSzProps, szcn, szr, szv, validateHydrationClass, verifyAllTokens, verifyMangleChecksum, verifyMangleChecksumAsync, verifyMangleMapIntegrity, verifyRecoveryToken };
|
|
996
|
-
export type { BoxRole, BoxSelector, Classification, HydrationError, HydrationErrorType, MangleMap, RecoveryManifest, RecoveryMode, RuntimeConfig, SSRContext, SplitBoxOptions, SplitBoxResult, SplitBoxSzOptions, SplitBoxSzResult, SzInput, TokenData, VerificationResult };
|
|
1089
|
+
export { DEFAULT_RUNTIME_CONFIG, VERSION, _sz, _sz2, _sz3, _szMerge, abortHydration, attemptCSRRecovery, classify, classifySzKey, clearHydrationErrors, computeMangleChecksumAsync, disableCSRRecovery, enableCSRRecovery, endHydration, getAbortedSubtreeCount, getHydrationErrors, getRecoveryMode, getRuntimeConfig, getSSRContext, guardHydration, has, hasRecoveryToken, hasSz, initRuntime, isCSRRecoveryAllowed, isHydrating, isHydrationAborted, isRuntimeInitialized, isSSREnvironment, isValidMangleMap, isValidManifest, loadMangleMapFromDOM, loadManifestFromDOM, omit, omitSz, pick, pickSz, registerSzcnGroups, resetRuntime, splitBox, splitBoxSz, startHydration, stripSzProps, szcn, szr, szsClass, szv, validateHydrationClass, verifyAllTokens, verifyMangleChecksum, verifyMangleChecksumAsync, verifyMangleMapIntegrity, verifyRecoveryToken };
|
|
1090
|
+
export type { BoxRole, BoxSelector, Classification, HydrationError, HydrationErrorType, MangleMap, RecoveryManifest, RecoveryMode, RuntimeConfig, SSRContext, SplitBoxOptions, SplitBoxResult, SplitBoxSzOptions, SplitBoxSzResult, SzInput, SzcnThemeGroups, TokenData, VerificationResult };
|
package/dist/index.d.mts
CHANGED
|
@@ -506,6 +506,10 @@ declare function clearHydrationErrors(): void;
|
|
|
506
506
|
/**
|
|
507
507
|
* Gets the count of aborted subtrees.
|
|
508
508
|
*
|
|
509
|
+
* Counts abort marks minus recoveries this session. Aborted elements that were
|
|
510
|
+
* garbage-collected after leaving the DOM stay counted — the number reports
|
|
511
|
+
* how many aborts happened, not how many aborted elements are still alive.
|
|
512
|
+
*
|
|
509
513
|
* @returns {number} Number of aborted subtrees
|
|
510
514
|
*/
|
|
511
515
|
declare function getAbortedSubtreeCount(): number;
|
|
@@ -630,7 +634,8 @@ declare function startHydration(): void;
|
|
|
630
634
|
declare function endHydration(): void;
|
|
631
635
|
|
|
632
636
|
/**
|
|
633
|
-
* Merge className strings with last-wins override per utility, mangle-aware
|
|
637
|
+
* Merge className strings with last-wins override per utility, mangle-aware and
|
|
638
|
+
* memoized (see the memo note above — repeated inputs return in one Map lookup).
|
|
634
639
|
*
|
|
635
640
|
* Intended for the single resolution point in a layered design-system component
|
|
636
641
|
* (typically at the leaf Box): combine the component's default classes with the
|
|
@@ -643,6 +648,63 @@ declare function endHydration(): void;
|
|
|
643
648
|
*/
|
|
644
649
|
declare function szcn(...inputs: (string | false | null | undefined)[]): string;
|
|
645
650
|
|
|
651
|
+
/**
|
|
652
|
+
* Value-set-aware conflict groups for the ambiguous utility prefixes.
|
|
653
|
+
*
|
|
654
|
+
* `szcn` merges by utility prefix, but eight prefixes span MORE than one CSS
|
|
655
|
+
* property (`text-sm` is font-size, `text-red-500` is color), so they used to
|
|
656
|
+
* be excluded from dedup entirely — a consumer's `text-sm` override after a
|
|
657
|
+
* `text-base` default kept BOTH classes and the stylesheet order, not the
|
|
658
|
+
* className order, picked the winner. This module classifies a token's VALUE
|
|
659
|
+
* into a property group (closed keyword sets + shape validators), so same-group
|
|
660
|
+
* tokens dedupe last-wins while different properties keep co-existing.
|
|
661
|
+
*
|
|
662
|
+
* Fail-safe contract (inherited from szcn): classification may only ever err
|
|
663
|
+
* toward `null` = keep-both. A value that matches no group — or matches more
|
|
664
|
+
* than one — is never merged away.
|
|
665
|
+
*
|
|
666
|
+
* Custom `@theme` tokens: the build plugin auto-registers theme token names via
|
|
667
|
+
* `registerSzcnGroups` (see `virtual:csszyx/theme-groups`); apps can call it
|
|
668
|
+
* directly for hand-written CSS classes. Registration is guarded: a name that
|
|
669
|
+
* collides with a static value keyword of an affected prefix (e.g. a color
|
|
670
|
+
* token named `cover` — `bg-cover` is background-size) or that is registered in
|
|
671
|
+
* two conflicting categories is dropped with a dev warning, falling back to
|
|
672
|
+
* keep-both rather than guessing. The ambiguity drop is remembered across
|
|
673
|
+
* registration batches, so a later batch re-registering only one side cannot
|
|
674
|
+
* resurrect the name into a single category.
|
|
675
|
+
*
|
|
676
|
+
* @module
|
|
677
|
+
*/
|
|
678
|
+
/** Custom token categories accepted by {@link registerSzcnGroups}. */
|
|
679
|
+
interface SzcnThemeGroups {
|
|
680
|
+
/** Color token names (`brand` → `text-brand`, `bg-brand`, `border-brand`, …). */
|
|
681
|
+
colors?: readonly string[];
|
|
682
|
+
/** Font-size token names (`huge` → `text-huge`). */
|
|
683
|
+
textSizes?: readonly string[];
|
|
684
|
+
/** Font-family token names (`display` → `font-display`). */
|
|
685
|
+
fontFamilies?: readonly string[];
|
|
686
|
+
/** Font-weight token names (`chunky` → `font-chunky`). */
|
|
687
|
+
fontWeights?: readonly string[];
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Register custom theme token names so szcn can dedupe classes built from them
|
|
691
|
+
* (`text-brand` + `text-accent` → last wins). Idempotent and additive; called
|
|
692
|
+
* automatically by the build plugin from the app's `@theme` blocks, or manually
|
|
693
|
+
* for hand-written CSS utilities.
|
|
694
|
+
*
|
|
695
|
+
* Guard rails (both fall back to keep-both, never a wrong merge):
|
|
696
|
+
* - a name colliding with a static utility keyword of an affected prefix is
|
|
697
|
+
* rejected (e.g. a color named `cover`);
|
|
698
|
+
* - a name registered in two conflicting categories (e.g. both a color and a
|
|
699
|
+
* text size — `text-huge` would be unclassifiable) is removed from both,
|
|
700
|
+
* and STAYS removed: later batches re-registering only one side are
|
|
701
|
+
* rejected too, so registration order can never resurrect an ambiguous
|
|
702
|
+
* name into a single category.
|
|
703
|
+
*
|
|
704
|
+
* @param groups - Custom token names per theme category.
|
|
705
|
+
*/
|
|
706
|
+
declare function registerSzcnGroups(groups: SzcnThemeGroups): void;
|
|
707
|
+
|
|
646
708
|
/** Which side of the CSS box-model border a property acts on. */
|
|
647
709
|
type BoxRole = 'outer' | 'inner';
|
|
648
710
|
|
|
@@ -837,6 +899,34 @@ declare function omitSz(sz: SzInput, selector: BoxSelector): SzObject;
|
|
|
837
899
|
*/
|
|
838
900
|
declare function stripSzProps<T extends Record<string, unknown>>(props: T): Omit<T, 'sz'>;
|
|
839
901
|
|
|
902
|
+
/**
|
|
903
|
+
* Narrow a compiled `szs` slot to the class string it becomes after build.
|
|
904
|
+
*
|
|
905
|
+
* A `Szs` slot is AUTHORED as an sz value (`szs={{ title: { text: 'lg' } }}`),
|
|
906
|
+
* but the compiler rewrites every slot to its class string before the component
|
|
907
|
+
* ever runs — so at runtime `szs?.title` IS a string, while its TYPE is still
|
|
908
|
+
* `SzPropValue`. Forwarding a slot into a `className?: string` prop therefore
|
|
909
|
+
* needed an `as string` cast in every compound component. This helper does that
|
|
910
|
+
* narrowing once, typed, and fail-safe: if a slot somehow reaches runtime
|
|
911
|
+
* uncompiled (a misconfigured build, or a dynamic value the v1 contract
|
|
912
|
+
* rejects), it returns `undefined` instead of letting an object coerce into
|
|
913
|
+
* `class="[object Object]"`.
|
|
914
|
+
*
|
|
915
|
+
* @param slot - One slot value from an `szs` prop.
|
|
916
|
+
* @returns The compiled class string, or `undefined` when the slot is absent or
|
|
917
|
+
* was not compiled to a string.
|
|
918
|
+
*
|
|
919
|
+
* @example
|
|
920
|
+
* ```tsx
|
|
921
|
+
* function Card({ szs }: { szs?: Szs<'title' | 'body'> }) {
|
|
922
|
+
* return <Box className={szcn('font-medium', szsClass(szs?.title))} />;
|
|
923
|
+
* }
|
|
924
|
+
* ```
|
|
925
|
+
*
|
|
926
|
+
* @module @csszyx/runtime/szs-class
|
|
927
|
+
*/
|
|
928
|
+
declare function szsClass(slot: unknown): string | undefined;
|
|
929
|
+
|
|
840
930
|
/**
|
|
841
931
|
* szv() — variant-based sz object factory.
|
|
842
932
|
*
|
|
@@ -857,10 +947,14 @@ type VariantSchema = Record<string, Record<string, SzObject>>;
|
|
|
857
947
|
type VariantSelection<V extends VariantSchema> = {
|
|
858
948
|
[K in keyof V]?: keyof V[K] | null | undefined;
|
|
859
949
|
};
|
|
860
|
-
/**
|
|
950
|
+
/**
|
|
951
|
+
* Configuration for a variant component: base styles, variants, and defaults.
|
|
952
|
+
* `variants` is optional — a base-only config is a legitimate way to declare
|
|
953
|
+
* one compiled-and-extracted class bundle for reuse.
|
|
954
|
+
*/
|
|
861
955
|
interface SzvConfig<V extends VariantSchema> {
|
|
862
956
|
base?: SzObject;
|
|
863
|
-
variants
|
|
957
|
+
variants?: V;
|
|
864
958
|
defaultVariants?: Partial<VariantSelection<V>>;
|
|
865
959
|
}
|
|
866
960
|
/**
|
|
@@ -992,5 +1086,5 @@ declare function isRuntimeInitialized(): boolean;
|
|
|
992
1086
|
*/
|
|
993
1087
|
declare function resetRuntime(): void;
|
|
994
1088
|
|
|
995
|
-
export { DEFAULT_RUNTIME_CONFIG, VERSION, _sz, _sz2, _sz3, _szMerge, abortHydration, attemptCSRRecovery, classify, classifySzKey, clearHydrationErrors, computeMangleChecksumAsync, disableCSRRecovery, enableCSRRecovery, endHydration, getAbortedSubtreeCount, getHydrationErrors, getRecoveryMode, getRuntimeConfig, getSSRContext, guardHydration, has, hasRecoveryToken, hasSz, initRuntime, isCSRRecoveryAllowed, isHydrating, isHydrationAborted, isRuntimeInitialized, isSSREnvironment, isValidMangleMap, isValidManifest, loadMangleMapFromDOM, loadManifestFromDOM, omit, omitSz, pick, pickSz, resetRuntime, splitBox, splitBoxSz, startHydration, stripSzProps, szcn, szr, szv, validateHydrationClass, verifyAllTokens, verifyMangleChecksum, verifyMangleChecksumAsync, verifyMangleMapIntegrity, verifyRecoveryToken };
|
|
996
|
-
export type { BoxRole, BoxSelector, Classification, HydrationError, HydrationErrorType, MangleMap, RecoveryManifest, RecoveryMode, RuntimeConfig, SSRContext, SplitBoxOptions, SplitBoxResult, SplitBoxSzOptions, SplitBoxSzResult, SzInput, TokenData, VerificationResult };
|
|
1089
|
+
export { DEFAULT_RUNTIME_CONFIG, VERSION, _sz, _sz2, _sz3, _szMerge, abortHydration, attemptCSRRecovery, classify, classifySzKey, clearHydrationErrors, computeMangleChecksumAsync, disableCSRRecovery, enableCSRRecovery, endHydration, getAbortedSubtreeCount, getHydrationErrors, getRecoveryMode, getRuntimeConfig, getSSRContext, guardHydration, has, hasRecoveryToken, hasSz, initRuntime, isCSRRecoveryAllowed, isHydrating, isHydrationAborted, isRuntimeInitialized, isSSREnvironment, isValidMangleMap, isValidManifest, loadMangleMapFromDOM, loadManifestFromDOM, omit, omitSz, pick, pickSz, registerSzcnGroups, resetRuntime, splitBox, splitBoxSz, startHydration, stripSzProps, szcn, szr, szsClass, szv, validateHydrationClass, verifyAllTokens, verifyMangleChecksum, verifyMangleChecksumAsync, verifyMangleMapIntegrity, verifyRecoveryToken };
|
|
1090
|
+
export type { BoxRole, BoxSelector, Classification, HydrationError, HydrationErrorType, MangleMap, RecoveryManifest, RecoveryMode, RuntimeConfig, SSRContext, SplitBoxOptions, SplitBoxResult, SplitBoxSzOptions, SplitBoxSzResult, SzInput, SzcnThemeGroups, TokenData, VerificationResult };
|