@yahoo/uds-create-config 2.14.0 → 2.15.0

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,456 @@
1
+ import { isAssetRef, isTokenRef } from "../refs.js";
2
+ import { isMixExpr } from "../colorExpressions.js";
3
+ import { isOperatingSystemValue } from "./values.js";
4
+ //#region src/native/validation.ts
5
+ const TOP_LEVEL_KEYS = new Set([
6
+ "schemaVersion",
7
+ "platform",
8
+ "builtAt",
9
+ "namespace",
10
+ "modes",
11
+ "tokenGroups",
12
+ "assetGroups"
13
+ ]);
14
+ const GROUP_KEYS = new Set([
15
+ "tokens",
16
+ "label",
17
+ "description"
18
+ ]);
19
+ const ASSET_GROUP_KEYS = new Set([
20
+ "assetKind",
21
+ "members",
22
+ "label",
23
+ "description"
24
+ ]);
25
+ const ASSET_MEMBER_KEYS = new Set(["postscriptName"]);
26
+ const MODE_OPTION_KEYS = new Set([
27
+ "modifier",
28
+ "label",
29
+ "description",
30
+ "css",
31
+ "media"
32
+ ]);
33
+ const OS_KEYS = new Set([
34
+ "__kind",
35
+ "default",
36
+ "ios",
37
+ "android"
38
+ ]);
39
+ const TOKEN_REF_KEYS = new Set(["__kind", "ref"]);
40
+ const MIX_KEYS = new Set([
41
+ "__kind",
42
+ "from",
43
+ "to",
44
+ "amount",
45
+ "colorSpace"
46
+ ]);
47
+ const COLOR_SPACES = new Set([
48
+ "srgb",
49
+ "srgb-linear",
50
+ "oklab",
51
+ "oklch",
52
+ "lab",
53
+ "lch",
54
+ "hsl",
55
+ "hwb"
56
+ ]);
57
+ function validateSerializedNativeConfig(input, expectedSchemaVersion = 1) {
58
+ const diagnostics = [];
59
+ const configDefinition = { kind: "config" };
60
+ if (!isRecord(input)) {
61
+ push(diagnostics, "INVALID_SCHEMA", [], configDefinition, "Native config must be a plain object.");
62
+ return diagnostics;
63
+ }
64
+ reportUnknownKeys(input, TOP_LEVEL_KEYS, [], configDefinition, diagnostics);
65
+ if (input.schemaVersion !== expectedSchemaVersion) push(diagnostics, typeof input.schemaVersion === "number" ? "UNSUPPORTED_SCHEMA_VERSION" : "INVALID_SCHEMA", ["schemaVersion"], configDefinition, `Native config schema version must be ${expectedSchemaVersion}; received ${String(input.schemaVersion)}.`);
66
+ if (input.platform !== "native") push(diagnostics, "PLATFORM_MISMATCH", ["platform"], configDefinition, "Native config must declare platform: \"native\".");
67
+ if (input.builtAt !== void 0 && typeof input.builtAt !== "string") push(diagnostics, "INVALID_SCHEMA", ["builtAt"], configDefinition, "builtAt must be a string when present.");
68
+ validateNamespace(input.namespace, diagnostics);
69
+ validateModes(input.modes, diagnostics);
70
+ validateAssetGroups(input.assetGroups, diagnostics);
71
+ validateTokenGroups(input.tokenGroups, diagnostics);
72
+ validateReferences(input, diagnostics);
73
+ validateModifierOwnership(input, diagnostics);
74
+ return dedupe(diagnostics);
75
+ }
76
+ function validateNamespace(value, diagnostics) {
77
+ if (value === void 0) return;
78
+ if (typeof value !== "string" || value.length === 0 || value.includes(":") || /\s/.test(value)) push(diagnostics, "INVALID_NAMESPACE", ["namespace"], { kind: "config" }, "Native config namespace must be a non-empty string without whitespace or \":\".");
79
+ }
80
+ function validateModes(value, diagnostics) {
81
+ if (value === void 0) return;
82
+ if (!isRecord(value)) {
83
+ push(diagnostics, "INVALID_SCHEMA", ["modes"], { kind: "config" }, "modes must be a record.");
84
+ return;
85
+ }
86
+ for (const [modeName, options] of Object.entries(value)) {
87
+ const definition = {
88
+ kind: "mode",
89
+ name: modeName
90
+ };
91
+ const modePath = ["modes", modeName];
92
+ if (!isRecord(options)) {
93
+ push(diagnostics, "INVALID_SCHEMA", modePath, definition, `Mode "${modeName}" must be an option record.`);
94
+ continue;
95
+ }
96
+ for (const [optionName, option] of Object.entries(options)) {
97
+ const optionPath = [...modePath, optionName];
98
+ if (!isRecord(option)) {
99
+ push(diagnostics, "INVALID_SCHEMA", optionPath, definition, `Mode option "${modeName}/${optionName}" must be an object.`);
100
+ continue;
101
+ }
102
+ reportUnknownKeys(option, MODE_OPTION_KEYS, optionPath, definition, diagnostics);
103
+ for (const key of [
104
+ "modifier",
105
+ "label",
106
+ "description"
107
+ ]) if (option[key] !== void 0 && typeof option[key] !== "string") push(diagnostics, "INVALID_SCHEMA", [...optionPath, key], definition, `${key} must be a string when present.`);
108
+ for (const key of ["css", "media"]) if (option[key] !== void 0) push(diagnostics, "UNSUPPORTED_NATIVE_FIELD", [...optionPath, key], definition, `Mode option field "${key}" is web-only and is not supported by NativeConfig.`);
109
+ }
110
+ }
111
+ }
112
+ function validateAssetGroups(value, diagnostics) {
113
+ if (value === void 0) return;
114
+ if (!isRecord(value)) {
115
+ push(diagnostics, "INVALID_SCHEMA", ["assetGroups"], { kind: "config" }, "assetGroups must be a record.");
116
+ return;
117
+ }
118
+ for (const [groupName, group] of Object.entries(value)) {
119
+ const definition = {
120
+ kind: "asset-group",
121
+ name: groupName
122
+ };
123
+ const groupPath = ["assetGroups", groupName];
124
+ if (!isRecord(group)) {
125
+ push(diagnostics, "INVALID_SCHEMA", groupPath, definition, `Asset group "${groupName}" must be an object.`);
126
+ continue;
127
+ }
128
+ reportUnknownKeys(group, ASSET_GROUP_KEYS, groupPath, definition, diagnostics);
129
+ if (group.assetKind !== "font") push(diagnostics, "INVALID_SCHEMA", [...groupPath, "assetKind"], definition, `Native asset group "${groupName}" must currently use assetKind "font".`);
130
+ for (const key of ["label", "description"]) if (group[key] !== void 0 && typeof group[key] !== "string") push(diagnostics, "INVALID_SCHEMA", [...groupPath, key], definition, `${key} must be a string when present.`);
131
+ if (!isRecord(group.members)) {
132
+ push(diagnostics, "INVALID_SCHEMA", [...groupPath, "members"], definition, `Native font asset group "${groupName}" must have a members record.`);
133
+ continue;
134
+ }
135
+ for (const [memberName, member] of Object.entries(group.members)) {
136
+ const memberDefinition = {
137
+ kind: "asset",
138
+ name: `${groupName}/${memberName}`
139
+ };
140
+ const memberPath = [
141
+ ...groupPath,
142
+ "members",
143
+ memberName
144
+ ];
145
+ if (!isRecord(member)) {
146
+ push(diagnostics, "INVALID_SCHEMA", memberPath, memberDefinition, `Native font asset "${groupName}/${memberName}" must be an object.`);
147
+ continue;
148
+ }
149
+ reportUnknownKeys(member, ASSET_MEMBER_KEYS, memberPath, memberDefinition, diagnostics);
150
+ if (typeof member.postscriptName !== "string" || member.postscriptName.length === 0) push(diagnostics, "INVALID_SCHEMA", [...memberPath, "postscriptName"], memberDefinition, `Native font asset "${groupName}/${memberName}" requires a non-empty postscriptName.`);
151
+ }
152
+ }
153
+ }
154
+ function validateTokenGroups(value, diagnostics) {
155
+ if (value === void 0) return;
156
+ if (!isRecord(value)) {
157
+ push(diagnostics, "INVALID_SCHEMA", ["tokenGroups"], { kind: "config" }, "tokenGroups must be a record.");
158
+ return;
159
+ }
160
+ for (const [groupName, group] of Object.entries(value)) {
161
+ const groupDefinition = {
162
+ kind: "token-group",
163
+ name: groupName
164
+ };
165
+ const groupPath = ["tokenGroups", groupName];
166
+ if (!isRecord(group)) {
167
+ push(diagnostics, "INVALID_SCHEMA", groupPath, groupDefinition, `Token group "${groupName}" must be an object.`);
168
+ continue;
169
+ }
170
+ reportUnknownKeys(group, GROUP_KEYS, groupPath, groupDefinition, diagnostics);
171
+ for (const key of ["label", "description"]) if (group[key] !== void 0 && typeof group[key] !== "string") push(diagnostics, "INVALID_SCHEMA", [...groupPath, key], groupDefinition, `${key} must be a string when present.`);
172
+ if (!isRecord(group.tokens)) {
173
+ push(diagnostics, "INVALID_SCHEMA", [...groupPath, "tokens"], groupDefinition, `Token group "${groupName}" must have a tokens record.`);
174
+ continue;
175
+ }
176
+ for (const [tokenName, token] of Object.entries(group.tokens)) validateTokenDefinition(token, [
177
+ ...groupPath,
178
+ "tokens",
179
+ tokenName
180
+ ], {
181
+ kind: "token",
182
+ name: `${groupName}/${tokenName}`
183
+ }, diagnostics, true);
184
+ }
185
+ }
186
+ function validateTokenDefinition(value, path, definition, diagnostics, allowModifiers) {
187
+ if (!isRecord(value)) {
188
+ push(diagnostics, "INVALID_SCHEMA", path, definition, `Native token "${definition.name ?? ""}" must be an object.`);
189
+ return;
190
+ }
191
+ if (!("value" in value)) push(diagnostics, "INVALID_SCHEMA", [...path, "value"], definition, `Native token "${definition.name ?? ""}" requires a value.`);
192
+ else validateNativeValue(value.value, [...path, "value"], definition, diagnostics, true);
193
+ if (value.type !== void 0 && typeof value.type !== "string") push(diagnostics, "INVALID_SCHEMA", [...path, "type"], definition, "Token type must be a string when present.");
194
+ validateSystemLink(value.link, [...path, "link"], definition, diagnostics);
195
+ for (const [key, modifier] of Object.entries(value)) {
196
+ if (key === "value" || key === "type" || key === "link") continue;
197
+ if (!key.startsWith("_")) {
198
+ push(diagnostics, "INVALID_SCHEMA", [...path, key], definition, `Unknown token definition field "${key}"; modifier fields must start with "_".`);
199
+ continue;
200
+ }
201
+ if (!allowModifiers) push(diagnostics, "UNSUPPORTED_NATIVE_FIELD", [...path, key], definition, "Compound native token modifiers are completed by the production modes work; this config cannot emit them yet.");
202
+ if (looksLikeTokenDefinition(modifier)) validateTokenDefinition(modifier, [...path, key], definition, diagnostics, false);
203
+ else validateNativeValue(modifier, [...path, key], definition, diagnostics, true);
204
+ }
205
+ }
206
+ function validateSystemLink(value, path, definition, diagnostics) {
207
+ if (value === void 0) return;
208
+ if (!isRecord(value)) {
209
+ push(diagnostics, "INVALID_SCHEMA", path, definition, "Token link provenance must be an object.");
210
+ return;
211
+ }
212
+ reportUnknownKeys(value, new Set([
213
+ "kind",
214
+ "systemId",
215
+ "systemVersion",
216
+ "sourceKey"
217
+ ]), path, definition, diagnostics);
218
+ if (value.kind !== "token") push(diagnostics, "INVALID_SCHEMA", [...path, "kind"], definition, "Token link provenance must use kind \"token\".");
219
+ for (const key of [
220
+ "systemId",
221
+ "systemVersion",
222
+ "sourceKey"
223
+ ]) if (typeof value[key] !== "string" || value[key].length === 0) push(diagnostics, "INVALID_SCHEMA", [...path, key], definition, `Token link provenance requires a non-empty ${key}.`);
224
+ }
225
+ function validateNativeValue(value, path, definition, diagnostics, allowOperatingSystem) {
226
+ if (typeof value === "string" || typeof value === "boolean") return;
227
+ if (typeof value === "number") {
228
+ if (!Number.isFinite(value)) push(diagnostics, "INVALID_NATIVE_VALUE", path, definition, "Native numeric values must be finite.");
229
+ return;
230
+ }
231
+ if (!isRecord(value)) {
232
+ push(diagnostics, "INVALID_NATIVE_VALUE", path, definition, "Native token values must be serializable strings, numbers, booleans, references, supported color expressions, or operatingSystem() values.");
233
+ return;
234
+ }
235
+ if (isTokenRef(value) || isAssetRef(value)) {
236
+ reportUnknownKeys(value, TOKEN_REF_KEYS, path, definition, diagnostics);
237
+ if (typeof value.ref !== "string" || value.ref.length === 0) push(diagnostics, "INVALID_REFERENCE", [...path, "ref"], definition, "Reference markers require a non-empty ref string.");
238
+ return;
239
+ }
240
+ if (isOperatingSystemValue(value)) {
241
+ if (!allowOperatingSystem) {
242
+ push(diagnostics, "NESTED_OS_VALUE", path, definition, "An operatingSystem() branch cannot contain another operatingSystem() value.");
243
+ return;
244
+ }
245
+ validateOperatingSystem(value, path, definition, diagnostics);
246
+ return;
247
+ }
248
+ if (isMixExpr(value)) {
249
+ validateMix(value, path, definition, diagnostics);
250
+ return;
251
+ }
252
+ const kind = typeof value.__kind === "string" ? value.__kind : void 0;
253
+ if (kind === "darken" || kind === "lighten" || kind === "linear-gradient" || kind === "radial-gradient") {
254
+ push(diagnostics, "UNSUPPORTED_COLOR_EXPRESSION", path, definition, `Color expression "${kind}" does not yet have cross-platform native semantics; use mix(), alpha(), or a resolved native color.`);
255
+ return;
256
+ }
257
+ push(diagnostics, "INVALID_NATIVE_VALUE", path, definition, "Native token values do not support arbitrary objects or arrays.");
258
+ }
259
+ function validateOperatingSystem(value, path, definition, diagnostics) {
260
+ reportUnknownKeys(value, OS_KEYS, path, definition, diagnostics);
261
+ if (value.default === void 0 && (value.ios === void 0 || value.android === void 0)) push(diagnostics, "INCOMPLETE_OS_VALUE", path, definition, "operatingSystem() requires a default value or explicit ios and android values.");
262
+ for (const key of [
263
+ "default",
264
+ "ios",
265
+ "android"
266
+ ]) if (value[key] !== void 0) validateNativeValue(value[key], [...path, key], definition, diagnostics, false);
267
+ }
268
+ function validateMix(value, path, definition, diagnostics) {
269
+ reportUnknownKeys(value, MIX_KEYS, path, definition, diagnostics);
270
+ validateColorOperand(value.from, [...path, "from"], definition, diagnostics);
271
+ validateColorOperand(value.to, [...path, "to"], definition, diagnostics);
272
+ const amount = typeof value.amount === "string" ? /^(-?(?:\d+(?:\.\d+)?|\.\d+))%$/.exec(value.amount) : null;
273
+ const amountNumber = amount ? Number(amount[1]) : NaN;
274
+ if (!Number.isFinite(amountNumber) || amountNumber < 0 || amountNumber > 100) push(diagnostics, "INVALID_NATIVE_VALUE", [...path, "amount"], definition, "mix() amount must be a percentage between 0% and 100%.");
275
+ if (value.colorSpace !== void 0 && !COLOR_SPACES.has(value.colorSpace)) push(diagnostics, "INVALID_NATIVE_VALUE", [...path, "colorSpace"], definition, `mix() colorSpace "${String(value.colorSpace)}" is unsupported.`);
276
+ }
277
+ function validateColorOperand(value, path, definition, diagnostics) {
278
+ if (typeof value === "string") return;
279
+ if (isTokenRef(value)) {
280
+ validateNativeValue(value, path, definition, diagnostics, false);
281
+ return;
282
+ }
283
+ if (isMixExpr(value)) {
284
+ validateMix(value, path, definition, diagnostics);
285
+ return;
286
+ }
287
+ push(diagnostics, "INVALID_NATIVE_VALUE", path, definition, "Native color expressions accept color strings, token references, or nested mix() expressions.");
288
+ }
289
+ function validateReferences(config, diagnostics) {
290
+ if (!isRecord(config.tokenGroups)) return;
291
+ const tokens = /* @__PURE__ */ new Map();
292
+ for (const [groupName, group] of Object.entries(config.tokenGroups)) {
293
+ if (!isRecord(group) || !isRecord(group.tokens)) continue;
294
+ for (const [tokenName, definition] of Object.entries(group.tokens)) {
295
+ if (!isRecord(definition)) continue;
296
+ tokens.set(`${groupName}/${tokenName}`, {
297
+ definition,
298
+ path: [
299
+ "tokenGroups",
300
+ groupName,
301
+ "tokens",
302
+ tokenName
303
+ ]
304
+ });
305
+ }
306
+ }
307
+ const assets = isRecord(config.assetGroups) ? config.assetGroups : {};
308
+ const modifiers = /* @__PURE__ */ new Set();
309
+ for (const { definition } of tokens.values()) for (const key of Object.keys(definition)) if (key.startsWith("_")) modifiers.add(key);
310
+ const contexts = [void 0, ...modifiers];
311
+ for (const [tokenRef, token] of tokens) {
312
+ collectAllReferences(token.definition, token.path, {
313
+ kind: "token",
314
+ name: tokenRef
315
+ }, tokens, assets, diagnostics);
316
+ for (const modifier of contexts) resolveTokenContext(tokenRef, modifier, tokens, diagnostics, [], token.path);
317
+ }
318
+ }
319
+ function collectAllReferences(value, path, definition, tokens, assets, diagnostics) {
320
+ walkValues(value, path, (entry, entryPath) => {
321
+ if (isTokenRef(entry)) {
322
+ if (typeof entry.ref === "string" && !tokens.has(entry.ref)) push(diagnostics, "UNRESOLVED_TOKEN_REFERENCE", entryPath, definition, `Token reference "${entry.ref}" does not resolve within this native config.`);
323
+ return;
324
+ }
325
+ if (!isAssetRef(entry) || typeof entry.ref !== "string") return;
326
+ const slash = entry.ref.indexOf("/");
327
+ const groupName = slash > 0 ? entry.ref.slice(0, slash) : "";
328
+ const memberName = slash > 0 ? entry.ref.slice(slash + 1) : "";
329
+ const group = assets[groupName];
330
+ if (!groupName || !memberName || !group || group.assetKind !== "font" || !isRecord(group.members) || !group.members[memberName]) push(diagnostics, "UNRESOLVED_ASSET_REFERENCE", entryPath, definition, `Asset reference "${entry.ref}" does not resolve to a registered native font asset.`);
331
+ });
332
+ }
333
+ function resolveTokenContext(ref, modifier, tokens, diagnostics, stack, sourcePath) {
334
+ if (stack.includes(ref)) {
335
+ const cycle = [...stack.slice(stack.indexOf(ref)), ref].join(" -> ");
336
+ push(diagnostics, "TOKEN_REFERENCE_CYCLE", sourcePath, {
337
+ kind: "token",
338
+ name: stack[0] ?? ref
339
+ }, `Native token reference cycle detected: ${cycle}.`);
340
+ return;
341
+ }
342
+ const token = tokens.get(ref);
343
+ if (!token) return;
344
+ const selected = selectTokenValue(token.definition, token.path, modifier);
345
+ const nextStack = [...stack, ref];
346
+ walkValues(selected.value, selected.path, (entry, entryPath) => {
347
+ if (isTokenRef(entry) && typeof entry.ref === "string") resolveTokenContext(entry.ref, modifier, tokens, diagnostics, nextStack, entryPath);
348
+ });
349
+ }
350
+ function selectTokenValue(definition, path, modifier) {
351
+ const override = modifier ? definition[modifier] : void 0;
352
+ if (override === void 0) return {
353
+ value: definition.value,
354
+ path: [...path, "value"]
355
+ };
356
+ if (looksLikeTokenDefinition(override)) return {
357
+ value: override.value,
358
+ path: [
359
+ ...path,
360
+ modifier,
361
+ "value"
362
+ ]
363
+ };
364
+ return {
365
+ value: override,
366
+ path: [...path, modifier]
367
+ };
368
+ }
369
+ function validateModifierOwnership(config, diagnostics) {
370
+ const owned = /* @__PURE__ */ new Set();
371
+ if (isRecord(config.modes)) for (const options of Object.values(config.modes)) {
372
+ if (!isRecord(options)) continue;
373
+ for (const [optionName, option] of Object.entries(options)) {
374
+ if (!isRecord(option)) continue;
375
+ owned.add(typeof option.modifier === "string" ? option.modifier : `_${optionName}`);
376
+ }
377
+ }
378
+ if (!isRecord(config.tokenGroups)) return;
379
+ for (const [groupName, group] of Object.entries(config.tokenGroups)) {
380
+ if (!isRecord(group) || !isRecord(group.tokens)) continue;
381
+ for (const [tokenName, definition] of Object.entries(group.tokens)) {
382
+ if (!isRecord(definition)) continue;
383
+ for (const key of Object.keys(definition)) {
384
+ if (!key.startsWith("_") || owned.has(key)) continue;
385
+ push(diagnostics, "UNOWNED_MODIFIER", [
386
+ "tokenGroups",
387
+ groupName,
388
+ "tokens",
389
+ tokenName,
390
+ key
391
+ ], {
392
+ kind: "token",
393
+ name: `${groupName}/${tokenName}`
394
+ }, `Modifier "${key}" is not owned by a registered mode option.`);
395
+ }
396
+ }
397
+ }
398
+ }
399
+ function walkValues(value, path, visit) {
400
+ if (!isRecord(value)) return;
401
+ if (isTokenRef(value) || isAssetRef(value)) {
402
+ visit(value, path);
403
+ return;
404
+ }
405
+ if (isOperatingSystemValue(value)) {
406
+ for (const key of [
407
+ "default",
408
+ "ios",
409
+ "android"
410
+ ]) if (value[key] !== void 0) walkValues(value[key], [...path, key], visit);
411
+ return;
412
+ }
413
+ if (isMixExpr(value)) {
414
+ walkValues(value.from, [...path, "from"], visit);
415
+ walkValues(value.to, [...path, "to"], visit);
416
+ return;
417
+ }
418
+ if (looksLikeTokenDefinition(value)) {
419
+ walkValues(value.value, [...path, "value"], visit);
420
+ for (const [key, nested] of Object.entries(value)) if (key.startsWith("_")) walkValues(nested, [...path, key], visit);
421
+ return;
422
+ }
423
+ for (const [key, nested] of Object.entries(value)) if (key.startsWith("_")) walkValues(nested, [...path, key], visit);
424
+ }
425
+ function looksLikeTokenDefinition(value) {
426
+ return isRecord(value) && "value" in value && !("__kind" in value);
427
+ }
428
+ function reportUnknownKeys(value, allowed, path, definition, diagnostics) {
429
+ for (const key of Object.keys(value)) {
430
+ if (allowed.has(key)) continue;
431
+ push(diagnostics, "INVALID_SCHEMA", [...path, key], definition, `Unknown native config field "${key}".`);
432
+ }
433
+ }
434
+ function isRecord(value) {
435
+ return typeof value === "object" && value !== null && !Array.isArray(value);
436
+ }
437
+ function push(diagnostics, code, path, definition, reason) {
438
+ diagnostics.push({
439
+ code,
440
+ severity: "error",
441
+ path,
442
+ definition,
443
+ reason
444
+ });
445
+ }
446
+ function dedupe(diagnostics) {
447
+ const seen = /* @__PURE__ */ new Set();
448
+ return diagnostics.filter((diagnostic) => {
449
+ const key = `${diagnostic.code}:${diagnostic.path.join(".")}:${diagnostic.reason}`;
450
+ if (seen.has(key)) return false;
451
+ seen.add(key);
452
+ return true;
453
+ });
454
+ }
455
+ //#endregion
456
+ export { validateSerializedNativeConfig };
@@ -0,0 +1,7 @@
1
+ import { OperatingSystemInput, OperatingSystemValue } from "./types.js";
2
+
3
+ //#region src/native/values.d.ts
4
+ declare function operatingSystem(input: OperatingSystemInput): OperatingSystemValue;
5
+ declare function isOperatingSystemValue(value: unknown): value is OperatingSystemValue;
6
+ //#endregion
7
+ export { isOperatingSystemValue, operatingSystem };
@@ -0,0 +1,15 @@
1
+ //#region src/native/values.ts
2
+ function operatingSystem(input) {
3
+ if (input.default === void 0 && (input.ios === void 0 || input.android === void 0)) throw new Error("operatingSystem() requires a default value or explicit ios and android values.");
4
+ return {
5
+ __kind: "operatingSystem",
6
+ ...input.default !== void 0 ? { default: input.default } : {},
7
+ ...input.ios !== void 0 ? { ios: input.ios } : {},
8
+ ...input.android !== void 0 ? { android: input.android } : {}
9
+ };
10
+ }
11
+ function isOperatingSystemValue(value) {
12
+ return typeof value === "object" && value !== null && value.__kind === "operatingSystem";
13
+ }
14
+ //#endregion
15
+ export { isOperatingSystemValue, operatingSystem };
package/dist/native.d.ts CHANGED
@@ -1,4 +1,11 @@
1
- import { TokenRef, token } from "./refs.js";
2
- import { ModeDefinition } from "./types.js";
3
- import { DefinedNativeTokenGroup, NativeConfig, NativeLiteral, NativeSelectableValue, NativeTokenDefinition, NativeTokenGroupDefinition, NativeTokenGroupMetadata, NativeTokenModifierValue, NativeTokenValue, OperatingSystemInput, OperatingSystemValue, SerializedNativeConfig, defineMode, defineTokenGroup, isOperatingSystemValue, operatingSystem } from "./native/index.js";
4
- export { DefinedNativeTokenGroup, ModeDefinition, NativeConfig, NativeLiteral, NativeSelectableValue, NativeTokenDefinition, NativeTokenGroupDefinition, NativeTokenGroupMetadata, NativeTokenModifierValue, NativeTokenValue, OperatingSystemInput, OperatingSystemValue, SerializedNativeConfig, TokenRef, defineMode, defineTokenGroup, isOperatingSystemValue, operatingSystem, token };
1
+ import { AssetRef, TokenRef, asset, token } from "./refs.js";
2
+ import { ColorSpace, MixExpr, alpha, mix } from "./colorExpressions.js";
3
+ import { ModeDefinition, SystemLink, TokenType } from "./types.js";
4
+ import { defineMode } from "./factories.js";
5
+ import { NativeAssetGroupDefinition, NativeColorExpression, NativeFontAssetGroupDefinition, NativeFontAssetMember, NativeLiteral, NativeSelectableValue, NativeTokenDefinition, NativeTokenGroupDefinition, NativeTokenValue, OperatingSystemInput, OperatingSystemValue, SerializedNativeConfig } from "./native/types.js";
6
+ import { NativeAssetGroupBuilder, NativeFontAssetGroupConfig, defineAssetGroup } from "./native/assets.js";
7
+ import { NativeConfigDiagnostic, NativeConfigDiagnosticCode, validateSerializedNativeConfig } from "./native/validation.js";
8
+ import { NativeConfig, NativeConfigValidationError } from "./native/NativeConfig.js";
9
+ import { isOperatingSystemValue, operatingSystem } from "./native/values.js";
10
+ import { DefinedNativeTokenGroup, defineTokenGroup } from "./native/index.js";
11
+ export { AssetRef, ColorSpace, DefinedNativeTokenGroup, MixExpr, ModeDefinition, NativeAssetGroupBuilder, NativeAssetGroupDefinition, NativeColorExpression, NativeConfig, NativeConfigDiagnostic, NativeConfigDiagnosticCode, NativeConfigValidationError, NativeFontAssetGroupConfig, NativeFontAssetGroupDefinition, NativeFontAssetMember, NativeLiteral, NativeSelectableValue, NativeTokenDefinition, NativeTokenGroupDefinition, NativeTokenValue, OperatingSystemInput, OperatingSystemValue, SerializedNativeConfig, SystemLink, TokenRef, TokenType, alpha, asset, defineAssetGroup, defineMode, defineTokenGroup, isOperatingSystemValue, mix, operatingSystem, token, validateSerializedNativeConfig };
package/dist/native.js CHANGED
@@ -1,3 +1,9 @@
1
- import { token } from "./refs.js";
2
- import { NativeConfig, defineMode, defineTokenGroup, isOperatingSystemValue, operatingSystem } from "./native/index.js";
3
- export { NativeConfig, defineMode, defineTokenGroup, isOperatingSystemValue, operatingSystem, token };
1
+ import { asset, token } from "./refs.js";
2
+ import { alpha, mix } from "./colorExpressions.js";
3
+ import { defineMode } from "./factories.js";
4
+ import { defineAssetGroup } from "./native/assets.js";
5
+ import { isOperatingSystemValue, operatingSystem } from "./native/values.js";
6
+ import { validateSerializedNativeConfig } from "./native/validation.js";
7
+ import { NativeConfig, NativeConfigValidationError } from "./native/NativeConfig.js";
8
+ import { defineTokenGroup } from "./native/index.js";
9
+ export { NativeConfig, NativeConfigValidationError, alpha, asset, defineAssetGroup, defineMode, defineTokenGroup, isOperatingSystemValue, mix, operatingSystem, token, validateSerializedNativeConfig };