stoop 0.3.0 → 0.4.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/README.md +125 -0
- package/dist/api/core-api.d.ts +34 -0
- package/dist/api/{keyframes.js → core-api.js} +45 -5
- package/dist/api/global-css.js +11 -58
- package/dist/api/styled.d.ts +0 -1
- package/dist/api/styled.js +265 -16
- package/dist/api/theme-provider.d.ts +41 -0
- package/dist/api/theme-provider.js +223 -0
- package/dist/constants.d.ts +11 -1
- package/dist/constants.js +11 -1
- package/dist/core/compiler.d.ts +11 -0
- package/dist/core/compiler.js +15 -7
- package/dist/core/theme-manager.d.ts +34 -3
- package/dist/core/theme-manager.js +55 -45
- package/dist/core/variants.js +9 -3
- package/dist/create-stoop-internal.d.ts +30 -0
- package/dist/create-stoop-internal.js +123 -0
- package/dist/create-stoop-ssr.d.ts +10 -0
- package/dist/create-stoop-ssr.js +26 -0
- package/dist/create-stoop.d.ts +32 -1
- package/dist/create-stoop.js +78 -69
- package/dist/inject.d.ts +113 -0
- package/dist/inject.js +308 -0
- package/dist/types/index.d.ts +147 -12
- package/dist/types/react-polymorphic-types.d.ts +13 -2
- package/dist/utils/auto-preload.d.ts +45 -0
- package/dist/utils/auto-preload.js +167 -0
- package/dist/utils/helpers.d.ts +64 -0
- package/dist/utils/helpers.js +150 -0
- package/dist/utils/storage.d.ts +148 -0
- package/dist/utils/storage.js +396 -0
- package/dist/utils/{string.d.ts → theme-utils.d.ts} +20 -3
- package/dist/utils/{string.js → theme-utils.js} +109 -9
- package/dist/utils/theme.d.ts +14 -2
- package/dist/utils/theme.js +41 -16
- package/package.json +48 -23
- package/dist/api/create-theme.d.ts +0 -13
- package/dist/api/create-theme.js +0 -43
- package/dist/api/css.d.ts +0 -16
- package/dist/api/css.js +0 -20
- package/dist/api/keyframes.d.ts +0 -16
- package/dist/api/provider.d.ts +0 -19
- package/dist/api/provider.js +0 -109
- package/dist/api/use-theme.d.ts +0 -13
- package/dist/api/use-theme.js +0 -21
- package/dist/create-stoop-server.d.ts +0 -33
- package/dist/create-stoop-server.js +0 -130
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -5
- package/dist/inject/browser.d.ts +0 -58
- package/dist/inject/browser.js +0 -149
- package/dist/inject/dedup.d.ts +0 -29
- package/dist/inject/dedup.js +0 -38
- package/dist/inject/index.d.ts +0 -40
- package/dist/inject/index.js +0 -75
- package/dist/inject/ssr.d.ts +0 -27
- package/dist/inject/ssr.js +0 -46
- package/dist/ssr.d.ts +0 -21
- package/dist/ssr.js +0 -19
- package/dist/utils/environment.d.ts +0 -6
- package/dist/utils/environment.js +0 -12
- package/dist/utils/theme-map.d.ts +0 -22
- package/dist/utils/theme-map.js +0 -97
- package/dist/utils/theme-validation.d.ts +0 -13
- package/dist/utils/theme-validation.js +0 -36
- package/dist/utils/type-guards.d.ts +0 -26
- package/dist/utils/type-guards.js +0 -38
- package/dist/utils/utilities.d.ts +0 -14
- package/dist/utils/utilities.js +0 -43
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ThemeMap utilities for property-aware token resolution.
|
|
3
|
-
* Maps CSS properties to theme scales for deterministic token resolution.
|
|
4
|
-
*/
|
|
5
|
-
import type { ThemeScale } from "../types";
|
|
6
|
-
/**
|
|
7
|
-
* Auto-detects theme scale from CSS property name using pattern matching.
|
|
8
|
-
* Used as fallback when property is not in DEFAULT_THEME_MAP.
|
|
9
|
-
*
|
|
10
|
-
* @param property - CSS property name
|
|
11
|
-
* @returns Theme scale name or undefined if no pattern matches
|
|
12
|
-
*/
|
|
13
|
-
export declare function autoDetectScale(property: string): ThemeScale | undefined;
|
|
14
|
-
/**
|
|
15
|
-
* Gets the theme scale for a CSS property.
|
|
16
|
-
* Checks user themeMap first, then default themeMap, then pattern matching.
|
|
17
|
-
*
|
|
18
|
-
* @param property - CSS property name
|
|
19
|
-
* @param userThemeMap - Optional user-provided themeMap override
|
|
20
|
-
* @returns Theme scale name or undefined if no mapping found
|
|
21
|
-
*/
|
|
22
|
-
export declare function getScaleForProperty(property: string, userThemeMap?: Record<string, ThemeScale>): ThemeScale | undefined;
|
package/dist/utils/theme-map.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ThemeMap utilities for property-aware token resolution.
|
|
3
|
-
* Maps CSS properties to theme scales for deterministic token resolution.
|
|
4
|
-
*/
|
|
5
|
-
import { DEFAULT_THEME_MAP } from "../constants";
|
|
6
|
-
/**
|
|
7
|
-
* Auto-detects theme scale from CSS property name using pattern matching.
|
|
8
|
-
* Used as fallback when property is not in DEFAULT_THEME_MAP.
|
|
9
|
-
*
|
|
10
|
-
* @param property - CSS property name
|
|
11
|
-
* @returns Theme scale name or undefined if no pattern matches
|
|
12
|
-
*/
|
|
13
|
-
export function autoDetectScale(property) {
|
|
14
|
-
// Color properties
|
|
15
|
-
if (property.includes("Color") ||
|
|
16
|
-
property === "fill" ||
|
|
17
|
-
property === "stroke" ||
|
|
18
|
-
property === "accentColor" ||
|
|
19
|
-
property === "caretColor" ||
|
|
20
|
-
property === "border" ||
|
|
21
|
-
property === "outline" ||
|
|
22
|
-
(property.includes("background") && !property.includes("Size") && !property.includes("Image"))) {
|
|
23
|
-
return "colors";
|
|
24
|
-
}
|
|
25
|
-
// Spacing properties
|
|
26
|
-
if (/^(margin|padding|gap|inset|top|right|bottom|left|rowGap|columnGap|gridGap|gridRowGap|gridColumnGap)/.test(property) ||
|
|
27
|
-
property.includes("Block") ||
|
|
28
|
-
property.includes("Inline")) {
|
|
29
|
-
return "space";
|
|
30
|
-
}
|
|
31
|
-
// Size properties
|
|
32
|
-
if (/(width|height|size|basis)$/i.test(property) ||
|
|
33
|
-
property.includes("BlockSize") ||
|
|
34
|
-
property.includes("InlineSize")) {
|
|
35
|
-
return "sizes";
|
|
36
|
-
}
|
|
37
|
-
// Typography: Font Size
|
|
38
|
-
if (property === "fontSize" || (property === "font" && !property.includes("Family"))) {
|
|
39
|
-
return "fontSizes";
|
|
40
|
-
}
|
|
41
|
-
// Typography: Font Family
|
|
42
|
-
if (property === "fontFamily" || property.includes("FontFamily")) {
|
|
43
|
-
return "fonts";
|
|
44
|
-
}
|
|
45
|
-
// Typography: Font Weight
|
|
46
|
-
if (property === "fontWeight" || property.includes("FontWeight")) {
|
|
47
|
-
return "fontWeights";
|
|
48
|
-
}
|
|
49
|
-
// Typography: Letter Spacing
|
|
50
|
-
if (property === "letterSpacing" || property.includes("LetterSpacing")) {
|
|
51
|
-
return "letterSpacings";
|
|
52
|
-
}
|
|
53
|
-
// Border Radius
|
|
54
|
-
if (property.includes("Radius") || property.includes("radius")) {
|
|
55
|
-
return "radii";
|
|
56
|
-
}
|
|
57
|
-
// Shadows
|
|
58
|
-
if (property.includes("Shadow") ||
|
|
59
|
-
property.includes("shadow") ||
|
|
60
|
-
property === "filter" ||
|
|
61
|
-
property === "backdropFilter") {
|
|
62
|
-
return "shadows";
|
|
63
|
-
}
|
|
64
|
-
// Z-Index
|
|
65
|
-
if (property === "zIndex" || property.includes("ZIndex") || property.includes("z-index")) {
|
|
66
|
-
return "zIndices";
|
|
67
|
-
}
|
|
68
|
-
// Opacity
|
|
69
|
-
if (property === "opacity" || property.includes("Opacity")) {
|
|
70
|
-
return "opacities";
|
|
71
|
-
}
|
|
72
|
-
// Transitions and animations
|
|
73
|
-
if (property.startsWith("transition") ||
|
|
74
|
-
property.startsWith("animation") ||
|
|
75
|
-
property.includes("Transition") ||
|
|
76
|
-
property.includes("Animation")) {
|
|
77
|
-
return "transitions";
|
|
78
|
-
}
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Gets the theme scale for a CSS property.
|
|
83
|
-
* Checks user themeMap first, then default themeMap, then pattern matching.
|
|
84
|
-
*
|
|
85
|
-
* @param property - CSS property name
|
|
86
|
-
* @param userThemeMap - Optional user-provided themeMap override
|
|
87
|
-
* @returns Theme scale name or undefined if no mapping found
|
|
88
|
-
*/
|
|
89
|
-
export function getScaleForProperty(property, userThemeMap) {
|
|
90
|
-
if (userThemeMap && property in userThemeMap) {
|
|
91
|
-
return userThemeMap[property];
|
|
92
|
-
}
|
|
93
|
-
if (property in DEFAULT_THEME_MAP) {
|
|
94
|
-
return DEFAULT_THEME_MAP[property];
|
|
95
|
-
}
|
|
96
|
-
return autoDetectScale(property);
|
|
97
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Theme validation utilities.
|
|
3
|
-
* Ensures theme objects only contain approved scales.
|
|
4
|
-
*/
|
|
5
|
-
import type { DefaultTheme } from "../types";
|
|
6
|
-
/**
|
|
7
|
-
* Validates that a theme object only contains approved scales.
|
|
8
|
-
*
|
|
9
|
-
* @param theme - Theme object to validate
|
|
10
|
-
* @returns Validated theme as DefaultTheme
|
|
11
|
-
* @throws Error if theme contains invalid scales (in development)
|
|
12
|
-
*/
|
|
13
|
-
export declare function validateTheme(theme: unknown): DefaultTheme;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Theme validation utilities.
|
|
3
|
-
* Ensures theme objects only contain approved scales.
|
|
4
|
-
*/
|
|
5
|
-
import { APPROVED_THEME_SCALES } from "../constants";
|
|
6
|
-
/**
|
|
7
|
-
* Validates that a theme object only contains approved scales.
|
|
8
|
-
*
|
|
9
|
-
* @param theme - Theme object to validate
|
|
10
|
-
* @returns Validated theme as DefaultTheme
|
|
11
|
-
* @throws Error if theme contains invalid scales (in development)
|
|
12
|
-
*/
|
|
13
|
-
export function validateTheme(theme) {
|
|
14
|
-
if (!theme || typeof theme !== "object" || Array.isArray(theme)) {
|
|
15
|
-
throw new Error("[Stoop] Theme must be a non-null object");
|
|
16
|
-
}
|
|
17
|
-
if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") {
|
|
18
|
-
return theme;
|
|
19
|
-
}
|
|
20
|
-
const themeObj = theme;
|
|
21
|
-
const invalidScales = [];
|
|
22
|
-
for (const key in themeObj) {
|
|
23
|
-
if (key === "media") {
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
if (!APPROVED_THEME_SCALES.includes(key)) {
|
|
27
|
-
invalidScales.push(key);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (invalidScales.length > 0) {
|
|
31
|
-
const errorMessage = `[Stoop] Theme contains invalid scales: ${invalidScales.join(", ")}. ` +
|
|
32
|
-
`Only these scales are allowed: ${APPROVED_THEME_SCALES.join(", ")}`;
|
|
33
|
-
throw new Error(errorMessage);
|
|
34
|
-
}
|
|
35
|
-
return theme;
|
|
36
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guard utilities.
|
|
3
|
-
* Provides runtime type checking for CSS objects, themes, and styled component references.
|
|
4
|
-
*/
|
|
5
|
-
import type { CSS, Theme } from "../types";
|
|
6
|
-
/**
|
|
7
|
-
* Type guard for CSS objects.
|
|
8
|
-
*
|
|
9
|
-
* @param value - Value to check
|
|
10
|
-
* @returns True if value is a CSS object
|
|
11
|
-
*/
|
|
12
|
-
export declare function isCSSObject(value: unknown): value is CSS;
|
|
13
|
-
/**
|
|
14
|
-
* Type guard for valid CSS objects (excludes styled component references).
|
|
15
|
-
*
|
|
16
|
-
* @param value - Value to check
|
|
17
|
-
* @returns True if value is a valid CSS object
|
|
18
|
-
*/
|
|
19
|
-
export declare function isValidCSSObject(value: unknown): value is CSS;
|
|
20
|
-
/**
|
|
21
|
-
* Type guard for theme objects.
|
|
22
|
-
*
|
|
23
|
-
* @param value - Value to check
|
|
24
|
-
* @returns True if value is a theme object
|
|
25
|
-
*/
|
|
26
|
-
export declare function isThemeObject(value: unknown): value is Theme;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type guard utilities.
|
|
3
|
-
* Provides runtime type checking for CSS objects, themes, and styled component references.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Type guard for CSS objects.
|
|
7
|
-
*
|
|
8
|
-
* @param value - Value to check
|
|
9
|
-
* @returns True if value is a CSS object
|
|
10
|
-
*/
|
|
11
|
-
export function isCSSObject(value) {
|
|
12
|
-
return typeof value === "object" && value !== null;
|
|
13
|
-
}
|
|
14
|
-
function isStyledComponentRef(value) {
|
|
15
|
-
return (typeof value === "object" &&
|
|
16
|
-
value !== null &&
|
|
17
|
-
"__isStoopStyled" in value &&
|
|
18
|
-
"__stoopClassName" in value &&
|
|
19
|
-
value.__isStoopStyled === true);
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Type guard for valid CSS objects (excludes styled component references).
|
|
23
|
-
*
|
|
24
|
-
* @param value - Value to check
|
|
25
|
-
* @returns True if value is a valid CSS object
|
|
26
|
-
*/
|
|
27
|
-
export function isValidCSSObject(value) {
|
|
28
|
-
return isCSSObject(value) && !isStyledComponentRef(value);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Type guard for theme objects.
|
|
32
|
-
*
|
|
33
|
-
* @param value - Value to check
|
|
34
|
-
* @returns True if value is a theme object
|
|
35
|
-
*/
|
|
36
|
-
export function isThemeObject(value) {
|
|
37
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
38
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility function application.
|
|
3
|
-
* Applies utility functions (e.g., px, py) to transform shorthand properties into CSS.
|
|
4
|
-
* Recursively processes nested CSS objects.
|
|
5
|
-
*/
|
|
6
|
-
import type { CSS, UtilityFunction } from "../types";
|
|
7
|
-
/**
|
|
8
|
-
* Applies utility functions to transform shorthand properties into CSS.
|
|
9
|
-
*
|
|
10
|
-
* @param styles - CSS object to process
|
|
11
|
-
* @param utils - Optional utility functions object
|
|
12
|
-
* @returns CSS object with utilities applied
|
|
13
|
-
*/
|
|
14
|
-
export declare function applyUtilities(styles: CSS, utils?: Record<string, UtilityFunction>): CSS;
|
package/dist/utils/utilities.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Utility function application.
|
|
3
|
-
* Applies utility functions (e.g., px, py) to transform shorthand properties into CSS.
|
|
4
|
-
* Recursively processes nested CSS objects.
|
|
5
|
-
*/
|
|
6
|
-
import { isCSSObject } from "./type-guards";
|
|
7
|
-
/**
|
|
8
|
-
* Applies utility functions to transform shorthand properties into CSS.
|
|
9
|
-
*
|
|
10
|
-
* @param styles - CSS object to process
|
|
11
|
-
* @param utils - Optional utility functions object
|
|
12
|
-
* @returns CSS object with utilities applied
|
|
13
|
-
*/
|
|
14
|
-
export function applyUtilities(styles, utils) {
|
|
15
|
-
if (!utils || !styles || typeof styles !== "object") {
|
|
16
|
-
return styles;
|
|
17
|
-
}
|
|
18
|
-
const result = {};
|
|
19
|
-
const utilityKeys = Object.keys(utils);
|
|
20
|
-
for (const key in styles) {
|
|
21
|
-
const value = styles[key];
|
|
22
|
-
if (utilityKeys.includes(key) && utils[key]) {
|
|
23
|
-
try {
|
|
24
|
-
const utilityResult = utils[key](value);
|
|
25
|
-
if (utilityResult && typeof utilityResult === "object") {
|
|
26
|
-
for (const utilKey in utilityResult) {
|
|
27
|
-
result[utilKey] = utilityResult[utilKey];
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
result[key] = value;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
else if (isCSSObject(value)) {
|
|
36
|
-
result[key] = applyUtilities(value, utils);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
result[key] = value;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
}
|