@xaui/native 0.9.1-alpha.16 → 0.9.1-alpha.18

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.
Files changed (42) hide show
  1. package/dist/chunk-4K3LZS7M.js +448 -0
  2. package/dist/chunk-5SU7FXWH.cjs +448 -0
  3. package/dist/chunk-6PZF4PI7.js +100 -0
  4. package/dist/chunk-6VTBGBPP.cjs +100 -0
  5. package/dist/{chunk-KCUT47FY.cjs → chunk-BHAHJHAI.cjs} +5 -1
  6. package/dist/{chunk-UOJBK5Z4.js → chunk-L3AQNVRN.js} +1 -1
  7. package/dist/{chunk-BAACHVM4.cjs → chunk-M2VYRHVS.cjs} +2 -2
  8. package/dist/{chunk-E3756MJC.js → chunk-MBLPPOSO.js} +16 -15
  9. package/dist/{chunk-NLFE3CRM.cjs → chunk-ODH5WAVM.cjs} +24 -23
  10. package/dist/{chunk-PUER6Y4M.cjs → chunk-P5MKOLIW.cjs} +110 -409
  11. package/dist/chunk-VQPP6FCB.js +728 -0
  12. package/dist/{chunk-EHHSY2KB.js → chunk-XQE5PXOD.js} +5 -1
  13. package/dist/components/button/index.cjs +4 -3
  14. package/dist/components/button/index.d.cts +179 -178
  15. package/dist/components/button/index.d.ts +179 -178
  16. package/dist/components/button/index.js +3 -2
  17. package/dist/components/typography/index.cjs +12 -0
  18. package/dist/components/typography/index.d.cts +115 -0
  19. package/dist/components/typography/index.d.ts +115 -0
  20. package/dist/components/typography/index.js +12 -0
  21. package/dist/create-recipe-3_ElpCYt.d.cts +117 -0
  22. package/dist/create-recipe-DImq1AZA.d.ts +117 -0
  23. package/dist/index.cjs +17 -7
  24. package/dist/index.d.cts +4 -2
  25. package/dist/index.d.ts +4 -2
  26. package/dist/index.js +21 -11
  27. package/dist/pressable-feedback.type-UwqIG6ES.d.ts +195 -0
  28. package/dist/pressable-feedback.type-lgW5wQx5.d.cts +195 -0
  29. package/dist/system/index.cjs +5 -3
  30. package/dist/system/index.d.cts +10 -4
  31. package/dist/system/index.d.ts +10 -4
  32. package/dist/system/index.js +11 -9
  33. package/dist/theme/index.cjs +2 -2
  34. package/dist/theme/index.d.cts +2 -2
  35. package/dist/theme/index.d.ts +2 -2
  36. package/dist/theme/index.js +1 -1
  37. package/dist/{theme.type-C9bFJKFm.d.cts → theme.type-C2gNHpEx.d.cts} +1 -1
  38. package/dist/{theme.type-C9bFJKFm.d.ts → theme.type-C2gNHpEx.d.ts} +1 -1
  39. package/package.json +11 -1
  40. package/dist/chunk-64L44HEI.js +0 -1021
  41. package/dist/create-recipe-BcUu9b2I.d.cts +0 -280
  42. package/dist/create-recipe-DD9W6m9b.d.ts +0 -280
