@tenphi/tasty 0.1.0 → 0.1.3
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 +27 -2
- package/dist/_virtual/_rolldown/runtime.js +8 -0
- package/dist/chunks/renderChunk.js.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/debug.js.map +1 -1
- package/dist/hooks/useKeyframes.js.map +1 -1
- package/dist/hooks/useRawCSS.js.map +1 -1
- package/dist/injector/injector.js.map +1 -1
- package/dist/injector/sheet-manager.js.map +1 -1
- package/dist/parser/index.d.ts +3 -0
- package/dist/parser/index.js +4 -0
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/types.d.ts +6 -1
- package/dist/pipeline/conditions.js.map +1 -1
- package/dist/pipeline/exclusive.js.map +1 -1
- package/dist/pipeline/index.js.map +1 -1
- package/dist/pipeline/materialize.js.map +1 -1
- package/dist/pipeline/parseStateKey.js.map +1 -1
- package/dist/pipeline/simplify.js.map +1 -1
- package/dist/styles/dimension.js.map +1 -1
- package/dist/styles/predefined.js.map +1 -1
- package/dist/styles/radius.js.map +1 -1
- package/dist/styles/scrollbar.js.map +1 -1
- package/dist/styles/shadow.js.map +1 -1
- package/dist/tasty.d.ts +8 -8
- package/dist/tasty.js.map +1 -1
- package/dist/utils/resolve-recipes.js.map +1 -1
- package/dist/utils/styles.js.map +1 -1
- package/dist/zero/{babel.d.mts → babel.d.ts} +6 -6
- package/dist/zero/{babel.mjs → babel.js} +6 -6
- package/dist/zero/babel.js.map +1 -0
- package/dist/{css-writer.d.mts → zero/css-writer.d.ts} +1 -1
- package/dist/{css-writer.mjs → zero/css-writer.js} +1 -1
- package/dist/zero/css-writer.js.map +1 -0
- package/dist/{extractor.d.mts → zero/extractor.d.ts} +3 -2
- package/dist/{extractor.mjs → zero/extractor.js} +6 -6
- package/dist/zero/extractor.js.map +1 -0
- package/dist/zero/index.d.ts +3 -0
- package/dist/zero/{index.mjs → index.js} +2 -2
- package/dist/zero/{next.d.mts → next.d.ts} +1 -1
- package/dist/zero/{next.mjs → next.js} +2 -2
- package/dist/zero/next.js.map +1 -0
- package/package.json +22 -23
- package/dist/_virtual/_rolldown/runtime.mjs +0 -7
- package/dist/chunks/cacheKey.mjs +0 -70
- package/dist/chunks/cacheKey.mjs.map +0 -1
- package/dist/chunks/definitions.mjs +0 -260
- package/dist/chunks/definitions.mjs.map +0 -1
- package/dist/chunks/renderChunk.mjs +0 -61
- package/dist/chunks/renderChunk.mjs.map +0 -1
- package/dist/config.mjs +0 -231
- package/dist/config.mjs.map +0 -1
- package/dist/css-writer.mjs.map +0 -1
- package/dist/extractor.mjs.map +0 -1
- package/dist/injector/injector.mjs +0 -404
- package/dist/injector/injector.mjs.map +0 -1
- package/dist/injector/sheet-manager.mjs +0 -714
- package/dist/injector/sheet-manager.mjs.map +0 -1
- package/dist/injector/types.d.mts +0 -18
- package/dist/keyframes/index.mjs +0 -156
- package/dist/keyframes/index.mjs.map +0 -1
- package/dist/parser/classify.mjs +0 -319
- package/dist/parser/classify.mjs.map +0 -1
- package/dist/parser/const.mjs +0 -33
- package/dist/parser/const.mjs.map +0 -1
- package/dist/parser/lru.mjs +0 -109
- package/dist/parser/lru.mjs.map +0 -1
- package/dist/parser/parser.mjs +0 -116
- package/dist/parser/parser.mjs.map +0 -1
- package/dist/parser/tokenizer.mjs +0 -69
- package/dist/parser/tokenizer.mjs.map +0 -1
- package/dist/parser/types.d.mts +0 -37
- package/dist/parser/types.mjs +0 -46
- package/dist/parser/types.mjs.map +0 -1
- package/dist/pipeline/conditions.mjs +0 -377
- package/dist/pipeline/conditions.mjs.map +0 -1
- package/dist/pipeline/exclusive.mjs +0 -231
- package/dist/pipeline/exclusive.mjs.map +0 -1
- package/dist/pipeline/index.mjs +0 -635
- package/dist/pipeline/index.mjs.map +0 -1
- package/dist/pipeline/materialize.mjs +0 -821
- package/dist/pipeline/materialize.mjs.map +0 -1
- package/dist/pipeline/parseStateKey.mjs +0 -418
- package/dist/pipeline/parseStateKey.mjs.map +0 -1
- package/dist/pipeline/simplify.mjs +0 -557
- package/dist/pipeline/simplify.mjs.map +0 -1
- package/dist/plugins/okhsl-plugin.mjs +0 -345
- package/dist/plugins/okhsl-plugin.mjs.map +0 -1
- package/dist/plugins/types.d.mts +0 -49
- package/dist/properties/index.mjs +0 -141
- package/dist/properties/index.mjs.map +0 -1
- package/dist/states/index.mjs +0 -161
- package/dist/states/index.mjs.map +0 -1
- package/dist/styles/align.mjs +0 -14
- package/dist/styles/align.mjs.map +0 -1
- package/dist/styles/border.mjs +0 -114
- package/dist/styles/border.mjs.map +0 -1
- package/dist/styles/color.mjs +0 -23
- package/dist/styles/color.mjs.map +0 -1
- package/dist/styles/createStyle.mjs +0 -77
- package/dist/styles/createStyle.mjs.map +0 -1
- package/dist/styles/dimension.mjs +0 -97
- package/dist/styles/dimension.mjs.map +0 -1
- package/dist/styles/display.mjs +0 -67
- package/dist/styles/display.mjs.map +0 -1
- package/dist/styles/fade.mjs +0 -58
- package/dist/styles/fade.mjs.map +0 -1
- package/dist/styles/fill.mjs +0 -51
- package/dist/styles/fill.mjs.map +0 -1
- package/dist/styles/flow.mjs +0 -12
- package/dist/styles/flow.mjs.map +0 -1
- package/dist/styles/gap.mjs +0 -37
- package/dist/styles/gap.mjs.map +0 -1
- package/dist/styles/height.mjs +0 -20
- package/dist/styles/height.mjs.map +0 -1
- package/dist/styles/index.mjs +0 -9
- package/dist/styles/index.mjs.map +0 -1
- package/dist/styles/inset.mjs +0 -142
- package/dist/styles/inset.mjs.map +0 -1
- package/dist/styles/justify.mjs +0 -14
- package/dist/styles/justify.mjs.map +0 -1
- package/dist/styles/margin.mjs +0 -96
- package/dist/styles/margin.mjs.map +0 -1
- package/dist/styles/outline.mjs +0 -65
- package/dist/styles/outline.mjs.map +0 -1
- package/dist/styles/padding.mjs +0 -96
- package/dist/styles/padding.mjs.map +0 -1
- package/dist/styles/predefined.mjs +0 -232
- package/dist/styles/predefined.mjs.map +0 -1
- package/dist/styles/preset.mjs +0 -126
- package/dist/styles/preset.mjs.map +0 -1
- package/dist/styles/radius.mjs +0 -51
- package/dist/styles/radius.mjs.map +0 -1
- package/dist/styles/scrollbar.mjs +0 -105
- package/dist/styles/scrollbar.mjs.map +0 -1
- package/dist/styles/shadow.mjs +0 -24
- package/dist/styles/shadow.mjs.map +0 -1
- package/dist/styles/styledScrollbar.mjs +0 -38
- package/dist/styles/styledScrollbar.mjs.map +0 -1
- package/dist/styles/transition.mjs +0 -138
- package/dist/styles/transition.mjs.map +0 -1
- package/dist/styles/types.d.mts +0 -492
- package/dist/styles/width.mjs +0 -20
- package/dist/styles/width.mjs.map +0 -1
- package/dist/utils/cache-wrapper.mjs +0 -26
- package/dist/utils/cache-wrapper.mjs.map +0 -1
- package/dist/utils/case-converter.mjs +0 -8
- package/dist/utils/case-converter.mjs.map +0 -1
- package/dist/utils/hsl-to-rgb.mjs +0 -38
- package/dist/utils/hsl-to-rgb.mjs.map +0 -1
- package/dist/utils/is-dev-env.mjs +0 -19
- package/dist/utils/is-dev-env.mjs.map +0 -1
- package/dist/utils/merge-styles.mjs +0 -146
- package/dist/utils/merge-styles.mjs.map +0 -1
- package/dist/utils/okhsl-to-rgb.mjs +0 -296
- package/dist/utils/okhsl-to-rgb.mjs.map +0 -1
- package/dist/utils/process-tokens.mjs +0 -28
- package/dist/utils/process-tokens.mjs.map +0 -1
- package/dist/utils/resolve-recipes.mjs +0 -143
- package/dist/utils/resolve-recipes.mjs.map +0 -1
- package/dist/utils/string.mjs +0 -8
- package/dist/utils/string.mjs.map +0 -1
- package/dist/utils/styles.d.mts +0 -18
- package/dist/utils/styles.mjs +0 -346
- package/dist/utils/styles.mjs.map +0 -1
- package/dist/zero/babel.mjs.map +0 -1
- package/dist/zero/index.d.mts +0 -3
- package/dist/zero/next.mjs.map +0 -1
package/dist/styles/outline.mjs
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { filterMods, parseStyle } from "../utils/styles.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/styles/outline.ts
|
|
4
|
-
const BORDER_STYLES = [
|
|
5
|
-
"none",
|
|
6
|
-
"hidden",
|
|
7
|
-
"dotted",
|
|
8
|
-
"dashed",
|
|
9
|
-
"solid",
|
|
10
|
-
"double",
|
|
11
|
-
"groove",
|
|
12
|
-
"ridge",
|
|
13
|
-
"inset",
|
|
14
|
-
"outset"
|
|
15
|
-
];
|
|
16
|
-
/**
|
|
17
|
-
* Generates CSS for outline property with optional offset.
|
|
18
|
-
*
|
|
19
|
-
* Syntax:
|
|
20
|
-
* - `outline="2px solid #red"` - outline only
|
|
21
|
-
* - `outline="2px solid #red / 4px"` - outline with offset (slash separator)
|
|
22
|
-
* - `outline="2px / 4px"` - width with offset (simpler form)
|
|
23
|
-
* - `outline={true}` - default 1ow solid outline
|
|
24
|
-
* - `outlineOffset="4px"` - offset as separate prop (can be combined with outline)
|
|
25
|
-
*
|
|
26
|
-
* Priority: slash syntax in outline takes precedence over outlineOffset prop
|
|
27
|
-
*
|
|
28
|
-
* @return CSS properties for outline and optionally outline-offset
|
|
29
|
-
*/
|
|
30
|
-
function outlineStyle({ outline, outlineOffset }) {
|
|
31
|
-
const result = {};
|
|
32
|
-
if (outline != null && outline !== false) {
|
|
33
|
-
let outlineValue = outline;
|
|
34
|
-
if (outline === true) outlineValue = "1ow";
|
|
35
|
-
if (outline === 0) outlineValue = "0";
|
|
36
|
-
const group = parseStyle(String(outlineValue)).groups[0];
|
|
37
|
-
if (group) {
|
|
38
|
-
const { parts } = group;
|
|
39
|
-
const outlinePart = parts[0] ?? {
|
|
40
|
-
values: [],
|
|
41
|
-
mods: [],
|
|
42
|
-
colors: []
|
|
43
|
-
};
|
|
44
|
-
const offsetPart = parts[1];
|
|
45
|
-
const typeMods = filterMods(outlinePart.mods, BORDER_STYLES);
|
|
46
|
-
result["outline"] = [
|
|
47
|
-
outlinePart.values[0] || "var(--outline-width)",
|
|
48
|
-
typeMods[0] || "solid",
|
|
49
|
-
outlinePart.colors[0] || "var(--outline-color)"
|
|
50
|
-
].join(" ");
|
|
51
|
-
if (offsetPart?.values[0]) result["outline-offset"] = offsetPart.values[0];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (outlineOffset != null && !result["outline-offset"]) {
|
|
55
|
-
const offsetValue = typeof outlineOffset === "number" ? `${outlineOffset}px` : outlineOffset;
|
|
56
|
-
result["outline-offset"] = parseStyle(offsetValue).groups[0]?.values[0] || offsetValue;
|
|
57
|
-
}
|
|
58
|
-
if (Object.keys(result).length === 0) return;
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
outlineStyle.__lookupStyles = ["outline", "outlineOffset"];
|
|
62
|
-
|
|
63
|
-
//#endregion
|
|
64
|
-
export { outlineStyle };
|
|
65
|
-
//# sourceMappingURL=outline.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"outline.mjs","names":[],"sources":["../../src/styles/outline.ts"],"sourcesContent":["import { filterMods, parseStyle } from '../utils/styles';\n\nconst BORDER_STYLES = [\n 'none',\n 'hidden',\n 'dotted',\n 'dashed',\n 'solid',\n 'double',\n 'groove',\n 'ridge',\n 'inset',\n 'outset',\n];\n\ninterface OutlineStyleProps {\n outline?: string | boolean | number;\n outlineOffset?: string | number;\n}\n\n/**\n * Generates CSS for outline property with optional offset.\n *\n * Syntax:\n * - `outline=\"2px solid #red\"` - outline only\n * - `outline=\"2px solid #red / 4px\"` - outline with offset (slash separator)\n * - `outline=\"2px / 4px\"` - width with offset (simpler form)\n * - `outline={true}` - default 1ow solid outline\n * - `outlineOffset=\"4px\"` - offset as separate prop (can be combined with outline)\n *\n * Priority: slash syntax in outline takes precedence over outlineOffset prop\n *\n * @return CSS properties for outline and optionally outline-offset\n */\nexport function outlineStyle({ outline, outlineOffset }: OutlineStyleProps) {\n const result: Record<string, string> = {};\n\n // Handle outline (0 is valid - means no outline)\n if (outline != null && outline !== false) {\n let outlineValue: string | boolean | number = outline;\n if (outline === true) outlineValue = '1ow';\n if (outline === 0) outlineValue = '0';\n\n const processed = parseStyle(String(outlineValue));\n const group = processed.groups[0];\n\n if (group) {\n const { parts } = group;\n const outlinePart = parts[0] ?? { values: [], mods: [], colors: [] };\n const offsetPart = parts[1];\n\n const typeMods = filterMods(outlinePart.mods, BORDER_STYLES);\n\n const value = outlinePart.values[0] || 'var(--outline-width)';\n const type = typeMods[0] || 'solid';\n const outlineColor = outlinePart.colors[0] || 'var(--outline-color)';\n\n result['outline'] = [value, type, outlineColor].join(' ');\n\n // Check for offset in second part (after /) - takes precedence\n if (offsetPart?.values[0]) {\n result['outline-offset'] = offsetPart.values[0];\n }\n }\n }\n\n // Handle outlineOffset prop (only if not already set by slash syntax)\n if (outlineOffset != null && !result['outline-offset']) {\n const offsetValue =\n typeof outlineOffset === 'number' ? `${outlineOffset}px` : outlineOffset;\n const processed = parseStyle(offsetValue);\n result['outline-offset'] = processed.groups[0]?.values[0] || offsetValue;\n }\n\n // Return undefined if no styles to apply\n if (Object.keys(result).length === 0) {\n return;\n }\n\n return result;\n}\n\noutlineStyle.__lookupStyles = ['outline', 'outlineOffset'];\n"],"mappings":";;;AAEA,MAAM,gBAAgB;CACpB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;;;;;;;;;AAqBD,SAAgB,aAAa,EAAE,SAAS,iBAAoC;CAC1E,MAAM,SAAiC,EAAE;AAGzC,KAAI,WAAW,QAAQ,YAAY,OAAO;EACxC,IAAI,eAA0C;AAC9C,MAAI,YAAY,KAAM,gBAAe;AACrC,MAAI,YAAY,EAAG,gBAAe;EAGlC,MAAM,QADY,WAAW,OAAO,aAAa,CAAC,CAC1B,OAAO;AAE/B,MAAI,OAAO;GACT,MAAM,EAAE,UAAU;GAClB,MAAM,cAAc,MAAM,MAAM;IAAE,QAAQ,EAAE;IAAE,MAAM,EAAE;IAAE,QAAQ,EAAE;IAAE;GACpE,MAAM,aAAa,MAAM;GAEzB,MAAM,WAAW,WAAW,YAAY,MAAM,cAAc;AAM5D,UAAO,aAAa;IAJN,YAAY,OAAO,MAAM;IAC1B,SAAS,MAAM;IACP,YAAY,OAAO,MAAM;IAEC,CAAC,KAAK,IAAI;AAGzD,OAAI,YAAY,OAAO,GACrB,QAAO,oBAAoB,WAAW,OAAO;;;AAMnD,KAAI,iBAAiB,QAAQ,CAAC,OAAO,mBAAmB;EACtD,MAAM,cACJ,OAAO,kBAAkB,WAAW,GAAG,cAAc,MAAM;AAE7D,SAAO,oBADW,WAAW,YAAY,CACJ,OAAO,IAAI,OAAO,MAAM;;AAI/D,KAAI,OAAO,KAAK,OAAO,CAAC,WAAW,EACjC;AAGF,QAAO;;AAGT,aAAa,iBAAiB,CAAC,WAAW,gBAAgB"}
|
package/dist/styles/padding.mjs
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { DIRECTIONS, filterMods, parseStyle } from "../utils/styles.mjs";
|
|
2
|
-
|
|
3
|
-
//#region src/styles/padding.ts
|
|
4
|
-
/**
|
|
5
|
-
* Parse a padding value and return the first processed value
|
|
6
|
-
*/
|
|
7
|
-
function parsePaddingValue(value) {
|
|
8
|
-
if (typeof value === "number") return `${value}px`;
|
|
9
|
-
if (!value) return null;
|
|
10
|
-
if (value === true) value = "1x";
|
|
11
|
-
const { values } = parseStyle(value).groups[0] ?? { values: [] };
|
|
12
|
-
return values[0] || "var(--gap)";
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Parse padding value with optional directions (like "1x top" or "2x left right")
|
|
16
|
-
*/
|
|
17
|
-
function parseDirectionalPadding(value) {
|
|
18
|
-
if (typeof value === "number") return {
|
|
19
|
-
values: [`${value}px`],
|
|
20
|
-
directions: []
|
|
21
|
-
};
|
|
22
|
-
if (!value) return {
|
|
23
|
-
values: [],
|
|
24
|
-
directions: []
|
|
25
|
-
};
|
|
26
|
-
if (value === true) value = "1x";
|
|
27
|
-
const { values = [], mods = [] } = parseStyle(value).groups[0] ?? {};
|
|
28
|
-
return {
|
|
29
|
-
values: values.length ? values : ["var(--gap)"],
|
|
30
|
-
directions: filterMods(mods, DIRECTIONS)
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function paddingStyle({ padding, paddingBlock, paddingInline, paddingTop, paddingRight, paddingBottom, paddingLeft }) {
|
|
34
|
-
if (padding == null && paddingBlock == null && paddingInline == null && paddingTop == null && paddingRight == null && paddingBottom == null && paddingLeft == null) return {};
|
|
35
|
-
let [top, right, bottom, left] = [
|
|
36
|
-
"0",
|
|
37
|
-
"0",
|
|
38
|
-
"0",
|
|
39
|
-
"0"
|
|
40
|
-
];
|
|
41
|
-
if (padding != null) {
|
|
42
|
-
const { values, directions } = parseDirectionalPadding(padding);
|
|
43
|
-
if (values.length) if (directions.length === 0) {
|
|
44
|
-
top = values[0];
|
|
45
|
-
right = values[1] || values[0];
|
|
46
|
-
bottom = values[2] || values[0];
|
|
47
|
-
left = values[3] || values[1] || values[0];
|
|
48
|
-
} else directions.forEach((dir, i) => {
|
|
49
|
-
const val = values[i] ?? values[0];
|
|
50
|
-
if (dir === "top") top = val;
|
|
51
|
-
else if (dir === "right") right = val;
|
|
52
|
-
else if (dir === "bottom") bottom = val;
|
|
53
|
-
else if (dir === "left") left = val;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
if (paddingBlock != null) {
|
|
57
|
-
const val = parsePaddingValue(paddingBlock);
|
|
58
|
-
if (val) top = bottom = val;
|
|
59
|
-
}
|
|
60
|
-
if (paddingInline != null) {
|
|
61
|
-
const val = parsePaddingValue(paddingInline);
|
|
62
|
-
if (val) left = right = val;
|
|
63
|
-
}
|
|
64
|
-
if (paddingTop != null) {
|
|
65
|
-
const val = parsePaddingValue(paddingTop);
|
|
66
|
-
if (val) top = val;
|
|
67
|
-
}
|
|
68
|
-
if (paddingRight != null) {
|
|
69
|
-
const val = parsePaddingValue(paddingRight);
|
|
70
|
-
if (val) right = val;
|
|
71
|
-
}
|
|
72
|
-
if (paddingBottom != null) {
|
|
73
|
-
const val = parsePaddingValue(paddingBottom);
|
|
74
|
-
if (val) bottom = val;
|
|
75
|
-
}
|
|
76
|
-
if (paddingLeft != null) {
|
|
77
|
-
const val = parsePaddingValue(paddingLeft);
|
|
78
|
-
if (val) left = val;
|
|
79
|
-
}
|
|
80
|
-
if (top === right && right === bottom && bottom === left) return { padding: top };
|
|
81
|
-
if (top === bottom && left === right) return { padding: `${top} ${left}` };
|
|
82
|
-
return { padding: `${top} ${right} ${bottom} ${left}` };
|
|
83
|
-
}
|
|
84
|
-
paddingStyle.__lookupStyles = [
|
|
85
|
-
"padding",
|
|
86
|
-
"paddingTop",
|
|
87
|
-
"paddingRight",
|
|
88
|
-
"paddingBottom",
|
|
89
|
-
"paddingLeft",
|
|
90
|
-
"paddingBlock",
|
|
91
|
-
"paddingInline"
|
|
92
|
-
];
|
|
93
|
-
|
|
94
|
-
//#endregion
|
|
95
|
-
export { paddingStyle };
|
|
96
|
-
//# sourceMappingURL=padding.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"padding.mjs","names":[],"sources":["../../src/styles/padding.ts"],"sourcesContent":["import { DIRECTIONS, filterMods, parseStyle } from '../utils/styles';\n\n/**\n * Parse a padding value and return the first processed value\n */\nfunction parsePaddingValue(value: string | number | boolean): string | null {\n if (typeof value === 'number') return `${value}px`;\n if (!value) return null;\n if (value === true) value = '1x';\n\n const { values } = parseStyle(value).groups[0] ?? { values: [] };\n\n return values[0] || 'var(--gap)';\n}\n\n/**\n * Parse padding value with optional directions (like \"1x top\" or \"2x left right\")\n */\nfunction parseDirectionalPadding(value: string | number | boolean): {\n values: string[];\n directions: string[];\n} {\n if (typeof value === 'number') {\n return { values: [`${value}px`], directions: [] };\n }\n if (!value) return { values: [], directions: [] };\n if (value === true) value = '1x';\n\n const { values = [], mods = [] } = parseStyle(value).groups[0] ?? {};\n\n return {\n values: values.length ? values : ['var(--gap)'],\n directions: filterMods(mods, DIRECTIONS),\n };\n}\n\nexport function paddingStyle({\n padding,\n paddingBlock,\n paddingInline,\n paddingTop,\n paddingRight,\n paddingBottom,\n paddingLeft,\n}: {\n padding?: string | number | boolean;\n paddingBlock?: string | number | boolean;\n paddingInline?: string | number | boolean;\n paddingTop?: string | number | boolean;\n paddingRight?: string | number | boolean;\n paddingBottom?: string | number | boolean;\n paddingLeft?: string | number | boolean;\n}) {\n // If no padding is defined, return empty object\n if (\n padding == null &&\n paddingBlock == null &&\n paddingInline == null &&\n paddingTop == null &&\n paddingRight == null &&\n paddingBottom == null &&\n paddingLeft == null\n ) {\n return {};\n }\n\n // Initialize all directions to 0\n let [top, right, bottom, left] = ['0', '0', '0', '0'];\n\n // Priority 1 (lowest): padding\n if (padding != null) {\n const { values, directions } = parseDirectionalPadding(padding);\n\n if (values.length) {\n if (directions.length === 0) {\n top = values[0];\n right = values[1] || values[0];\n bottom = values[2] || values[0];\n left = values[3] || values[1] || values[0];\n } else {\n // Assign values to directions in the order they appear\n // e.g., 'right 1x top 2x' → right: 1x, top: 2x\n directions.forEach((dir, i) => {\n const val = values[i] ?? values[0];\n if (dir === 'top') top = val;\n else if (dir === 'right') right = val;\n else if (dir === 'bottom') bottom = val;\n else if (dir === 'left') left = val;\n });\n }\n }\n }\n\n // Priority 2 (medium): paddingBlock/paddingInline\n if (paddingBlock != null) {\n const val = parsePaddingValue(paddingBlock);\n if (val) top = bottom = val;\n }\n if (paddingInline != null) {\n const val = parsePaddingValue(paddingInline);\n if (val) left = right = val;\n }\n\n // Priority 3 (highest): individual directions\n if (paddingTop != null) {\n const val = parsePaddingValue(paddingTop);\n if (val) top = val;\n }\n if (paddingRight != null) {\n const val = parsePaddingValue(paddingRight);\n if (val) right = val;\n }\n if (paddingBottom != null) {\n const val = parsePaddingValue(paddingBottom);\n if (val) bottom = val;\n }\n if (paddingLeft != null) {\n const val = parsePaddingValue(paddingLeft);\n if (val) left = val;\n }\n\n // Optimize output: 1 value if all same, 2 values if top==bottom && left==right\n if (top === right && right === bottom && bottom === left) {\n return { padding: top };\n }\n if (top === bottom && left === right) {\n return { padding: `${top} ${left}` };\n }\n\n return { padding: `${top} ${right} ${bottom} ${left}` };\n}\n\npaddingStyle.__lookupStyles = [\n 'padding',\n 'paddingTop',\n 'paddingRight',\n 'paddingBottom',\n 'paddingLeft',\n 'paddingBlock',\n 'paddingInline',\n];\n"],"mappings":";;;;;;AAKA,SAAS,kBAAkB,OAAiD;AAC1E,KAAI,OAAO,UAAU,SAAU,QAAO,GAAG,MAAM;AAC/C,KAAI,CAAC,MAAO,QAAO;AACnB,KAAI,UAAU,KAAM,SAAQ;CAE5B,MAAM,EAAE,WAAW,WAAW,MAAM,CAAC,OAAO,MAAM,EAAE,QAAQ,EAAE,EAAE;AAEhE,QAAO,OAAO,MAAM;;;;;AAMtB,SAAS,wBAAwB,OAG/B;AACA,KAAI,OAAO,UAAU,SACnB,QAAO;EAAE,QAAQ,CAAC,GAAG,MAAM,IAAI;EAAE,YAAY,EAAE;EAAE;AAEnD,KAAI,CAAC,MAAO,QAAO;EAAE,QAAQ,EAAE;EAAE,YAAY,EAAE;EAAE;AACjD,KAAI,UAAU,KAAM,SAAQ;CAE5B,MAAM,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,WAAW,MAAM,CAAC,OAAO,MAAM,EAAE;AAEpE,QAAO;EACL,QAAQ,OAAO,SAAS,SAAS,CAAC,aAAa;EAC/C,YAAY,WAAW,MAAM,WAAW;EACzC;;AAGH,SAAgB,aAAa,EAC3B,SACA,cACA,eACA,YACA,cACA,eACA,eASC;AAED,KACE,WAAW,QACX,gBAAgB,QAChB,iBAAiB,QACjB,cAAc,QACd,gBAAgB,QAChB,iBAAiB,QACjB,eAAe,KAEf,QAAO,EAAE;CAIX,IAAI,CAAC,KAAK,OAAO,QAAQ,QAAQ;EAAC;EAAK;EAAK;EAAK;EAAI;AAGrD,KAAI,WAAW,MAAM;EACnB,MAAM,EAAE,QAAQ,eAAe,wBAAwB,QAAQ;AAE/D,MAAI,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-env.mjs";
|
|
2
|
-
import { alignStyle } from "./align.mjs";
|
|
3
|
-
import { borderStyle } from "./border.mjs";
|
|
4
|
-
import { createStyle } from "./createStyle.mjs";
|
|
5
|
-
import { colorStyle } from "./color.mjs";
|
|
6
|
-
import { displayStyle } from "./display.mjs";
|
|
7
|
-
import { fadeStyle } from "./fade.mjs";
|
|
8
|
-
import { fillStyle, svgFillStyle } from "./fill.mjs";
|
|
9
|
-
import { flowStyle } from "./flow.mjs";
|
|
10
|
-
import { gapStyle } from "./gap.mjs";
|
|
11
|
-
import { heightStyle } from "./height.mjs";
|
|
12
|
-
import { insetStyle } from "./inset.mjs";
|
|
13
|
-
import { justifyStyle } from "./justify.mjs";
|
|
14
|
-
import { marginStyle } from "./margin.mjs";
|
|
15
|
-
import { outlineStyle } from "./outline.mjs";
|
|
16
|
-
import { paddingStyle } from "./padding.mjs";
|
|
17
|
-
import { presetStyle } from "./preset.mjs";
|
|
18
|
-
import { radiusStyle } from "./radius.mjs";
|
|
19
|
-
import { scrollbarStyle } from "./scrollbar.mjs";
|
|
20
|
-
import { shadowStyle } from "./shadow.mjs";
|
|
21
|
-
import { styledScrollbarStyle } from "./styledScrollbar.mjs";
|
|
22
|
-
import { transitionStyle } from "./transition.mjs";
|
|
23
|
-
import { widthStyle } from "./width.mjs";
|
|
24
|
-
|
|
25
|
-
//#region src/styles/predefined.ts
|
|
26
|
-
const devMode = isDevEnv();
|
|
27
|
-
const columnsConverter = (val) => {
|
|
28
|
-
if (typeof val === "number") return "minmax(1px, 1fr) ".repeat(val).trim();
|
|
29
|
-
};
|
|
30
|
-
const rowsConverter = (val) => {
|
|
31
|
-
if (typeof val === "number") return "auto ".repeat(val).trim();
|
|
32
|
-
};
|
|
33
|
-
const STYLE_HANDLER_MAP = {};
|
|
34
|
-
let initialHandlerMapSnapshot = null;
|
|
35
|
-
/**
|
|
36
|
-
* Capture a snapshot of the current STYLE_HANDLER_MAP.
|
|
37
|
-
* Called after predefine() to preserve built-in handler state.
|
|
38
|
-
*/
|
|
39
|
-
function captureInitialHandlerState() {
|
|
40
|
-
initialHandlerMapSnapshot = {};
|
|
41
|
-
for (const key of Object.keys(STYLE_HANDLER_MAP)) initialHandlerMapSnapshot[key] = [...STYLE_HANDLER_MAP[key]];
|
|
42
|
-
}
|
|
43
|
-
function defineCustomStyle(names, handler) {
|
|
44
|
-
let handlerWithLookup;
|
|
45
|
-
if (typeof names === "function") {
|
|
46
|
-
handlerWithLookup = names;
|
|
47
|
-
names = handlerWithLookup.__lookupStyles;
|
|
48
|
-
} else if (handler) handlerWithLookup = Object.assign(handler, { __lookupStyles: names });
|
|
49
|
-
else {
|
|
50
|
-
console.warn("CubeUIKit: incorrect custom style definition: ", names);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
if (Array.isArray(names)) names.forEach((name) => {
|
|
54
|
-
if (!STYLE_HANDLER_MAP[name]) STYLE_HANDLER_MAP[name] = [];
|
|
55
|
-
STYLE_HANDLER_MAP[name].push(handlerWithLookup);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
function defineStyleAlias(styleName, cssStyleName, converter) {
|
|
59
|
-
const styleHandler = createStyle(styleName, cssStyleName, converter);
|
|
60
|
-
if (!STYLE_HANDLER_MAP[styleName]) STYLE_HANDLER_MAP[styleName] = [];
|
|
61
|
-
STYLE_HANDLER_MAP[styleName].push(styleHandler);
|
|
62
|
-
}
|
|
63
|
-
function predefine() {
|
|
64
|
-
defineStyleAlias("gridAreas", "grid-template-areas");
|
|
65
|
-
defineStyleAlias("gridColumns", "grid-template-columns", columnsConverter);
|
|
66
|
-
defineStyleAlias("gridRows", "grid-template-rows", rowsConverter);
|
|
67
|
-
defineStyleAlias("gridTemplate", "grid-template", (val) => {
|
|
68
|
-
if (typeof val !== "string") return;
|
|
69
|
-
return val.split("/").map((s, i) => (i ? columnsConverter : rowsConverter)(s)).join("/");
|
|
70
|
-
});
|
|
71
|
-
[
|
|
72
|
-
displayStyle,
|
|
73
|
-
transitionStyle,
|
|
74
|
-
fillStyle,
|
|
75
|
-
svgFillStyle,
|
|
76
|
-
widthStyle,
|
|
77
|
-
marginStyle,
|
|
78
|
-
gapStyle,
|
|
79
|
-
flowStyle,
|
|
80
|
-
colorStyle,
|
|
81
|
-
heightStyle,
|
|
82
|
-
radiusStyle,
|
|
83
|
-
borderStyle,
|
|
84
|
-
shadowStyle,
|
|
85
|
-
paddingStyle,
|
|
86
|
-
alignStyle,
|
|
87
|
-
justifyStyle,
|
|
88
|
-
presetStyle,
|
|
89
|
-
outlineStyle,
|
|
90
|
-
styledScrollbarStyle,
|
|
91
|
-
scrollbarStyle,
|
|
92
|
-
fadeStyle,
|
|
93
|
-
insetStyle
|
|
94
|
-
].forEach((handler) => defineCustomStyle(handler));
|
|
95
|
-
captureInitialHandlerState();
|
|
96
|
-
return {
|
|
97
|
-
STYLE_HANDLER_MAP,
|
|
98
|
-
defineCustomStyle,
|
|
99
|
-
defineStyleAlias
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Normalize a handler definition to a StyleHandler with __lookupStyles.
|
|
104
|
-
* - Function only: lookup styles inferred from key name
|
|
105
|
-
* - [string, fn]: single lookup style
|
|
106
|
-
* - [string[], fn]: multiple lookup styles
|
|
107
|
-
*/
|
|
108
|
-
function normalizeHandlerDefinition(keyName, definition) {
|
|
109
|
-
let handler;
|
|
110
|
-
let lookupStyles;
|
|
111
|
-
if (typeof definition === "function") {
|
|
112
|
-
handler = definition;
|
|
113
|
-
lookupStyles = [keyName];
|
|
114
|
-
} else if (Array.isArray(definition)) {
|
|
115
|
-
const [first, fn] = definition;
|
|
116
|
-
if (typeof fn !== "function") throw new Error(`[Tasty] Invalid handler definition for "${keyName}". Tuple must have a function as the second element: [string, function] or [string[], function].`);
|
|
117
|
-
handler = fn;
|
|
118
|
-
if (typeof first === "string") lookupStyles = [first];
|
|
119
|
-
else if (Array.isArray(first)) lookupStyles = first;
|
|
120
|
-
else throw new Error(`[Tasty] Invalid handler definition for "${keyName}". First element must be a string or string array.`);
|
|
121
|
-
} else throw new Error(`[Tasty] Invalid handler definition for "${keyName}". Expected function, [string, function], or [string[], function].`);
|
|
122
|
-
validateHandler(keyName, handler, lookupStyles);
|
|
123
|
-
const wrappedHandler = ((props) => handler(props));
|
|
124
|
-
wrappedHandler.__lookupStyles = lookupStyles;
|
|
125
|
-
return wrappedHandler;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Validate a handler definition in development mode.
|
|
129
|
-
*/
|
|
130
|
-
function validateHandler(name, handler, lookupStyles) {
|
|
131
|
-
if (!devMode) return;
|
|
132
|
-
if (typeof handler !== "function") console.warn(`[Tasty] Handler "${name}" is not a function. Handlers must be functions that return CSSMap, CSSMap[], or void.`);
|
|
133
|
-
if (!lookupStyles || !Array.isArray(lookupStyles) || lookupStyles.length === 0) console.warn(`[Tasty] Handler "${name}" has invalid lookupStyles. Expected non-empty array of style names.`);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Register a custom handler, replacing any existing handlers for the same lookup styles.
|
|
137
|
-
* This is called by configure() to process user-defined handlers.
|
|
138
|
-
*
|
|
139
|
-
* When registering a handler for style X, any existing handler that processes X
|
|
140
|
-
* is removed from ALL its lookup styles to prevent double-processing.
|
|
141
|
-
* For example, if gapStyle handles ['display', 'flow', 'gap'] and a new handler
|
|
142
|
-
* is registered for just ['gap'], gapStyle is removed from display and flow too.
|
|
143
|
-
*/
|
|
144
|
-
function registerHandler(handler) {
|
|
145
|
-
const lookupStyles = handler.__lookupStyles;
|
|
146
|
-
if (!lookupStyles || lookupStyles.length === 0) {
|
|
147
|
-
if (devMode) console.warn("[Tasty] Cannot register handler without __lookupStyles property.");
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
const handlersToRemove = /* @__PURE__ */ new Set();
|
|
151
|
-
for (const styleName of lookupStyles) {
|
|
152
|
-
const existing = STYLE_HANDLER_MAP[styleName];
|
|
153
|
-
if (existing) for (const existingHandler of existing) handlersToRemove.add(existingHandler);
|
|
154
|
-
}
|
|
155
|
-
for (const oldHandler of handlersToRemove) {
|
|
156
|
-
const oldLookupStyles = oldHandler.__lookupStyles;
|
|
157
|
-
if (oldLookupStyles) for (const oldStyleName of oldLookupStyles) {
|
|
158
|
-
const handlers = STYLE_HANDLER_MAP[oldStyleName];
|
|
159
|
-
if (handlers) {
|
|
160
|
-
const filtered = handlers.filter((h) => h !== oldHandler);
|
|
161
|
-
if (filtered.length === 0) delete STYLE_HANDLER_MAP[oldStyleName];
|
|
162
|
-
else STYLE_HANDLER_MAP[oldStyleName] = filtered;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
for (const styleName of lookupStyles) {
|
|
167
|
-
const existing = STYLE_HANDLER_MAP[styleName];
|
|
168
|
-
if (existing) existing.push(handler);
|
|
169
|
-
else STYLE_HANDLER_MAP[styleName] = [handler];
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Create a wrapped handler that can be safely called by users.
|
|
174
|
-
* The wrapper preserves __lookupStyles for proper registration.
|
|
175
|
-
*/
|
|
176
|
-
function wrapHandler(handler) {
|
|
177
|
-
const fn = handler;
|
|
178
|
-
const wrapped = ((props) => fn(props));
|
|
179
|
-
wrapped.__lookupStyles = handler.__lookupStyles;
|
|
180
|
-
return wrapped;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Exported object containing wrapped predefined style handlers.
|
|
184
|
-
* Users can import and call these to extend or delegate to built-in behavior.
|
|
185
|
-
*
|
|
186
|
-
* Internal handlers use *Style suffix for searchability.
|
|
187
|
-
* External API uses short names for convenience.
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```ts
|
|
191
|
-
* import { styleHandlers, configure } from '@tenphi/tasty';
|
|
192
|
-
*
|
|
193
|
-
* configure({
|
|
194
|
-
* handlers: {
|
|
195
|
-
* fill: ({ fill }) => {
|
|
196
|
-
* if (fill?.startsWith('gradient:')) {
|
|
197
|
-
* return { background: fill.slice(9) };
|
|
198
|
-
* }
|
|
199
|
-
* return styleHandlers.fill({ fill });
|
|
200
|
-
* },
|
|
201
|
-
* },
|
|
202
|
-
* });
|
|
203
|
-
* ```
|
|
204
|
-
*/
|
|
205
|
-
const styleHandlers = {
|
|
206
|
-
align: wrapHandler(alignStyle),
|
|
207
|
-
border: wrapHandler(borderStyle),
|
|
208
|
-
color: wrapHandler(colorStyle),
|
|
209
|
-
display: wrapHandler(displayStyle),
|
|
210
|
-
fade: wrapHandler(fadeStyle),
|
|
211
|
-
fill: wrapHandler(fillStyle),
|
|
212
|
-
svgFill: wrapHandler(svgFillStyle),
|
|
213
|
-
flow: wrapHandler(flowStyle),
|
|
214
|
-
gap: wrapHandler(gapStyle),
|
|
215
|
-
height: wrapHandler(heightStyle),
|
|
216
|
-
inset: wrapHandler(insetStyle),
|
|
217
|
-
justify: wrapHandler(justifyStyle),
|
|
218
|
-
margin: wrapHandler(marginStyle),
|
|
219
|
-
outline: wrapHandler(outlineStyle),
|
|
220
|
-
padding: wrapHandler(paddingStyle),
|
|
221
|
-
preset: wrapHandler(presetStyle),
|
|
222
|
-
radius: wrapHandler(radiusStyle),
|
|
223
|
-
scrollbar: wrapHandler(scrollbarStyle),
|
|
224
|
-
shadow: wrapHandler(shadowStyle),
|
|
225
|
-
styledScrollbar: wrapHandler(styledScrollbarStyle),
|
|
226
|
-
transition: wrapHandler(transitionStyle),
|
|
227
|
-
width: wrapHandler(widthStyle)
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
//#endregion
|
|
231
|
-
export { normalizeHandlerDefinition, predefine, registerHandler };
|
|
232
|
-
//# sourceMappingURL=predefined.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"predefined.mjs","names":[],"sources":["../../src/styles/predefined.ts"],"sourcesContent":["import { isDevEnv } from '../utils/is-dev-env';\nimport type {\n RawStyleHandler,\n StyleHandler,\n StyleHandlerDefinition,\n} from '../utils/styles';\n\nimport { alignStyle } from './align';\nimport { borderStyle } from './border';\nimport { colorStyle } from './color';\nimport { createStyle } from './createStyle';\nimport { displayStyle } from './display';\nimport { fadeStyle } from './fade';\nimport { fillStyle, svgFillStyle } from './fill';\nimport { flowStyle } from './flow';\n// Note: fontStyle (font.ts) and fontStyleStyle (fontStyle.ts) removed\n// Both font and fontStyle props are now handled by presetStyle\nimport { gapStyle } from './gap';\nimport { heightStyle } from './height';\nimport { insetStyle } from './inset';\nimport { justifyStyle } from './justify';\nimport { marginStyle } from './margin';\nimport { outlineStyle } from './outline';\nimport { paddingStyle } from './padding';\nimport { presetStyle } from './preset';\nimport { radiusStyle } from './radius';\nimport { scrollbarStyle } from './scrollbar';\nimport { shadowStyle } from './shadow';\nimport { styledScrollbarStyle } from './styledScrollbar';\nimport { transitionStyle } from './transition';\nimport { widthStyle } from './width';\n\nconst devMode = isDevEnv();\n\n \nconst _numberConverter = (val) => {\n if (typeof val === 'number') {\n return `${val}px`;\n }\n\n return val;\n};\nconst columnsConverter = (val) => {\n if (typeof val === 'number') {\n return 'minmax(1px, 1fr) '.repeat(val).trim();\n }\n\n return;\n};\nconst rowsConverter = (val) => {\n if (typeof val === 'number') {\n return 'auto '.repeat(val).trim();\n }\n\n return;\n};\n\ntype StyleHandlerMap = Record<string, StyleHandler[]>;\n\nexport const STYLE_HANDLER_MAP: StyleHandlerMap = {};\n\n// Store initial handler state for reset functionality\nlet initialHandlerMapSnapshot: StyleHandlerMap | null = null;\n\n/**\n * Capture a snapshot of the current STYLE_HANDLER_MAP.\n * Called after predefine() to preserve built-in handler state.\n */\nfunction captureInitialHandlerState(): void {\n initialHandlerMapSnapshot = {};\n for (const key of Object.keys(STYLE_HANDLER_MAP)) {\n // Shallow copy the array - handlers themselves are immutable\n initialHandlerMapSnapshot[key] = [...STYLE_HANDLER_MAP[key]];\n }\n}\n\n/**\n * Reset STYLE_HANDLER_MAP to the initial built-in state.\n * Called by resetConfig() to restore handlers after tests.\n */\nexport function resetHandlers(): void {\n if (!initialHandlerMapSnapshot) {\n // predefine() hasn't been called yet, nothing to reset\n return;\n }\n\n // Clear current map\n for (const key of Object.keys(STYLE_HANDLER_MAP)) {\n delete STYLE_HANDLER_MAP[key];\n }\n\n // Restore initial state\n for (const key of Object.keys(initialHandlerMapSnapshot)) {\n STYLE_HANDLER_MAP[key] = [...initialHandlerMapSnapshot[key]];\n }\n}\n\nexport function defineCustomStyle(\n names: string[] | StyleHandler,\n handler?: RawStyleHandler,\n) {\n let handlerWithLookup: StyleHandler;\n\n if (typeof names === 'function') {\n handlerWithLookup = names;\n names = handlerWithLookup.__lookupStyles;\n } else if (handler) {\n handlerWithLookup = Object.assign(handler, { __lookupStyles: names });\n } else {\n console.warn('CubeUIKit: incorrect custom style definition: ', names);\n return;\n }\n\n if (Array.isArray(names)) {\n // just to pass type checking\n names.forEach((name) => {\n if (!STYLE_HANDLER_MAP[name]) {\n STYLE_HANDLER_MAP[name] = [];\n }\n\n STYLE_HANDLER_MAP[name].push(handlerWithLookup);\n });\n }\n}\n\ntype ConverterHandler = (\n s: string | boolean | number | undefined,\n) => string | undefined;\n\nexport function defineStyleAlias(\n styleName: string,\n cssStyleName?: string,\n converter?: ConverterHandler,\n) {\n const styleHandler = createStyle(styleName, cssStyleName, converter);\n\n if (!STYLE_HANDLER_MAP[styleName]) {\n STYLE_HANDLER_MAP[styleName] = [];\n }\n\n STYLE_HANDLER_MAP[styleName].push(styleHandler);\n}\n\nexport function predefine() {\n // Style aliases\n defineStyleAlias('gridAreas', 'grid-template-areas');\n defineStyleAlias('gridColumns', 'grid-template-columns', columnsConverter);\n defineStyleAlias('gridRows', 'grid-template-rows', rowsConverter);\n defineStyleAlias('gridTemplate', 'grid-template', (val) => {\n if (typeof val !== 'string') return;\n\n return val\n .split('/')\n .map((s, i) => (i ? columnsConverter : rowsConverter)(s))\n .join('/');\n });\n // Note: outlineOffset is now handled by outlineStyle\n\n [\n displayStyle,\n transitionStyle,\n fillStyle,\n svgFillStyle,\n widthStyle,\n marginStyle,\n gapStyle,\n flowStyle,\n colorStyle,\n heightStyle,\n radiusStyle,\n borderStyle,\n shadowStyle,\n paddingStyle,\n alignStyle,\n justifyStyle,\n presetStyle,\n outlineStyle,\n // DEPRECATED: `styledScrollbar` is deprecated, use `scrollbar` instead\n styledScrollbarStyle,\n scrollbarStyle,\n fadeStyle,\n insetStyle,\n ]\n // @ts-expect-error handler type varies across built-in style handlers\n .forEach((handler) => defineCustomStyle(handler));\n\n // Capture initial state after all built-in handlers are registered\n captureInitialHandlerState();\n\n return { STYLE_HANDLER_MAP, defineCustomStyle, defineStyleAlias };\n}\n\n// ============================================================================\n// Handler Registration API (for configure())\n// ============================================================================\n\n/**\n * Normalize a handler definition to a StyleHandler with __lookupStyles.\n * - Function only: lookup styles inferred from key name\n * - [string, fn]: single lookup style\n * - [string[], fn]: multiple lookup styles\n */\nexport function normalizeHandlerDefinition(\n keyName: string,\n definition: StyleHandlerDefinition,\n): StyleHandler {\n let handler: RawStyleHandler;\n let lookupStyles: string[];\n\n if (typeof definition === 'function') {\n // Function only - lookup styles inferred from key name\n handler = definition;\n lookupStyles = [keyName];\n } else if (Array.isArray(definition)) {\n const [first, fn] = definition;\n\n if (typeof fn !== 'function') {\n throw new Error(\n `[Tasty] Invalid handler definition for \"${keyName}\". ` +\n 'Tuple must have a function as the second element: [string, function] or [string[], function].',\n );\n }\n\n handler = fn;\n\n if (typeof first === 'string') {\n // [string, fn] - single lookup style\n lookupStyles = [first];\n } else if (Array.isArray(first)) {\n // [string[], fn] - multiple lookup styles\n lookupStyles = first;\n } else {\n throw new Error(\n `[Tasty] Invalid handler definition for \"${keyName}\". ` +\n 'First element must be a string or string array.',\n );\n }\n } else {\n throw new Error(\n `[Tasty] Invalid handler definition for \"${keyName}\". ` +\n 'Expected function, [string, function], or [string[], function].',\n );\n }\n\n // Validate handler in dev mode\n validateHandler(keyName, handler, lookupStyles);\n\n // Wrap the handler to avoid mutation issues when the same function\n // is reused for multiple handler definitions. Each registration\n // gets its own function identity with its own __lookupStyles.\n const wrappedHandler = ((props) => handler(props)) as StyleHandler;\n wrappedHandler.__lookupStyles = lookupStyles;\n\n return wrappedHandler;\n}\n\n/**\n * Validate a handler definition in development mode.\n */\nfunction validateHandler(\n name: string,\n handler: RawStyleHandler,\n lookupStyles: string[],\n): void {\n if (!devMode) return;\n\n if (typeof handler !== 'function') {\n console.warn(\n `[Tasty] Handler \"${name}\" is not a function. ` +\n 'Handlers must be functions that return CSSMap, CSSMap[], or void.',\n );\n }\n\n if (\n !lookupStyles ||\n !Array.isArray(lookupStyles) ||\n lookupStyles.length === 0\n ) {\n console.warn(\n `[Tasty] Handler \"${name}\" has invalid lookupStyles. ` +\n 'Expected non-empty array of style names.',\n );\n }\n}\n\n/**\n * Validate a handler result in development mode.\n * Call this after invoking a handler to check the return value.\n */\nexport function validateHandlerResult(name: string, result: unknown): void {\n if (!devMode) return;\n if (result === undefined || result === null) return; // void is valid\n\n // Check for empty string (migration from old pattern)\n if (result === '') {\n console.warn(\n `[Tasty] Handler \"${name}\" returned empty string. ` +\n 'Return void/undefined instead for no output.',\n );\n return;\n }\n\n // Check result is object (CSSMap or CSSMap[])\n if (typeof result !== 'object') {\n console.warn(\n `[Tasty] Handler \"${name}\" returned invalid type: ${typeof result}. ` +\n 'Expected CSSMap, CSSMap[], or void.',\n );\n }\n}\n\n/**\n * Register a custom handler, replacing any existing handlers for the same lookup styles.\n * This is called by configure() to process user-defined handlers.\n *\n * When registering a handler for style X, any existing handler that processes X\n * is removed from ALL its lookup styles to prevent double-processing.\n * For example, if gapStyle handles ['display', 'flow', 'gap'] and a new handler\n * is registered for just ['gap'], gapStyle is removed from display and flow too.\n */\nexport function registerHandler(handler: StyleHandler): void {\n const lookupStyles = handler.__lookupStyles;\n\n if (!lookupStyles || lookupStyles.length === 0) {\n if (devMode) {\n console.warn(\n '[Tasty] Cannot register handler without __lookupStyles property.',\n );\n }\n return;\n }\n\n // Find and remove existing handlers that would conflict\n // A handler conflicts if it handles any of the same styles as the new handler\n const handlersToRemove = new Set<StyleHandler>();\n\n for (const styleName of lookupStyles) {\n const existing = STYLE_HANDLER_MAP[styleName];\n if (existing) {\n for (const existingHandler of existing) {\n handlersToRemove.add(existingHandler);\n }\n }\n }\n\n // Remove conflicting handlers from ALL their lookup styles\n for (const oldHandler of handlersToRemove) {\n const oldLookupStyles = oldHandler.__lookupStyles;\n if (oldLookupStyles) {\n for (const oldStyleName of oldLookupStyles) {\n const handlers = STYLE_HANDLER_MAP[oldStyleName];\n if (handlers) {\n const filtered = handlers.filter((h) => h !== oldHandler);\n if (filtered.length === 0) {\n delete STYLE_HANDLER_MAP[oldStyleName];\n } else {\n STYLE_HANDLER_MAP[oldStyleName] = filtered;\n }\n }\n }\n }\n }\n\n // Register the new handler under its lookup styles\n for (const styleName of lookupStyles) {\n const existing = STYLE_HANDLER_MAP[styleName];\n if (existing) {\n existing.push(handler);\n } else {\n STYLE_HANDLER_MAP[styleName] = [handler];\n }\n }\n}\n\n// ============================================================================\n// Wrapped Style Handlers Export\n// ============================================================================\n\n/**\n * Create a wrapped handler that can be safely called by users.\n * The wrapper preserves __lookupStyles for proper registration.\n */\nfunction wrapHandler<T extends { __lookupStyles: string[] }>(handler: T): T {\n const fn = handler as unknown as (props: unknown) => unknown;\n const wrapped = ((props: unknown) => fn(props)) as unknown as T;\n wrapped.__lookupStyles = handler.__lookupStyles;\n return wrapped;\n}\n\n/**\n * Exported object containing wrapped predefined style handlers.\n * Users can import and call these to extend or delegate to built-in behavior.\n *\n * Internal handlers use *Style suffix for searchability.\n * External API uses short names for convenience.\n *\n * @example\n * ```ts\n * import { styleHandlers, configure } from '@tenphi/tasty';\n *\n * configure({\n * handlers: {\n * fill: ({ fill }) => {\n * if (fill?.startsWith('gradient:')) {\n * return { background: fill.slice(9) };\n * }\n * return styleHandlers.fill({ fill });\n * },\n * },\n * });\n * ```\n */\nexport const styleHandlers = {\n align: wrapHandler(alignStyle),\n border: wrapHandler(borderStyle),\n color: wrapHandler(colorStyle),\n display: wrapHandler(displayStyle),\n fade: wrapHandler(fadeStyle),\n fill: wrapHandler(fillStyle),\n svgFill: wrapHandler(svgFillStyle),\n flow: wrapHandler(flowStyle),\n gap: wrapHandler(gapStyle),\n height: wrapHandler(heightStyle),\n inset: wrapHandler(insetStyle),\n justify: wrapHandler(justifyStyle),\n margin: wrapHandler(marginStyle),\n outline: wrapHandler(outlineStyle),\n padding: wrapHandler(paddingStyle),\n preset: wrapHandler(presetStyle),\n radius: wrapHandler(radiusStyle),\n scrollbar: wrapHandler(scrollbarStyle),\n shadow: wrapHandler(shadowStyle),\n styledScrollbar: wrapHandler(styledScrollbarStyle),\n transition: wrapHandler(transitionStyle),\n width: wrapHandler(widthStyle),\n} as const;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAM,UAAU,UAAU;AAU1B,MAAM,oBAAoB,QAAQ;AAChC,KAAI,OAAO,QAAQ,SACjB,QAAO,oBAAoB,OAAO,IAAI,CAAC,MAAM;;AAKjD,MAAM,iBAAiB,QAAQ;AAC7B,KAAI,OAAO,QAAQ,SACjB,QAAO,QAAQ,OAAO,IAAI,CAAC,MAAM;;AAQrC,MAAa,oBAAqC,EAAE;AAGpD,IAAI,4BAAoD;;;;;AAMxD,SAAS,6BAAmC;AAC1C,6BAA4B,EAAE;AAC9B,MAAK,MAAM,OAAO,OAAO,KAAK,kBAAkB,CAE9C,2BAA0B,OAAO,CAAC,GAAG,kBAAkB,KAAK;;AAyBhE,SAAgB,kBACd,OACA,SACA;CACA,IAAI;AAEJ,KAAI,OAAO,UAAU,YAAY;AAC/B,sBAAoB;AACpB,UAAQ,kBAAkB;YACjB,QACT,qBAAoB,OAAO,OAAO,SAAS,EAAE,gBAAgB,OAAO,CAAC;MAChE;AACL,UAAQ,KAAK,kDAAkD,MAAM;AACrE;;AAGF,KAAI,MAAM,QAAQ,MAAM,CAEtB,OAAM,SAAS,SAAS;AACtB,MAAI,C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AAgB;CAC3B,OAAO,YAAY,WAAW;CAC9B,QAAQ,YAAY,YAAY;CAChC,OAAO,YAAY,WAAW;CAC9B,SAAS,YAAY,aAAa;CAClC,MAAM,YAAY,UAAU;CAC5B,MAAM,YAAY,UAAU;CAC5B,SAAS,YAAY,aAAa;CAClC,MAAM,YAAY,UAAU;CAC5B,KAAK,YAAY,SAAS;CAC1B,QAAQ,YAAY,YAAY;CAChC,OAAO,YAAY,WAAW;CAC9B,SAAS,YAAY,aAAa;CAClC,QAAQ,YAAY,YAAY;CAChC,SAAS,YAAY,aAAa;CAClC,SAAS,YAAY,aAAa;CAClC,QAAQ,YAAY,YAAY;CAChC,QAAQ,YAAY,YAAY;CAChC,WAAW,YAAY,eAAe;CACtC,QAAQ,YAAY,YAAY;CAChC,iBAAiB,YAAY,qBAAqB;CAClD,YAAY,YAAY,gBAAgB;CACxC,OAAO,YAAY,WAAW;CAC/B"}
|
package/dist/styles/preset.mjs
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { makeEmptyDetails } from "../parser/types.mjs";
|
|
2
|
-
import { parseStyle } from "../utils/styles.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/styles/preset.ts
|
|
5
|
-
/**
|
|
6
|
-
* Convert a value to CSS, handling numbers as pixels for numeric properties
|
|
7
|
-
*/
|
|
8
|
-
function toCSS(value, isNumeric) {
|
|
9
|
-
if (value == null) return null;
|
|
10
|
-
if (typeof value === "number") return isNumeric ? `${value}px` : String(value);
|
|
11
|
-
return parseStyle(String(value)).groups[0]?.values[0] || String(value);
|
|
12
|
-
}
|
|
13
|
-
function setCSSValue(styles, styleName, presetName, isPropOnly = false) {
|
|
14
|
-
styles[`--${styleName}`] = (() => {
|
|
15
|
-
if (presetName === "inherit") return "inherit";
|
|
16
|
-
const defaultValue = `var(--default-${styleName}, ${styleName === "font-family" ? "var(--font, NonexistentFontName)" : "inherit"})`;
|
|
17
|
-
const fontSuffix = styleName === "font-family" ? ", var(--font, sans-serif)" : "";
|
|
18
|
-
if (presetName === "default") return `${defaultValue}${fontSuffix}`;
|
|
19
|
-
else return `var(--${presetName}-${styleName}, ${defaultValue})${fontSuffix}`;
|
|
20
|
-
})();
|
|
21
|
-
if (!isPropOnly) styles[styleName] = styles[`--${styleName}`];
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Resolve font/fontFamily value to CSS font-family string.
|
|
25
|
-
*
|
|
26
|
-
* - `font="monospace"` → var(--monospace-font)
|
|
27
|
-
* - `font={true}` → var(--font)
|
|
28
|
-
* - `font="CustomFont"` → CustomFont, var(--font)
|
|
29
|
-
* - `fontFamily="Arial"` → Arial (direct, no fallback)
|
|
30
|
-
*/
|
|
31
|
-
function resolveFontFamily(font, fontFamily) {
|
|
32
|
-
if (fontFamily) return {
|
|
33
|
-
value: fontFamily,
|
|
34
|
-
setVar: false
|
|
35
|
-
};
|
|
36
|
-
if (font == null || font === false) return null;
|
|
37
|
-
if (font === "monospace") return {
|
|
38
|
-
value: "var(--monospace-font)",
|
|
39
|
-
setVar: true
|
|
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
|
-
};
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Handles typography preset and individual font properties.
|
|
52
|
-
*
|
|
53
|
-
* When `preset` is defined, it sets up CSS custom properties for typography.
|
|
54
|
-
* Individual font props can be used with or without `preset`:
|
|
55
|
-
* - With `preset`: overrides the preset value for that property
|
|
56
|
-
* - Without `preset`: outputs the CSS directly
|
|
57
|
-
*
|
|
58
|
-
* Number values are converted to pixels for fontSize, lineHeight, letterSpacing.
|
|
59
|
-
* fontWeight accepts numbers directly (e.g., 400, 700).
|
|
60
|
-
*
|
|
61
|
-
* font vs fontFamily:
|
|
62
|
-
* - `font` is the recommended prop with special handling (monospace, boolean, fallback)
|
|
63
|
-
* - `fontFamily` is a direct value without special handling
|
|
64
|
-
*/
|
|
65
|
-
function presetStyle({ preset, fontSize, lineHeight, textTransform, letterSpacing, fontWeight, fontStyle, fontFamily, font }) {
|
|
66
|
-
const styles = {};
|
|
67
|
-
if (preset != null && preset !== false) {
|
|
68
|
-
let { mods } = parseStyle(preset === true ? "" : String(preset)).groups[0] ?? makeEmptyDetails();
|
|
69
|
-
const isStrong = mods.includes("strong");
|
|
70
|
-
const isItalic = mods.includes("italic");
|
|
71
|
-
const isIcon = mods.includes("icon");
|
|
72
|
-
const isTight = mods.includes("tight");
|
|
73
|
-
mods = mods.filter((mod) => mod !== "strong" && mod !== "bold" && mod !== "italic" && mod !== "icon" && mod !== "tight");
|
|
74
|
-
const name = mods[0] || "inherit";
|
|
75
|
-
if (fontSize == null) setCSSValue(styles, "font-size", name);
|
|
76
|
-
if (lineHeight == null) setCSSValue(styles, "line-height", name);
|
|
77
|
-
if (letterSpacing == null) setCSSValue(styles, "letter-spacing", name);
|
|
78
|
-
if (fontWeight == null) setCSSValue(styles, "font-weight", name);
|
|
79
|
-
if (fontStyle == null) setCSSValue(styles, "font-style", name);
|
|
80
|
-
if (textTransform == null) setCSSValue(styles, "text-transform", name);
|
|
81
|
-
if (fontFamily == null && font == null) setCSSValue(styles, "font-family", name);
|
|
82
|
-
setCSSValue(styles, "bold-font-weight", name, true);
|
|
83
|
-
setCSSValue(styles, "icon-size", name, true);
|
|
84
|
-
if (isStrong) styles["font-weight"] = "var(--bold-font-weight)";
|
|
85
|
-
if (isItalic) styles["font-style"] = "italic";
|
|
86
|
-
if (isIcon) {
|
|
87
|
-
styles["font-size"] = "var(--icon-size)";
|
|
88
|
-
styles["line-height"] = "var(--icon-size)";
|
|
89
|
-
}
|
|
90
|
-
if (isTight) styles["line-height"] = "var(--font-size)";
|
|
91
|
-
}
|
|
92
|
-
const fontSizeVal = toCSS(fontSize, true);
|
|
93
|
-
if (fontSizeVal) styles["font-size"] = fontSizeVal;
|
|
94
|
-
const lineHeightVal = toCSS(lineHeight, true);
|
|
95
|
-
if (lineHeightVal) styles["line-height"] = lineHeightVal;
|
|
96
|
-
const letterSpacingVal = toCSS(letterSpacing, true);
|
|
97
|
-
if (letterSpacingVal) styles["letter-spacing"] = letterSpacingVal;
|
|
98
|
-
const fontWeightVal = toCSS(fontWeight, false);
|
|
99
|
-
if (fontWeightVal) styles["font-weight"] = fontWeightVal;
|
|
100
|
-
if (fontStyle != null) if (fontStyle === true) styles["font-style"] = "italic";
|
|
101
|
-
else if (fontStyle !== "inherit") styles["font-style"] = fontStyle ? "italic" : "normal";
|
|
102
|
-
else styles["font-style"] = "inherit";
|
|
103
|
-
if (textTransform) styles["text-transform"] = textTransform;
|
|
104
|
-
const fontResult = resolveFontFamily(font, fontFamily);
|
|
105
|
-
if (fontResult) {
|
|
106
|
-
styles["font-family"] = fontResult.value;
|
|
107
|
-
if (fontResult.setVar) styles["--font-family"] = fontResult.value;
|
|
108
|
-
}
|
|
109
|
-
if (Object.keys(styles).length === 0) return;
|
|
110
|
-
return styles;
|
|
111
|
-
}
|
|
112
|
-
presetStyle.__lookupStyles = [
|
|
113
|
-
"preset",
|
|
114
|
-
"fontSize",
|
|
115
|
-
"lineHeight",
|
|
116
|
-
"letterSpacing",
|
|
117
|
-
"textTransform",
|
|
118
|
-
"fontWeight",
|
|
119
|
-
"fontStyle",
|
|
120
|
-
"fontFamily",
|
|
121
|
-
"font"
|
|
122
|
-
];
|
|
123
|
-
|
|
124
|
-
//#endregion
|
|
125
|
-
export { presetStyle };
|
|
126
|
-
//# sourceMappingURL=preset.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preset.mjs","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 'preset',\n 'fontSize',\n 'lineHeight',\n 'letterSpacing',\n 'textTransform',\n 'fontWeight',\n 'fontStyle',\n 'fontFamily',\n 'font',\n];\n"],"mappings":";;;;;;;AAQA,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,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iBAAiB;CAC3B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD"}
|
package/dist/styles/radius.mjs
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { makeEmptyDetails } from "../parser/types.mjs";
|
|
2
|
-
import { DIRECTIONS, parseStyle } from "../utils/styles.mjs";
|
|
3
|
-
|
|
4
|
-
//#region src/styles/radius.ts
|
|
5
|
-
const PROP = "var(--radius)";
|
|
6
|
-
const SHARP = "var(--sharp-radius)";
|
|
7
|
-
function radiusStyle({ radius }) {
|
|
8
|
-
if (typeof radius === "number") radius = `${radius}px`;
|
|
9
|
-
if (!radius) return;
|
|
10
|
-
if (radius === true) radius = "1r";
|
|
11
|
-
const processed = parseStyle(radius);
|
|
12
|
-
const { mods } = processed.groups[0] ?? makeEmptyDetails();
|
|
13
|
-
let { values } = processed.groups[0] ?? makeEmptyDetails();
|
|
14
|
-
if (mods.includes("round")) values = ["9999rem"];
|
|
15
|
-
else if (mods.includes("ellipse")) values = ["50%"];
|
|
16
|
-
else if (!values.length) values = [PROP];
|
|
17
|
-
if (mods.includes("leaf")) values = [
|
|
18
|
-
values[1] || SHARP,
|
|
19
|
-
values[0] || PROP,
|
|
20
|
-
values[1] || SHARP,
|
|
21
|
-
values[0] || PROP
|
|
22
|
-
];
|
|
23
|
-
else if (mods.includes("backleaf")) values = [
|
|
24
|
-
values[0] || PROP,
|
|
25
|
-
values[1] || SHARP,
|
|
26
|
-
values[0] || PROP,
|
|
27
|
-
values[1] || SHARP
|
|
28
|
-
];
|
|
29
|
-
else if (mods.length) {
|
|
30
|
-
const arr = [
|
|
31
|
-
"0",
|
|
32
|
-
"0",
|
|
33
|
-
"0",
|
|
34
|
-
"0"
|
|
35
|
-
];
|
|
36
|
-
let flag = false;
|
|
37
|
-
DIRECTIONS.forEach((dir, i) => {
|
|
38
|
-
if (!mods.includes(dir)) return;
|
|
39
|
-
flag = true;
|
|
40
|
-
arr[i] = values[0] || PROP;
|
|
41
|
-
arr[(i + 1) % 4] = values[0] || PROP;
|
|
42
|
-
});
|
|
43
|
-
if (flag) values = arr;
|
|
44
|
-
}
|
|
45
|
-
return { "border-radius": values.join(" ") };
|
|
46
|
-
}
|
|
47
|
-
radiusStyle.__lookupStyles = ["radius"];
|
|
48
|
-
|
|
49
|
-
//#endregion
|
|
50
|
-
export { radiusStyle };
|
|
51
|
-
//# sourceMappingURL=radius.mjs.map
|