@xaui/native 0.9.1-alpha.0 → 0.9.1-alpha.2

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,100 @@
1
+ // src/utils/colors.ts
2
+ var srgbToLinear = (c) => c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
3
+ var linearToSrgb = (c) => c <= 31308e-7 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055;
4
+ var clamp01 = (n) => Math.min(1, Math.max(0, n));
5
+ var HEX = /^#?(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
6
+ function isHex(value) {
7
+ return HEX.test(value);
8
+ }
9
+ function hexToRgb(hex) {
10
+ if (!isHex(hex)) {
11
+ throw new Error(
12
+ `XAUI: "${hex}" is not a hex colour. Tokens that feed mix() and alpha() must be #rgb or #rrggbb \u2014 named colours and rgb()/rgba() values cannot be blended.`
13
+ );
14
+ }
15
+ const raw = hex.replace("#", "");
16
+ const full = raw.length === 3 ? raw.split("").map((c) => c + c).join("") : raw;
17
+ return [
18
+ parseInt(full.slice(0, 2), 16) / 255,
19
+ parseInt(full.slice(2, 4), 16) / 255,
20
+ parseInt(full.slice(4, 6), 16) / 255
21
+ ];
22
+ }
23
+ function rgbToHex([r, g, b]) {
24
+ const to = (n) => Math.round(clamp01(n) * 255).toString(16).padStart(2, "0");
25
+ return `#${to(r)}${to(g)}${to(b)}`;
26
+ }
27
+ function rgbToOklab([r, g, b]) {
28
+ const R = srgbToLinear(r);
29
+ const G = srgbToLinear(g);
30
+ const B = srgbToLinear(b);
31
+ const l = Math.cbrt(0.4122214708 * R + 0.5363325363 * G + 0.0514459929 * B);
32
+ const m = Math.cbrt(0.2119034982 * R + 0.6806995451 * G + 0.1073969566 * B);
33
+ const s = Math.cbrt(0.0883024619 * R + 0.2817188376 * G + 0.6299787005 * B);
34
+ return [
35
+ 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
36
+ 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
37
+ 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s
38
+ ];
39
+ }
40
+ function oklabToRgb([L, a, b]) {
41
+ const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
42
+ const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
43
+ const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
44
+ return [
45
+ clamp01(linearToSrgb(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s)),
46
+ clamp01(linearToSrgb(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s)),
47
+ clamp01(linearToSrgb(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s))
48
+ ];
49
+ }
50
+ function mix(base, other, amount) {
51
+ const from = rgbToOklab(hexToRgb(base));
52
+ const to = rgbToOklab(hexToRgb(other));
53
+ return rgbToHex(
54
+ oklabToRgb([
55
+ from[0] + (to[0] - from[0]) * amount,
56
+ from[1] + (to[1] - from[1]) * amount,
57
+ from[2] + (to[2] - from[2]) * amount
58
+ ])
59
+ );
60
+ }
61
+ function alpha(hex, amount) {
62
+ const [r, g, b] = hexToRgb(hex).map((v) => Math.round(v * 255));
63
+ return `rgba(${r}, ${g}, ${b}, ${amount})`;
64
+ }
65
+ function lightnessOf(hex) {
66
+ return rgbToOklab(hexToRgb(hex))[0];
67
+ }
68
+ function contrastOn(hex, light, dark) {
69
+ return lightnessOf(hex) > 0.62 ? dark : light;
70
+ }
71
+
72
+ // src/theme/derive-tint.ts
73
+ var cache = /* @__PURE__ */ new Map();
74
+ function deriveTint(tint, theme) {
75
+ const key = `${theme.id}|${theme.mode}|${tint}`;
76
+ const hit = cache.get(key);
77
+ if (hit) return hit;
78
+ if (!isHex(tint)) {
79
+ throw new Error(
80
+ `XAUI: color="${tint}" must be a hex value (#rgb or #rrggbb). A tint's contrasted, soft and pressed slices are derived in OKLab, which cannot read rgba() or a named colour. Pass the hex here and put the transparency in \`style\`.`
81
+ );
82
+ }
83
+ const foreground = contrastOn(tint, theme.colors.snow, theme.colors.eclipse);
84
+ const derived = {
85
+ base: tint,
86
+ foreground,
87
+ soft: alpha(tint, 0.15),
88
+ softForeground: mix(tint, theme.colors.foreground, 0.2),
89
+ pressed: mix(tint, foreground, 0.1),
90
+ softPressed: alpha(tint, 0.2)
91
+ };
92
+ cache.set(key, derived);
93
+ return derived;
94
+ }
95
+
96
+ export {
97
+ mix,
98
+ alpha,
99
+ deriveTint
100
+ };
@@ -0,0 +1,274 @@
1
+ import {
2
+ deriveTint
3
+ } from "./chunk-RBNCR5KB.js";
4
+
5
+ // src/system/recipe/resolve-tint.ts
6
+ var TINT_SLICE_BY_SUFFIX = [
7
+ [/SoftForeground$/, "softForeground"],
8
+ [/SoftPressed$/, "softPressed"],
9
+ [/Soft$/, "soft"],
10
+ [/Foreground$/, "foreground"],
11
+ [/Pressed$/, "pressed"]
12
+ ];
13
+ function tintSliceFor(token) {
14
+ for (const [suffix, slice] of TINT_SLICE_BY_SUFFIX) {
15
+ if (suffix.test(token)) return slice;
16
+ }
17
+ return "base";
18
+ }
19
+ function resolveTint(tokens, color, theme) {
20
+ const tint = deriveTint(color, theme);
21
+ const colors = {};
22
+ for (const [role, token] of Object.entries(tokens ?? {})) {
23
+ colors[role] = tint[tintSliceFor(token)];
24
+ }
25
+ return colors;
26
+ }
27
+
28
+ // src/system/recipe/style-cache.ts
29
+ import { StyleSheet } from "react-native";
30
+
31
+ // src/system/recipe/variant-map.ts
32
+ var STATE_ORDER = ["focused", "pressed", "disabled"];
33
+ function resolveSelection(defaultVariants, selection) {
34
+ const resolved = { ...defaultVariants };
35
+ for (const [axis, value] of Object.entries(selection ?? {})) {
36
+ if (value !== void 0) resolved[axis] = value;
37
+ }
38
+ return resolved;
39
+ }
40
+ function resolveVariantColors(tokens, theme) {
41
+ const colors = {};
42
+ for (const [role, token] of entriesOf(tokens)) {
43
+ const value = theme.colors[token];
44
+ if (value === void 0) {
45
+ throw new Error(
46
+ `XAUI: the recipe names "${token}" for its "${role}" role, but the theme has no such colour token. Check the spelling against XAUIColors.`
47
+ );
48
+ }
49
+ colors[role] = value;
50
+ }
51
+ return colors;
52
+ }
53
+ function activeStateFns(states, active) {
54
+ const fns = [];
55
+ for (const state of STATE_ORDER) {
56
+ const fn = active[state] ? states?.[state] : void 0;
57
+ if (fn) fns.push(fn);
58
+ }
59
+ return fns;
60
+ }
61
+ function collectStyleFns(config, selection, states) {
62
+ const fns = [];
63
+ if (config.base) fns.push(config.base);
64
+ if (config.paint) fns.push(config.paint);
65
+ for (const [axis, values] of Object.entries(config.variants ?? {})) {
66
+ const value = selection[axis];
67
+ const fn = value === void 0 ? void 0 : values[value];
68
+ if (fn) fns.push(fn);
69
+ }
70
+ for (const compound of config.compoundVariants ?? []) {
71
+ if (appliesTo(compound.when, selection)) fns.push(compound.style);
72
+ }
73
+ return [...fns, ...activeStateFns(config.states, states)];
74
+ }
75
+ function appliesTo(when, selection) {
76
+ return Object.entries(when).every(([axis, value]) => selection[axis] === value);
77
+ }
78
+ function entriesOf(tokens) {
79
+ return Object.entries(tokens ?? {});
80
+ }
81
+
82
+ // src/system/recipe/style-cache.ts
83
+ function createStyleCache(slots) {
84
+ const entries = /* @__PURE__ */ new Map();
85
+ return {
86
+ read(key, build) {
87
+ const hit = entries.get(key);
88
+ if (hit) return hit;
89
+ const built = build();
90
+ const complete = {};
91
+ for (const slot of slots) complete[slot] = built[slot] ?? {};
92
+ const created = StyleSheet.create(complete);
93
+ entries.set(key, created);
94
+ return created;
95
+ },
96
+ get size() {
97
+ return entries.size;
98
+ },
99
+ clear() {
100
+ entries.clear();
101
+ }
102
+ };
103
+ }
104
+ function cacheKey(theme, selection, states) {
105
+ const axes = Object.keys(selection).sort().map((axis) => `${axis}:${selection[axis] ?? "-"}`).join("|");
106
+ const active = STATE_ORDER.filter((state) => states[state]).join(",");
107
+ return `${theme.id}|${theme.mode}|${axes}|${active}`;
108
+ }
109
+
110
+ // src/system/recipe/create-recipe.ts
111
+ function createRecipe(config) {
112
+ const cache = createStyleCache(config.slots);
113
+ const tokensFor = (variant) => variant === void 0 ? void 0 : config.variantTokens?.[variant];
114
+ return {
115
+ slots: config.slots,
116
+ resolve({ theme, selection, states = {} }) {
117
+ const resolved = resolveSelection(config.defaultVariants, selection);
118
+ return cache.read(cacheKey(theme, resolved, states), () => {
119
+ const colors = resolveVariantColors(tokensFor(resolved.variant), theme);
120
+ return apply(collectStyleFns(config, resolved, states), theme, colors);
121
+ });
122
+ },
123
+ tint({ theme, color, selection, states = {} }) {
124
+ if (!config.paint) return {};
125
+ const resolved = resolveSelection(config.defaultVariants, selection);
126
+ const tokens = tokensFor(resolved.variant);
127
+ if (!tokens) return {};
128
+ const colors = resolveTint(tokens, color, theme);
129
+ const fns = [config.paint, ...activeStateFns(config.states, states)];
130
+ return apply(fns, theme, colors);
131
+ }
132
+ };
133
+ }
134
+ function apply(fns, theme, colors) {
135
+ const merged = {};
136
+ for (const fn of fns) {
137
+ const produced = fn(theme, colors);
138
+ for (const slot of Object.keys(produced)) {
139
+ const style = produced[slot];
140
+ if (!style) continue;
141
+ const previous = merged[slot];
142
+ merged[slot] = previous ? { ...previous, ...style } : style;
143
+ }
144
+ }
145
+ return merged;
146
+ }
147
+
148
+ // src/system/slot/children-to-string.ts
149
+ import { isValidElement } from "react";
150
+ function childrenToString(children) {
151
+ const text = stringify(children);
152
+ return text === null || text === "" ? null : text;
153
+ }
154
+ function stringify(node) {
155
+ if (node === null || node === void 0 || typeof node === "boolean") return "";
156
+ if (typeof node === "string") return node;
157
+ if (typeof node === "number") return String(node);
158
+ if (isValidElement(node)) return null;
159
+ if (Array.isArray(node)) {
160
+ let text = "";
161
+ for (const child of node) {
162
+ const part = stringify(child);
163
+ if (part === null) return null;
164
+ text += part;
165
+ }
166
+ return text;
167
+ }
168
+ return null;
169
+ }
170
+
171
+ // src/system/slot/create-slot-context.ts
172
+ import { createContext, useContext } from "react";
173
+ function createSlotContext(name) {
174
+ const Context = createContext(null);
175
+ Context.displayName = `XAUI.${name}.Context`;
176
+ function useSlotContext() {
177
+ const value = useContext(Context);
178
+ if (value === null) {
179
+ const error = new Error(
180
+ `XAUI: use${name} must be called inside <${name}>. A slot reads the values its root resolved, so it can only be rendered as a child of one.`
181
+ );
182
+ Error.captureStackTrace?.(
183
+ error,
184
+ useSlotContext
185
+ );
186
+ throw error;
187
+ }
188
+ return value;
189
+ }
190
+ return [Context.Provider, useSlotContext];
191
+ }
192
+
193
+ // src/system/slot/merge-refs.ts
194
+ function mergeRefs(...refs) {
195
+ return (value) => {
196
+ for (const ref of refs) {
197
+ if (typeof ref === "function") ref(value);
198
+ else if (ref) ref.current = value;
199
+ }
200
+ };
201
+ }
202
+
203
+ // src/system/slot/merge-props.ts
204
+ var EVENT_HANDLER = /^on[A-Z]/;
205
+ function mergeProps(ours, theirs) {
206
+ const merged = { ...ours };
207
+ for (const key of Object.keys(theirs)) {
208
+ const ourValue = ours[key];
209
+ const theirValue = theirs[key];
210
+ if (EVENT_HANDLER.test(key)) {
211
+ merged[key] = composeHandlers(ourValue, theirValue);
212
+ } else if (key === "style") {
213
+ merged[key] = mergeStyles(ourValue, theirValue);
214
+ } else if (key === "ref") {
215
+ merged[key] = mergeRefs(
216
+ ourValue,
217
+ theirValue
218
+ );
219
+ } else {
220
+ merged[key] = theirValue;
221
+ }
222
+ }
223
+ return merged;
224
+ }
225
+ function composeHandlers(ours, theirs) {
226
+ if (typeof ours !== "function") return theirs;
227
+ if (typeof theirs !== "function") return ours;
228
+ return (...args) => {
229
+ ;
230
+ ours(...args);
231
+ return theirs(...args);
232
+ };
233
+ }
234
+ function mergeStyles(ours, theirs) {
235
+ if (typeof ours === "function" || typeof theirs === "function") {
236
+ return (state) => [
237
+ resolveStyle(ours, state),
238
+ resolveStyle(theirs, state)
239
+ ];
240
+ }
241
+ return [ours, theirs];
242
+ }
243
+ function resolveStyle(style, state) {
244
+ return typeof style === "function" ? style(state) : style;
245
+ }
246
+
247
+ // src/system/slot/slot.tsx
248
+ import { cloneElement, forwardRef, isValidElement as isValidElement2 } from "react";
249
+ var Slot = forwardRef(function Slot2({ children, ...ours }, ref) {
250
+ if (!isValidElement2(children)) {
251
+ throw new Error(
252
+ "XAUI: asChild expects exactly one React element as its child, and merges the component's props into it. Text, a fragment, several children or none give it nothing to merge into \u2014 drop `asChild` to render the component itself."
253
+ );
254
+ }
255
+ const child = children;
256
+ const merged = mergeProps(ours, child.props);
257
+ merged.ref = mergeRefs(ref, refOf(child));
258
+ return cloneElement(child, merged);
259
+ });
260
+ Slot.displayName = "XAUI.Slot";
261
+ function refOf(element) {
262
+ const fromProps = element.props.ref;
263
+ const fromElement = element.ref;
264
+ return fromProps ?? fromElement;
265
+ }
266
+
267
+ export {
268
+ createRecipe,
269
+ childrenToString,
270
+ createSlotContext,
271
+ mergeRefs,
272
+ mergeProps,
273
+ Slot
274
+ };
package/dist/index.cjs CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
 
