@tenphi/tasty 0.0.0-snapshot.b3fbcbb → 0.0.0-snapshot.b478bc9
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 +297 -208
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +17 -10
- package/dist/chunks/cacheKey.js.map +1 -1
- package/dist/chunks/definitions.d.ts +1 -1
- package/dist/chunks/definitions.js +3 -5
- package/dist/chunks/definitions.js.map +1 -1
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +32 -34
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/compute-styles.d.ts +31 -0
- package/dist/compute-styles.js +322 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +149 -30
- package/dist/config.js +233 -45
- package/dist/config.js.map +1 -1
- package/dist/core/index.d.ts +12 -11
- package/dist/core/index.js +12 -11
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.d.ts +26 -141
- package/dist/debug.js +359 -639
- package/dist/debug.js.map +1 -1
- package/dist/font-face/index.js +63 -0
- package/dist/font-face/index.js.map +1 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/useCounterStyle.d.ts +36 -0
- package/dist/hooks/useCounterStyle.js +65 -0
- package/dist/hooks/useCounterStyle.js.map +1 -0
- package/dist/hooks/useFontFace.d.ts +45 -0
- package/dist/hooks/useFontFace.js +66 -0
- package/dist/hooks/useFontFace.js.map +1 -0
- package/dist/hooks/useGlobalStyles.d.ts +21 -2
- package/dist/hooks/useGlobalStyles.js +60 -28
- package/dist/hooks/useGlobalStyles.js.map +1 -1
- package/dist/hooks/useKeyframes.d.ts +4 -2
- package/dist/hooks/useKeyframes.js +44 -43
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useProperty.d.ts +4 -2
- package/dist/hooks/useProperty.js +36 -31
- package/dist/hooks/useProperty.js.map +1 -1
- package/dist/hooks/useRawCSS.d.ts +13 -44
- package/dist/hooks/useRawCSS.js +91 -16
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/hooks/useStyles.d.ts +3 -3
- package/dist/hooks/useStyles.js +8 -146
- package/dist/hooks/useStyles.js.map +1 -1
- package/dist/index.d.ts +15 -12
- package/dist/index.js +15 -12
- package/dist/injector/index.d.ts +36 -11
- package/dist/injector/index.js +43 -12
- package/dist/injector/index.js.map +1 -1
- package/dist/injector/injector.d.ts +62 -3
- package/dist/injector/injector.js +256 -31
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.d.ts +10 -13
- package/dist/injector/sheet-manager.js +42 -71
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/injector/types.d.ts +112 -21
- package/dist/keyframes/index.js +1 -1
- package/dist/parser/classify.js +6 -6
- package/dist/parser/classify.js.map +1 -1
- package/dist/parser/const.js +30 -3
- package/dist/parser/const.js.map +1 -1
- package/dist/parser/lru.js +1 -1
- package/dist/parser/lru.js.map +1 -1
- package/dist/parser/parser.js +2 -3
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/tokenizer.js +1 -1
- package/dist/parser/tokenizer.js.map +1 -1
- package/dist/parser/types.js +1 -1
- package/dist/parser/types.js.map +1 -1
- package/dist/pipeline/conditions.js +1 -1
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/exclusive.js +163 -5
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.d.ts +3 -1
- package/dist/pipeline/index.js +172 -83
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize-contradictions.js +125 -0
- package/dist/pipeline/materialize-contradictions.js.map +1 -0
- package/dist/pipeline/materialize.js +437 -243
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.d.ts +1 -1
- package/dist/pipeline/parseStateKey.js +21 -13
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js +181 -7
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/pipeline/warnings.js +1 -1
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.js +3 -277
- package/dist/plugins/okhsl-plugin.js.map +1 -1
- package/dist/plugins/types.d.ts +20 -2
- package/dist/properties/index.js +15 -30
- package/dist/properties/index.js.map +1 -1
- package/dist/properties/property-type-resolver.js +13 -2
- package/dist/properties/property-type-resolver.js.map +1 -1
- package/dist/rsc-cache.js +79 -0
- package/dist/rsc-cache.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +19 -0
- package/dist/ssr/astro-client.js.map +1 -0
- package/dist/ssr/astro-middleware.d.ts +15 -0
- package/dist/ssr/astro-middleware.js +19 -0
- package/dist/ssr/astro-middleware.js.map +1 -0
- package/dist/ssr/astro.d.ts +108 -0
- package/dist/ssr/astro.js +149 -0
- package/dist/ssr/astro.js.map +1 -0
- package/dist/ssr/async-storage.d.ts +17 -0
- package/dist/ssr/async-storage.js +44 -0
- package/dist/ssr/async-storage.js.map +1 -0
- package/dist/ssr/collect-auto-properties.js +58 -0
- package/dist/ssr/collect-auto-properties.js.map +1 -0
- package/dist/ssr/collector.d.ts +98 -0
- package/dist/ssr/collector.js +235 -0
- package/dist/ssr/collector.js.map +1 -0
- package/dist/ssr/context.js +16 -0
- package/dist/ssr/context.js.map +1 -0
- package/dist/ssr/format-global-rules.js +22 -0
- package/dist/ssr/format-global-rules.js.map +1 -0
- package/dist/ssr/format-keyframes.js +69 -0
- package/dist/ssr/format-keyframes.js.map +1 -0
- package/dist/ssr/format-property.js +49 -0
- package/dist/ssr/format-property.js.map +1 -0
- package/dist/ssr/format-rules.js +73 -0
- package/dist/ssr/format-rules.js.map +1 -0
- package/dist/ssr/hydrate.d.ts +29 -0
- package/dist/ssr/hydrate.js +45 -0
- package/dist/ssr/hydrate.js.map +1 -0
- package/dist/ssr/index.d.ts +4 -0
- package/dist/ssr/index.js +10 -0
- package/dist/ssr/index.js.map +1 -0
- package/dist/ssr/next.d.ts +46 -0
- package/dist/ssr/next.js +75 -0
- package/dist/ssr/next.js.map +1 -0
- package/dist/ssr/ssr-collector-ref.js +29 -0
- package/dist/ssr/ssr-collector-ref.js.map +1 -0
- package/dist/states/index.js +13 -259
- package/dist/states/index.js.map +1 -1
- package/dist/static/index.js +1 -2
- package/dist/static/inject.d.ts +5 -0
- package/dist/static/inject.js +17 -0
- package/dist/static/inject.js.map +1 -0
- package/dist/static/tastyStatic.js +1 -2
- package/dist/static/tastyStatic.js.map +1 -1
- package/dist/static/types.js +1 -1
- package/dist/styles/border.d.ts +1 -1
- package/dist/styles/border.js +30 -24
- package/dist/styles/border.js.map +1 -1
- package/dist/styles/color.d.ts +1 -1
- package/dist/styles/color.js +11 -8
- package/dist/styles/color.js.map +1 -1
- package/dist/styles/const.js +17 -0
- package/dist/styles/const.js.map +1 -0
- package/dist/styles/createStyle.js +28 -26
- package/dist/styles/createStyle.js.map +1 -1
- package/dist/styles/dimension.js +15 -3
- package/dist/styles/dimension.js.map +1 -1
- package/dist/styles/directional.js +133 -0
- package/dist/styles/directional.js.map +1 -0
- package/dist/styles/display.d.ts +3 -10
- package/dist/styles/display.js +45 -39
- package/dist/styles/display.js.map +1 -1
- package/dist/styles/fade.d.ts +1 -1
- package/dist/styles/fade.js +9 -5
- package/dist/styles/fade.js.map +1 -1
- package/dist/styles/fill.d.ts +2 -2
- package/dist/styles/fill.js +3 -4
- package/dist/styles/fill.js.map +1 -1
- package/dist/styles/flow.js +1 -1
- package/dist/styles/gap.d.ts +1 -1
- package/dist/styles/gap.js +4 -3
- package/dist/styles/gap.js.map +1 -1
- package/dist/styles/height.d.ts +1 -1
- package/dist/styles/height.js +1 -2
- package/dist/styles/height.js.map +1 -1
- package/dist/styles/index.d.ts +0 -1
- package/dist/styles/index.js +3 -4
- package/dist/styles/index.js.map +1 -1
- package/dist/styles/inset.d.ts +1 -29
- package/dist/styles/inset.js +19 -135
- package/dist/styles/inset.js.map +1 -1
- package/dist/styles/list.d.ts +5 -5
- package/dist/styles/list.js +4 -2
- package/dist/styles/list.js.map +1 -1
- package/dist/styles/margin.d.ts +1 -1
- package/dist/styles/margin.js +17 -89
- package/dist/styles/margin.js.map +1 -1
- package/dist/styles/outline.d.ts +1 -1
- package/dist/styles/outline.js +6 -16
- package/dist/styles/outline.js.map +1 -1
- package/dist/styles/padding.d.ts +1 -1
- package/dist/styles/padding.js +17 -89
- package/dist/styles/padding.js.map +1 -1
- package/dist/styles/placement.d.ts +37 -0
- package/dist/styles/placement.js +74 -0
- package/dist/styles/placement.js.map +1 -0
- package/dist/styles/predefined.d.ts +4 -6
- package/dist/styles/predefined.js +9 -13
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/preset.d.ts +6 -1
- package/dist/styles/preset.js +54 -53
- package/dist/styles/preset.js.map +1 -1
- package/dist/styles/radius.d.ts +1 -3
- package/dist/styles/radius.js +38 -6
- package/dist/styles/radius.js.map +1 -1
- package/dist/styles/scrollMargin.d.ts +24 -0
- package/dist/styles/scrollMargin.js +32 -0
- package/dist/styles/scrollMargin.js.map +1 -0
- package/dist/styles/scrollbar.d.ts +9 -5
- package/dist/styles/scrollbar.js +31 -92
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.d.ts +1 -1
- package/dist/styles/shadow.js +4 -3
- package/dist/styles/shadow.js.map +1 -1
- package/dist/styles/shared.js +17 -0
- package/dist/styles/shared.js.map +1 -0
- package/dist/styles/transition.d.ts +1 -1
- package/dist/styles/transition.js +6 -5
- package/dist/styles/transition.js.map +1 -1
- package/dist/styles/types.d.ts +94 -28
- package/dist/styles/width.d.ts +1 -1
- package/dist/styles/width.js +1 -2
- package/dist/styles/width.js.map +1 -1
- package/dist/tasty.d.ts +46 -894
- package/dist/tasty.js +101 -59
- package/dist/tasty.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils/cache-wrapper.js +4 -9
- package/dist/utils/cache-wrapper.js.map +1 -1
- package/dist/utils/case-converter.js +1 -1
- package/dist/utils/color-math.d.ts +46 -0
- package/dist/utils/color-math.js +749 -0
- package/dist/utils/color-math.js.map +1 -0
- package/dist/utils/color-space.d.ts +5 -0
- package/dist/utils/color-space.js +228 -0
- package/dist/utils/color-space.js.map +1 -0
- package/dist/utils/colors.js +3 -2
- package/dist/utils/colors.js.map +1 -1
- package/dist/utils/deps-equal.js +15 -0
- package/dist/utils/deps-equal.js.map +1 -0
- package/dist/utils/dotize.js +1 -1
- package/dist/utils/dotize.js.map +1 -1
- package/dist/utils/filter-base-props.d.ts +1 -1
- package/dist/utils/filter-base-props.js +1 -1
- package/dist/utils/filter-base-props.js.map +1 -1
- package/dist/utils/get-display-name.js +1 -1
- package/dist/utils/has-keys.js +13 -0
- package/dist/utils/has-keys.js.map +1 -0
- package/dist/utils/hash.js +14 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/is-dev-env.js +1 -1
- package/dist/utils/is-dev-env.js.map +1 -1
- package/dist/utils/is-valid-element-type.js +1 -1
- package/dist/utils/merge-styles.js +1 -2
- package/dist/utils/merge-styles.js.map +1 -1
- package/dist/utils/mod-attrs.d.ts +0 -2
- package/dist/utils/mod-attrs.js +3 -4
- package/dist/utils/mod-attrs.js.map +1 -1
- package/dist/utils/process-tokens.d.ts +3 -17
- package/dist/utils/process-tokens.js +19 -107
- package/dist/utils/process-tokens.js.map +1 -1
- package/dist/utils/resolve-recipes.js +1 -2
- package/dist/utils/resolve-recipes.js.map +1 -1
- package/dist/utils/selector-transform.js +32 -0
- package/dist/utils/selector-transform.js.map +1 -0
- package/dist/utils/string.js +1 -1
- package/dist/utils/styles.d.ts +3 -82
- package/dist/utils/styles.js +29 -560
- package/dist/utils/styles.js.map +1 -1
- package/dist/utils/typography.d.ts +35 -13
- package/dist/utils/typography.js +16 -18
- package/dist/utils/typography.js.map +1 -1
- package/dist/utils/warnings.js +1 -1
- package/dist/zero/babel.d.ts +57 -89
- package/dist/zero/babel.js +214 -40
- package/dist/zero/babel.js.map +1 -1
- package/dist/zero/css-writer.js +1 -2
- package/dist/zero/css-writer.js.map +1 -1
- package/dist/zero/extractor.js +54 -3
- package/dist/zero/extractor.js.map +1 -1
- package/dist/zero/index.js +1 -2
- package/dist/zero/next.d.ts +56 -30
- package/dist/zero/next.js +105 -40
- package/dist/zero/next.js.map +1 -1
- package/docs/README.md +31 -0
- package/docs/adoption.md +298 -0
- package/docs/comparison.md +419 -0
- package/docs/configuration.md +394 -0
- package/docs/debug.md +320 -0
- package/docs/design-system.md +436 -0
- package/docs/dsl.md +688 -0
- package/docs/getting-started.md +217 -0
- package/docs/injector.md +544 -0
- package/docs/methodology.md +616 -0
- package/docs/pipeline.md +673 -0
- package/docs/react-api.md +557 -0
- package/docs/ssr.md +442 -0
- package/docs/styles.md +596 -0
- package/docs/tasty-static.md +532 -0
- package/package.json +68 -36
- package/dist/styles/align.d.ts +0 -15
- package/dist/styles/align.js +0 -14
- package/dist/styles/align.js.map +0 -1
- package/dist/styles/justify.d.ts +0 -15
- package/dist/styles/justify.js +0 -14
- package/dist/styles/justify.js.map +0 -1
- package/dist/styles/styledScrollbar.d.ts +0 -47
- package/dist/styles/styledScrollbar.js +0 -38
- package/dist/styles/styledScrollbar.js.map +0 -1
- package/dist/tokens/typography.d.ts +0 -19
- package/dist/tokens/typography.js +0 -237
- package/dist/tokens/typography.js.map +0 -1
- package/dist/utils/hsl-to-rgb.js +0 -38
- package/dist/utils/hsl-to-rgb.js.map +0 -1
- package/dist/utils/okhsl-to-rgb.js +0 -296
- package/dist/utils/okhsl-to-rgb.js.map +0 -1
package/dist/styles/preset.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CSS_WIDE_KEYWORDS } from "../parser/const.js";
|
|
2
2
|
import { parseStyle } from "../utils/styles.js";
|
|
3
|
-
|
|
4
3
|
//#region src/styles/preset.ts
|
|
4
|
+
const PRESET_MODIFIERS = new Set([
|
|
5
|
+
"strong",
|
|
6
|
+
"bold",
|
|
7
|
+
"italic",
|
|
8
|
+
"icon",
|
|
9
|
+
"tight"
|
|
10
|
+
]);
|
|
5
11
|
/**
|
|
6
12
|
* Convert a value to CSS, handling numbers as pixels for numeric properties
|
|
7
13
|
*/
|
|
@@ -10,46 +16,40 @@ function toCSS(value, isNumeric) {
|
|
|
10
16
|
if (typeof value === "number") return isNumeric ? `${value}px` : String(value);
|
|
11
17
|
return parseStyle(String(value)).groups[0]?.values[0] || String(value);
|
|
12
18
|
}
|
|
13
|
-
function setCSSValue(styles, styleName, presetName,
|
|
14
|
-
|
|
15
|
-
if (presetName
|
|
16
|
-
const defaultValue = `var(--default-${styleName}
|
|
17
|
-
const fontSuffix = styleName === "font-family" ? ", var(--font, sans-
|
|
19
|
+
function setCSSValue(styles, styleName, presetName, { varOnly, cssOnly } = {}) {
|
|
20
|
+
const value = (() => {
|
|
21
|
+
if (CSS_WIDE_KEYWORDS.has(presetName)) return presetName;
|
|
22
|
+
const defaultValue = `var(--default-${styleName}${styleName === "font-family" ? ", var(--font-sans, var(--font-sans-fallback))" : ""})`;
|
|
23
|
+
const fontSuffix = styleName === "font-family" ? ", var(--font-sans, var(--font-sans-fallback))" : "";
|
|
18
24
|
if (presetName === "default") return `${defaultValue}${fontSuffix}`;
|
|
19
25
|
else return `var(--${presetName}-${styleName}, ${defaultValue})${fontSuffix}`;
|
|
20
26
|
})();
|
|
21
|
-
if (!
|
|
27
|
+
if (!cssOnly) styles[`--${styleName}`] = value;
|
|
28
|
+
if (!varOnly) styles[styleName] = value;
|
|
22
29
|
}
|
|
23
30
|
/**
|
|
24
31
|
* Resolve font/fontFamily value to CSS font-family string.
|
|
25
32
|
*
|
|
26
|
-
* - `font="monospace"` → var(--
|
|
27
|
-
* - `font={true}` → var(--font)
|
|
28
|
-
* - `font="CustomFont"` → CustomFont, var(--font)
|
|
33
|
+
* - `font="monospace"` → var(--font-mono, var(--font-mono-fallback))
|
|
34
|
+
* - `font={true}` → var(--font-sans, var(--font-sans-fallback))
|
|
35
|
+
* - `font="CustomFont"` → CustomFont, var(--font-sans, var(--font-sans-fallback))
|
|
29
36
|
* - `fontFamily="Arial"` → Arial (direct, no fallback)
|
|
30
37
|
*/
|
|
31
38
|
function resolveFontFamily(font, fontFamily) {
|
|
32
|
-
if (fontFamily) return
|
|
33
|
-
value: fontFamily,
|
|
34
|
-
setVar: false
|
|
35
|
-
};
|
|
39
|
+
if (fontFamily) return fontFamily;
|
|
36
40
|
if (font == null || font === false) return null;
|
|
37
|
-
if (font === "monospace") return
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
if (font === true) return {
|
|
42
|
-
value: "var(--font)",
|
|
43
|
-
setVar: true
|
|
44
|
-
};
|
|
45
|
-
return {
|
|
46
|
-
value: `${font}, var(--font)`,
|
|
47
|
-
setVar: true
|
|
48
|
-
};
|
|
41
|
+
if (font === "monospace") return "var(--font-mono, var(--font-mono-fallback))";
|
|
42
|
+
if (font === true) return "var(--font-sans, var(--font-sans-fallback))";
|
|
43
|
+
return `${font}, var(--font-sans, var(--font-sans-fallback))`;
|
|
49
44
|
}
|
|
50
45
|
/**
|
|
51
46
|
* Handles typography preset and individual font properties.
|
|
52
47
|
*
|
|
48
|
+
* Preset syntax uses `/` to separate name from modifier:
|
|
49
|
+
* - `preset="h1"` — name only
|
|
50
|
+
* - `preset="h2 / strong"` — name + modifier
|
|
51
|
+
* - `preset="bold"` — modifier-only shorthand (name defaults to `inherit`)
|
|
52
|
+
*
|
|
53
53
|
* When `preset` is defined, it sets up CSS custom properties for typography.
|
|
54
54
|
* Individual font props can be used with or without `preset`:
|
|
55
55
|
* - With `preset`: overrides the preset value for that property
|
|
@@ -65,29 +65,33 @@ function resolveFontFamily(font, fontFamily) {
|
|
|
65
65
|
function presetStyle({ preset, fontSize, lineHeight, textTransform, letterSpacing, fontWeight, fontStyle, fontFamily, font }) {
|
|
66
66
|
const styles = {};
|
|
67
67
|
if (preset != null && preset !== false) {
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
if (
|
|
81
|
-
if (
|
|
82
|
-
setCSSValue(styles, "
|
|
83
|
-
setCSSValue(styles, "
|
|
68
|
+
const { parts } = parseStyle(preset === true ? "" : String(preset)).groups[0] ?? { parts: [] };
|
|
69
|
+
const namePart = parts[0];
|
|
70
|
+
const modPart = parts[1];
|
|
71
|
+
const nameToken = namePart?.mods[0] ?? namePart?.values[0] ?? "";
|
|
72
|
+
const isModOnly = PRESET_MODIFIERS.has(nameToken);
|
|
73
|
+
const name = isModOnly ? "inherit" : nameToken || "inherit";
|
|
74
|
+
const modifier = isModOnly ? nameToken : modPart?.mods[0] ?? "";
|
|
75
|
+
const isStrong = modifier === "strong" || modifier === "bold";
|
|
76
|
+
const isItalic = modifier === "italic";
|
|
77
|
+
const isIcon = modifier === "icon";
|
|
78
|
+
const isTight = modifier === "tight";
|
|
79
|
+
if (fontSize == null) setCSSValue(styles, "font-size", name, { cssOnly: true });
|
|
80
|
+
if (lineHeight == null) setCSSValue(styles, "line-height", name, { cssOnly: true });
|
|
81
|
+
if (letterSpacing == null) setCSSValue(styles, "letter-spacing", name, { cssOnly: true });
|
|
82
|
+
if (fontWeight == null) setCSSValue(styles, "font-weight", name, { cssOnly: true });
|
|
83
|
+
if (fontStyle == null) setCSSValue(styles, "font-style", name, { cssOnly: true });
|
|
84
|
+
if (textTransform == null) setCSSValue(styles, "text-transform", name, { cssOnly: true });
|
|
85
|
+
if (fontFamily == null && font == null) setCSSValue(styles, "font-family", name, { cssOnly: true });
|
|
86
|
+
setCSSValue(styles, "bold-font-weight", name, { varOnly: true });
|
|
87
|
+
setCSSValue(styles, "icon-size", name, { varOnly: true });
|
|
84
88
|
if (isStrong) styles["font-weight"] = "var(--bold-font-weight)";
|
|
85
89
|
if (isItalic) styles["font-style"] = "italic";
|
|
86
90
|
if (isIcon) {
|
|
87
91
|
styles["font-size"] = "var(--icon-size)";
|
|
88
92
|
styles["line-height"] = "var(--icon-size)";
|
|
89
93
|
}
|
|
90
|
-
if (isTight) styles["line-height"] = "
|
|
94
|
+
if (isTight) styles["line-height"] = "1em";
|
|
91
95
|
}
|
|
92
96
|
const fontSizeVal = toCSS(fontSize, true);
|
|
93
97
|
if (fontSizeVal) styles["font-size"] = fontSizeVal;
|
|
@@ -98,15 +102,12 @@ function presetStyle({ preset, fontSize, lineHeight, textTransform, letterSpacin
|
|
|
98
102
|
const fontWeightVal = toCSS(fontWeight, false);
|
|
99
103
|
if (fontWeightVal) styles["font-weight"] = fontWeightVal;
|
|
100
104
|
if (fontStyle != null) if (fontStyle === true) styles["font-style"] = "italic";
|
|
101
|
-
else if (fontStyle
|
|
102
|
-
else styles["font-style"] = "
|
|
105
|
+
else if (typeof fontStyle === "string" && CSS_WIDE_KEYWORDS.has(fontStyle)) styles["font-style"] = fontStyle;
|
|
106
|
+
else styles["font-style"] = fontStyle ? "italic" : "normal";
|
|
103
107
|
if (textTransform) styles["text-transform"] = textTransform;
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
if (fontResult.setVar) styles["--font-family"] = fontResult.value;
|
|
108
|
-
}
|
|
109
|
-
if (Object.keys(styles).length === 0) return;
|
|
108
|
+
const fontFamily_ = resolveFontFamily(font, fontFamily);
|
|
109
|
+
if (fontFamily_) styles["font-family"] = fontFamily_;
|
|
110
|
+
if (Object.keys(styles).length === 0) return null;
|
|
110
111
|
return styles;
|
|
111
112
|
}
|
|
112
113
|
presetStyle.__lookupStyles = [
|
|
@@ -120,7 +121,7 @@ presetStyle.__lookupStyles = [
|
|
|
120
121
|
"fontFamily",
|
|
121
122
|
"font"
|
|
122
123
|
];
|
|
123
|
-
|
|
124
124
|
//#endregion
|
|
125
125
|
export { presetStyle };
|
|
126
|
+
|
|
126
127
|
//# sourceMappingURL=preset.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset.js","names":[],"sources":["../../src/styles/preset.ts"],"sourcesContent":["import { makeEmptyDetails } from '../parser/types';\nimport { parseStyle } from '../utils/styles';\n\nimport type { Styles } from './types';\n\n/**\n * Convert a value to CSS, handling numbers as pixels for numeric properties\n */\nfunction toCSS(\n value: string | number | undefined,\n isNumeric: boolean,\n): string | null {\n if (value == null) return null;\n if (typeof value === 'number') {\n return isNumeric ? `${value}px` : String(value);\n }\n // Parse through style parser to handle custom units like 1x, 2r, etc.\n const processed = parseStyle(String(value));\n return processed.groups[0]?.values[0] || String(value);\n}\n\nfunction setCSSValue(\n styles: Styles,\n styleName: string,\n presetName: string,\n isPropOnly = false,\n) {\n styles[`--${styleName}`] = (() => {\n if (presetName === 'inherit') {\n return 'inherit';\n }\n\n const defaultValue = `var(--default-${styleName}, ${\n styleName === 'font-family'\n ? 'var(--font, NonexistentFontName)'\n : 'inherit'\n })`;\n const fontSuffix =\n styleName === 'font-family' ? ', var(--font, sans-serif)' : '';\n\n if (presetName === 'default') {\n return `${defaultValue}${fontSuffix}`;\n } else {\n return `var(--${presetName}-${styleName}, ${defaultValue})${fontSuffix}`;\n }\n })();\n\n if (!isPropOnly) {\n styles[styleName] = styles[`--${styleName}`];\n }\n}\n\ninterface PresetStyleProps {\n preset?: string | boolean;\n fontSize?: string | number;\n lineHeight?: string | number;\n textTransform?: string;\n letterSpacing?: string | number;\n fontWeight?: string | number;\n fontStyle?: string | boolean;\n fontFamily?: string;\n /** Alias for fontFamily with special handling for 'monospace' and boolean */\n font?: string | boolean;\n}\n\n/**\n * Resolve font/fontFamily value to CSS font-family string.\n *\n * - `font=\"monospace\"` → var(--monospace-font)\n * - `font={true}` → var(--font)\n * - `font=\"CustomFont\"` → CustomFont, var(--font)\n * - `fontFamily=\"Arial\"` → Arial (direct, no fallback)\n */\nfunction resolveFontFamily(\n font: string | boolean | undefined,\n fontFamily: string | undefined,\n): { value: string; setVar: boolean } | null {\n // fontFamily takes precedence as a direct value\n if (fontFamily) {\n return { value: fontFamily, setVar: false };\n }\n\n if (font == null || font === false) {\n return null;\n }\n\n if (font === 'monospace') {\n return { value: 'var(--monospace-font)', setVar: true };\n }\n\n if (font === true) {\n return { value: 'var(--font)', setVar: true };\n }\n\n return { value: `${font}, var(--font)`, setVar: true };\n}\n\n/**\n * Handles typography preset and individual font properties.\n *\n * When `preset` is defined, it sets up CSS custom properties for typography.\n * Individual font props can be used with or without `preset`:\n * - With `preset`: overrides the preset value for that property\n * - Without `preset`: outputs the CSS directly\n *\n * Number values are converted to pixels for fontSize, lineHeight, letterSpacing.\n * fontWeight accepts numbers directly (e.g., 400, 700).\n *\n * font vs fontFamily:\n * - `font` is the recommended prop with special handling (monospace, boolean, fallback)\n * - `fontFamily` is a direct value without special handling\n */\nexport function presetStyle({\n preset,\n fontSize,\n lineHeight,\n textTransform,\n letterSpacing,\n fontWeight,\n fontStyle,\n fontFamily,\n font,\n}: PresetStyleProps) {\n const styles: Styles = {};\n const hasPreset = preset != null && preset !== false;\n\n // Handle preset if defined\n if (hasPreset) {\n const presetValue = preset === true ? '' : String(preset);\n\n const processed = parseStyle(presetValue);\n let { mods } = processed.groups[0] ?? makeEmptyDetails();\n\n const isStrong = mods.includes('strong');\n const isItalic = mods.includes('italic');\n const isIcon = mods.includes('icon');\n const isTight = mods.includes('tight');\n\n mods = mods.filter(\n (mod) =>\n mod !== 'strong' &&\n mod !== 'bold' &&\n mod !== 'italic' &&\n mod !== 'icon' &&\n mod !== 'tight',\n );\n\n const name = mods[0] || 'inherit';\n\n // Set preset values for properties not explicitly overridden\n if (fontSize == null) {\n setCSSValue(styles, 'font-size', name);\n }\n if (lineHeight == null) {\n setCSSValue(styles, 'line-height', name);\n }\n if (letterSpacing == null) {\n setCSSValue(styles, 'letter-spacing', name);\n }\n if (fontWeight == null) {\n setCSSValue(styles, 'font-weight', name);\n }\n if (fontStyle == null) {\n setCSSValue(styles, 'font-style', name);\n }\n if (textTransform == null) {\n setCSSValue(styles, 'text-transform', name);\n }\n if (fontFamily == null && font == null) {\n setCSSValue(styles, 'font-family', name);\n }\n\n setCSSValue(styles, 'bold-font-weight', name, true);\n setCSSValue(styles, 'icon-size', name, true);\n\n if (isStrong) {\n styles['font-weight'] = 'var(--bold-font-weight)';\n }\n if (isItalic) {\n styles['font-style'] = 'italic';\n }\n if (isIcon) {\n styles['font-size'] = 'var(--icon-size)';\n styles['line-height'] = 'var(--icon-size)';\n }\n if (isTight) {\n styles['line-height'] = 'var(--font-size)';\n }\n }\n\n // Handle individual font properties (work with or without preset)\n const fontSizeVal = toCSS(fontSize, true);\n if (fontSizeVal) {\n styles['font-size'] = fontSizeVal;\n }\n\n const lineHeightVal = toCSS(lineHeight, true);\n if (lineHeightVal) {\n styles['line-height'] = lineHeightVal;\n }\n\n const letterSpacingVal = toCSS(letterSpacing, true);\n if (letterSpacingVal) {\n styles['letter-spacing'] = letterSpacingVal;\n }\n\n // fontWeight: numbers should NOT get 'px' suffix\n const fontWeightVal = toCSS(fontWeight, false);\n if (fontWeightVal) {\n styles['font-weight'] = fontWeightVal;\n }\n\n // fontStyle: handle boolean (true → italic) and string values\n if (fontStyle != null) {\n if (fontStyle === true) {\n styles['font-style'] = 'italic';\n } else if (fontStyle !== 'inherit') {\n styles['font-style'] = fontStyle ? 'italic' : 'normal';\n } else {\n styles['font-style'] = 'inherit';\n }\n }\n\n if (textTransform) {\n styles['text-transform'] = textTransform;\n }\n\n // Handle font/fontFamily (font has special handling, fontFamily is direct)\n const fontResult = resolveFontFamily(font, fontFamily);\n if (fontResult) {\n styles['font-family'] = fontResult.value;\n if (fontResult.setVar) {\n styles['--font-family'] = fontResult.value;\n }\n }\n\n // Return undefined if no styles to apply\n if (Object.keys(styles).length === 0) {\n return;\n }\n\n return styles;\n}\n\npresetStyle.__lookupStyles = [\n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O,gBAAgB;UACd,cAAc,UACvB,QAAO,gBAAgB,YAAY,WAAW;KAE9C,QAAO,gBAAgB;AAI3B,KAAI,cACF,QAAO,oBAAoB;CAI7B,MAAM,aAAa,kBAAkB,MAAM,WAAW;AACtD,KAAI,YAAY;AACd,SAAO,iBAAiB,WAAW;AACnC,MAAI,WAAW,OACb,QAAO,mBAAmB,WAAW;;AAKzC,KAAI,OAAO,KAAK,OAAO,CAAC,WAAW,EACjC;AAGF,QAAO;;AAGT,YAAY,iBAAiB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
|
|
1
|
+
{"version":3,"file":"preset.js","names":[],"sources":["../../src/styles/preset.ts"],"sourcesContent":["import { CSS_WIDE_KEYWORDS } from '../parser/const';\nimport { parseStyle } from '../utils/styles';\n\nimport type { Styles } from './types';\n\nconst PRESET_MODIFIERS = new Set(['strong', 'bold', 'italic', 'icon', 'tight']);\n\n/**\n * Convert a value to CSS, handling numbers as pixels for numeric properties\n */\nfunction toCSS(\n value: string | number | undefined,\n isNumeric: boolean,\n): string | null {\n if (value == null) return null;\n if (typeof value === 'number') {\n return isNumeric ? `${value}px` : String(value);\n }\n // Parse through style parser to handle custom units like 1x, 2r, etc.\n const processed = parseStyle(String(value));\n return processed.groups[0]?.values[0] || String(value);\n}\n\nfunction setCSSValue(\n styles: Styles,\n styleName: string,\n presetName: string,\n { varOnly, cssOnly }: { varOnly?: boolean; cssOnly?: boolean } = {},\n) {\n const value = (() => {\n if (CSS_WIDE_KEYWORDS.has(presetName)) {\n return presetName;\n }\n\n const defaultValue = `var(--default-${styleName}${\n styleName === 'font-family'\n ? ', var(--font-sans, var(--font-sans-fallback))'\n : ''\n })`;\n const fontSuffix =\n styleName === 'font-family'\n ? ', var(--font-sans, var(--font-sans-fallback))'\n : '';\n\n if (presetName === 'default') {\n return `${defaultValue}${fontSuffix}`;\n } else {\n return `var(--${presetName}-${styleName}, ${defaultValue})${fontSuffix}`;\n }\n })();\n\n if (!cssOnly) {\n styles[`--${styleName}`] = value;\n }\n\n if (!varOnly) {\n styles[styleName] = value;\n }\n}\n\ninterface PresetStyleProps {\n preset?: string | boolean;\n fontSize?: string | number;\n lineHeight?: string | number;\n textTransform?: string;\n letterSpacing?: string | number;\n fontWeight?: string | number;\n fontStyle?: string | boolean;\n fontFamily?: string;\n /** Alias for fontFamily with special handling for 'monospace' and boolean */\n font?: string | boolean;\n}\n\n/**\n * Resolve font/fontFamily value to CSS font-family string.\n *\n * - `font=\"monospace\"` → var(--font-mono, var(--font-mono-fallback))\n * - `font={true}` → var(--font-sans, var(--font-sans-fallback))\n * - `font=\"CustomFont\"` → CustomFont, var(--font-sans, var(--font-sans-fallback))\n * - `fontFamily=\"Arial\"` → Arial (direct, no fallback)\n */\nfunction resolveFontFamily(\n font: string | boolean | undefined,\n fontFamily: string | undefined,\n): string | null {\n // fontFamily takes precedence as a direct value\n if (fontFamily) {\n return fontFamily;\n }\n\n if (font == null || font === false) {\n return null;\n }\n\n if (font === 'monospace') {\n return 'var(--font-mono, var(--font-mono-fallback))';\n }\n\n if (font === true) {\n return 'var(--font-sans, var(--font-sans-fallback))';\n }\n\n return `${font}, var(--font-sans, var(--font-sans-fallback))`;\n}\n\n/**\n * Handles typography preset and individual font properties.\n *\n * Preset syntax uses `/` to separate name from modifier:\n * - `preset=\"h1\"` — name only\n * - `preset=\"h2 / strong\"` — name + modifier\n * - `preset=\"bold\"` — modifier-only shorthand (name defaults to `inherit`)\n *\n * When `preset` is defined, it sets up CSS custom properties for typography.\n * Individual font props can be used with or without `preset`:\n * - With `preset`: overrides the preset value for that property\n * - Without `preset`: outputs the CSS directly\n *\n * Number values are converted to pixels for fontSize, lineHeight, letterSpacing.\n * fontWeight accepts numbers directly (e.g., 400, 700).\n *\n * font vs fontFamily:\n * - `font` is the recommended prop with special handling (monospace, boolean, fallback)\n * - `fontFamily` is a direct value without special handling\n */\nexport function presetStyle({\n preset,\n fontSize,\n lineHeight,\n textTransform,\n letterSpacing,\n fontWeight,\n fontStyle,\n fontFamily,\n font,\n}: PresetStyleProps) {\n const styles: Styles = {};\n const hasPreset = preset != null && preset !== false;\n\n // Handle preset if defined\n if (hasPreset) {\n const presetValue = preset === true ? '' : String(preset);\n\n const processed = parseStyle(presetValue);\n const group = processed.groups[0];\n const { parts } = group ?? { parts: [] };\n\n // parts[0] = preset name (or a modifier for shorthand like preset=\"bold\")\n // parts[1] = optional modifier after slash (e.g. \"t3 / bold\")\n const namePart = parts[0];\n const modPart = parts[1];\n\n const nameToken = namePart?.mods[0] ?? namePart?.values[0] ?? '';\n const isModOnly = PRESET_MODIFIERS.has(nameToken);\n\n const name = isModOnly ? 'inherit' : nameToken || 'inherit';\n const modifier = isModOnly ? nameToken : (modPart?.mods[0] ?? '');\n\n const isStrong = modifier === 'strong' || modifier === 'bold';\n const isItalic = modifier === 'italic';\n const isIcon = modifier === 'icon';\n const isTight = modifier === 'tight';\n\n // Set preset values for properties not explicitly overridden\n if (fontSize == null) {\n setCSSValue(styles, 'font-size', name, { cssOnly: true });\n }\n if (lineHeight == null) {\n setCSSValue(styles, 'line-height', name, { cssOnly: true });\n }\n if (letterSpacing == null) {\n setCSSValue(styles, 'letter-spacing', name, { cssOnly: true });\n }\n if (fontWeight == null) {\n setCSSValue(styles, 'font-weight', name, { cssOnly: true });\n }\n if (fontStyle == null) {\n setCSSValue(styles, 'font-style', name, { cssOnly: true });\n }\n if (textTransform == null) {\n setCSSValue(styles, 'text-transform', name, { cssOnly: true });\n }\n if (fontFamily == null && font == null) {\n setCSSValue(styles, 'font-family', name, { cssOnly: true });\n }\n\n setCSSValue(styles, 'bold-font-weight', name, { varOnly: true });\n setCSSValue(styles, 'icon-size', name, { varOnly: true });\n\n if (isStrong) {\n styles['font-weight'] = 'var(--bold-font-weight)';\n }\n if (isItalic) {\n styles['font-style'] = 'italic';\n }\n if (isIcon) {\n styles['font-size'] = 'var(--icon-size)';\n styles['line-height'] = 'var(--icon-size)';\n }\n if (isTight) {\n styles['line-height'] = '1em';\n }\n }\n\n // Handle individual font properties (work with or without preset)\n const fontSizeVal = toCSS(fontSize, true);\n if (fontSizeVal) {\n styles['font-size'] = fontSizeVal;\n }\n\n const lineHeightVal = toCSS(lineHeight, true);\n if (lineHeightVal) {\n styles['line-height'] = lineHeightVal;\n }\n\n const letterSpacingVal = toCSS(letterSpacing, true);\n if (letterSpacingVal) {\n styles['letter-spacing'] = letterSpacingVal;\n }\n\n // fontWeight: numbers should NOT get 'px' suffix\n const fontWeightVal = toCSS(fontWeight, false);\n if (fontWeightVal) {\n styles['font-weight'] = fontWeightVal;\n }\n\n if (fontStyle != null) {\n if (fontStyle === true) {\n styles['font-style'] = 'italic';\n } else if (\n typeof fontStyle === 'string' &&\n CSS_WIDE_KEYWORDS.has(fontStyle)\n ) {\n styles['font-style'] = fontStyle;\n } else {\n styles['font-style'] = fontStyle ? 'italic' : 'normal';\n }\n }\n\n if (textTransform) {\n styles['text-transform'] = textTransform;\n }\n\n // Handle font/fontFamily (font has special handling, fontFamily is direct)\n const fontFamily_ = resolveFontFamily(font, fontFamily);\n if (fontFamily_) {\n styles['font-family'] = fontFamily_;\n }\n\n if (Object.keys(styles).length === 0) {\n return null;\n }\n\n return styles;\n}\n\npresetStyle.__lookupStyles = [\n 'preset',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textTransform',\n 'fontWeight',\n 'fontStyle',\n 'fontFamily',\n 'font',\n];\n"],"mappings":";;;AAKA,MAAM,mBAAmB,IAAI,IAAI;CAAC;CAAU;CAAQ;CAAU;CAAQ;CAAQ,CAAC;;;;AAK/E,SAAS,MACP,OACA,WACe;AACf,KAAI,SAAS,KAAM,QAAO;AAC1B,KAAI,OAAO,UAAU,SACnB,QAAO,YAAY,GAAG,MAAM,MAAM,OAAO,MAAM;AAIjD,QADkB,WAAW,OAAO,MAAM,CAAC,CAC1B,OAAO,IAAI,OAAO,MAAM,OAAO,MAAM;;AAGxD,SAAS,YACP,QACA,WACA,YACA,EAAE,SAAS,Y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Ac,kBAAkB,MAAM,WAAW;AACvD,KAAI,YACF,QAAO,iBAAiB;AAG1B,KAAI,OAAO,KAAK,OAAO,CAAC,WAAW,EACjC,QAAO;AAGT,QAAO;;AAGT,YAAY,iBAAiB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
|
package/dist/styles/radius.d.ts
CHANGED
package/dist/styles/radius.js
CHANGED
|
@@ -1,16 +1,42 @@
|
|
|
1
1
|
import { makeEmptyDetails } from "../parser/types.js";
|
|
2
2
|
import { DIRECTIONS, parseStyle } from "../utils/styles.js";
|
|
3
|
-
|
|
3
|
+
import { extractCSSWideKeyword } from "./shared.js";
|
|
4
4
|
//#region src/styles/radius.ts
|
|
5
5
|
const PROP = "var(--radius)";
|
|
6
6
|
const SHARP = "var(--sharp-radius)";
|
|
7
|
+
const RADIUS_LONGHANDS = [
|
|
8
|
+
"border-top-left-radius",
|
|
9
|
+
"border-top-right-radius",
|
|
10
|
+
"border-bottom-right-radius",
|
|
11
|
+
"border-bottom-left-radius"
|
|
12
|
+
];
|
|
7
13
|
function radiusStyle({ radius }) {
|
|
8
14
|
if (typeof radius === "number") radius = `${radius}px`;
|
|
9
|
-
if (!radius) return;
|
|
15
|
+
if (!radius) return null;
|
|
10
16
|
if (radius === true) radius = "1r";
|
|
11
|
-
const
|
|
12
|
-
const { mods } =
|
|
13
|
-
let { values } =
|
|
17
|
+
const group = parseStyle(radius).groups[0] ?? makeEmptyDetails();
|
|
18
|
+
const { mods } = group;
|
|
19
|
+
let { values } = group;
|
|
20
|
+
const keyword = extractCSSWideKeyword(group);
|
|
21
|
+
const useLonghand = mods.includes("longhand");
|
|
22
|
+
if (keyword) {
|
|
23
|
+
const dirMods = mods.filter((m) => DIRECTIONS.includes(m));
|
|
24
|
+
if (!dirMods.length) {
|
|
25
|
+
if (useLonghand) return Object.fromEntries(RADIUS_LONGHANDS.map((prop) => [prop, keyword]));
|
|
26
|
+
return { "border-radius": keyword };
|
|
27
|
+
}
|
|
28
|
+
const result = {};
|
|
29
|
+
const corners = /* @__PURE__ */ new Set();
|
|
30
|
+
dirMods.forEach((dir) => {
|
|
31
|
+
const i = DIRECTIONS.indexOf(dir);
|
|
32
|
+
corners.add(i);
|
|
33
|
+
corners.add((i + 1) % 4);
|
|
34
|
+
});
|
|
35
|
+
corners.forEach((i) => {
|
|
36
|
+
result[RADIUS_LONGHANDS[i]] = keyword;
|
|
37
|
+
});
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
14
40
|
if (mods.includes("round")) values = ["9999rem"];
|
|
15
41
|
else if (mods.includes("ellipse")) values = ["50%"];
|
|
16
42
|
else if (!values.length) values = [PROP];
|
|
@@ -42,10 +68,16 @@ function radiusStyle({ radius }) {
|
|
|
42
68
|
});
|
|
43
69
|
if (flag) values = arr;
|
|
44
70
|
}
|
|
71
|
+
if (useLonghand) return {
|
|
72
|
+
[RADIUS_LONGHANDS[0]]: values[0],
|
|
73
|
+
[RADIUS_LONGHANDS[1]]: values[1] || values[0],
|
|
74
|
+
[RADIUS_LONGHANDS[2]]: values[2] || values[0],
|
|
75
|
+
[RADIUS_LONGHANDS[3]]: values[3] || values[1] || values[0]
|
|
76
|
+
};
|
|
45
77
|
return { "border-radius": values.join(" ") };
|
|
46
78
|
}
|
|
47
79
|
radiusStyle.__lookupStyles = ["radius"];
|
|
48
|
-
|
|
49
80
|
//#endregion
|
|
50
81
|
export { radiusStyle };
|
|
82
|
+
|
|
51
83
|
//# sourceMappingURL=radius.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"radius.js","names":[],"sources":["../../src/styles/radius.ts"],"sourcesContent":["import { makeEmptyDetails } from '../parser/types';\nimport { DIRECTIONS, parseStyle } from '../utils/styles';\n\nconst PROP = 'var(--radius)';\nconst SHARP = 'var(--sharp-radius)';\n\nexport function radiusStyle({\n radius,\n}: {\n radius?: string | number | boolean;\n}) {\n if (typeof radius === 'number') {\n radius = `${radius}px`;\n }\n\n if (!radius) return;\n\n if (radius === true) radius = '1r';\n\n const processed = parseStyle(radius);\n const
|
|
1
|
+
{"version":3,"file":"radius.js","names":[],"sources":["../../src/styles/radius.ts"],"sourcesContent":["import { makeEmptyDetails } from '../parser/types';\nimport { DIRECTIONS, parseStyle } from '../utils/styles';\nimport { extractCSSWideKeyword } from './shared';\n\nconst PROP = 'var(--radius)';\nconst SHARP = 'var(--sharp-radius)';\n\nconst RADIUS_LONGHANDS = [\n 'border-top-left-radius',\n 'border-top-right-radius',\n 'border-bottom-right-radius',\n 'border-bottom-left-radius',\n];\n\nexport function radiusStyle({\n radius,\n}: {\n radius?: string | number | boolean;\n}) {\n if (typeof radius === 'number') {\n radius = `${radius}px`;\n }\n\n if (!radius) return null;\n\n if (radius === true) radius = '1r';\n\n const processed = parseStyle(radius);\n const group = processed.groups[0] ?? makeEmptyDetails();\n const { mods } = group;\n let { values } = group;\n\n const keyword = extractCSSWideKeyword(group);\n\n const useLonghand = mods.includes('longhand');\n\n if (keyword) {\n const dirMods = mods.filter((m) => DIRECTIONS.includes(m));\n\n if (!dirMods.length) {\n if (useLonghand) {\n return Object.fromEntries(\n RADIUS_LONGHANDS.map((prop) => [prop, keyword]),\n );\n }\n\n return { 'border-radius': keyword };\n }\n\n const result: Record<string, string> = {};\n const corners = new Set<number>();\n\n dirMods.forEach((dir) => {\n const i = DIRECTIONS.indexOf(dir);\n corners.add(i);\n corners.add((i + 1) % 4);\n });\n\n corners.forEach((i) => {\n result[RADIUS_LONGHANDS[i]] = keyword;\n });\n\n return result;\n }\n\n if (mods.includes('round')) {\n values = ['9999rem'];\n } else if (mods.includes('ellipse')) {\n values = ['50%'];\n } else if (!values.length) {\n values = [PROP];\n }\n\n if (mods.includes('leaf')) {\n values = [\n values[1] || SHARP,\n values[0] || PROP,\n values[1] || SHARP,\n values[0] || PROP,\n ];\n } else if (mods.includes('backleaf')) {\n values = [\n values[0] || PROP,\n values[1] || SHARP,\n values[0] || PROP,\n values[1] || SHARP,\n ];\n } else if (mods.length) {\n const arr = ['0', '0', '0', '0'];\n\n let flag = false;\n\n DIRECTIONS.forEach((dir, i) => {\n if (!mods.includes(dir)) return;\n\n flag = true;\n\n arr[i] = values[0] || PROP;\n arr[(i + 1) % 4] = values[0] || PROP;\n });\n\n if (flag) {\n values = arr;\n }\n }\n\n if (useLonghand) {\n return {\n [RADIUS_LONGHANDS[0]]: values[0],\n [RADIUS_LONGHANDS[1]]: values[1] || values[0],\n [RADIUS_LONGHANDS[2]]: values[2] || values[0],\n [RADIUS_LONGHANDS[3]]: values[3] || values[1] || values[0],\n };\n }\n\n return {\n 'border-radius': values.join(' '),\n };\n}\n\nradiusStyle.__lookupStyles = ['radius'];\n"],"mappings":";;;;AAIA,MAAM,OAAO;AACb,MAAM,QAAQ;AAEd,MAAM,mBAAmB;CACvB;CACA;CACA;CACA;CACD;AAED,SAAgB,YAAY,EAC1B,UAGC;AACD,KAAI,OAAO,WAAW,SACpB,UAAS,GAAG,OAAO;AAGrB,KAAI,CAAC,OAAQ,QAAO;AAEpB,KAAI,WAAW,KAAM,UAAS;CAG9B,MAAM,QADY,WAAW,OAAO,CACZ,OAAO,MAAM,kBAAkB;CACvD,MAAM,EAAE,SAAS;CACjB,IAAI,EAAE,WAAW;CAEjB,MAAM,UAAU,sBAAsB,MAAM;CAE5C,MAAM,cAAc,KAAK,SAAS,WAAW;AAE7C,KAAI,SAAS;EACX,MAAM,UAAU,KAAK,QAAQ,MAAM,WAAW,SAAS,EAAE,CAAC;AAE1D,MAAI,CAAC,QAAQ,QAAQ;AACnB,OAAI,YACF,QAAO,OAAO,YACZ,iBAAiB,KAAK,SAAS,CAAC,MAAM,QAAQ,CAAC,CAChD;AAGH,UAAO,EAAE,iBAAiB,SAAS;;EAGrC,MAAM,SAAiC,EAAE;EACzC,MAAM,0BAAU,IAAI,KAAa;AAEjC,UAAQ,SAAS,QAAQ;GACvB,MAAM,IAAI,WAAW,QAAQ,IAAI;AACjC,WAAQ,IAAI,EAAE;AACd,WAAQ,KAAK,IAAI,KAAK,EAAE;IACxB;AAEF,UAAQ,SAAS,MAAM;AACrB,UAAO,iBAAiB,MAAM;IAC9B;AAEF,SAAO;;AAGT,KAAI,KAAK,SAAS,QAAQ,CACxB,UAAS,CAAC,UAAU;UACX,KAAK,SAAS,UAAU,CACjC,UAAS,CAAC,MAAM;UACP,CAAC,OAAO,OACjB,UAAS,CAAC,KAAK;AAGjB,KAAI,KAAK,SAAS,OAAO,CACvB,UAAS;EACP,OAAO,MAAM;EACb,OAAO,MAAM;EACb,OAAO,MAAM;EACb,OAAO,MAAM;EACd;UACQ,KAAK,SAAS,WAAW,CAClC,UAAS;EACP,OAAO,MAAM;EACb,OAAO,MAAM;EACb,OAAO,MAAM;EACb,OAAO,MAAM;EACd;UACQ,KAAK,QAAQ;EACtB,MAAM,MAAM;GAAC;GAAK;GAAK;GAAK;GAAI;EAEhC,IAAI,OAAO;AAEX,aAAW,SAAS,KAAK,MAAM;AAC7B,OAAI,CAAC,KAAK,SAAS,IAAI,CAAE;AAEzB,UAAO;AAEP,OAAI,KAAK,OAAO,MAAM;AACtB,QAAK,IAAI,KAAK,KAAK,OAAO,MAAM;IAChC;AAEF,MAAI,KACF,UAAS;;AAIb,KAAI,YACF,QAAO;GACJ,iBAAiB,KAAK,OAAO;GAC7B,iBAAiB,KAAK,OAAO,MAAM,OAAO;GAC1C,iBAAiB,KAAK,OAAO,MAAM,OAAO;GAC1C,iBAAiB,KAAK,OAAO,MAAM,OAAO,MAAM,OAAO;EACzD;AAGH,QAAO,EACL,iBAAiB,OAAO,KAAK,IAAI,EAClC;;AAGH,YAAY,iBAAiB,CAAC,SAAS"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/styles/scrollMargin.d.ts
|
|
2
|
+
declare function scrollMarginStyle({
|
|
3
|
+
scrollMargin,
|
|
4
|
+
scrollMarginBlock,
|
|
5
|
+
scrollMarginInline,
|
|
6
|
+
scrollMarginTop,
|
|
7
|
+
scrollMarginRight,
|
|
8
|
+
scrollMarginBottom,
|
|
9
|
+
scrollMarginLeft
|
|
10
|
+
}: {
|
|
11
|
+
scrollMargin?: string | number | boolean;
|
|
12
|
+
scrollMarginBlock?: string | number | boolean;
|
|
13
|
+
scrollMarginInline?: string | number | boolean;
|
|
14
|
+
scrollMarginTop?: string | number | boolean;
|
|
15
|
+
scrollMarginRight?: string | number | boolean;
|
|
16
|
+
scrollMarginBottom?: string | number | boolean;
|
|
17
|
+
scrollMarginLeft?: string | number | boolean;
|
|
18
|
+
}): Record<string, string> | null;
|
|
19
|
+
declare namespace scrollMarginStyle {
|
|
20
|
+
var __lookupStyles: string[];
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { scrollMarginStyle };
|
|
24
|
+
//# sourceMappingURL=scrollMargin.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { processDirectionalStyle } from "./directional.js";
|
|
2
|
+
//#region src/styles/scrollMargin.ts
|
|
3
|
+
const SCROLL_MARGIN_CONFIG = {
|
|
4
|
+
property: "scroll-margin",
|
|
5
|
+
defaultValue: "0",
|
|
6
|
+
trueValue: "1x",
|
|
7
|
+
defaultInit: "0"
|
|
8
|
+
};
|
|
9
|
+
function scrollMarginStyle({ scrollMargin, scrollMarginBlock, scrollMarginInline, scrollMarginTop, scrollMarginRight, scrollMarginBottom, scrollMarginLeft }) {
|
|
10
|
+
return processDirectionalStyle(SCROLL_MARGIN_CONFIG, {
|
|
11
|
+
main: scrollMargin,
|
|
12
|
+
block: scrollMarginBlock,
|
|
13
|
+
inline: scrollMarginInline,
|
|
14
|
+
top: scrollMarginTop,
|
|
15
|
+
right: scrollMarginRight,
|
|
16
|
+
bottom: scrollMarginBottom,
|
|
17
|
+
left: scrollMarginLeft
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
scrollMarginStyle.__lookupStyles = [
|
|
21
|
+
"scrollMargin",
|
|
22
|
+
"scrollMarginTop",
|
|
23
|
+
"scrollMarginRight",
|
|
24
|
+
"scrollMarginBottom",
|
|
25
|
+
"scrollMarginLeft",
|
|
26
|
+
"scrollMarginBlock",
|
|
27
|
+
"scrollMarginInline"
|
|
28
|
+
];
|
|
29
|
+
//#endregion
|
|
30
|
+
export { scrollMarginStyle };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=scrollMargin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrollMargin.js","names":[],"sources":["../../src/styles/scrollMargin.ts"],"sourcesContent":["import { processDirectionalStyle } from './directional';\n\nconst SCROLL_MARGIN_CONFIG = {\n property: 'scroll-margin',\n defaultValue: '0',\n trueValue: '1x',\n defaultInit: '0',\n} as const;\n\nexport function scrollMarginStyle({\n scrollMargin,\n scrollMarginBlock,\n scrollMarginInline,\n scrollMarginTop,\n scrollMarginRight,\n scrollMarginBottom,\n scrollMarginLeft,\n}: {\n scrollMargin?: string | number | boolean;\n scrollMarginBlock?: string | number | boolean;\n scrollMarginInline?: string | number | boolean;\n scrollMarginTop?: string | number | boolean;\n scrollMarginRight?: string | number | boolean;\n scrollMarginBottom?: string | number | boolean;\n scrollMarginLeft?: string | number | boolean;\n}) {\n return processDirectionalStyle(SCROLL_MARGIN_CONFIG, {\n main: scrollMargin,\n block: scrollMarginBlock,\n inline: scrollMarginInline,\n top: scrollMarginTop,\n right: scrollMarginRight,\n bottom: scrollMarginBottom,\n left: scrollMarginLeft,\n });\n}\n\nscrollMarginStyle.__lookupStyles = [\n 'scrollMargin',\n 'scrollMarginTop',\n 'scrollMarginRight',\n 'scrollMarginBottom',\n 'scrollMarginLeft',\n 'scrollMarginBlock',\n 'scrollMarginInline',\n];\n"],"mappings":";;AAEA,MAAM,uBAAuB;CAC3B,UAAU;CACV,cAAc;CACd,WAAW;CACX,aAAa;CACd;AAED,SAAgB,kBAAkB,EAChC,cACA,mBACA,oBACA,iBACA,mBACA,oBACA,oBASC;AACD,QAAO,wBAAwB,sBAAsB;EACnD,MAAM;EACN,OAAO;EACP,QAAQ;EACR,KAAK;EACL,OAAO;EACP,QAAQ;EACR,MAAM;EACP,CAAC;;AAGJ,kBAAkB,iBAAiB;CACjC;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
//#region src/styles/scrollbar.d.ts
|
|
2
2
|
interface ScrollbarStyleProps {
|
|
3
|
-
scrollbar?: string | boolean
|
|
3
|
+
scrollbar?: string | boolean;
|
|
4
4
|
overflow?: string;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Standard CSS scrollbar styling via `scrollbar-width`, `scrollbar-color`,
|
|
8
|
+
* and `scrollbar-gutter`.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
10
|
+
* Width values: `thin` (default), `auto`, `none`
|
|
11
|
+
* Modifiers: `stable`, `both-edges`, `always`
|
|
12
|
+
*
|
|
13
|
+
* Note: `auto` is classified as a VALUE_KEYWORD by the parser, so it lands
|
|
14
|
+
* in `values` rather than `mods`. Both locations are checked for robustness.
|
|
11
15
|
*/
|
|
12
16
|
declare function scrollbarStyle({
|
|
13
17
|
scrollbar,
|
|
14
18
|
overflow
|
|
15
|
-
}: ScrollbarStyleProps): Record<string, string |
|
|
19
|
+
}: ScrollbarStyleProps): Record<string, string> | null;
|
|
16
20
|
declare namespace scrollbarStyle {
|
|
17
21
|
var __lookupStyles: string[];
|
|
18
22
|
}
|
package/dist/styles/scrollbar.js
CHANGED
|
@@ -1,112 +1,51 @@
|
|
|
1
|
+
import { CSS_WIDE_KEYWORDS } from "../parser/const.js";
|
|
1
2
|
import { makeEmptyDetails } from "../parser/types.js";
|
|
2
3
|
import { parseStyle } from "../utils/styles.js";
|
|
3
|
-
|
|
4
|
+
import { warn } from "../utils/warnings.js";
|
|
4
5
|
//#region src/styles/scrollbar.ts
|
|
5
6
|
/**
|
|
6
|
-
*
|
|
7
|
+
* Standard CSS scrollbar styling via `scrollbar-width`, `scrollbar-color`,
|
|
8
|
+
* and `scrollbar-gutter`.
|
|
9
|
+
*
|
|
10
|
+
* Width values: `thin` (default), `auto`, `none`
|
|
11
|
+
* Modifiers: `stable`, `both-edges`, `always`
|
|
7
12
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
13
|
+
* Note: `auto` is classified as a VALUE_KEYWORD by the parser, so it lands
|
|
14
|
+
* in `values` rather than `mods`. Both locations are checked for robustness.
|
|
10
15
|
*/
|
|
11
16
|
function scrollbarStyle({ scrollbar, overflow }) {
|
|
12
|
-
if (!scrollbar
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (v && typeof v === "object") return v;
|
|
19
|
-
return {};
|
|
20
|
-
}
|
|
17
|
+
if (!scrollbar) return null;
|
|
18
|
+
if (typeof scrollbar === "string" && CSS_WIDE_KEYWORDS.has(scrollbar)) return {
|
|
19
|
+
"scrollbar-width": scrollbar,
|
|
20
|
+
"scrollbar-color": scrollbar
|
|
21
|
+
};
|
|
22
|
+
const { mods, colors, values } = parseStyle(String(scrollbar === true ? "thin" : scrollbar)).groups[0] ?? makeEmptyDetails();
|
|
21
23
|
const defaultThumbColor = "var(--scrollbar-thumb-color)";
|
|
22
24
|
const defaultTrackColor = "var(--scrollbar-track-color, transparent)";
|
|
23
|
-
style
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const style = {};
|
|
26
|
+
if (mods.includes("none")) {
|
|
27
|
+
const ignored = [
|
|
28
|
+
...mods.filter((m) => m !== "none"),
|
|
29
|
+
...values,
|
|
30
|
+
...colors
|
|
31
|
+
];
|
|
32
|
+
if (ignored.length) warn(`scrollbar="none" hides the scrollbar; other tokens are ignored: ${ignored.join(", ")}`);
|
|
27
33
|
style["scrollbar-width"] = "none";
|
|
28
|
-
delete style["scrollbar-color"];
|
|
29
|
-
style["&::-webkit-scrollbar"] = {
|
|
30
|
-
width: "0px",
|
|
31
|
-
height: "0px",
|
|
32
|
-
display: "none"
|
|
33
|
-
};
|
|
34
34
|
return style;
|
|
35
|
-
} else if (mods.includes("auto")) style["scrollbar-width"] = "auto";
|
|
36
|
-
if (mods.includes("stable") || mods.includes("both-edges")) style["scrollbar-gutter"] = mods.includes("both-edges") ? "stable both-edges" : "stable";
|
|
37
|
-
if (sizeValue) style["&::-webkit-scrollbar"] = {
|
|
38
|
-
...getNested("&::-webkit-scrollbar"),
|
|
39
|
-
width: sizeValue,
|
|
40
|
-
height: sizeValue
|
|
41
|
-
};
|
|
42
|
-
const thumbColor = colors && colors[0] ? colors[0] : defaultThumbColor;
|
|
43
|
-
const trackColor = colors && colors[1] ? colors[1] : defaultTrackColor;
|
|
44
|
-
const cornerColor = colors && colors[2] ? colors[2] : trackColor;
|
|
45
|
-
if (colors && colors.length) {
|
|
46
|
-
style["scrollbar-color"] = `${thumbColor} ${trackColor}`;
|
|
47
|
-
const webkitScrollbar = getNested("&::-webkit-scrollbar");
|
|
48
|
-
webkitScrollbar["background"] = trackColor;
|
|
49
|
-
style["&::-webkit-scrollbar"] = webkitScrollbar;
|
|
50
|
-
style["&::-webkit-scrollbar-track"] = {
|
|
51
|
-
...getNested("&::-webkit-scrollbar-track"),
|
|
52
|
-
background: trackColor
|
|
53
|
-
};
|
|
54
|
-
style["&::-webkit-scrollbar-thumb"] = {
|
|
55
|
-
...getNested("&::-webkit-scrollbar-thumb"),
|
|
56
|
-
background: thumbColor
|
|
57
|
-
};
|
|
58
|
-
style["&::-webkit-scrollbar-corner"] = {
|
|
59
|
-
...getNested("&::-webkit-scrollbar-corner"),
|
|
60
|
-
background: cornerColor
|
|
61
|
-
};
|
|
62
35
|
}
|
|
36
|
+
if (mods.includes("auto") || values.includes("auto")) style["scrollbar-width"] = "auto";
|
|
37
|
+
else style["scrollbar-width"] = "thin";
|
|
38
|
+
style["scrollbar-color"] = `${colors?.[0] || defaultThumbColor} ${colors?.[1] || defaultTrackColor}`;
|
|
39
|
+
if (mods.includes("stable") || mods.includes("both-edges")) style["scrollbar-gutter"] = mods.includes("both-edges") ? "stable both-edges" : "stable";
|
|
63
40
|
if (mods.includes("always")) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
alwaysScrollbar["display"] = "block";
|
|
68
|
-
style["&::-webkit-scrollbar"] = alwaysScrollbar;
|
|
69
|
-
}
|
|
70
|
-
if (mods.includes("styled")) {
|
|
71
|
-
const baseTransition = [
|
|
72
|
-
"background var(--transition)",
|
|
73
|
-
"border-radius var(--transition)",
|
|
74
|
-
"box-shadow var(--transition)",
|
|
75
|
-
"width var(--transition)",
|
|
76
|
-
"height var(--transition)",
|
|
77
|
-
"border var(--transition)"
|
|
78
|
-
].join(", ");
|
|
79
|
-
style["scrollbar-width"] = style["scrollbar-width"] || "thin";
|
|
80
|
-
style["scrollbar-color"] = style["scrollbar-color"] || `${defaultThumbColor} ${defaultTrackColor}`;
|
|
81
|
-
style["&::-webkit-scrollbar"] = {
|
|
82
|
-
width: sizeValue,
|
|
83
|
-
height: sizeValue,
|
|
84
|
-
transition: baseTransition,
|
|
85
|
-
background: defaultTrackColor,
|
|
86
|
-
...getNested("&::-webkit-scrollbar")
|
|
87
|
-
};
|
|
88
|
-
style["&::-webkit-scrollbar-thumb"] = {
|
|
89
|
-
"border-radius": "8px",
|
|
90
|
-
"min-height": "24px",
|
|
91
|
-
transition: baseTransition,
|
|
92
|
-
background: defaultThumbColor,
|
|
93
|
-
...getNested("&::-webkit-scrollbar-thumb")
|
|
94
|
-
};
|
|
95
|
-
style["&::-webkit-scrollbar-track"] = {
|
|
96
|
-
background: defaultTrackColor,
|
|
97
|
-
transition: baseTransition,
|
|
98
|
-
...getNested("&::-webkit-scrollbar-track")
|
|
99
|
-
};
|
|
100
|
-
style["&::-webkit-scrollbar-corner"] = {
|
|
101
|
-
background: defaultTrackColor,
|
|
102
|
-
transition: baseTransition,
|
|
103
|
-
...getNested("&::-webkit-scrollbar-corner")
|
|
104
|
-
};
|
|
41
|
+
const effectiveOverflow = overflow || "scroll";
|
|
42
|
+
style["overflow"] = effectiveOverflow;
|
|
43
|
+
if (!style["scrollbar-gutter"] && (effectiveOverflow === "scroll" || effectiveOverflow === "auto")) style["scrollbar-gutter"] = "stable";
|
|
105
44
|
}
|
|
106
45
|
return style;
|
|
107
46
|
}
|
|
108
47
|
scrollbarStyle.__lookupStyles = ["scrollbar", "overflow"];
|
|
109
|
-
|
|
110
48
|
//#endregion
|
|
111
49
|
export { scrollbarStyle };
|
|
50
|
+
|
|
112
51
|
//# sourceMappingURL=scrollbar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrollbar.js","names":[],"sources":["../../src/styles/scrollbar.ts"],"sourcesContent":["import { makeEmptyDetails } from '../parser/types';\nimport { parseStyle } from '../utils/styles';\n\ninterface ScrollbarStyleProps {\n scrollbar?: string | boolean
|
|
1
|
+
{"version":3,"file":"scrollbar.js","names":[],"sources":["../../src/styles/scrollbar.ts"],"sourcesContent":["import { CSS_WIDE_KEYWORDS } from '../parser/const';\nimport { makeEmptyDetails } from '../parser/types';\nimport { parseStyle } from '../utils/styles';\nimport { warn } from '../utils/warnings';\n\ninterface ScrollbarStyleProps {\n scrollbar?: string | boolean;\n overflow?: string;\n}\n\n/**\n * Standard CSS scrollbar styling via `scrollbar-width`, `scrollbar-color`,\n * and `scrollbar-gutter`.\n *\n * Width values: `thin` (default), `auto`, `none`\n * Modifiers: `stable`, `both-edges`, `always`\n *\n * Note: `auto` is classified as a VALUE_KEYWORD by the parser, so it lands\n * in `values` rather than `mods`. Both locations are checked for robustness.\n */\nexport function scrollbarStyle({\n scrollbar,\n overflow,\n}: ScrollbarStyleProps): Record<string, string> | null {\n if (!scrollbar) return null;\n\n if (typeof scrollbar === 'string' && CSS_WIDE_KEYWORDS.has(scrollbar)) {\n return {\n 'scrollbar-width': scrollbar,\n 'scrollbar-color': scrollbar,\n };\n }\n\n // `true` is treated as `thin` (empty string is falsy, caught by the guard above)\n const value = scrollbar === true ? 'thin' : scrollbar;\n const processed = parseStyle(String(value));\n const { mods, colors, values } = processed.groups[0] ?? makeEmptyDetails();\n\n const defaultThumbColor = 'var(--scrollbar-thumb-color)';\n const defaultTrackColor = 'var(--scrollbar-track-color, transparent)';\n\n const style: Record<string, string> = {};\n\n if (mods.includes('none')) {\n const ignored = [...mods.filter((m) => m !== 'none'), ...values, ...colors];\n\n if (ignored.length) {\n warn(\n `scrollbar=\"none\" hides the scrollbar; other tokens are ignored: ${ignored.join(', ')}`,\n );\n }\n\n style['scrollbar-width'] = 'none';\n\n return style;\n }\n\n // `thin` is the default — accepted as a value for readability but always\n // the fallback when neither `auto` nor `none` is specified.\n // `auto` is a VALUE_KEYWORD in the parser, so it may land in `values`.\n if (mods.includes('auto') || values.includes('auto')) {\n style['scrollbar-width'] = 'auto';\n } else {\n style['scrollbar-width'] = 'thin';\n }\n\n const thumbColor = colors?.[0] || defaultThumbColor;\n const trackColor = colors?.[1] || defaultTrackColor;\n style['scrollbar-color'] = `${thumbColor} ${trackColor}`;\n\n if (mods.includes('stable') || mods.includes('both-edges')) {\n style['scrollbar-gutter'] = mods.includes('both-edges')\n ? 'stable both-edges'\n : 'stable';\n }\n\n if (mods.includes('always')) {\n const effectiveOverflow = overflow || 'scroll';\n style['overflow'] = effectiveOverflow;\n\n // scrollbar-gutter only applies with scroll/auto overflow\n if (\n !style['scrollbar-gutter'] &&\n (effectiveOverflow === 'scroll' || effectiveOverflow === 'auto')\n ) {\n style['scrollbar-gutter'] = 'stable';\n }\n }\n\n return style;\n}\n\nscrollbarStyle.__lookupStyles = ['scrollbar', 'overflow'];\n"],"mappings":";;;;;;;;;;;;;;;AAoBA,SAAgB,eAAe,EAC7B,WACA,YACqD;AACrD,KAAI,CAAC,UAAW,QAAO;AAEvB,KAAI,OAAO,cAAc,YAAY,kBAAkB,IAAI,UAAU,CACnE,QAAO;EACL,mBAAmB;EACnB,mBAAmB;EACpB;CAMH,MAAM,EAAE,MAAM,QAAQ,WADJ,WAAW,OADf,cAAc,OAAO,SAAS,UACF,CAAC,CACA,OAAO,MAAM,kBAAkB;CAE1E,MAAM,oBAAoB;CAC1B,MAAM,oBAAoB;CAE1B,MAAM,QAAgC,EAAE;AAExC,KAAI,KAAK,SAAS,OAAO,EAAE;EACzB,MAAM,UAAU;GAAC,GAAG,KAAK,QAAQ,MAAM,MAAM,OAAO;GAAE,GAAG;GAAQ,GAAG;GAAO;AAE3E,MAAI,QAAQ,OACV,MACE,mEAAmE,QAAQ,KAAK,KAAK,GACtF;AAGH,QAAM,qBAAqB;AAE3B,SAAO;;AAMT,KAAI,KAAK,SAAS,OAAO,IAAI,OAAO,SAAS,OAAO,CAClD,OAAM,qBAAqB;KAE3B,OAAM,qBAAqB;AAK7B,OAAM,qBAAqB,GAFR,SAAS,MAAM,kBAEO,GADtB,SAAS,MAAM;AAGlC,KAAI,KAAK,SAAS,SAAS,IAAI,KAAK,SAAS,aAAa,CACxD,OAAM,sBAAsB,KAAK,SAAS,aAAa,GACnD,sBACA;AAGN,KAAI,KAAK,SAAS,SAAS,EAAE;EAC3B,MAAM,oBAAoB,YAAY;AACtC,QAAM,cAAc;AAGpB,MACE,CAAC,MAAM,wBACN,sBAAsB,YAAY,sBAAsB,QAEzD,OAAM,sBAAsB;;AAIhC,QAAO;;AAGT,eAAe,iBAAiB,CAAC,aAAa,WAAW"}
|
package/dist/styles/shadow.d.ts
CHANGED
package/dist/styles/shadow.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { CSS_WIDE_KEYWORDS } from "../parser/const.js";
|
|
1
2
|
import { makeEmptyDetails } from "../parser/types.js";
|
|
2
3
|
import { parseStyle } from "../utils/styles.js";
|
|
3
|
-
|
|
4
4
|
//#region src/styles/shadow.ts
|
|
5
5
|
function toBoxShadow(shadow) {
|
|
6
6
|
const { values, mods, colors } = parseStyle(shadow).groups[0] ?? makeEmptyDetails();
|
|
@@ -13,12 +13,13 @@ function toBoxShadow(shadow) {
|
|
|
13
13
|
].join(" ");
|
|
14
14
|
}
|
|
15
15
|
function shadowStyle({ shadow }) {
|
|
16
|
-
if (!shadow) return;
|
|
16
|
+
if (!shadow) return null;
|
|
17
17
|
if (shadow === true) shadow = "var(--shadow)";
|
|
18
|
+
if (CSS_WIDE_KEYWORDS.has(shadow)) return { "box-shadow": shadow };
|
|
18
19
|
return { "box-shadow": shadow.split(",").map(toBoxShadow).join(",") };
|
|
19
20
|
}
|
|
20
21
|
shadowStyle.__lookupStyles = ["shadow"];
|
|
21
|
-
|
|
22
22
|
//#endregion
|
|
23
23
|
export { shadowStyle };
|
|
24
|
+
|
|
24
25
|
//# sourceMappingURL=shadow.js.map
|