@ariaui/shadow 0.1.4 → 0.1.5

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.
@@ -0,0 +1,49 @@
1
+ import { ElevationLevel, Shadow, FocusRing } from './index.cjs';
2
+ export { ELEVATION_PRESETS, ElevationConfig, ShadowLayer, addLayer, buildRing, colorRing, colorShadow, createElevationScale, createErrorRing, createFocusRing, createLayer, createShadow, getElevationLevels, insetLayer, interpolateElevation, layerToString, mergeShadows, multiplyAlpha, offsetLayer, parseLayer, parseShadow, removeLayer, scaleLayer, scaleShadow, setLayerColor, setLayerOpacity, stepElevation, toBoxShadow, toCSSDeclaration, toCSSProperties, toTailwindClass, withFocusRing } from './index.cjs';
3
+ import '@ariaui/color';
4
+
5
+ /**
6
+ * Resolve a token shadow level to a structured `Shadow` object.
7
+ *
8
+ * Reads the depth layer colors from `@ariaui/tokens` semantic maps
9
+ * to get the correct alpha values for the given mode.
10
+ *
11
+ * @param level - Elevation level name
12
+ * @param mode - `"light"` or `"dark"` (default `"light"`)
13
+ *
14
+ * @example
15
+ * resolveShadow("md", "light")
16
+ * // → Shadow with 2 layers, alphas 0.102 and 0.059
17
+ *
18
+ * resolveShadow("md", "dark")
19
+ * // → Shadow with 2 layers, alphas 0.14 and 0.09
20
+ */
21
+ declare function resolveShadow(level: ElevationLevel, mode?: "light" | "dark"): Shadow;
22
+ /**
23
+ * Resolve all shadow elevation levels for a given mode.
24
+ */
25
+ declare function resolveAllShadows(mode?: "light" | "dark"): Record<ElevationLevel, Shadow>;
26
+ /**
27
+ * Resolve a focus ring from token values.
28
+ *
29
+ * @param variant - `"default"` (brand) or `"error"` (red)
30
+ *
31
+ * @example
32
+ * resolveFocusRing("default")
33
+ * // → FocusRing with brand-500 ringColor and white bgColor
34
+ */
35
+ declare function resolveFocusRing(variant?: "default" | "error"): FocusRing;
36
+ /**
37
+ * Resolve the layer alpha values for a given shadow level and mode.
38
+ *
39
+ * @returns Array of alpha values (one per depth layer).
40
+ */
41
+ declare function resolveLayerAlphas(level: ElevationLevel, mode?: "light" | "dark"): number[];
42
+ /**
43
+ * Calculate the dark/light alpha multiplier for a given shadow level.
44
+ *
45
+ * Returns the average ratio of dark-mode to light-mode alphas.
46
+ */
47
+ declare function resolveDarkMultiplier(level: ElevationLevel): number;
48
+
49
+ export { ElevationLevel, FocusRing, Shadow, resolveAllShadows, resolveDarkMultiplier, resolveFocusRing, resolveLayerAlphas, resolveShadow };
@@ -0,0 +1,49 @@
1
+ import { ElevationLevel, Shadow, FocusRing } from './index.js';
2
+ export { ELEVATION_PRESETS, ElevationConfig, ShadowLayer, addLayer, buildRing, colorRing, colorShadow, createElevationScale, createErrorRing, createFocusRing, createLayer, createShadow, getElevationLevels, insetLayer, interpolateElevation, layerToString, mergeShadows, multiplyAlpha, offsetLayer, parseLayer, parseShadow, removeLayer, scaleLayer, scaleShadow, setLayerColor, setLayerOpacity, stepElevation, toBoxShadow, toCSSDeclaration, toCSSProperties, toTailwindClass, withFocusRing } from './index.js';
3
+ import '@ariaui/color';
4
+
5
+ /**
6
+ * Resolve a token shadow level to a structured `Shadow` object.
7
+ *
8
+ * Reads the depth layer colors from `@ariaui/tokens` semantic maps
9
+ * to get the correct alpha values for the given mode.
10
+ *
11
+ * @param level - Elevation level name
12
+ * @param mode - `"light"` or `"dark"` (default `"light"`)
13
+ *
14
+ * @example
15
+ * resolveShadow("md", "light")
16
+ * // → Shadow with 2 layers, alphas 0.102 and 0.059
17
+ *
18
+ * resolveShadow("md", "dark")
19
+ * // → Shadow with 2 layers, alphas 0.14 and 0.09
20
+ */
21
+ declare function resolveShadow(level: ElevationLevel, mode?: "light" | "dark"): Shadow;
22
+ /**
23
+ * Resolve all shadow elevation levels for a given mode.
24
+ */
25
+ declare function resolveAllShadows(mode?: "light" | "dark"): Record<ElevationLevel, Shadow>;
26
+ /**
27
+ * Resolve a focus ring from token values.
28
+ *
29
+ * @param variant - `"default"` (brand) or `"error"` (red)
30
+ *
31
+ * @example
32
+ * resolveFocusRing("default")
33
+ * // → FocusRing with brand-500 ringColor and white bgColor
34
+ */
35
+ declare function resolveFocusRing(variant?: "default" | "error"): FocusRing;
36
+ /**
37
+ * Resolve the layer alpha values for a given shadow level and mode.
38
+ *
39
+ * @returns Array of alpha values (one per depth layer).
40
+ */
41
+ declare function resolveLayerAlphas(level: ElevationLevel, mode?: "light" | "dark"): number[];
42
+ /**
43
+ * Calculate the dark/light alpha multiplier for a given shadow level.
44
+ *
45
+ * Returns the average ratio of dark-mode to light-mode alphas.
46
+ */
47
+ declare function resolveDarkMultiplier(level: ElevationLevel): number;
48
+
49
+ export { ElevationLevel, FocusRing, Shadow, resolveAllShadows, resolveDarkMultiplier, resolveFocusRing, resolveLayerAlphas, resolveShadow };
package/dist/tokens.js ADDED
@@ -0,0 +1,167 @@
1
+ import {
2
+ ELEVATION_PRESETS,
3
+ __spreadProps,
4
+ __spreadValues,
5
+ addLayer,
6
+ buildRing,
7
+ colorRing,
8
+ colorShadow,
9
+ createElevationScale,
10
+ createErrorRing,
11
+ createFocusRing,
12
+ createLayer,
13
+ createShadow,
14
+ getElevationLevels,
15
+ insetLayer,
16
+ interpolateElevation,
17
+ layerToString,
18
+ mergeShadows,
19
+ multiplyAlpha,
20
+ offsetLayer,
21
+ parseLayer,
22
+ parseShadow,
23
+ removeLayer,
24
+ scaleLayer,
25
+ scaleShadow,
26
+ setLayerColor,
27
+ setLayerOpacity,
28
+ stepElevation,
29
+ toBoxShadow,
30
+ toCSSDeclaration,
31
+ toCSSProperties,
32
+ toTailwindClass,
33
+ withFocusRing
34
+ } from "./chunk-TCSURVQN.js";
35
+
36
+ // src/resolve.ts
37
+ import { light, dark, base } from "@ariaui/tokens";
38
+ var SHADOW_GEOMETRY = {
39
+ xs: [["0px", "1px", "2px", "0px"]],
40
+ sm: [["0px", "1px", "3px", "0px"], ["0px", "1px", "2px", "-1px"]],
41
+ md: [["0px", "4px", "6px", "-1px"], ["0px", "2px", "4px", "-2px"]],
42
+ lg: [["0px", "12px", "16px", "-4px"], ["0px", "4px", "6px", "-2px"], ["0px", "2px", "2px", "-1px"]],
43
+ xl: [["0px", "20px", "24px", "-4px"], ["0px", "8px", "8px", "-4px"], ["0px", "3px", "3px", "-1.5px"]],
44
+ "2xl": [["0px", "24px", "48px", "-12px"], ["0px", "4px", "4px", "-2px"]],
45
+ "3xl": [["0px", "32px", "64px", "-12px"], ["0px", "5px", "5px", "-2.5px"]]
46
+ };
47
+ var DEPTH_KEYS = {
48
+ xs: ["shadow-xs-depth-1"],
49
+ sm: ["shadow-sm-depth-1", "shadow-sm-depth-2"],
50
+ md: ["shadow-md-depth-1", "shadow-md-depth-2"],
51
+ lg: ["shadow-lg-depth-1", "shadow-lg-depth-2", "shadow-lg-depth-3"],
52
+ xl: ["shadow-xl-depth-1", "shadow-xl-depth-2", "shadow-xl-depth-3"],
53
+ "2xl": ["shadow-2xl-depth-1", "shadow-2xl-depth-2"],
54
+ "3xl": ["shadow-3xl-depth-1", "shadow-3xl-depth-2"]
55
+ };
56
+ function extractAlpha(tokenValue) {
57
+ const match = tokenValue.match(/\/\s*([\d.]+)\s*\)/);
58
+ if (match) return parseFloat(match[1]);
59
+ return 0;
60
+ }
61
+ function resolveBlack() {
62
+ const channels = base["black"];
63
+ return { l: 0, c: 0, h: 0, alpha: 1 };
64
+ }
65
+ function resolveShadow(level, mode = "light") {
66
+ if (level === "none") return { layers: [] };
67
+ const geometry = SHADOW_GEOMETRY[level];
68
+ const depthKeys = DEPTH_KEYS[level];
69
+ const map = mode === "dark" ? dark : light;
70
+ const baseColor = resolveBlack();
71
+ const layers = geometry.map((geo, i) => {
72
+ var _a, _b;
73
+ const depthKey = depthKeys[i];
74
+ const tokenValue = (_b = (_a = map[depthKey]) != null ? _a : light[depthKey]) != null ? _b : "";
75
+ const alpha = extractAlpha(tokenValue);
76
+ return {
77
+ offsetX: geo[0],
78
+ offsetY: geo[1],
79
+ blur: geo[2],
80
+ spread: geo[3],
81
+ color: __spreadProps(__spreadValues({}, baseColor), { alpha }),
82
+ inset: false
83
+ };
84
+ });
85
+ return { layers };
86
+ }
87
+ function resolveAllShadows(mode = "light") {
88
+ const levels = ["none", "xs", "sm", "md", "lg", "xl", "2xl", "3xl"];
89
+ return Object.fromEntries(
90
+ levels.map((level) => [level, resolveShadow(level, mode)])
91
+ );
92
+ }
93
+ function resolveFocusRing(variant = "default") {
94
+ var _a, _b;
95
+ const ringWidth = (_a = light["ring-width"]) != null ? _a : "2px";
96
+ const ringOffset = (_b = light["ring-offset"]) != null ? _b : "2px";
97
+ const ringColorKey = variant === "error" ? "focus-ring-error-color" : "focus-ring-color";
98
+ const ringColorRef = light[ringColorKey];
99
+ const bgColor = { l: 1, c: 0, h: 0, alpha: 1 };
100
+ let ringColor;
101
+ if (variant === "error") {
102
+ ringColor = { l: 0.637, c: 0.208, h: 25, alpha: 1 };
103
+ } else {
104
+ ringColor = { l: 0.606, c: 0.219, h: 293, alpha: 1 };
105
+ }
106
+ return { ringWidth, ringOffset, ringColor, bgColor };
107
+ }
108
+ function resolveLayerAlphas(level, mode = "light") {
109
+ if (level === "none") return [];
110
+ const depthKeys = DEPTH_KEYS[level];
111
+ const map = mode === "dark" ? dark : light;
112
+ return depthKeys.map((key) => {
113
+ var _a, _b;
114
+ const value = (_b = (_a = map[key]) != null ? _a : light[key]) != null ? _b : "";
115
+ return extractAlpha(value);
116
+ });
117
+ }
118
+ function resolveDarkMultiplier(level) {
119
+ if (level === "none") return 1;
120
+ const lightAlphas = resolveLayerAlphas(level, "light");
121
+ const darkAlphas = resolveLayerAlphas(level, "dark");
122
+ if (lightAlphas.length === 0) return 1;
123
+ let totalRatio = 0;
124
+ for (let i = 0; i < lightAlphas.length; i++) {
125
+ if (lightAlphas[i] > 0) {
126
+ totalRatio += darkAlphas[i] / lightAlphas[i];
127
+ }
128
+ }
129
+ return Math.round(totalRatio / lightAlphas.length * 1e3) / 1e3;
130
+ }
131
+ export {
132
+ ELEVATION_PRESETS,
133
+ addLayer,
134
+ buildRing,
135
+ colorRing,
136
+ colorShadow,
137
+ createElevationScale,
138
+ createErrorRing,
139
+ createFocusRing,
140
+ createLayer,
141
+ createShadow,
142
+ getElevationLevels,
143
+ insetLayer,
144
+ interpolateElevation,
145
+ layerToString,
146
+ mergeShadows,
147
+ multiplyAlpha,
148
+ offsetLayer,
149
+ parseLayer,
150
+ parseShadow,
151
+ removeLayer,
152
+ resolveAllShadows,
153
+ resolveDarkMultiplier,
154
+ resolveFocusRing,
155
+ resolveLayerAlphas,
156
+ resolveShadow,
157
+ scaleLayer,
158
+ scaleShadow,
159
+ setLayerColor,
160
+ setLayerOpacity,
161
+ stepElevation,
162
+ toBoxShadow,
163
+ toCSSDeclaration,
164
+ toCSSProperties,
165
+ toTailwindClass,
166
+ withFocusRing
167
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ariaui/shadow",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -24,10 +24,10 @@
24
24
  ],
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "@ariaui/color": "0.1.3"
27
+ "@ariaui/color": "0.1.4"
28
28
  },
29
29
  "peerDependencies": {
30
- "@ariaui/tokens": "0.2.0"
30
+ "@ariaui/tokens": "0.2.1"
31
31
  },
32
32
  "peerDependenciesMeta": {
33
33
  "@ariaui/tokens": {
@@ -35,7 +35,7 @@
35
35
  }
36
36
  },
37
37
  "devDependencies": {
38
- "@ariaui/tokens": "0.2.0"
38
+ "@ariaui/tokens": "0.2.1"
39
39
  },
40
40
  "scripts": {
41
41
  "build": "rimraf dist && tsup",