@xaui/native 0.9.1-alpha.2 → 0.9.1-alpha.4
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/dist/{chunk-PBVPOX7D.js → chunk-2KXQATVL.js} +3 -27
- package/dist/{chunk-M7P46XKI.cjs → chunk-3QBT3Q65.cjs} +27 -2
- package/dist/{chunk-NHPQQQ7P.cjs → chunk-AW63PTQ4.cjs} +33 -57
- package/dist/chunk-ECDWSSHJ.js +688 -0
- package/dist/chunk-IYFGO523.cjs +688 -0
- package/dist/{chunk-RBNCR5KB.js → chunk-X2K2FX3W.js} +25 -0
- package/dist/index.cjs +32 -4
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +36 -8
- package/dist/system/index.cjs +31 -3
- package/dist/system/index.d.cts +224 -3
- package/dist/system/index.d.ts +224 -3
- package/dist/system/index.js +32 -4
- package/dist/theme/index.cjs +3 -3
- package/dist/theme/index.d.cts +3 -2
- package/dist/theme/index.d.ts +3 -2
- package/dist/theme/index.js +6 -6
- package/dist/{theme.type-B3ODSLbB.d.cts → theme.type-C9bFJKFm.d.cts} +7 -1
- package/dist/{theme.type-B3ODSLbB.d.ts → theme.type-C9bFJKFm.d.ts} +7 -1
- package/package.json +1 -1
- package/dist/chunk-B755PRVJ.cjs +0 -274
- package/dist/chunk-RCP3SD26.js +0 -274
package/dist/chunk-RCP3SD26.js
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
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
|
-
};
|