7
7
 
8
+ var _chunkB755PRVJcjs = require('./chunk-B755PRVJ.cjs');
8
9
 
9
10
 
10
11
 
@@ -13,7 +14,6 @@
13
14
 
14
15
 
15
16
 
16
- var _chunkJDS6KGCMcjs = require('./chunk-JDS6KGCM.cjs');
17
17
 
18
18
 
19
19
 
@@ -21,12 +21,30 @@ var _chunkJDS6KGCMcjs = require('./chunk-JDS6KGCM.cjs');
21
21
 
22
22
 
23
23
 
24
+ var _chunkNHPQQQ7Pcjs = require('./chunk-NHPQQQ7P.cjs');
24
25
 
25
26
 
27
+ var _chunkM7P46XKIcjs = require('./chunk-M7P46XKI.cjs');
26
28
 
27
29
 
28
30
 
29
31
 
30
32
 
31
33
 
32
- exports.ThemeContext = _chunkJDS6KGCMcjs.ThemeContext; exports.XAUIProvider = _chunkJDS6KGCMcjs.XAUIProvider; exports.buildRadius = _chunkJDS6KGCMcjs.buildRadius; exports.buildShadows = _chunkJDS6KGCMcjs.buildShadows; exports.createTheme = _chunkJDS6KGCMcjs.createTheme; exports.defaultTheme = _chunkJDS6KGCMcjs.defaultTheme; exports.deriveColors = _chunkJDS6KGCMcjs.deriveColors; exports.palette = _chunkJDS6KGCMcjs.palette; exports.primitives = _chunkJDS6KGCMcjs.primitives; exports.sourceKeys = _chunkJDS6KGCMcjs.sourceKeys; exports.tokens = _chunkJDS6KGCMcjs.tokens; exports.useColorMode = _chunkJDS6KGCMcjs.useColorMode; exports.useThemeColor = _chunkJDS6KGCMcjs.useThemeColor; exports.useXAUITheme = _chunkJDS6KGCMcjs.useXAUITheme;
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+ exports.Slot = _chunkB755PRVJcjs.Slot; exports.ThemeContext = _chunkNHPQQQ7Pcjs.ThemeContext; exports.XAUIProvider = _chunkNHPQQQ7Pcjs.XAUIProvider; exports.buildRadius = _chunkNHPQQQ7Pcjs.buildRadius; exports.buildShadows = _chunkNHPQQQ7Pcjs.buildShadows; exports.childrenToString = _chunkB755PRVJcjs.childrenToString; exports.createRecipe = _chunkB755PRVJcjs.createRecipe; exports.createSlotContext = _chunkB755PRVJcjs.createSlotContext; exports.createTheme = _chunkNHPQQQ7Pcjs.createTheme; exports.defaultTheme = _chunkNHPQQQ7Pcjs.defaultTheme; exports.deriveColors = _chunkNHPQQQ7Pcjs.deriveColors; exports.deriveTint = _chunkM7P46XKIcjs.deriveTint; exports.mergeProps = _chunkB755PRVJcjs.mergeProps; exports.mergeRefs = _chunkB755PRVJcjs.mergeRefs; exports.palette = _chunkNHPQQQ7Pcjs.palette; exports.primitives = _chunkNHPQQQ7Pcjs.primitives; exports.sourceKeys = _chunkNHPQQQ7Pcjs.sourceKeys; exports.tokens = _chunkNHPQQQ7Pcjs.tokens; exports.useColorMode = _chunkNHPQQQ7Pcjs.useColorMode; exports.useThemeColor = _chunkNHPQQQ7Pcjs.useThemeColor; exports.useXAUITheme = _chunkNHPQQQ7Pcjs.useXAUITheme;
package/dist/index.d.cts CHANGED
@@ -1,2 +1,5 @@
1
- export { ColorMode, ColorModePreference, FontSizeKey, FontWeightKey, PaletteFamily, PaletteShade, RadiusKey, Size, ThemeContext, XAUIColors, XAUIDerivedColors, XAUIPrimitiveColors, XAUIProvider, XAUIProviderProps, XAUIRadius, XAUIShadow, XAUISourceColors, XAUITheme, XAUIThemeConfig, XAUIThemeSet, buildRadius, buildShadows, createTheme, defaultTheme, deriveColors, palette, primitives, sourceKeys, tokens, useColorMode, useThemeColor, useXAUITheme } from './theme/index.cjs';
1
+ export { AsChildProps, Axes, CompoundVariant, MergeableProps, PossibleRef, Recipe, RecipeConfig, ResolveArgs, ResolvedSelection, ResolvedStyles, Selection, Slot, SlotProps, SlotStyle, SlotStyles, StateName, States, StyleFn, TintArgs, VariantColors, VariantRole, VariantTokens, childrenToString, createRecipe, createSlotContext, mergeProps, mergeRefs } from './system/index.cjs';
2
+ export { ColorModePreference, PaletteFamily, PaletteShade, ThemeContext, XAUIProvider, XAUIProviderProps, XAUITint, buildRadius, buildShadows, createTheme, defaultTheme, deriveColors, deriveTint, palette, primitives, sourceKeys, tokens, useColorMode, useThemeColor, useXAUITheme } from './theme/index.cjs';
3
+ export { C as ColorMode, F as FontSizeKey, a as FontWeightKey, R as RadiusKey, S as Size, X as XAUIColors, b as XAUIDerivedColors, c as XAUIPrimitiveColors, d as XAUIRadius, e as XAUIShadow, f as XAUISourceColors, g as XAUITheme, h as XAUIThemeConfig, i as XAUIThemeSet } from './theme.type-B3ODSLbB.cjs';
4
+ import 'react-native';
2
5
  import 'react';
