@tenphi/tasty 0.0.0-snapshot.056b911
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/LICENSE +21 -0
- package/README.md +635 -0
- package/dist/_virtual/_rolldown/runtime.js +7 -0
- package/dist/chunks/cacheKey.d.ts +1 -0
- package/dist/chunks/cacheKey.js +77 -0
- package/dist/chunks/cacheKey.js.map +1 -0
- package/dist/chunks/definitions.d.ts +37 -0
- package/dist/chunks/definitions.js +258 -0
- package/dist/chunks/definitions.js.map +1 -0
- package/dist/chunks/index.d.ts +1 -0
- package/dist/chunks/renderChunk.d.ts +1 -0
- package/dist/chunks/renderChunk.js +59 -0
- package/dist/chunks/renderChunk.js.map +1 -0
- package/dist/compute-styles.d.ts +31 -0
- package/dist/compute-styles.js +335 -0
- package/dist/compute-styles.js.map +1 -0
- package/dist/config.d.ts +409 -0
- package/dist/config.js +584 -0
- package/dist/config.js.map +1 -0
- package/dist/core/index.d.ts +34 -0
- package/dist/core/index.js +27 -0
- package/dist/counter-style/index.js +51 -0
- package/dist/counter-style/index.js.map +1 -0
- package/dist/debug.d.ts +89 -0
- package/dist/debug.js +453 -0
- package/dist/debug.js.map +1 -0
- 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 +64 -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 +46 -0
- package/dist/hooks/useGlobalStyles.js +88 -0
- package/dist/hooks/useGlobalStyles.js.map +1 -0
- package/dist/hooks/useKeyframes.d.ts +58 -0
- package/dist/hooks/useKeyframes.js +54 -0
- package/dist/hooks/useKeyframes.js.map +1 -0
- package/dist/hooks/useProperty.d.ts +81 -0
- package/dist/hooks/useProperty.js +96 -0
- package/dist/hooks/useProperty.js.map +1 -0
- package/dist/hooks/useRawCSS.d.ts +22 -0
- package/dist/hooks/useRawCSS.js +103 -0
- package/dist/hooks/useRawCSS.js.map +1 -0
- package/dist/hooks/useStyles.d.ts +40 -0
- package/dist/hooks/useStyles.js +31 -0
- package/dist/hooks/useStyles.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +36 -0
- package/dist/injector/index.d.ts +182 -0
- package/dist/injector/index.js +185 -0
- package/dist/injector/index.js.map +1 -0
- package/dist/injector/injector.d.ts +193 -0
- package/dist/injector/injector.js +564 -0
- package/dist/injector/injector.js.map +1 -0
- package/dist/injector/sheet-manager.d.ts +132 -0
- package/dist/injector/sheet-manager.js +698 -0
- package/dist/injector/sheet-manager.js.map +1 -0
- package/dist/injector/types.d.ts +228 -0
- package/dist/keyframes/index.js +206 -0
- package/dist/keyframes/index.js.map +1 -0
- package/dist/parser/classify.js +319 -0
- package/dist/parser/classify.js.map +1 -0
- package/dist/parser/const.js +60 -0
- package/dist/parser/const.js.map +1 -0
- package/dist/parser/lru.js +109 -0
- package/dist/parser/lru.js.map +1 -0
- package/dist/parser/parser.d.ts +25 -0
- package/dist/parser/parser.js +115 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/tokenizer.js +69 -0
- package/dist/parser/tokenizer.js.map +1 -0
- package/dist/parser/types.d.ts +51 -0
- package/dist/parser/types.js +46 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/pipeline/conditions.d.ts +134 -0
- package/dist/pipeline/conditions.js +406 -0
- package/dist/pipeline/conditions.js.map +1 -0
- package/dist/pipeline/exclusive.js +230 -0
- package/dist/pipeline/exclusive.js.map +1 -0
- package/dist/pipeline/index.d.ts +55 -0
- package/dist/pipeline/index.js +708 -0
- package/dist/pipeline/index.js.map +1 -0
- package/dist/pipeline/materialize.js +1103 -0
- package/dist/pipeline/materialize.js.map +1 -0
- package/dist/pipeline/parseStateKey.d.ts +15 -0
- package/dist/pipeline/parseStateKey.js +446 -0
- package/dist/pipeline/parseStateKey.js.map +1 -0
- package/dist/pipeline/simplify.js +515 -0
- package/dist/pipeline/simplify.js.map +1 -0
- package/dist/pipeline/warnings.js +18 -0
- package/dist/pipeline/warnings.js.map +1 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/okhsl-plugin.d.ts +35 -0
- package/dist/plugins/okhsl-plugin.js +97 -0
- package/dist/plugins/okhsl-plugin.js.map +1 -0
- package/dist/plugins/types.d.ts +87 -0
- package/dist/properties/index.js +222 -0
- package/dist/properties/index.js.map +1 -0
- package/dist/properties/property-type-resolver.d.ts +24 -0
- package/dist/properties/property-type-resolver.js +90 -0
- package/dist/properties/property-type-resolver.js.map +1 -0
- package/dist/rsc-cache.js +81 -0
- package/dist/rsc-cache.js.map +1 -0
- package/dist/ssr/astro-client.d.ts +1 -0
- package/dist/ssr/astro-client.js +24 -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 +106 -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 +102 -0
- package/dist/ssr/collector.js +227 -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 +22 -0
- package/dist/ssr/hydrate.js +49 -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 +45 -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.d.ts +49 -0
- package/dist/states/index.js +170 -0
- package/dist/states/index.js.map +1 -0
- package/dist/static/index.d.ts +5 -0
- package/dist/static/index.js +4 -0
- 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.d.ts +46 -0
- package/dist/static/tastyStatic.js +30 -0
- package/dist/static/tastyStatic.js.map +1 -0
- package/dist/static/types.d.ts +49 -0
- package/dist/static/types.js +24 -0
- package/dist/static/types.js.map +1 -0
- package/dist/styles/border.d.ts +25 -0
- package/dist/styles/border.js +120 -0
- package/dist/styles/border.js.map +1 -0
- package/dist/styles/color.d.ts +14 -0
- package/dist/styles/color.js +26 -0
- package/dist/styles/color.js.map +1 -0
- package/dist/styles/const.js +17 -0
- package/dist/styles/const.js.map +1 -0
- package/dist/styles/createStyle.js +79 -0
- package/dist/styles/createStyle.js.map +1 -0
- package/dist/styles/dimension.js +109 -0
- package/dist/styles/dimension.js.map +1 -0
- package/dist/styles/directional.js +133 -0
- package/dist/styles/directional.js.map +1 -0
- package/dist/styles/display.d.ts +30 -0
- package/dist/styles/display.js +73 -0
- package/dist/styles/display.js.map +1 -0
- package/dist/styles/fade.d.ts +15 -0
- package/dist/styles/fade.js +62 -0
- package/dist/styles/fade.js.map +1 -0
- package/dist/styles/fill.d.ts +42 -0
- package/dist/styles/fill.js +51 -0
- package/dist/styles/fill.js.map +1 -0
- package/dist/styles/flow.d.ts +16 -0
- package/dist/styles/flow.js +12 -0
- package/dist/styles/flow.js.map +1 -0
- package/dist/styles/gap.d.ts +31 -0
- package/dist/styles/gap.js +38 -0
- package/dist/styles/gap.js.map +1 -0
- package/dist/styles/height.d.ts +17 -0
- package/dist/styles/height.js +19 -0
- package/dist/styles/height.js.map +1 -0
- package/dist/styles/index.d.ts +1 -0
- package/dist/styles/index.js +8 -0
- package/dist/styles/index.js.map +1 -0
- package/dist/styles/inset.d.ts +24 -0
- package/dist/styles/inset.js +34 -0
- package/dist/styles/inset.js.map +1 -0
- package/dist/styles/list.d.ts +16 -0
- package/dist/styles/list.js +100 -0
- package/dist/styles/list.js.map +1 -0
- package/dist/styles/margin.d.ts +24 -0
- package/dist/styles/margin.js +32 -0
- package/dist/styles/margin.js.map +1 -0
- package/dist/styles/outline.d.ts +29 -0
- package/dist/styles/outline.js +55 -0
- package/dist/styles/outline.js.map +1 -0
- package/dist/styles/padding.d.ts +24 -0
- package/dist/styles/padding.js +32 -0
- package/dist/styles/padding.js.map +1 -0
- 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 +71 -0
- package/dist/styles/predefined.js +237 -0
- package/dist/styles/predefined.js.map +1 -0
- package/dist/styles/preset.d.ts +52 -0
- package/dist/styles/preset.js +127 -0
- package/dist/styles/preset.js.map +1 -0
- package/dist/styles/radius.d.ts +12 -0
- package/dist/styles/radius.js +83 -0
- package/dist/styles/radius.js.map +1 -0
- 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 +25 -0
- package/dist/styles/scrollbar.js +51 -0
- package/dist/styles/scrollbar.js.map +1 -0
- package/dist/styles/shadow.d.ts +14 -0
- package/dist/styles/shadow.js +25 -0
- package/dist/styles/shadow.js.map +1 -0
- package/dist/styles/shared.js +17 -0
- package/dist/styles/shared.js.map +1 -0
- package/dist/styles/transition.d.ts +14 -0
- package/dist/styles/transition.js +159 -0
- package/dist/styles/transition.js.map +1 -0
- package/dist/styles/types.d.ts +564 -0
- package/dist/styles/width.d.ts +17 -0
- package/dist/styles/width.js +19 -0
- package/dist/styles/width.js.map +1 -0
- package/dist/tasty.d.ts +134 -0
- package/dist/tasty.js +243 -0
- package/dist/tasty.js.map +1 -0
- package/dist/types.d.ts +184 -0
- package/dist/utils/cache-wrapper.js +21 -0
- package/dist/utils/cache-wrapper.js.map +1 -0
- package/dist/utils/case-converter.js +8 -0
- package/dist/utils/case-converter.js.map +1 -0
- 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.d.ts +5 -0
- package/dist/utils/colors.js +10 -0
- package/dist/utils/colors.js.map +1 -0
- package/dist/utils/css-types.d.ts +7 -0
- package/dist/utils/deps-equal.js +15 -0
- package/dist/utils/deps-equal.js.map +1 -0
- package/dist/utils/dotize.d.ts +26 -0
- package/dist/utils/dotize.js +122 -0
- package/dist/utils/dotize.js.map +1 -0
- package/dist/utils/filter-base-props.d.ts +15 -0
- package/dist/utils/filter-base-props.js +45 -0
- package/dist/utils/filter-base-props.js.map +1 -0
- package/dist/utils/get-display-name.d.ts +7 -0
- package/dist/utils/get-display-name.js +10 -0
- package/dist/utils/get-display-name.js.map +1 -0
- 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 +19 -0
- package/dist/utils/is-dev-env.js.map +1 -0
- package/dist/utils/is-valid-element-type.js +15 -0
- package/dist/utils/is-valid-element-type.js.map +1 -0
- package/dist/utils/merge-styles.d.ts +7 -0
- package/dist/utils/merge-styles.js +145 -0
- package/dist/utils/merge-styles.js.map +1 -0
- package/dist/utils/mod-attrs.d.ts +6 -0
- package/dist/utils/mod-attrs.js +20 -0
- package/dist/utils/mod-attrs.js.map +1 -0
- package/dist/utils/process-tokens.d.ts +17 -0
- package/dist/utils/process-tokens.js +83 -0
- package/dist/utils/process-tokens.js.map +1 -0
- package/dist/utils/resolve-recipes.d.ts +17 -0
- package/dist/utils/resolve-recipes.js +146 -0
- package/dist/utils/resolve-recipes.js.map +1 -0
- package/dist/utils/selector-transform.js +32 -0
- package/dist/utils/selector-transform.js.map +1 -0
- package/dist/utils/string.js +8 -0
- package/dist/utils/string.js.map +1 -0
- package/dist/utils/styles.d.ts +99 -0
- package/dist/utils/styles.js +220 -0
- package/dist/utils/styles.js.map +1 -0
- package/dist/utils/typography.d.ts +58 -0
- package/dist/utils/typography.js +51 -0
- package/dist/utils/typography.js.map +1 -0
- package/dist/utils/warnings.d.ts +16 -0
- package/dist/utils/warnings.js +16 -0
- package/dist/utils/warnings.js.map +1 -0
- package/dist/zero/babel.d.ts +195 -0
- package/dist/zero/babel.js +456 -0
- package/dist/zero/babel.js.map +1 -0
- package/dist/zero/css-writer.d.ts +45 -0
- package/dist/zero/css-writer.js +73 -0
- package/dist/zero/css-writer.js.map +1 -0
- package/dist/zero/extractor.d.ts +24 -0
- package/dist/zero/extractor.js +266 -0
- package/dist/zero/extractor.js.map +1 -0
- package/dist/zero/index.d.ts +3 -0
- package/dist/zero/index.js +3 -0
- package/dist/zero/next.d.ts +86 -0
- package/dist/zero/next.js +143 -0
- package/dist/zero/next.js.map +1 -0
- package/docs/PIPELINE.md +519 -0
- package/docs/README.md +31 -0
- package/docs/adoption.md +298 -0
- package/docs/comparison.md +419 -0
- package/docs/configuration.md +389 -0
- package/docs/debug.md +318 -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/react-api.md +557 -0
- package/docs/ssr.md +440 -0
- package/docs/styles.md +596 -0
- package/docs/tasty-static.md +532 -0
- package/package.json +221 -0
- package/tasty.config.ts +14 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Styles } from "../styles/types.js";
|
|
2
|
+
import { mergeStyles } from "../utils/merge-styles.js";
|
|
3
|
+
import { StaticStyle, createStaticStyle, isStaticStyle } from "./types.js";
|
|
4
|
+
import { tastyStatic } from "./tastyStatic.js";
|
|
5
|
+
export { type StaticStyle, type Styles, createStaticStyle, isStaticStyle, mergeStyles, tastyStatic };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/static/inject.ts
|
|
2
|
+
const _ids = /* @__PURE__ */ new Set();
|
|
3
|
+
function injectCSS(id, css) {
|
|
4
|
+
if (_ids.has(id) || typeof document === "undefined") return;
|
|
5
|
+
_ids.add(id);
|
|
6
|
+
let el = document.head.querySelector("style[data-tasty-static]");
|
|
7
|
+
if (!el) {
|
|
8
|
+
el = document.createElement("style");
|
|
9
|
+
el.setAttribute("data-tasty-static", "");
|
|
10
|
+
document.head.appendChild(el);
|
|
11
|
+
}
|
|
12
|
+
el.appendChild(document.createTextNode(css + "\n"));
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { injectCSS };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=inject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.js","names":[],"sources":["../../src/static/inject.ts"],"sourcesContent":["const _ids = new Set<string>();\n\nexport function injectCSS(id: string, css: string): void {\n if (_ids.has(id) || typeof document === 'undefined') return;\n _ids.add(id);\n let el = document.head.querySelector(\n 'style[data-tasty-static]',\n ) as HTMLStyleElement | null;\n if (!el) {\n el = document.createElement('style');\n el.setAttribute('data-tasty-static', '');\n document.head.appendChild(el);\n }\n el.appendChild(document.createTextNode(css + '\\n'));\n}\n"],"mappings":";AAAA,MAAM,uBAAO,IAAI,KAAa;AAE9B,SAAgB,UAAU,IAAY,KAAmB;AACvD,KAAI,KAAK,IAAI,GAAG,IAAI,OAAO,aAAa,YAAa;AACrD,MAAK,IAAI,GAAG;CACZ,IAAI,KAAK,SAAS,KAAK,cACrB,2BACD;AACD,KAAI,CAAC,IAAI;AACP,OAAK,SAAS,cAAc,QAAQ;AACpC,KAAG,aAAa,qBAAqB,GAAG;AACxC,WAAS,KAAK,YAAY,GAAG;;AAE/B,IAAG,YAAY,SAAS,eAAe,MAAM,KAAK,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Styles } from "../styles/types.js";
|
|
2
|
+
import { StaticStyle } from "./types.js";
|
|
3
|
+
|
|
4
|
+
//#region src/static/tastyStatic.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Generate styles and return a StaticStyle object.
|
|
7
|
+
* The object has `className`, `styles`, and `toString()`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const button = tastyStatic({
|
|
12
|
+
* fill: '#blue',
|
|
13
|
+
* padding: '2x',
|
|
14
|
+
* });
|
|
15
|
+
* // After build: { className: 'ts3f2a1b', styles: {...}, toString() }
|
|
16
|
+
*
|
|
17
|
+
* <div className={button} /> // Works via toString()
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
declare function tastyStatic(styles: Styles): StaticStyle;
|
|
21
|
+
/**
|
|
22
|
+
* Extend an existing StaticStyle with additional styles.
|
|
23
|
+
* Uses mergeStyles() internally for proper nested selector handling.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const button = tastyStatic({ fill: '#blue' });
|
|
28
|
+
* const primary = tastyStatic(button, { fill: '#purple' });
|
|
29
|
+
* // After build: { className: 'ts8c4d2e', styles: {...merged...}, toString() }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare function tastyStatic(base: StaticStyle, styles: Styles): StaticStyle;
|
|
33
|
+
/**
|
|
34
|
+
* Generate styles for a specific CSS selector.
|
|
35
|
+
* The call is completely removed after build transformation.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* tastyStatic('.heading', { preset: 'h1', color: '#primary' });
|
|
40
|
+
* // After build: (removed)
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
declare function tastyStatic(selector: string, styles: Styles): void;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { tastyStatic };
|
|
46
|
+
//# sourceMappingURL=tastyStatic.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { mergeStyles } from "../utils/merge-styles.js";
|
|
2
|
+
import { createStaticStyle, isStaticStyle } from "./types.js";
|
|
3
|
+
//#region src/static/tastyStatic.ts
|
|
4
|
+
/**
|
|
5
|
+
* Build-time only function for zero-runtime static site generation.
|
|
6
|
+
*
|
|
7
|
+
* This function is transformed by the Babel plugin:
|
|
8
|
+
* - `tastyStatic(styles)` → StaticStyle object with className
|
|
9
|
+
* - `tastyStatic(base, styles)` → StaticStyle object with merged styles
|
|
10
|
+
* - `tastyStatic(selector, styles)` → removed entirely
|
|
11
|
+
*
|
|
12
|
+
* At runtime (during development/build), this function returns a placeholder.
|
|
13
|
+
* In production, all calls are replaced/removed by the build plugin.
|
|
14
|
+
*/
|
|
15
|
+
function tastyStatic(stylesOrBaseOrSelector, styles) {
|
|
16
|
+
if (typeof stylesOrBaseOrSelector === "string") {
|
|
17
|
+
console.warn(`[tasty] tastyStatic('${stylesOrBaseOrSelector}', styles) was called at runtime. This indicates the Babel plugin is not configured. Add @tenphi/tasty/babel-plugin to your Babel config.`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (isStaticStyle(stylesOrBaseOrSelector)) {
|
|
21
|
+
console.warn("[tasty] tastyStatic(base, styles) was called at runtime. This indicates the Babel plugin is not configured. Add @tenphi/tasty/babel-plugin to your Babel config.");
|
|
22
|
+
return createStaticStyle("__TASTY_STATIC_NOT_TRANSFORMED__", mergeStyles(stylesOrBaseOrSelector.styles, styles || {}));
|
|
23
|
+
}
|
|
24
|
+
console.warn("[tasty] tastyStatic(styles) was called at runtime. This indicates the Babel plugin is not configured. Add @tenphi/tasty/babel-plugin to your Babel config.");
|
|
25
|
+
return createStaticStyle("__TASTY_STATIC_NOT_TRANSFORMED__", stylesOrBaseOrSelector);
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { tastyStatic };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=tastyStatic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tastyStatic.js","names":[],"sources":["../../src/static/tastyStatic.ts"],"sourcesContent":["import type { Styles } from '../styles/types';\nimport { mergeStyles } from '../utils/merge-styles';\n\nimport type { StaticStyle } from './types';\nimport { createStaticStyle, isStaticStyle } from './types';\n\n/**\n * Generate styles and return a StaticStyle object.\n * The object has `className`, `styles`, and `toString()`.\n *\n * @example\n * ```typescript\n * const button = tastyStatic({\n * fill: '#blue',\n * padding: '2x',\n * });\n * // After build: { className: 'ts3f2a1b', styles: {...}, toString() }\n *\n * <div className={button} /> // Works via toString()\n * ```\n */\nexport function tastyStatic(styles: Styles): StaticStyle;\n\n/**\n * Extend an existing StaticStyle with additional styles.\n * Uses mergeStyles() internally for proper nested selector handling.\n *\n * @example\n * ```typescript\n * const button = tastyStatic({ fill: '#blue' });\n * const primary = tastyStatic(button, { fill: '#purple' });\n * // After build: { className: 'ts8c4d2e', styles: {...merged...}, toString() }\n * ```\n */\nexport function tastyStatic(base: StaticStyle, styles: Styles): StaticStyle;\n\n/**\n * Generate styles for a specific CSS selector.\n * The call is completely removed after build transformation.\n *\n * @example\n * ```typescript\n * tastyStatic('.heading', { preset: 'h1', color: '#primary' });\n * // After build: (removed)\n * ```\n */\nexport function tastyStatic(selector: string, styles: Styles): void;\n\n/**\n * Build-time only function for zero-runtime static site generation.\n *\n * This function is transformed by the Babel plugin:\n * - `tastyStatic(styles)` → StaticStyle object with className\n * - `tastyStatic(base, styles)` → StaticStyle object with merged styles\n * - `tastyStatic(selector, styles)` → removed entirely\n *\n * At runtime (during development/build), this function returns a placeholder.\n * In production, all calls are replaced/removed by the build plugin.\n */\nexport function tastyStatic(\n stylesOrBaseOrSelector: Styles | StaticStyle | string,\n styles?: Styles,\n): StaticStyle | void {\n // This code only executes if the Babel plugin hasn't processed the file yet.\n // In a properly configured build, this function is never called at runtime.\n\n if (typeof stylesOrBaseOrSelector === 'string') {\n // Selector mode: tastyStatic(selector, styles)\n // The plugin will remove this call entirely\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n `[tasty] tastyStatic('${stylesOrBaseOrSelector}', styles) was called at runtime. ` +\n 'This indicates the Babel plugin is not configured. ' +\n 'Add @tenphi/tasty/babel-plugin to your Babel config.',\n );\n }\n return; // void\n }\n\n if (isStaticStyle(stylesOrBaseOrSelector)) {\n // Extension mode: tastyStatic(base, styles)\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n '[tasty] tastyStatic(base, styles) was called at runtime. ' +\n 'This indicates the Babel plugin is not configured. ' +\n 'Add @tenphi/tasty/babel-plugin to your Babel config.',\n );\n }\n // Merge styles for dev mode preview (won't have real classNames)\n const mergedStyles = mergeStyles(\n stylesOrBaseOrSelector.styles,\n styles || {},\n );\n return createStaticStyle('__TASTY_STATIC_NOT_TRANSFORMED__', mergedStyles);\n }\n\n // Styles mode: tastyStatic(styles)\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n '[tasty] tastyStatic(styles) was called at runtime. ' +\n 'This indicates the Babel plugin is not configured. ' +\n 'Add @tenphi/tasty/babel-plugin to your Babel config.',\n );\n }\n\n // Return placeholder - styles won't be applied without the plugin\n return createStaticStyle(\n '__TASTY_STATIC_NOT_TRANSFORMED__',\n stylesOrBaseOrSelector,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;AA2DA,SAAgB,YACd,wBACA,QACoB;AAIpB,KAAI,OAAO,2BAA2B,UAAU;AAI5C,UAAQ,KACN,wBAAwB,uBAAuB,2IAGhD;AAEH;;AAGF,KAAI,cAAc,uBAAuB,EAAE;AAGvC,UAAQ,KACN,mKAGD;AAOH,SAAO,kBAAkB,oCAJJ,YACnB,uBAAuB,QACvB,UAAU,EAAE,CACb,CACyE;;AAK1E,SAAQ,KACN,6JAGD;AAIH,QAAO,kBACL,oCACA,uBACD"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Styles } from "../styles/types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/static/types.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Static style definition returned by tastyStatic().
|
|
6
|
+
*
|
|
7
|
+
* Supports both explicit className access and implicit string coercion via toString().
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* const button = tastyStatic({ fill: '#blue' });
|
|
12
|
+
*
|
|
13
|
+
* // Both work in JSX:
|
|
14
|
+
* <div className={button} /> // Uses toString()
|
|
15
|
+
* <div className={button.className} /> // Explicit
|
|
16
|
+
*
|
|
17
|
+
* // Extension:
|
|
18
|
+
* const primary = tastyStatic(button, { fill: '#purple' });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
interface StaticStyle {
|
|
22
|
+
/**
|
|
23
|
+
* Generated className(s) for use in JSX.
|
|
24
|
+
* May contain multiple space-separated class names due to chunking.
|
|
25
|
+
*/
|
|
26
|
+
className: string;
|
|
27
|
+
/**
|
|
28
|
+
* The original (or merged) styles object.
|
|
29
|
+
* Available for extension via tastyStatic(base, overrides).
|
|
30
|
+
*/
|
|
31
|
+
styles: Styles;
|
|
32
|
+
/**
|
|
33
|
+
* Returns className for implicit string coercion.
|
|
34
|
+
* Enables `<div className={button} />` syntax.
|
|
35
|
+
*/
|
|
36
|
+
toString(): string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a StaticStyle object.
|
|
40
|
+
* Used internally by the Babel plugin to generate output.
|
|
41
|
+
*/
|
|
42
|
+
declare function createStaticStyle(className: string, styles: Styles): StaticStyle;
|
|
43
|
+
/**
|
|
44
|
+
* Type guard to check if a value is a StaticStyle object.
|
|
45
|
+
*/
|
|
46
|
+
declare function isStaticStyle(value: unknown): value is StaticStyle;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { StaticStyle, createStaticStyle, isStaticStyle };
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/static/types.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create a StaticStyle object.
|
|
4
|
+
* Used internally by the Babel plugin to generate output.
|
|
5
|
+
*/
|
|
6
|
+
function createStaticStyle(className, styles) {
|
|
7
|
+
return {
|
|
8
|
+
className,
|
|
9
|
+
styles,
|
|
10
|
+
toString() {
|
|
11
|
+
return this.className;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Type guard to check if a value is a StaticStyle object.
|
|
17
|
+
*/
|
|
18
|
+
function isStaticStyle(value) {
|
|
19
|
+
return typeof value === "object" && value !== null && "className" in value && "styles" in value && "toString" in value && typeof value.className === "string" && typeof value.styles === "object";
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { createStaticStyle, isStaticStyle };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/static/types.ts"],"sourcesContent":["import type { Styles } from '../styles/types';\n\n/**\n * Static style definition returned by tastyStatic().\n *\n * Supports both explicit className access and implicit string coercion via toString().\n *\n * @example\n * ```typescript\n * const button = tastyStatic({ fill: '#blue' });\n *\n * // Both work in JSX:\n * <div className={button} /> // Uses toString()\n * <div className={button.className} /> // Explicit\n *\n * // Extension:\n * const primary = tastyStatic(button, { fill: '#purple' });\n * ```\n */\nexport interface StaticStyle {\n /**\n * Generated className(s) for use in JSX.\n * May contain multiple space-separated class names due to chunking.\n */\n className: string;\n\n /**\n * The original (or merged) styles object.\n * Available for extension via tastyStatic(base, overrides).\n */\n styles: Styles;\n\n /**\n * Returns className for implicit string coercion.\n * Enables `<div className={button} />` syntax.\n */\n toString(): string;\n}\n\n/**\n * Create a StaticStyle object.\n * Used internally by the Babel plugin to generate output.\n */\nexport function createStaticStyle(\n className: string,\n styles: Styles,\n): StaticStyle {\n return {\n className,\n styles,\n toString() {\n return this.className;\n },\n };\n}\n\n/**\n * Type guard to check if a value is a StaticStyle object.\n */\nexport function isStaticStyle(value: unknown): value is StaticStyle {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'className' in value &&\n 'styles' in value &&\n 'toString' in value &&\n typeof (value as StaticStyle).className === 'string' &&\n typeof (value as StaticStyle).styles === 'object'\n );\n}\n"],"mappings":";;;;;AA2CA,SAAgB,kBACd,WACA,QACa;AACb,QAAO;EACL;EACA;EACA,WAAW;AACT,UAAO,KAAK;;EAEf;;;;;AAMH,SAAgB,cAAc,OAAsC;AAClE,QACE,OAAO,UAAU,YACjB,UAAU,QACV,eAAe,SACf,YAAY,SACZ,cAAc,SACd,OAAQ,MAAsB,cAAc,YAC5C,OAAQ,MAAsB,WAAW"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/styles/border.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Border style handler with multi-group support.
|
|
4
|
+
*
|
|
5
|
+
* Single group (backward compatible):
|
|
6
|
+
* - `border="1bw solid #red"` - all sides
|
|
7
|
+
* - `border="1bw solid #red top left"` - only top and left
|
|
8
|
+
*
|
|
9
|
+
* Multi-group (new):
|
|
10
|
+
* - `border="1bw #red, 2bw #blue top"` - all sides red 1bw, then top overridden to blue 2bw
|
|
11
|
+
* - `border="1bw, dashed top bottom, #purple left right"` - base 1bw, dashed on top/bottom, purple on left/right
|
|
12
|
+
*
|
|
13
|
+
* Later groups override earlier groups for conflicting directions.
|
|
14
|
+
*/
|
|
15
|
+
declare function borderStyle({
|
|
16
|
+
border
|
|
17
|
+
}: {
|
|
18
|
+
border?: string | number | boolean;
|
|
19
|
+
}): Record<string, string> | null;
|
|
20
|
+
declare namespace borderStyle {
|
|
21
|
+
var __lookupStyles: string[];
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { borderStyle };
|
|
25
|
+
//# sourceMappingURL=border.d.ts.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { CSS_WIDE_KEYWORDS } from "../parser/const.js";
|
|
2
|
+
import { DIRECTIONS, filterMods, parseStyle } from "../utils/styles.js";
|
|
3
|
+
import { BORDER_STYLES } from "./const.js";
|
|
4
|
+
import { extractCSSWideKeyword } from "./shared.js";
|
|
5
|
+
//#region src/styles/border.ts
|
|
6
|
+
/**
|
|
7
|
+
* Process a single group and return border values for its directions.
|
|
8
|
+
* @returns Object with directions as keys and border values, or null for "all directions"
|
|
9
|
+
*/
|
|
10
|
+
function processGroup(group) {
|
|
11
|
+
const { values, mods, colors } = group;
|
|
12
|
+
const directions = filterMods(mods, DIRECTIONS);
|
|
13
|
+
const typeMods = filterMods(mods, BORDER_STYLES);
|
|
14
|
+
return {
|
|
15
|
+
directions,
|
|
16
|
+
borderValue: {
|
|
17
|
+
width: values[0] || "var(--border-width)",
|
|
18
|
+
style: typeMods[0] || "solid",
|
|
19
|
+
color: colors?.[0] || "var(--border-color, currentColor)"
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Format a border value to CSS string.
|
|
25
|
+
*/
|
|
26
|
+
function formatBorderValue(value) {
|
|
27
|
+
return `${value.width} ${value.style} ${value.color}`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Border style handler with multi-group support.
|
|
31
|
+
*
|
|
32
|
+
* Single group (backward compatible):
|
|
33
|
+
* - `border="1bw solid #red"` - all sides
|
|
34
|
+
* - `border="1bw solid #red top left"` - only top and left
|
|
35
|
+
*
|
|
36
|
+
* Multi-group (new):
|
|
37
|
+
* - `border="1bw #red, 2bw #blue top"` - all sides red 1bw, then top overridden to blue 2bw
|
|
38
|
+
* - `border="1bw, dashed top bottom, #purple left right"` - base 1bw, dashed on top/bottom, purple on left/right
|
|
39
|
+
*
|
|
40
|
+
* Later groups override earlier groups for conflicting directions.
|
|
41
|
+
*/
|
|
42
|
+
function borderStyle({ border }) {
|
|
43
|
+
if (!border && border !== 0) return null;
|
|
44
|
+
if (border === true) border = "1bw";
|
|
45
|
+
const strBorder = String(border);
|
|
46
|
+
if (CSS_WIDE_KEYWORDS.has(strBorder)) return { border: strBorder };
|
|
47
|
+
const groups = parseStyle(strBorder).groups ?? [];
|
|
48
|
+
if (!groups.length) return null;
|
|
49
|
+
const useLonghand = groups.some((g) => (g.mods ?? []).includes("longhand"));
|
|
50
|
+
if (groups.length === 1) {
|
|
51
|
+
const group = groups[0];
|
|
52
|
+
const keyword = extractCSSWideKeyword(group);
|
|
53
|
+
if (keyword) {
|
|
54
|
+
if (useLonghand) return Object.fromEntries(DIRECTIONS.map((dir) => [`border-${dir}`, keyword]));
|
|
55
|
+
return { border: keyword };
|
|
56
|
+
}
|
|
57
|
+
const { directions, borderValue } = processGroup({
|
|
58
|
+
values: group.values ?? [],
|
|
59
|
+
mods: group.mods ?? [],
|
|
60
|
+
colors: group.colors ?? []
|
|
61
|
+
});
|
|
62
|
+
const styleValue = formatBorderValue(borderValue);
|
|
63
|
+
if (!directions.length) {
|
|
64
|
+
if (useLonghand) return Object.fromEntries(DIRECTIONS.map((dir) => [`border-${dir}`, styleValue]));
|
|
65
|
+
return { border: styleValue };
|
|
66
|
+
}
|
|
67
|
+
const zeroValue = `0 ${borderValue.style} ${borderValue.color}`;
|
|
68
|
+
return DIRECTIONS.reduce((styles, dir) => {
|
|
69
|
+
if (directions.includes(dir)) styles[`border-${dir}`] = styleValue;
|
|
70
|
+
else styles[`border-${dir}`] = zeroValue;
|
|
71
|
+
return styles;
|
|
72
|
+
}, {});
|
|
73
|
+
}
|
|
74
|
+
let hasAnyDirections = false;
|
|
75
|
+
const directionMap = {
|
|
76
|
+
top: null,
|
|
77
|
+
right: null,
|
|
78
|
+
bottom: null,
|
|
79
|
+
left: null
|
|
80
|
+
};
|
|
81
|
+
let allDirectionsValue = null;
|
|
82
|
+
for (const group of groups) {
|
|
83
|
+
const { directions, borderValue } = processGroup({
|
|
84
|
+
values: group.values ?? [],
|
|
85
|
+
mods: group.mods ?? [],
|
|
86
|
+
colors: group.colors ?? []
|
|
87
|
+
});
|
|
88
|
+
if (directions.length === 0) {
|
|
89
|
+
allDirectionsValue = borderValue;
|
|
90
|
+
for (const dir of DIRECTIONS) directionMap[dir] = borderValue;
|
|
91
|
+
} else {
|
|
92
|
+
hasAnyDirections = true;
|
|
93
|
+
for (const dir of directions) directionMap[dir] = borderValue;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (!hasAnyDirections && allDirectionsValue) {
|
|
97
|
+
const formatted = formatBorderValue(allDirectionsValue);
|
|
98
|
+
if (useLonghand) return Object.fromEntries(DIRECTIONS.map((dir) => [`border-${dir}`, formatted]));
|
|
99
|
+
return { border: formatted };
|
|
100
|
+
}
|
|
101
|
+
const result = {};
|
|
102
|
+
for (const dir of DIRECTIONS) {
|
|
103
|
+
const value = directionMap[dir];
|
|
104
|
+
if (value) result[`border-${dir}`] = formatBorderValue(value);
|
|
105
|
+
else {
|
|
106
|
+
const fallback = allDirectionsValue || {
|
|
107
|
+
width: "0",
|
|
108
|
+
style: "solid",
|
|
109
|
+
color: "var(--border-color, currentColor)"
|
|
110
|
+
};
|
|
111
|
+
result[`border-${dir}`] = `0 ${fallback.style} ${fallback.color}`;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
borderStyle.__lookupStyles = ["border"];
|
|
117
|
+
//#endregion
|
|
118
|
+
export { borderStyle };
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=border.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"border.js","names":[],"sources":["../../src/styles/border.ts"],"sourcesContent":["import { CSS_WIDE_KEYWORDS } from '../parser/const';\nimport { DIRECTIONS, filterMods, parseStyle } from '../utils/styles';\nimport { BORDER_STYLES } from './const';\nimport { extractCSSWideKeyword } from './shared';\n\ntype Direction = (typeof DIRECTIONS)[number];\n\ninterface GroupData {\n values: string[];\n mods: string[];\n colors: string[];\n}\n\ninterface BorderValue {\n width: string;\n style: string;\n color: string;\n}\n\n/**\n * Process a single group and return border values for its directions.\n * @returns Object with directions as keys and border values, or null for \"all directions\"\n */\nfunction processGroup(group: GroupData): {\n directions: Direction[];\n borderValue: BorderValue;\n} {\n const { values, mods, colors } = group;\n\n const directions = filterMods(mods, DIRECTIONS) as Direction[];\n const typeMods = filterMods(mods, BORDER_STYLES as unknown as string[]);\n\n const width = values[0] || 'var(--border-width)';\n const style = typeMods[0] || 'solid';\n const color = colors?.[0] || 'var(--border-color, currentColor)';\n\n return {\n directions,\n borderValue: { width, style, color },\n };\n}\n\n/**\n * Format a border value to CSS string.\n */\nfunction formatBorderValue(value: BorderValue): string {\n return `${value.width} ${value.style} ${value.color}`;\n}\n\n/**\n * Border style handler with multi-group support.\n *\n * Single group (backward compatible):\n * - `border=\"1bw solid #red\"` - all sides\n * - `border=\"1bw solid #red top left\"` - only top and left\n *\n * Multi-group (new):\n * - `border=\"1bw #red, 2bw #blue top\"` - all sides red 1bw, then top overridden to blue 2bw\n * - `border=\"1bw, dashed top bottom, #purple left right\"` - base 1bw, dashed on top/bottom, purple on left/right\n *\n * Later groups override earlier groups for conflicting directions.\n */\nexport function borderStyle({\n border,\n}: {\n border?: string | number | boolean;\n}) {\n if (!border && border !== 0) return null;\n\n if (border === true) border = '1bw';\n\n const strBorder = String(border);\n\n if (CSS_WIDE_KEYWORDS.has(strBorder)) {\n return { border: strBorder };\n }\n\n const processed = parseStyle(strBorder);\n const groups = processed.groups ?? [];\n\n if (!groups.length) return null;\n\n const useLonghand = groups.some((g) => (g.mods ?? []).includes('longhand'));\n\n // Single group - use original logic for backward compatibility\n if (groups.length === 1) {\n const group = groups[0];\n const keyword = extractCSSWideKeyword(group);\n\n if (keyword) {\n if (useLonghand) {\n return Object.fromEntries(\n DIRECTIONS.map((dir) => [`border-${dir}`, keyword]),\n );\n }\n\n return { border: keyword };\n }\n\n const { directions, borderValue } = processGroup({\n values: group.values ?? [],\n mods: group.mods ?? [],\n colors: group.colors ?? [],\n });\n\n const styleValue = formatBorderValue(borderValue);\n\n if (!directions.length) {\n if (useLonghand) {\n return Object.fromEntries(\n DIRECTIONS.map((dir) => [`border-${dir}`, styleValue]),\n );\n }\n\n return { border: styleValue };\n }\n\n const zeroValue = `0 ${borderValue.style} ${borderValue.color}`;\n\n return DIRECTIONS.reduce(\n (styles, dir) => {\n if (directions.includes(dir)) {\n styles[`border-${dir}`] = styleValue;\n } else {\n styles[`border-${dir}`] = zeroValue;\n }\n return styles;\n },\n {} as Record<string, string>,\n );\n }\n\n // Multi-group - process groups in order, later groups override earlier\n // Track whether any group specifies directions\n let hasAnyDirections = false;\n\n // Build a map of direction -> border value\n // Start with undefined (no border set)\n const directionMap: Record<Direction, BorderValue | null> = {\n top: null,\n right: null,\n bottom: null,\n left: null,\n };\n\n // Track the last \"all directions\" value for fallback\n let allDirectionsValue: BorderValue | null = null;\n\n // Process groups in order (first to last)\n for (const group of groups) {\n const { directions, borderValue } = processGroup({\n values: group.values ?? [],\n mods: group.mods ?? [],\n colors: group.colors ?? [],\n });\n\n if (directions.length === 0) {\n // No specific directions - applies to all\n allDirectionsValue = borderValue;\n // Set all directions\n for (const dir of DIRECTIONS) {\n directionMap[dir] = borderValue;\n }\n } else {\n // Specific directions - override only those\n hasAnyDirections = true;\n for (const dir of directions) {\n directionMap[dir] = borderValue;\n }\n }\n }\n\n // If no group specified any directions and we have an all-directions value,\n // return the simple `border` shorthand (or longhands if requested)\n if (!hasAnyDirections && allDirectionsValue) {\n const formatted = formatBorderValue(allDirectionsValue);\n\n if (useLonghand) {\n return Object.fromEntries(\n DIRECTIONS.map((dir) => [`border-${dir}`, formatted]),\n );\n }\n\n return { border: formatted };\n }\n\n // Otherwise, output individual border-* properties\n const result: Record<string, string> = {};\n\n for (const dir of DIRECTIONS) {\n const value = directionMap[dir];\n if (value) {\n result[`border-${dir}`] = formatBorderValue(value);\n } else {\n // No border for this direction - set to 0\n // Use the last all-directions value for style/color consistency, or defaults\n const fallback = allDirectionsValue || {\n width: '0',\n style: 'solid',\n color: 'var(--border-color, currentColor)',\n };\n result[`border-${dir}`] = `0 ${fallback.style} ${fallback.color}`;\n }\n }\n\n return result;\n}\n\nborderStyle.__lookupStyles = ['border'];\n"],"mappings":";;;;;;;;;AAuBA,SAAS,aAAa,OAGpB;CACA,MAAM,EAAE,QAAQ,MAAM,WAAW;CAEjC,MAAM,aAAa,WAAW,MAAM,WAAW;CAC/C,MAAM,WAAW,WAAW,MAAM,cAAqC;AAMvE,QAAO;EACL;EACA,aAAa;GAAE,OANH,OAAO,MAAM;GAMH,OALV,SAAS,MAAM;GAKE,OAJjB,SAAS,MAAM;GAIS;EACrC;;;;;AAMH,SAAS,kBAAkB,OAA4B;AACrD,QAAO,GAAG,MAAM,MAAM,GAAG,MAAM,MAAM,GAAG,MAAM;;;;;;;;;;;;;;;AAgBhD,SAAgB,YAAY,EAC1B,UAGC;AACD,KAAI,CAAC,UAAU,WAAW,EAAG,QAAO;AAEpC,KAAI,WAAW,KAAM,UAAS;CAE9B,MAAM,YAAY,OAAO,OAAO;AAEhC,KAAI,kBAAkB,IAAI,UAAU,CAClC,QAAO,EAAE,QAAQ,WAAW;CAI9B,MAAM,SADY,WAAW,UAAU,CACd,UAAU,EAAE;AAErC,KAAI,CAAC,OAAO,OAAQ,QAAO;CAE3B,MAAM,cAAc,OAAO,MAAM,OAAO,EAAE,QAAQ,EAAE,EAAE,SAAS,WAAW,CAAC;AAG3E,KAAI,OAAO,WAAW,GAAG;EACvB,MAAM,QAAQ,OAAO;EACrB,MAAM,UAAU,sBAAsB,MAAM;AAE5C,MAAI,SAAS;AACX,OAAI,YACF,QAAO,OAAO,YACZ,WAAW,KAAK,QAAQ,CAAC,UAAU,OAAO,QAAQ,CAAC,CACpD;AAGH,UAAO,EAAE,QAAQ,SAAS;;EAG5B,MAAM,EAAE,YAAY,gBAAgB,aAAa;GAC/C,QAAQ,MAAM,UAAU,EAAE;GAC1B,MAAM,MAAM,QAAQ,EAAE;GACtB,QAAQ,MAAM,UAAU,EAAE;GAC3B,CAAC;EAEF,MAAM,aAAa,kBAAkB,YAAY;AAEjD,MAAI,CAAC,WAAW,QAAQ;AACtB,OAAI,YACF,QAAO,OAAO,YACZ,WAAW,KAAK,QAAQ,CAAC,UAAU,OAAO,WAAW,CAAC,CACvD;AAGH,UAAO,EAAE,QAAQ,YAAY;;EAG/B,MAAM,YAAY,KAAK,YAAY,MAAM,GAAG,YAAY;AAExD,SAAO,WAAW,QACf,QAAQ,QAAQ;AACf,OAAI,WAAW,SAAS,IAAI,CAC1B,QAAO,UAAU,SAAS;OAE1B,QAAO,UAAU,SAAS;AAE5B,UAAO;KAET,EAAE,CACH;;CAKH,IAAI,mBAAmB;CAIvB,MAAM,eAAsD;EAC1D,KAAK;EACL,OAAO;EACP,QAAQ;EACR,MAAM;EACP;CAGD,IAAI,qBAAyC;AAG7C,MAAK,MAAM,SAAS,QAAQ;EAC1B,MAAM,EAAE,YAAY,gBAAgB,aAAa;GAC/C,QAAQ,MAAM,UAAU,EAAE;GAC1B,MAAM,MAAM,QAAQ,EAAE;GACtB,QAAQ,MAAM,UAAU,EAAE;GAC3B,CAAC;AAEF,MAAI,WAAW,WAAW,GAAG;AAE3B,wBAAqB;AAErB,QAAK,MAAM,OAAO,WAChB,cAAa,OAAO;SAEjB;AAEL,sBAAmB;AACnB,QAAK,MAAM,OAAO,WAChB,cAAa,OAAO;;;AAO1B,KAAI,CAAC,oBAAoB,oBAAoB;EAC3C,MAAM,YAAY,kBAAkB,mBAAmB;AAEvD,MAAI,YACF,QAAO,OAAO,YACZ,WAAW,KAAK,QAAQ,CAAC,UAAU,OAAO,UAAU,CAAC,CACtD;AAGH,SAAO,EAAE,QAAQ,WAAW;;CAI9B,MAAM,SAAiC,EAAE;AAEzC,MAAK,MAAM,OAAO,YAAY;EAC5B,MAAM,QAAQ,aAAa;AAC3B,MAAI,MACF,QAAO,UAAU,SAAS,kBAAkB,MAAM;OAC7C;GAGL,MAAM,WAAW,sBAAsB;IACrC,OAAO;IACP,OAAO;IACP,OAAO;IACR;AACD,UAAO,UAAU,SAAS,KAAK,SAAS,MAAM,GAAG,SAAS;;;AAI9D,QAAO;;AAGT,YAAY,iBAAiB,CAAC,SAAS"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/styles/color.d.ts
|
|
2
|
+
declare function colorStyle({
|
|
3
|
+
color
|
|
4
|
+
}: {
|
|
5
|
+
color?: string | boolean;
|
|
6
|
+
}): {
|
|
7
|
+
color: string;
|
|
8
|
+
} | null;
|
|
9
|
+
declare namespace colorStyle {
|
|
10
|
+
var __lookupStyles: string[];
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
export { colorStyle };
|
|
14
|
+
//# sourceMappingURL=color.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getColorSpaceSuffix } from "../utils/color-space.js";
|
|
2
|
+
import { parseColor } from "../utils/styles.js";
|
|
3
|
+
import { convertColorChainToComponentChain } from "./createStyle.js";
|
|
4
|
+
//#region src/styles/color.ts
|
|
5
|
+
function colorStyle({ color }) {
|
|
6
|
+
if (!color) return null;
|
|
7
|
+
if (color === true) color = "currentColor";
|
|
8
|
+
if (typeof color === "string" && (color.startsWith("#") || color.startsWith("(#"))) color = parseColor(color).color || color;
|
|
9
|
+
const match = color.match(/var\(--(.+?)-color/);
|
|
10
|
+
let name = "";
|
|
11
|
+
if (match) name = match[1];
|
|
12
|
+
const styles = { color };
|
|
13
|
+
if (name && name !== "current") {
|
|
14
|
+
const suffix = getColorSpaceSuffix();
|
|
15
|
+
Object.assign(styles, {
|
|
16
|
+
"--current-color": color,
|
|
17
|
+
[`--current-color-${suffix}`]: convertColorChainToComponentChain(color)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return styles;
|
|
21
|
+
}
|
|
22
|
+
colorStyle.__lookupStyles = ["color"];
|
|
23
|
+
//#endregion
|
|
24
|
+
export { colorStyle };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=color.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.js","names":[],"sources":["../../src/styles/color.ts"],"sourcesContent":["import { getColorSpaceSuffix } from '../utils/color-space';\nimport { parseColor } from '../utils/styles';\n\nimport { convertColorChainToComponentChain } from './createStyle';\n\nexport function colorStyle({ color }: { color?: string | boolean }) {\n if (!color) return null;\n\n if (color === true) color = 'currentColor';\n\n if (\n typeof color === 'string' &&\n (color.startsWith('#') || color.startsWith('(#'))\n ) {\n color = parseColor(color).color || color;\n }\n\n const match = color.match(/var\\(--(.+?)-color/);\n let name = '';\n\n if (match) {\n name = match[1];\n }\n\n const styles = {\n color: color,\n };\n\n if (name && name !== 'current') {\n const suffix = getColorSpaceSuffix();\n Object.assign(styles, {\n '--current-color': color,\n [`--current-color-${suffix}`]: convertColorChainToComponentChain(color),\n });\n }\n\n return styles;\n}\n\ncolorStyle.__lookupStyles = ['color'];\n"],"mappings":";;;;AAKA,SAAgB,WAAW,EAAE,SAAuC;AAClE,KAAI,CAAC,MAAO,QAAO;AAEnB,KAAI,UAAU,KAAM,SAAQ;AAE5B,KACE,OAAO,UAAU,aAChB,MAAM,WAAW,IAAI,IAAI,MAAM,WAAW,KAAK,EAEhD,SAAQ,WAAW,MAAM,CAAC,SAAS;CAGrC,MAAM,QAAQ,MAAM,MAAM,qBAAqB;CAC/C,IAAI,OAAO;AAEX,KAAI,MACF,QAAO,MAAM;CAGf,MAAM,SAAS,EACN,OACR;AAED,KAAI,QAAQ,SAAS,WAAW;EAC9B,MAAM,SAAS,qBAAqB;AACpC,SAAO,OAAO,QAAQ;GACpB,mBAAmB;IAClB,mBAAmB,WAAW,kCAAkC,MAAM;GACxE,CAAC;;AAGJ,QAAO;;AAGT,WAAW,iBAAiB,CAAC,QAAQ"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//#region src/styles/const.ts
|
|
2
|
+
const BORDER_STYLES = [
|
|
3
|
+
"none",
|
|
4
|
+
"hidden",
|
|
5
|
+
"dotted",
|
|
6
|
+
"dashed",
|
|
7
|
+
"solid",
|
|
8
|
+
"double",
|
|
9
|
+
"groove",
|
|
10
|
+
"ridge",
|
|
11
|
+
"inset",
|
|
12
|
+
"outset"
|
|
13
|
+
];
|
|
14
|
+
//#endregion
|
|
15
|
+
export { BORDER_STYLES };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=const.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"const.js","names":[],"sources":["../../src/styles/const.ts"],"sourcesContent":["export const BORDER_STYLES = [\n 'none',\n 'hidden',\n 'dotted',\n 'dashed',\n 'solid',\n 'double',\n 'groove',\n 'ridge',\n 'inset',\n 'outset',\n] as const;\n"],"mappings":";AAAA,MAAa,gBAAgB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { getColorSpaceComponents, getColorSpaceSuffix, strToColorSpace } from "../utils/color-space.js";
|
|
2
|
+
import { normalizeColorTokenValue, parseColor, parseStyle } from "../utils/styles.js";
|
|
3
|
+
import { toSnakeCase } from "../utils/string.js";
|
|
4
|
+
//#region src/styles/createStyle.ts
|
|
5
|
+
const CACHE = {};
|
|
6
|
+
/**
|
|
7
|
+
* Convert color fallback chain to component fallback chain.
|
|
8
|
+
* Example: var(--primary-color, var(--secondary-color))
|
|
9
|
+
* → var(--primary-color-oklch, var(--secondary-color-oklch))
|
|
10
|
+
*/
|
|
11
|
+
function convertColorChainToComponentChain(colorValue) {
|
|
12
|
+
const suffix = getColorSpaceSuffix();
|
|
13
|
+
const componentVarMatch = colorValue.match(/^(?:rgb|hsl|oklch)a?\(\s*(var\(--[a-z0-9-]+-color-(?:rgb|hsl|oklch)\))\s*\//);
|
|
14
|
+
if (componentVarMatch) return componentVarMatch[1];
|
|
15
|
+
const match = colorValue.match(/var\(--([a-z0-9-]+)-color\s*(?:,\s*(.+))?\)/);
|
|
16
|
+
if (!match) {
|
|
17
|
+
const components = getColorSpaceComponents(colorValue);
|
|
18
|
+
if (components !== colorValue) return components;
|
|
19
|
+
return colorValue;
|
|
20
|
+
}
|
|
21
|
+
const [, name, fallback] = match;
|
|
22
|
+
if (!fallback) return `var(--${name}-color-${suffix})`;
|
|
23
|
+
return `var(--${name}-color-${suffix}, ${convertColorChainToComponentChain(fallback.trim())})`;
|
|
24
|
+
}
|
|
25
|
+
function createStyle(styleName, cssStyle, converter) {
|
|
26
|
+
const key = `${styleName}.${cssStyle ?? ""}`;
|
|
27
|
+
if (!CACHE[key]) {
|
|
28
|
+
const styleHandler = (styleMap) => {
|
|
29
|
+
let styleValue = styleMap[styleName];
|
|
30
|
+
if (styleValue == null || styleValue === false) return null;
|
|
31
|
+
let finalCssStyle;
|
|
32
|
+
const isColorToken = !cssStyle && typeof styleName === "string" && styleName.startsWith("#");
|
|
33
|
+
if (isColorToken) finalCssStyle = `--${toSnakeCase(styleName.slice(1)).replace(/^-+/, "")}-color`;
|
|
34
|
+
else finalCssStyle = cssStyle || toSnakeCase(styleName).replace(/^\$/, "--");
|
|
35
|
+
if (isColorToken) {
|
|
36
|
+
const normalized = normalizeColorTokenValue(styleValue);
|
|
37
|
+
if (normalized === null) return null;
|
|
38
|
+
styleValue = normalized;
|
|
39
|
+
}
|
|
40
|
+
if (converter && typeof styleValue !== "string") {
|
|
41
|
+
styleValue = converter(styleValue);
|
|
42
|
+
if (!styleValue) return null;
|
|
43
|
+
}
|
|
44
|
+
if (typeof styleValue === "string" && finalCssStyle.startsWith("--") && finalCssStyle.endsWith("-color")) {
|
|
45
|
+
styleValue = styleValue.trim();
|
|
46
|
+
const suffix = getColorSpaceSuffix();
|
|
47
|
+
const colorSpaceStr = strToColorSpace(styleValue);
|
|
48
|
+
const { color, name } = parseColor(styleValue);
|
|
49
|
+
if (name && colorSpaceStr) return {
|
|
50
|
+
[finalCssStyle]: `var(--${name}-color, ${colorSpaceStr})`,
|
|
51
|
+
[`${finalCssStyle}-${suffix}`]: `var(--${name}-color-${suffix}, ${getColorSpaceComponents(colorSpaceStr)})`
|
|
52
|
+
};
|
|
53
|
+
else if (name) {
|
|
54
|
+
if (color) return {
|
|
55
|
+
[finalCssStyle]: color,
|
|
56
|
+
[`${finalCssStyle}-${suffix}`]: convertColorChainToComponentChain(color)
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
[finalCssStyle]: `var(--${name}-color)`,
|
|
60
|
+
[`${finalCssStyle}-${suffix}`]: `var(--${name}-color-${suffix})`
|
|
61
|
+
};
|
|
62
|
+
} else if (colorSpaceStr) return {
|
|
63
|
+
[finalCssStyle]: colorSpaceStr,
|
|
64
|
+
[`${finalCssStyle}-${suffix}`]: getColorSpaceComponents(colorSpaceStr)
|
|
65
|
+
};
|
|
66
|
+
return { [finalCssStyle]: color ?? "" };
|
|
67
|
+
}
|
|
68
|
+
const processed = parseStyle(styleValue);
|
|
69
|
+
return { [finalCssStyle]: processed.output };
|
|
70
|
+
};
|
|
71
|
+
styleHandler.__lookupStyles = [styleName];
|
|
72
|
+
CACHE[key] = styleHandler;
|
|
73
|
+
}
|
|
74
|
+
return CACHE[key];
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
export { convertColorChainToComponentChain, createStyle };
|
|
78
|
+
|
|
79
|
+
//# sourceMappingURL=createStyle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createStyle.js","names":[],"sources":["../../src/styles/createStyle.ts"],"sourcesContent":["import {\n getColorSpaceComponents,\n getColorSpaceSuffix,\n strToColorSpace,\n} from '../utils/color-space';\nimport { toSnakeCase } from '../utils/string';\nimport {\n normalizeColorTokenValue,\n parseColor,\n parseStyle,\n} from '../utils/styles';\nimport type {\n CSSMap,\n StyleHandler,\n StyleValue,\n StyleValueStateMap,\n} from '../utils/styles';\n\nconst CACHE: Record<string, StyleHandler> = {};\n\n/**\n * Convert color fallback chain to component fallback chain.\n * Example: var(--primary-color, var(--secondary-color))\n * → var(--primary-color-oklch, var(--secondary-color-oklch))\n */\nexport function convertColorChainToComponentChain(colorValue: string): string {\n const suffix = getColorSpaceSuffix();\n\n // Handle func(var(--name-color-{suffix}) / alpha) pattern.\n // When #name.opacity is parsed, the classifier produces e.g.\n // oklch(var(--name-color-oklch) / .opacity).\n // The component chain should be just the inner var() reference.\n const componentVarMatch = colorValue.match(\n /^(?:rgb|hsl|oklch)a?\\(\\s*(var\\(--[a-z0-9-]+-color-(?:rgb|hsl|oklch)\\))\\s*\\//,\n );\n if (componentVarMatch) {\n return componentVarMatch[1];\n }\n\n // Match var(--name-color, ...) pattern\n const varPattern = /var\\(--([a-z0-9-]+)-color\\s*(?:,\\s*(.+))?\\)/;\n const match = colorValue.match(varPattern);\n\n if (!match) {\n // Not a color variable — try to convert to components\n const components = getColorSpaceComponents(colorValue);\n if (components !== colorValue) return components;\n return colorValue;\n }\n\n const [, name, fallback] = match;\n\n if (!fallback) {\n return `var(--${name}-color-${suffix})`;\n }\n\n const processedFallback = convertColorChainToComponentChain(fallback.trim());\n return `var(--${name}-color-${suffix}, ${processedFallback})`;\n}\n\nexport function createStyle(\n styleName: string,\n cssStyle?: string,\n converter?: (styleValue: string | number | true) => string | undefined,\n) {\n const key = `${styleName}.${cssStyle ?? ''}`;\n\n if (!CACHE[key]) {\n const styleHandler = (styleMap: StyleValueStateMap): CSSMap | null => {\n let styleValue = styleMap[styleName];\n\n if (styleValue == null || styleValue === false) return null;\n\n let finalCssStyle: string;\n const isColorToken =\n !cssStyle && typeof styleName === 'string' && styleName.startsWith('#');\n\n if (isColorToken) {\n const raw = styleName.slice(1);\n const name = toSnakeCase(raw).replace(/^-+/, '');\n finalCssStyle = `--${name}-color`;\n } else {\n finalCssStyle = cssStyle || toSnakeCase(styleName).replace(/^\\$/, '--');\n }\n\n if (isColorToken) {\n const normalized = normalizeColorTokenValue(styleValue);\n if (normalized === null) return null;\n styleValue = normalized;\n }\n\n if (converter && typeof styleValue !== 'string') {\n styleValue = converter(styleValue as string | number | true);\n\n if (!styleValue) return null;\n }\n\n if (\n typeof styleValue === 'string' &&\n finalCssStyle.startsWith('--') &&\n finalCssStyle.endsWith('-color')\n ) {\n styleValue = styleValue.trim();\n const suffix = getColorSpaceSuffix();\n\n const colorSpaceStr = strToColorSpace(styleValue as string);\n\n const { color, name } = parseColor(styleValue as string);\n\n if (name && colorSpaceStr) {\n return {\n [finalCssStyle]: `var(--${name}-color, ${colorSpaceStr})`,\n [`${finalCssStyle}-${suffix}`]: `var(--${name}-color-${suffix}, ${getColorSpaceComponents(\n colorSpaceStr,\n )})`,\n };\n } else if (name) {\n if (color) {\n return {\n [finalCssStyle]: color,\n [`${finalCssStyle}-${suffix}`]:\n convertColorChainToComponentChain(color),\n };\n }\n\n return {\n [finalCssStyle]: `var(--${name}-color)`,\n [`${finalCssStyle}-${suffix}`]: `var(--${name}-color-${suffix})`,\n };\n } else if (colorSpaceStr) {\n return {\n [finalCssStyle]: colorSpaceStr,\n [`${finalCssStyle}-${suffix}`]:\n getColorSpaceComponents(colorSpaceStr),\n };\n }\n\n return {\n [finalCssStyle]: color ?? '',\n };\n }\n\n const processed = parseStyle(styleValue as StyleValue);\n return { [finalCssStyle]: processed.output };\n };\n\n styleHandler.__lookupStyles = [styleName];\n\n CACHE[key] = styleHandler;\n }\n\n return CACHE[key];\n}\n"],"mappings":";;;;AAkBA,MAAM,QAAsC,EAAE;;;;;;AAO9C,SAAgB,kCAAkC,YAA4B;CAC5E,MAAM,SAAS,qBAAqB;CAMpC,MAAM,oBAAoB,WAAW,MACnC,8EACD;AACD,KAAI,kBACF,QAAO,kBAAkB;CAK3B,MAAM,QAAQ,WAAW,MADN,8CACuB;AAE1C,KAAI,CAAC,OAAO;EAEV,MAAM,aAAa,wBAAwB,WAAW;AACtD,MAAI,eAAe,WAAY,QAAO;AACtC,SAAO;;CAGT,MAAM,GAAG,MAAM,YAAY;AAE3B,KAAI,CAAC,SACH,QAAO,SAAS,KAAK,SAAS,OAAO;AAIvC,QAAO,SAAS,KAAK,SAAS,OAAO,IADX,kCAAkC,SAAS,MAAM,CAAC,CACjB;;AAG7D,SAAgB,YACd,WACA,UACA,WACA;CACA,MAAM,MAAM,GAAG,UAAU,GAAG,YAAY;AAExC,KAAI,CAAC,MAAM,MAAM;EACf,MAAM,gBAAgB,aAAgD;GACpE,IAAI,aAAa,SAAS;AAE1B,OAAI,cAAc,QAAQ,eAAe,MAAO,QAAO;GAEvD,IAAI;GACJ,MAAM,eACJ,CAAC,YAAY,OAAO,cAAc,YAAY,UAAU,WAAW,IAAI;AAEzE,OAAI,aAGF,iBAAgB,KADH,YADD,UAAU,MAAM,EAAE,CACD,CAAC,QAAQ,OAAO,GAAG,CACtB;OAE1B,iBAAgB,YAAY,YAAY,UAAU,CAAC,QAAQ,OAAO,KAAK;AAGzE,OAAI,cAAc;IAChB,MAAM,aAAa,yBAAyB,WAAW;AACvD,QAAI,eAAe,KAAM,QAAO;AAChC,iBAAa;;AAGf,OAAI,aAAa,OAAO,eAAe,UAAU;AAC/C,iBAAa,UAAU,WAAqC;AAE5D,QAAI,CAAC,WAAY,QAAO;;AAG1B,OACE,OAAO,eAAe,YACtB,cAAc,WAAW,KAAK,IAC9B,cAAc,SAAS,SAAS,EAChC;AACA,iBAAa,WAAW,MAAM;IAC9B,MAAM,SAAS,qBAAqB;IAEpC,MAAM,gBAAgB,gBAAgB,WAAqB;IAE3D,MAAM,EAAE,OAAO,SAAS,WAAW,WAAqB;AAExD,QAAI,QAAQ,cACV,QAAO;MACJ,gBAAgB,SAAS,KAAK,UAAU,cAAc;MACtD,GAAG,cAAc,GAAG,WAAW,SAAS,KAAK,SAAS,OAAO,IAAI,wBAChE,cACD,CAAC;KACH;aACQ,MAAM;AACf,SAAI,MACF,QAAO;OACJ,gBAAgB;OAChB,GAAG,cAAc,GAAG,WACnB,kCAAkC,MAAM;MAC3C;AAGH,YAAO;OACJ,gBAAgB,SAAS,KAAK;OAC9B,GAAG,cAAc,GAAG,WAAW,SAAS,KAAK,SAAS,OAAO;MAC/D;eACQ,cACT,QAAO;MACJ,gBAAgB;MAChB,GAAG,cAAc,GAAG,WACnB,wBAAwB,cAAc;KACzC;AAGH,WAAO,GACJ,gBAAgB,SAAS,IAC3B;;GAGH,MAAM,YAAY,WAAW,WAAyB;AACtD,UAAO,GAAG,gBAAgB,UAAU,QAAQ;;AAG9C,eAAa,iBAAiB,CAAC,UAAU;AAEzC,QAAM,OAAO;;AAGf,QAAO,MAAM"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { CSS_WIDE_KEYWORDS } from "../parser/const.js";
|
|
2
|
+
import { makeEmptyDetails } from "../parser/types.js";
|
|
3
|
+
import { parseStyle } from "../utils/styles.js";
|
|
4
|
+
//#region src/styles/dimension.ts
|
|
5
|
+
const DEFAULT_MIN_SIZE = "var(--gap)";
|
|
6
|
+
const DEFAULT_MAX_SIZE = "100%";
|
|
7
|
+
/**
|
|
8
|
+
* Parse a dimension value (string, number, or boolean) into a CSS value
|
|
9
|
+
*/
|
|
10
|
+
function parseDimensionValue(val) {
|
|
11
|
+
if (val == null) return null;
|
|
12
|
+
if (typeof val === "number") return `${val}px`;
|
|
13
|
+
if (val === true) return "initial";
|
|
14
|
+
return parseStyle(String(val)).groups[0]?.values[0] || null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Creates a dimension style handler for width or height.
|
|
18
|
+
*
|
|
19
|
+
* Supports:
|
|
20
|
+
* - Main dimension prop (width/height) with syntax for min/max
|
|
21
|
+
* - Separate min/max props (minWidth/maxWidth or minHeight/maxHeight)
|
|
22
|
+
*
|
|
23
|
+
* Priority: Individual min/max props override values from main prop syntax
|
|
24
|
+
*/
|
|
25
|
+
function dimensionStyle(name) {
|
|
26
|
+
const minStyle = `min-${name}`;
|
|
27
|
+
const maxStyle = `max-${name}`;
|
|
28
|
+
return ({ value, min, max }) => {
|
|
29
|
+
if (value == null && min == null && max == null) return null;
|
|
30
|
+
if (value != null && typeof value === "string" && CSS_WIDE_KEYWORDS.has(value)) {
|
|
31
|
+
const styles = {
|
|
32
|
+
[name]: value,
|
|
33
|
+
[minStyle]: value,
|
|
34
|
+
[maxStyle]: value
|
|
35
|
+
};
|
|
36
|
+
const minVal = parseDimensionValue(min);
|
|
37
|
+
const maxVal = parseDimensionValue(max);
|
|
38
|
+
if (minVal) styles[minStyle] = minVal;
|
|
39
|
+
if (maxVal) styles[maxStyle] = maxVal;
|
|
40
|
+
return styles;
|
|
41
|
+
}
|
|
42
|
+
if (value === true) {
|
|
43
|
+
const styles = {
|
|
44
|
+
[name]: "auto",
|
|
45
|
+
[minStyle]: "initial",
|
|
46
|
+
[maxStyle]: "initial"
|
|
47
|
+
};
|
|
48
|
+
const minVal = parseDimensionValue(min);
|
|
49
|
+
const maxVal = parseDimensionValue(max);
|
|
50
|
+
if (minVal) styles[minStyle] = minVal;
|
|
51
|
+
if (maxVal) styles[maxStyle] = maxVal;
|
|
52
|
+
return styles;
|
|
53
|
+
}
|
|
54
|
+
const styles = {
|
|
55
|
+
[name]: "auto",
|
|
56
|
+
[minStyle]: "initial",
|
|
57
|
+
[maxStyle]: "initial"
|
|
58
|
+
};
|
|
59
|
+
if (value != null) {
|
|
60
|
+
let val = value;
|
|
61
|
+
if (typeof val === "number") val = `${val}px`;
|
|
62
|
+
val = String(val);
|
|
63
|
+
const { mods, values } = parseStyle(val).groups[0] ?? makeEmptyDetails();
|
|
64
|
+
let flag = false;
|
|
65
|
+
for (const mod of mods) switch (mod) {
|
|
66
|
+
case "min":
|
|
67
|
+
styles[minStyle] = values[0] || DEFAULT_MIN_SIZE;
|
|
68
|
+
flag = true;
|
|
69
|
+
break;
|
|
70
|
+
case "max":
|
|
71
|
+
styles[maxStyle] = values[0] || DEFAULT_MAX_SIZE;
|
|
72
|
+
flag = true;
|
|
73
|
+
break;
|
|
74
|
+
case "fixed": {
|
|
75
|
+
const fixedValue = values[0] || "max-content";
|
|
76
|
+
styles[minStyle] = fixedValue;
|
|
77
|
+
styles[name] = fixedValue;
|
|
78
|
+
styles[maxStyle] = fixedValue;
|
|
79
|
+
flag = true;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
default: break;
|
|
83
|
+
}
|
|
84
|
+
if (!flag || !mods.length) if (values.length === 2) {
|
|
85
|
+
styles[minStyle] = values[0];
|
|
86
|
+
styles[maxStyle] = values[1];
|
|
87
|
+
} else if (values.length === 3) {
|
|
88
|
+
styles[minStyle] = values[0];
|
|
89
|
+
styles[name] = values[1];
|
|
90
|
+
styles[maxStyle] = values[2];
|
|
91
|
+
} else styles[name] = values[0] || "auto";
|
|
92
|
+
if (styles[name] === "stretch") if (name === "width") styles[name] = [
|
|
93
|
+
"stretch",
|
|
94
|
+
"-webkit-fill-available",
|
|
95
|
+
"-moz-available"
|
|
96
|
+
];
|
|
97
|
+
else styles[name] = "auto";
|
|
98
|
+
}
|
|
99
|
+
const minVal = parseDimensionValue(min);
|
|
100
|
+
const maxVal = parseDimensionValue(max);
|
|
101
|
+
if (minVal) styles[minStyle] = minVal;
|
|
102
|
+
if (maxVal) styles[maxStyle] = maxVal;
|
|
103
|
+
return styles;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
//#endregion
|
|
107
|
+
export { dimensionStyle };
|
|
108
|
+
|
|
109
|
+
//# sourceMappingURL=dimension.js.map
|