@@ -0,0 +1,448 @@
1
+ import {
2
+ deriveTint,
3
+ stableHash
4
+ } from "./chunk-XJARE6SC.js";
5
+
6
+ // src/system/style-props/use-style-props.ts
7
+ import { useMemo } from "react";
8
+
9
+ // src/utils/style-props.ts
10
+ var STYLE_PROP_KEYS = [
11
+ // Flex and layout
12
+ "alignContent",
13
+ "alignItems",
14
+ "alignSelf",
15
+ "aspectRatio",
16
+ "boxSizing",
17
+ "columnGap",
18
+ "direction",
19
+ "display",
20
+ "flex",
21
+ "flexBasis",
22
+ "flexDirection",
23
+ "flexGrow",
24
+ "flexShrink",
25
+ "flexWrap",
26
+ "gap",
27
+ "justifyContent",
28
+ "overflow",
29
+ "rowGap",
30
+ // Position
31
+ "bottom",
32
+ "end",
33
+ "inset",
34
+ "insetBlock",
35
+ "insetBlockEnd",
36
+ "insetBlockStart",
37
+ "insetInline",
38
+ "insetInlineEnd",
39
+ "insetInlineStart",
40
+ "position",
41
+ "start",
42
+ "top",
43
+ "zIndex",
44
+ // Margin
45
+ "margin",
46
+ "marginBlock",
47
+ "marginBlockEnd",
48
+ "marginBlockStart",
49
+ "marginBottom",
50
+ "marginEnd",
51
+ "marginHorizontal",
52
+ "marginInline",
53
+ "marginInlineEnd",
54
+ "marginInlineStart",
55
+ "marginStart",
56
+ "marginTop",
57
+ "marginVertical",
58
+ // Padding
59
+ "padding",
60
+ "paddingBlock",
61
+ "paddingBlockEnd",
62
+ "paddingBlockStart",
63
+ "paddingBottom",
64
+ "paddingEnd",
65
+ "paddingHorizontal",
66
+ "paddingInline",
67
+ "paddingInlineEnd",
68
+ "paddingInlineStart",
69
+ "paddingStart",
70
+ "paddingTop",
71
+ "paddingVertical",
72
+ // Size
73
+ "height",
74
+ "maxHeight",
75
+ "maxWidth",
76
+ "minHeight",
77
+ "minWidth",
78
+ "width",
79
+ // Border
80
+ "borderBlockColor",
81
+ "borderBlockEndColor",
82
+ "borderBlockStartColor",
83
+ "borderBottomColor",
84
+ "borderBottomEndRadius",
85
+ "borderBottomStartRadius",
86
+ "borderBottomWidth",
87
+ "borderColor",
88
+ "borderCurve",
89
+ "borderEndColor",
90
+ "borderEndEndRadius",
91
+ "borderEndStartRadius",
92
+ "borderEndWidth",
93
+ "borderRadius",
94
+ "borderStartColor",
95
+ "borderStartEndRadius",
96
+ "borderStartStartRadius",
97
+ "borderStartWidth",
98
+ "borderStyle",
99
+ "borderTopColor",
100
+ "borderTopEndRadius",
101
+ "borderTopStartRadius",
102
+ "borderTopWidth",
103
+ "borderWidth",
104
+ // Fill, shadow, and the rest of a box's paint
105
+ "backfaceVisibility",
106
+ "backgroundColor",
107
+ "boxShadow",
108
+ "cursor",
109
+ "elevation",
110
+ "experimental_backgroundImage",
111
+ "filter",
112
+ "isolation",
113
+ "mixBlendMode",
114
+ "opacity",
115
+ "outlineColor",
116
+ "outlineOffset",
117
+ "outlineStyle",
118
+ "outlineWidth",
119
+ "shadowColor",
120
+ "shadowOffset",
121
+ "shadowOpacity",
122
+ "shadowRadius",
123
+ // Transform
124
+ "rotation",
125
+ "scaleX",
126
+ "scaleY",
127
+ "transform",
128
+ "transformMatrix",
129
+ "transformOrigin",
130
+ "translateX",
131
+ "translateY",
132
+ // Text — a text slot only
133
+ "color",
134
+ "fontFamily",
135
+ "fontSize",
136
+ "fontStyle",
137
+ "fontVariant",
138
+ "fontWeight",
139
+ "includeFontPadding",
140
+ "letterSpacing",
141
+ "lineHeight",
142
+ "textAlign",
143
+ "textAlignVertical",
144
+ "textDecorationColor",
145
+ "textDecorationLine",
146
+ "textDecorationStyle",
147
+ "textShadowColor",
148
+ "textShadowOffset",
149
+ "textShadowRadius",
150
+ "textTransform",
151
+ "userSelect",
152
+ "verticalAlign",
153
+ "writingDirection",
154
+ // Image — an image slot only
155
+ "objectFit",
156
+ "overlayColor",
157
+ "resizeMode",
158
+ "tintColor"
159
+ ];
160
+ var STYLE_PROP_KEY_SET = new Set(STYLE_PROP_KEYS);
161
+ function splitStyleProps(props) {
162
+ const styleProps = {};
163
+ const rest = {};
164
+ for (const [key, value] of Object.entries(props)) {
165
+ if (STYLE_PROP_KEY_SET.has(key)) styleProps[key] = value;
166
+ else rest[key] = value;
167
+ }
168
+ return [styleProps, rest];
169
+ }
170
+
171
+ // src/system/style-props/use-style-props.ts
172
+ function useStyleProps(props) {
173
+ const [styleProps, rest] = splitStyleProps(props);
174
+ const key = stableHash(styleProps);
175
+ return [useMemo(() => styleProps, [key]), rest];
176
+ }
177
+
178
+ // src/system/slot/children-to-string.ts
179
+ import { isValidElement } from "react";
180
+ function childrenToString(children) {
181
+ const text = stringify(children);
182
+ return text === null || text === "" ? null : text;
183
+ }
184
+ function stringify(node) {
185
+ if (node === null || node === void 0 || typeof node === "boolean") return "";
186
+ if (typeof node === "string") return node;
187
+ if (typeof node === "number") return String(node);
188
+ if (isValidElement(node)) return null;
189
+ if (Array.isArray(node)) {
190
+ let text = "";
191
+ for (const child of node) {
192
+ const part = stringify(child);
193
+ if (part === null) return null;
194
+ text += part;
195
+ }
196
+ return text;
197
+ }
198
+ return null;
199
+ }
200
+
201
+ // src/system/slot/create-slot-context.ts
202
+ import { createContext, useContext } from "react";
203
+ function createSlotContext(name) {
204
+ const Context = createContext(null);
205
+ Context.displayName = `XAUI.${name}.Context`;
206
+ function useSlotContext() {
207
+ const value = useContext(Context);
208
+ if (value === null) {
209
+ const error = new Error(
210
+ `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.`
211
+ );
212
+ Error.captureStackTrace?.(
213
+ error,
214
+ useSlotContext
215
+ );
216
+ throw error;
217
+ }
218
+ return value;
219
+ }
220
+ return [Context.Provider, useSlotContext];
221
+ }
222
+
223
+ // src/system/slot/merge-refs.ts
224
+ function mergeRefs(...refs) {
225
+ return (value) => {
226
+ for (const ref of refs) {
227
+ if (typeof ref === "function") ref(value);
228
+ else if (ref) ref.current = value;
229
+ }
230
+ };
231
+ }
232
+
233
+ // src/system/slot/merge-props.ts
234
+ var EVENT_HANDLER = /^on[A-Z]/;
235
+ function mergeProps(ours, theirs) {
236
+ const merged = { ...ours };
237
+ for (const key of Object.keys(theirs)) {
238
+ const ourValue = ours[key];
239
+ const theirValue = theirs[key];
240
+ if (EVENT_HANDLER.test(key)) {
241
+ merged[key] = composeHandlers(ourValue, theirValue);
242
+ } else if (key === "style") {
243
+ merged[key] = mergeStyles(ourValue, theirValue);
244
+ } else if (key === "ref") {
245
+ merged[key] = mergeRefs(
246
+ ourValue,
247
+ theirValue
248
+ );
249
+ } else {
250
+ merged[key] = theirValue;
251
+ }
252
+ }
253
+ return merged;
254
+ }
255
+ function composeHandlers(ours, theirs) {
256
+ if (typeof ours !== "function") return theirs;
257
+ if (typeof theirs !== "function") return ours;
258
+ return (...args) => {
259
+ ;
260
+ ours(...args);
261
+ return theirs(...args);
262
+ };
263
+ }
264
+ function mergeStyles(ours, theirs) {
265
+ if (typeof ours === "function" || typeof theirs === "function") {
266
+ return (state) => [
267
+ resolveStyle(ours, state),
268
+ resolveStyle(theirs, state)
269
+ ];
270
+ }
271
+ return [ours, theirs];
272
+ }
273
+ function resolveStyle(style, state) {
274
+ return typeof style === "function" ? style(state) : style;
275
+ }
276
+
277
+ // src/system/slot/slot.tsx
278
+ import { cloneElement, forwardRef, isValidElement as isValidElement2 } from "react";
279
+ var Slot = forwardRef(function Slot2({ children, ...ours }, ref) {
280
+ if (!isValidElement2(children)) {
281
+ throw new Error(
282
+ "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."
283
+ );
284
+ }
285
+ const child = children;
286
+ const merged = mergeProps(ours, child.props);
287
+ merged.ref = mergeRefs(ref, refOf(child));
288
+ return cloneElement(child, merged);
289
+ });
290
+ Slot.displayName = "XAUI.Slot";
291
+ function refOf(element) {
292
+ const fromProps = element.props.ref;
293
+ const fromElement = element.ref;
294
+ return fromProps ?? fromElement;
295
+ }
296
+
297
+ // src/system/recipe/resolve-tint.ts
298
+ var TINT_SLICE_BY_SUFFIX = [
299
+ [/SoftForeground$/, "softForeground"],
300
+ [/SoftPressed$/, "softPressed"],
301
+ [/Soft$/, "soft"],
302
+ [/Foreground$/, "foreground"],
303
+ [/Pressed$/, "pressed"]
304
+ ];
305
+ function tintSliceFor(token) {
306
+ for (const [suffix, slice] of TINT_SLICE_BY_SUFFIX) {
307
+ if (suffix.test(token)) return slice;
308
+ }
309
+ return "base";
310
+ }
311
+ function resolveTint(tokens, color, theme) {
312
+ const tint = deriveTint(color, theme);
313
+ const colors = {};
314
+ for (const [role, token] of Object.entries(tokens ?? {})) {
315
+ colors[role] = tint[tintSliceFor(token)];
316
+ }
317
+ return colors;
318
+ }
319
+
320
+ // src/system/recipe/style-cache.ts
321
+ import { StyleSheet } from "react-native";
322
+
323
+ // src/system/recipe/variant-map.ts
324
+ var STATE_ORDER = ["focused", "pressed", "disabled"];
325
+ function resolveSelection(defaultVariants, selection) {
326
+ const resolved = { ...defaultVariants };
327
+ for (const [axis, value] of Object.entries(selection ?? {})) {
328
+ if (value !== void 0) resolved[axis] = value;
329
+ }
330
+ return resolved;
331
+ }
332
+ function resolveVariantColors(tokens, theme) {
333
+ const colors = {};
334
+ for (const [role, token] of entriesOf(tokens)) {
335
+ const value = theme.colors[token];
336
+ if (value === void 0) {
337
+ throw new Error(
338
+ `XAUI: the recipe names "${token}" for its "${role}" role, but the theme has no such colour token. Check the spelling against XAUIColors.`
339
+ );
340
+ }
341
+ colors[role] = value;
342
+ }
343
+ return colors;
344
+ }
345
+ function activeStateFns(states, active) {
346
+ const fns = [];
347
+ for (const state of STATE_ORDER) {
348
+ const fn = active[state] ? states?.[state] : void 0;
349
+ if (fn) fns.push(fn);
350
+ }
351
+ return fns;
352
+ }
353
+ function collectStyleFns(config, selection, states) {
354
+ const fns = [];
355
+ if (config.base) fns.push(config.base);
356
+ if (config.paint) fns.push(config.paint);
357
+ for (const [axis, values] of Object.entries(config.variants ?? {})) {
358
+ const value = selection[axis];
359
+ const fn = value === void 0 ? void 0 : values[value];
360
+ if (fn) fns.push(fn);
361
+ }
362
+ for (const compound of config.compoundVariants ?? []) {
363
+ if (appliesTo(compound.when, selection)) fns.push(compound.style);
364
+ }
365
+ return [...fns, ...activeStateFns(config.states, states)];
366
+ }
367
+ function appliesTo(when, selection) {
368
+ return Object.entries(when).every(([axis, value]) => selection[axis] === value);
369
+ }
370
+ function entriesOf(tokens) {
371
+ return Object.entries(tokens ?? {});
372
+ }
373
+
374
+ // src/system/recipe/style-cache.ts
375
+ function createStyleCache(slots) {
376
+ const entries = /* @__PURE__ */ new Map();
377
+ return {
378
+ read(key, build) {
379
+ const hit = entries.get(key);
380
+ if (hit) return hit;
381
+ const built = build();
382
+ const complete = {};
383
+ for (const slot of slots) complete[slot] = built[slot] ?? {};
384
+ const created = StyleSheet.create(complete);
385
+ entries.set(key, created);
386
+ return created;
387
+ },
388
+ get size() {
389
+ return entries.size;
390
+ },
391
+ clear() {
392
+ entries.clear();
393
+ }
394
+ };
395
+ }
396
+ function cacheKey(theme, selection, states) {
397
+ const axes = Object.keys(selection).sort().map((axis) => `${axis}:${selection[axis] ?? "-"}`).join("|");
398
+ const active = STATE_ORDER.filter((state) => states[state]).join(",");
399
+ return `${theme.id}|${theme.mode}|${axes}|${active}`;
400
+ }
401
+
402
+ // src/system/recipe/create-recipe.ts
403
+ function createRecipe(config) {
404
+ const cache = createStyleCache(config.slots);
405
+ const tokensFor = (variant) => variant === void 0 ? void 0 : config.variantTokens?.[variant];
406
+ return {
407
+ slots: config.slots,
408
+ resolve({ theme, selection, states = {} }) {
409
+ const resolved = resolveSelection(config.defaultVariants, selection);
410
+ return cache.read(cacheKey(theme, resolved, states), () => {
411
+ const colors = resolveVariantColors(tokensFor(resolved.variant), theme);
412
+ return apply(collectStyleFns(config, resolved, states), theme, colors);
413
+ });
414
+ },
415
+ tint({ theme, color, selection, states = {} }) {
416
+ if (!config.paint) return {};
417
+ const resolved = resolveSelection(config.defaultVariants, selection);
418
+ const tokens = tokensFor(resolved.variant);
419
+ if (!tokens) return {};
420
+ const colors = resolveTint(tokens, color, theme);
421
+ const fns = [config.paint, ...activeStateFns(config.states, states)];
422
+ return apply(fns, theme, colors);
423
+ }
424
+ };
425
+ }
426
+ function apply(fns, theme, colors) {
427
+ const merged = {};
428
+ for (const fn of fns) {
429
+ const produced = fn(theme, colors);
430
+ for (const slot of Object.keys(produced)) {
431
+ const style = produced[slot];
432
+ if (!style) continue;
433
+ const previous = merged[slot];
434
+ merged[slot] = previous ? { ...previous, ...style } : style;
435
+ }
436
+ }
437
+ return merged;
438
+ }
439
+
440
+ export {
441
+ useStyleProps,
442
+ childrenToString,
443
+ createSlotContext,
444
+ mergeRefs,
445
+ mergeProps,
446
+ Slot,
447
+ createRecipe
448
+ };