package/dist/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
- export { ColorMode, ColorModePreference, FontSizeKey, FontWeightKey, PaletteFamily, PaletteShade, RadiusKey, Size, ThemeContext, XAUIColors, XAUIDerivedColors, XAUIPrimitiveColors, XAUIProvider, XAUIProviderProps, XAUIRadius, XAUIShadow, XAUISourceColors, XAUITheme, XAUIThemeConfig, XAUIThemeSet, buildRadius, buildShadows, createTheme, defaultTheme, deriveColors, palette, primitives, sourceKeys, tokens, useColorMode, useThemeColor, useXAUITheme } from './theme/index.js';
1
+ export { AsChildProps, Axes, CompoundVariant, MergeableProps, PossibleRef, Recipe, RecipeConfig, ResolveArgs, ResolvedSelection, ResolvedStyles, Selection, Slot, SlotProps, SlotStyle, SlotStyles, StateName, States, StyleFn, TintArgs, VariantColors, VariantRole, VariantTokens, childrenToString, createRecipe, createSlotContext, mergeProps, mergeRefs } from './system/index.js';
2
+ export { ColorModePreference, PaletteFamily, PaletteShade, ThemeContext, XAUIProvider, XAUIProviderProps, XAUITint, buildRadius, buildShadows, createTheme, defaultTheme, deriveColors, deriveTint, palette, primitives, sourceKeys, tokens, useColorMode, useThemeColor, useXAUITheme } from './theme/index.js';
3
+ export { C as ColorMode, F as FontSizeKey, a as FontWeightKey, R as RadiusKey, S as Size, X as XAUIColors, b as XAUIDerivedColors, c as XAUIPrimitiveColors, d as XAUIRadius, e as XAUIShadow, f as XAUISourceColors, g as XAUITheme, h as XAUIThemeConfig, i as XAUIThemeSet } from './theme.type-B3ODSLbB.js';
4
+ import 'react-native';
2
5
  import 'react';
package/dist/index.js CHANGED
@@ -1,3 +1,11 @@
1
+ import {
2
+ Slot,
3
+ childrenToString,
4
+ createRecipe,
5
+ createSlotContext,
6
+ mergeProps,
7
+ mergeRefs
8
+ } from "./chunk-RCP3SD26.js";
1
9
  import {
2
10
  ThemeContext,
3
11
  XAUIProvider,
@@ -13,15 +21,25 @@ import {
13
21
  useColorMode,
14
22
  useThemeColor,
15
23
  useXAUITheme
16
- } from "./chunk-T3ZI2PZ6.js";
24
+ } from "./chunk-PBVPOX7D.js";
25
+ import {
26
+ deriveTint
27
+ } from "./chunk-RBNCR5KB.js";
17
28
  export {
29
+ Slot,
18
30
  ThemeContext,
19
31
  XAUIProvider,
20
32
  buildRadius,
21
33
  buildShadows,
34
+ childrenToString,
35
+ createRecipe,
36
+ createSlotContext,
22
37
  createTheme,
23
38
  defaultTheme,
24
39
  deriveColors,
40
+ deriveTint,
41
+ mergeProps,
42
+ mergeRefs,
25
43
  palette,
26
44
  primitives,
27
45
  sourceKeys,
@@ -0,0 +1,17 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+
7
+
8
+ var _chunkB755PRVJcjs = require('../chunk-B755PRVJ.cjs');
9
+ require('../chunk-M7P46XKI.cjs');
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+ exports.Slot = _chunkB755PRVJcjs.Slot; exports.childrenToString = _chunkB755PRVJcjs.childrenToString; exports.createRecipe = _chunkB755PRVJcjs.createRecipe; exports.createSlotContext = _chunkB755PRVJcjs.createSlotContext; exports.mergeProps = _chunkB755PRVJcjs.mergeProps; exports.mergeRefs = _chunkB755PRVJcjs.mergeRefs;
@@ -0,0 +1,174 @@
1
+ import { g as XAUITheme, X as XAUIColors } from '../theme.type-B3ODSLbB.cjs';
2
+ import { ViewStyle, TextStyle } from 'react-native';
3
+ import * as react from 'react';
4
+ import { ReactNode, Provider, Ref, RefCallback } from 'react';
5
+
6
+ /**
7
+ * A slot is a view or a text node, and a recipe writes one object per slot, so the two
8
+ * RN style shapes are merged rather than discriminated per slot.
9
+ */
10
+ type SlotStyle = ViewStyle & TextStyle;
11
+ type SlotStyles<Slot extends string> = Partial<Record<Slot, SlotStyle>>;
12
+ /** The roles a variant consumes. The variant names tokens; `paint` says where they land. */
13
+ type VariantRole = 'bg' | 'bgPressed' | 'fg' | 'border';
14
+ /** Token names per role — no colour value ever appears in a recipe. */
15
+ type VariantTokens = Partial<Record<VariantRole, keyof XAUIColors>>;
16
+ /** The same roles resolved: theme colours, or the slices of a raw `color`. */
17
+ type VariantColors = Partial<Record<VariantRole, string>>;
18
+ /**
19
+ * `disabled` is applied last of the three: a control that is both pressed and disabled
20
+ * has to read disabled.
21
+ */
22
+ type StateName = 'focused' | 'pressed' | 'disabled';
23
+ type States = Partial<Record<StateName, boolean>>;
24
+ /** Reads the theme and the variant's resolved colours; returns one style per slot. */
25
+ type StyleFn<Slot extends string> = (theme: XAUITheme, colors: VariantColors) => SlotStyles<Slot>;
26
+ /** Named axes of finite token values — `{ size: { sm: fn, md: fn } }`. */
27
+ type Axes<Slot extends string> = Record<string, Record<string, StyleFn<Slot>>>;
28
+ /** One value per axis, plus the variant. Missing keys fall back to `defaultVariants`. */
29
+ type Selection<Variant extends string, A extends Axes<string>> = {
30
+ variant?: Variant;
31
+ } & {
32
+ [Axis in keyof A]?: Extract<keyof A[Axis], string>;
33
+ };
34
+ type CompoundVariant<Slot extends string, Variant extends string, A extends Axes<Slot>> = {
35
+ when: Selection<Variant, A>;
36
+ style: StyleFn<Slot>;
37
+ };
38
+ type RecipeConfig<Slot extends string, Variant extends string, A extends Axes<Slot>> = {
39
+ /** Every slot the component publishes. Slots a recipe never styles resolve to `{}`. */
40
+ slots: readonly Slot[];
41
+ base?: StyleFn<Slot>;
42
+ variantTokens?: Record<Variant, VariantTokens>;
43
+ /** Where the variant's colours land — written once, and it holds for every variant. */
44
+ paint?: StyleFn<Slot>;
45
+ variants?: A;
46
+ compoundVariants?: ReadonlyArray<CompoundVariant<Slot, Variant, A>>;
47
+ states?: Partial<Record<StateName, StyleFn<Slot>>>;
48
+ defaultVariants?: Selection<Variant, A>;
49
+ };
50
+ /** Stable references: the same object for the same tokens, for the app's lifetime. */
51
+ type ResolvedStyles<Slot extends string> = Readonly<Record<Slot, SlotStyle>>;
52
+ /** A selection with `defaultVariants` already folded in, keyed by axis name. */
53
+ type ResolvedSelection = Readonly<Record<string, string | undefined>>;
54
+
55
+ type ResolveArgs<Variant extends string, A extends Axes<string>> = {
56
+ theme: XAUITheme;
57
+ selection?: Selection<Variant, A>;
58
+ states?: States;
59
+ };
60
+ type TintArgs<Variant extends string, A extends Axes<string>> = ResolveArgs<Variant, A> & {
61
+ color: string;
62
+ };
63
+ type Recipe<Slot extends string, Variant extends string, A extends Axes<Slot>> = {
64
+ readonly slots: readonly Slot[];
65
+ /** The cached pass: stable `StyleSheet` references, keyed by tokens alone. */
66
+ resolve(args: ResolveArgs<Variant, A>): ResolvedStyles<Slot>;
67
+ /**
68
+ * The tint pass: the same functions run again with `color`'s slices in place of the
69
+ * theme's tokens. Uncached and allocating, and only ever called when `color` is set.
70
+ */
71
+ tint(args: TintArgs<Variant, A>): SlotStyles<Slot>;
72
+ };
73
+ /**
74
+ * A component's style, declared once. Resolution splits in two because the two halves
75
+ * have different lifetimes: everything keyed by a finite token is cached forever, and
76
+ * an arbitrary `color` is recomputed per render — which is what keeps the cache bounded
77
+ * by the number of token combinations rather than by the palette users invent.
78
+ *
79
+ * const styles = buttonRecipe.resolve({ theme, selection: { variant, size }, states })
80
+ * const tint = color ? buttonRecipe.tint({ theme, color, selection, states }) : undefined
81
+ * <View style={[styles.root, tint?.root, style]} />
82
+ */
83
+ declare function createRecipe<Slot extends string, Variant extends string, const A extends Axes<Slot>>(config: RecipeConfig<Slot, Variant, A>): Recipe<Slot, Variant, A>;
84
+
85
+ /**
86
+ * R3: the string a root should wrap in its default text slot, or `null` when it should
87
+ * render its children as they are.
88
+ *
89
+ * The whole tree is stringified recursively rather than the first child inspected. That
90
+ * is what makes `<Button>{count} items</Button>` work — children there are the array
91
+ * `[3, ' items']`, and an `isValidElement` check on the first entry would call it an
92
+ * element-free tree only by accident, while a check for "is the first child a string"
93
+ * would miss it outright.
94
+ *
95
+ * `null` for an empty result as much as for a tree containing an element: in both cases
96
+ * there is nothing to wrap, and a root's fallback — render the children — is right for
97
+ * both. It also keeps `<Button>{false}</Button>` from mounting an empty text node.
98
+ */
99
+ declare function childrenToString(children: ReactNode): string | null;
100
+
101
+ /**
102
+ * A context a slot cannot read by accident. Every compound gets one, and it carries
103
+ * **resolved** values — style references the root already computed, not tokens for the
104
+ * slot to resolve again (R5).
105
+ *
106
+ * ```ts
107
+ * const [ButtonProvider, useButton] = createSlotContext<ButtonContext>('Button')
108
+ * ```
109
+ *
110
+ * The tuple is what lets each compound name its own hook, which R10 requires it to
111
+ * export. `name` gives both halves of the error, so there is one place to spell it.
112
+ */
113
+ declare function createSlotContext<T>(name: string): readonly [Provider<T | null>, () => T];
114
+
115
+ /** Anything React accepts as a ref, plus the absence of one. */
116
+ type PossibleRef<T> = Ref<T> | undefined;
117
+ /**
118
+ * The props `mergeProps` knows how to combine. Deliberately loose: it merges whatever a
119
+ * root hands to whatever child it was given, and neither side is knowable from here.
120
+ */
121
+ type MergeableProps = Record<string, unknown>;
122
+ type AsChildProps = {
123
+ /**
124
+ * Merge this component's props into its single child instead of rendering an element
125
+ * of its own — a navigation `Link` as a `Button`, a bespoke trigger as a `Select`.
126
+ */
127
+ asChild?: boolean;
128
+ };
129
+
130
+ /**
131
+ * Merges a root's own props into the child it renders through `asChild` (R12). Four
132
+ * rules, and the child wins wherever they do not apply — it is the more specific intent:
133
+ *
134
+ * - **Event handlers compose.** Both run, ours first: the component's own behaviour (the
135
+ * press state that drives its styles) happens before the child's side effect (the
136
+ * navigation). Replacing one with the other is the bug this exists to prevent.
137
+ * - **Styles stack**, ours under the child's, so the child can override.
138
+ * - **`ref`s merge** through `mergeRefs`. React 19 passes `ref` as an ordinary prop, so
139
+ * it arrives here rather than beside the props, and dropping it would sever the root's
140
+ * handle on the node.
141
+ * - **Everything else: the child's value wins**, and ours fills in what it left unset.
142
+ */
143
+ declare function mergeProps(ours: MergeableProps, theirs: MergeableProps): MergeableProps;
144
+
145
+ /**
146
+ * One callback that feeds several refs — what lets a root keep its own handle on a node
147
+ * while still honouring the ref its caller passed (R9), and what `asChild` needs to
148
+ * forward a ref into the child it merges into (R12).
149
+ *
150
+ * It returns nothing on purpose. React 19 reads a ref callback's return value as a
151
+ * cleanup function while React 18 ignores it, and this package supports both; letting
152
+ * a merged cleanup through would behave differently on each. React calls every ref with
153
+ * `null` on unmount anyway, which this forwards.
154
+ */
155
+ declare function mergeRefs<T>(...refs: Array<PossibleRef<T>>): RefCallback<T>;
156
+
157
+ type SlotProps = MergeableProps & {
158
+ children?: ReactNode;
159
+ };
160
+ /**
161
+ * The render branch behind `asChild` (R12). A root picks it instead of its own element:
162
+ *
163
+ * ```tsx
164
+ * const Root = asChild ? Slot : Pressable
165
+ * return <Root ref={ref} {...rootProps}>{children}</Root>
166
+ * ```
167
+ *
168
+ * One line per root, which is the point — forty-seven roots each hand-rolling a
169
+ * `cloneElement` and a ref merge would drift, and R12 has to hold uniformly from the
170
+ * first component or the ref signature of the whole core changes later.
171
+ */
172
+ declare const Slot: react.ForwardRefExoticComponent<Omit<SlotProps, "ref"> & react.RefAttributes<unknown>>;
173
+
174
+ export { type AsChildProps, type Axes, type CompoundVariant, type MergeableProps, type PossibleRef, type Recipe, type RecipeConfig, type ResolveArgs, type ResolvedSelection, type ResolvedStyles, type Selection, Slot, type SlotProps, type SlotStyle, type SlotStyles, type StateName, type States, type StyleFn, type TintArgs, type VariantColors, type VariantRole, type VariantTokens, childrenToString, createRecipe, createSlotContext, mergeProps, mergeRefs };