@yahoo/uds-create-config 2.24.0 → 2.25.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.
- package/dist/CompositeStyle.d.ts +4 -1
- package/dist/CompositeStyle.js +8 -1
- package/dist/native/NativeConfig.d.ts +14 -5
- package/dist/native/NativeConfig.js +38 -4
- package/dist/native/components.d.ts +139 -0
- package/dist/native/components.js +66 -0
- package/dist/native/index.d.ts +2 -1
- package/dist/native/index.js +1 -0
- package/dist/native/types.d.ts +9 -1
- package/dist/native/validation.js +283 -2
- package/dist/native.d.ts +3 -2
- package/dist/native.js +2 -1
- package/dist/renderer/wrapRegistry.js +5 -5
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +10 -0
- package/package.json +3 -3
package/dist/CompositeStyle.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CompositeStyleDefinition, CompositeStyleObject } from "./types.js";
|
|
1
|
+
import { CompositeStyleDefinition, CompositeStyleObject, SystemLink } from "./types.js";
|
|
2
2
|
import { CssClassName, CssVar } from "./brands.js";
|
|
3
3
|
|
|
4
4
|
//#region src/CompositeStyle.d.ts
|
|
@@ -8,6 +8,9 @@ declare class CompositeStyle {
|
|
|
8
8
|
readonly label: string;
|
|
9
9
|
readonly description?: string;
|
|
10
10
|
readonly styles: ReadonlyMap<string, CompositeStyleObject>;
|
|
11
|
+
/** Provenance when this composite is linked from another system; `undefined`
|
|
12
|
+
* for local ones. Round-trips through `toJSON` so a stored config keeps it. */
|
|
13
|
+
readonly link?: SystemLink;
|
|
11
14
|
constructor(args: {
|
|
12
15
|
name: string;
|
|
13
16
|
definition: CompositeStyleDefinition;
|
package/dist/CompositeStyle.js
CHANGED
|
@@ -5,12 +5,16 @@ var CompositeStyle = class {
|
|
|
5
5
|
label;
|
|
6
6
|
description;
|
|
7
7
|
styles;
|
|
8
|
+
/** Provenance when this composite is linked from another system; `undefined`
|
|
9
|
+
* for local ones. Round-trips through `toJSON` so a stored config keeps it. */
|
|
10
|
+
link;
|
|
8
11
|
#prefixGetter;
|
|
9
12
|
#derived;
|
|
10
13
|
constructor(args) {
|
|
11
14
|
this.name = args.name;
|
|
12
15
|
this.label = args.definition.label;
|
|
13
16
|
this.description = args.definition.description;
|
|
17
|
+
this.link = args.definition.link;
|
|
14
18
|
this.#prefixGetter = args.prefixGetter ?? (() => "uds");
|
|
15
19
|
const styles = /* @__PURE__ */ new Map();
|
|
16
20
|
for (const [variant, bag] of Object.entries(args.definition.styles)) styles.set(variant, bag);
|
|
@@ -43,7 +47,10 @@ var CompositeStyle = class {
|
|
|
43
47
|
return {
|
|
44
48
|
name: this.name,
|
|
45
49
|
label: this.label,
|
|
46
|
-
...compact({
|
|
50
|
+
...compact({
|
|
51
|
+
description: this.description,
|
|
52
|
+
link: this.link
|
|
53
|
+
}),
|
|
47
54
|
styles
|
|
48
55
|
};
|
|
49
56
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LinkedSystemPin, LinkedSystemsInput } from "../types.js";
|
|
2
2
|
import { ConfigValidationError } from "../config-diagnostics.js";
|
|
3
|
-
import {
|
|
3
|
+
import { NativeComponentDefinition, NativeComponentGroupDefinition, NativeComponentPropMarker, NativeComponentPropsFromMarkers, NativeComponentStyles, NativeLayerDefinition, NativeLayerKind, SerializedNativeComponentGroup } from "./components.js";
|
|
4
|
+
import { NativeAssetGroupDefinition, NativeBuildOptions, NativeDefaultModes, NativeFontAssetGroupDefinition, NativeModeDefinition, NativeStyleEngine, NativeTokenGroupDefinition, SerializedNativeConfig } from "./types.js";
|
|
4
5
|
import { NativeConfigDiagnostic } from "./validation.js";
|
|
5
6
|
|
|
6
7
|
//#region src/native/NativeConfig.d.ts
|
|
@@ -13,28 +14,36 @@ declare class NativeConfig {
|
|
|
13
14
|
readonly platform: "native";
|
|
14
15
|
namespace?: string;
|
|
15
16
|
styleEngine?: NativeStyleEngine;
|
|
17
|
+
buildOptions?: NativeBuildOptions;
|
|
16
18
|
defaultModes?: NativeDefaultModes;
|
|
17
19
|
readonly modes: Map<string, NativeModeDefinition>;
|
|
18
20
|
readonly tokenGroups: Map<string, NativeTokenGroupDefinition>;
|
|
19
21
|
readonly assetGroups: Map<string, NativeFontAssetGroupDefinition>;
|
|
22
|
+
readonly components: Map<string, NativeComponentDefinition<string, Record<string, NativeLayerDefinition<NativeLayerKind, string | undefined>>, Record<string, NativeComponentPropMarker>, Partial<NativeComponentPropsFromMarkers<Record<string, NativeComponentPropMarker>>>, NativeComponentStyles<Record<string, NativeLayerDefinition<NativeLayerKind, string | undefined>>>>>;
|
|
23
|
+
readonly componentGroups: Map<string, SerializedNativeComponentGroup>;
|
|
20
24
|
/** Source systems pinned via {@link registerLinkedSystems} — same
|
|
21
25
|
* contract as the web `Config`: one exact version per system UUID. */
|
|
22
26
|
readonly linkedSystems: Map<string, LinkedSystemPin>;
|
|
27
|
+
/** Build-only source pointers. They are intentionally absent from JSON. */
|
|
28
|
+
readonly componentSources: Map<string, {
|
|
29
|
+
definitionPath?: string;
|
|
30
|
+
renderPath: string;
|
|
31
|
+
}>;
|
|
23
32
|
configure(options: {
|
|
24
33
|
namespace?: string;
|
|
25
34
|
styleEngine?: NativeStyleEngine;
|
|
35
|
+
buildOptions?: NativeBuildOptions;
|
|
26
36
|
defaultModes?: NativeDefaultModes;
|
|
27
37
|
}): this;
|
|
28
38
|
registerModes(modes: Record<string, NativeModeDefinition>): this;
|
|
29
39
|
/**
|
|
30
|
-
* Pin source systems this config links values from
|
|
31
|
-
*
|
|
32
|
-
* and register its token groups (token envelopes are shared). Pins must
|
|
33
|
-
* appear before the `register*` calls that use them.
|
|
40
|
+
* Pin source systems this config links values from. Pins must appear before
|
|
41
|
+
* the `register*` calls that use them.
|
|
34
42
|
*/
|
|
35
43
|
registerLinkedSystems(input: LinkedSystemsInput): this;
|
|
36
44
|
registerTokenGroups(groups: Record<string, NativeTokenGroupDefinition>): this;
|
|
37
45
|
registerAssetGroups(groups: Record<string, NativeAssetGroupDefinition>): this;
|
|
46
|
+
registerComponentGroups(groups: Record<string, NativeComponentGroupDefinition>): this;
|
|
38
47
|
validate(): NativeConfigDiagnostic[];
|
|
39
48
|
toJSON(meta?: {
|
|
40
49
|
builtAt?: string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readSourcePath } from "../captureCallerPath.js";
|
|
1
2
|
import { assertLinkedTokenPinned, validateLinkedSystemPin } from "../linked-system-pins.js";
|
|
2
3
|
import { ConfigValidationError } from "../config-diagnostics.js";
|
|
3
4
|
import { validateSerializedNativeConfig } from "./validation.js";
|
|
@@ -13,13 +14,18 @@ var NativeConfig = class NativeConfig {
|
|
|
13
14
|
platform = "native";
|
|
14
15
|
namespace;
|
|
15
16
|
styleEngine;
|
|
17
|
+
buildOptions;
|
|
16
18
|
defaultModes;
|
|
17
19
|
modes = /* @__PURE__ */ new Map();
|
|
18
20
|
tokenGroups = /* @__PURE__ */ new Map();
|
|
19
21
|
assetGroups = /* @__PURE__ */ new Map();
|
|
22
|
+
components = /* @__PURE__ */ new Map();
|
|
23
|
+
componentGroups = /* @__PURE__ */ new Map();
|
|
20
24
|
/** Source systems pinned via {@link registerLinkedSystems} — same
|
|
21
25
|
* contract as the web `Config`: one exact version per system UUID. */
|
|
22
26
|
linkedSystems = /* @__PURE__ */ new Map();
|
|
27
|
+
/** Build-only source pointers. They are intentionally absent from JSON. */
|
|
28
|
+
componentSources = /* @__PURE__ */ new Map();
|
|
23
29
|
configure(options) {
|
|
24
30
|
if (options.namespace !== void 0) {
|
|
25
31
|
const diagnostics = validateSerializedNativeConfig({
|
|
@@ -39,6 +45,7 @@ var NativeConfig = class NativeConfig {
|
|
|
39
45
|
if (diagnostics.length > 0) throw new NativeConfigValidationError(diagnostics);
|
|
40
46
|
this.styleEngine = options.styleEngine;
|
|
41
47
|
}
|
|
48
|
+
if (options.buildOptions !== void 0) this.buildOptions = { ...options.buildOptions };
|
|
42
49
|
if (options.defaultModes !== void 0) this.defaultModes = { ...options.defaultModes };
|
|
43
50
|
return this;
|
|
44
51
|
}
|
|
@@ -47,10 +54,8 @@ var NativeConfig = class NativeConfig {
|
|
|
47
54
|
return this;
|
|
48
55
|
}
|
|
49
56
|
/**
|
|
50
|
-
* Pin source systems this config links values from
|
|
51
|
-
*
|
|
52
|
-
* and register its token groups (token envelopes are shared). Pins must
|
|
53
|
-
* appear before the `register*` calls that use them.
|
|
57
|
+
* Pin source systems this config links values from. Pins must appear before
|
|
58
|
+
* the `register*` calls that use them.
|
|
54
59
|
*/
|
|
55
60
|
registerLinkedSystems(input) {
|
|
56
61
|
for (const [systemId, pin] of Object.entries(input)) {
|
|
@@ -73,6 +78,29 @@ var NativeConfig = class NativeConfig {
|
|
|
73
78
|
for (const [name, definition] of Object.entries(groups)) this.assetGroups.set(name, definition);
|
|
74
79
|
return this;
|
|
75
80
|
}
|
|
81
|
+
registerComponentGroups(groups) {
|
|
82
|
+
for (const [groupName, group] of Object.entries(groups)) {
|
|
83
|
+
const componentNames = [];
|
|
84
|
+
for (const [componentName, component] of Object.entries(group.components)) {
|
|
85
|
+
const existing = this.components.get(componentName);
|
|
86
|
+
if (existing !== void 0 && existing !== component) throw new Error(`Native component "${componentName}" is registered more than once.`);
|
|
87
|
+
const duplicateId = [...this.components].find(([name, value]) => name !== componentName && value.id === component.id);
|
|
88
|
+
if (duplicateId !== void 0) throw new Error(`Native component id "${component.id}" is already used by "${duplicateId[0]}".`);
|
|
89
|
+
this.components.set(componentName, component);
|
|
90
|
+
this.componentSources.set(componentName, {
|
|
91
|
+
definitionPath: readSourcePath(component),
|
|
92
|
+
renderPath: component.__renderPath
|
|
93
|
+
});
|
|
94
|
+
componentNames.push(componentName);
|
|
95
|
+
}
|
|
96
|
+
this.componentGroups.set(groupName, {
|
|
97
|
+
components: componentNames,
|
|
98
|
+
...group.label !== void 0 ? { label: group.label } : {},
|
|
99
|
+
...group.description !== void 0 ? { description: group.description } : {}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
76
104
|
validate() {
|
|
77
105
|
return validateSerializedNativeConfig(this.#serialize());
|
|
78
106
|
}
|
|
@@ -89,10 +117,13 @@ var NativeConfig = class NativeConfig {
|
|
|
89
117
|
const config = new NativeConfig();
|
|
90
118
|
config.namespace = json.namespace;
|
|
91
119
|
config.styleEngine = json.styleEngine;
|
|
120
|
+
config.buildOptions = json.buildOptions ? { ...json.buildOptions } : void 0;
|
|
92
121
|
config.defaultModes = json.defaultModes ? { ...json.defaultModes } : void 0;
|
|
93
122
|
for (const [name, mode] of Object.entries(json.modes ?? {})) config.modes.set(name, mode);
|
|
94
123
|
for (const [name, group] of Object.entries(json.tokenGroups ?? {})) config.tokenGroups.set(name, group);
|
|
95
124
|
for (const [name, group] of Object.entries(json.assetGroups ?? {})) config.assetGroups.set(name, group);
|
|
125
|
+
for (const [name, component] of Object.entries(json.components ?? {})) config.components.set(name, component);
|
|
126
|
+
for (const [name, group] of Object.entries(json.componentGroups ?? {})) config.componentGroups.set(name, group);
|
|
96
127
|
for (const [systemId, pin] of Object.entries(json.linkedSystems ?? {})) config.linkedSystems.set(systemId, { ...pin });
|
|
97
128
|
return config;
|
|
98
129
|
}
|
|
@@ -104,10 +135,13 @@ var NativeConfig = class NativeConfig {
|
|
|
104
135
|
if (meta?.builtAt !== void 0) out.builtAt = meta.builtAt;
|
|
105
136
|
if (this.namespace !== void 0) out.namespace = this.namespace;
|
|
106
137
|
if (this.styleEngine !== void 0) out.styleEngine = this.styleEngine;
|
|
138
|
+
if (this.buildOptions !== void 0) out.buildOptions = { ...this.buildOptions };
|
|
107
139
|
if (this.defaultModes !== void 0) out.defaultModes = { ...this.defaultModes };
|
|
108
140
|
if (this.modes.size > 0) out.modes = Object.fromEntries(this.modes);
|
|
109
141
|
if (this.tokenGroups.size > 0) out.tokenGroups = Object.fromEntries(this.tokenGroups);
|
|
110
142
|
if (this.assetGroups.size > 0) out.assetGroups = Object.fromEntries(this.assetGroups);
|
|
143
|
+
if (this.components.size > 0) out.components = Object.fromEntries(this.components);
|
|
144
|
+
if (this.componentGroups.size > 0) out.componentGroups = Object.fromEntries(this.componentGroups);
|
|
111
145
|
if (this.linkedSystems.size > 0) out.linkedSystems = Object.fromEntries([...this.linkedSystems].map(([id, pin]) => [id, { ...pin }]));
|
|
112
146
|
return out;
|
|
113
147
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { TokenRef } from "../refs.js";
|
|
2
|
+
import { BooleanMarker, NumberMarker, RequiredBrand, SlotMarker, StringMarker, VariantMarkerArray } from "../markers.js";
|
|
3
|
+
import { NativeTokenValue } from "./types.js";
|
|
4
|
+
import { ReactNode } from "react";
|
|
5
|
+
|
|
6
|
+
//#region src/native/components.d.ts
|
|
7
|
+
type RequiredBuilder<T extends {
|
|
8
|
+
readonly __required?: boolean;
|
|
9
|
+
}> = T & {
|
|
10
|
+
required(): T & RequiredBrand;
|
|
11
|
+
};
|
|
12
|
+
type NativeStringSlotMarker = Omit<SlotMarker, 'required'> & {
|
|
13
|
+
readonly __valueType: 'string';
|
|
14
|
+
required(): NativeStringSlotMarker & RequiredBrand;
|
|
15
|
+
};
|
|
16
|
+
type NativeComponentPropMarker = SlotMarker | BooleanMarker | StringMarker | NumberMarker | VariantMarkerArray;
|
|
17
|
+
interface NativeComponentPropHelpers {
|
|
18
|
+
slot(): SlotMarker;
|
|
19
|
+
slot(options: {
|
|
20
|
+
type: 'string';
|
|
21
|
+
}): NativeStringSlotMarker;
|
|
22
|
+
boolean(): RequiredBuilder<BooleanMarker>;
|
|
23
|
+
string(): RequiredBuilder<StringMarker>;
|
|
24
|
+
number(): RequiredBuilder<NumberMarker>;
|
|
25
|
+
variant<const TValues extends readonly (string | number)[]>(values: TValues): RequiredBuilder<VariantMarkerArray<TValues>>;
|
|
26
|
+
}
|
|
27
|
+
type NativeSlotValue<TMarker extends SlotMarker> = TMarker['__valueType'] extends 'string' ? string : ReactNode;
|
|
28
|
+
type NativePropValue<TMarker> = TMarker extends SlotMarker ? NativeSlotValue<TMarker> : TMarker extends BooleanMarker ? boolean : TMarker extends StringMarker ? string : TMarker extends NumberMarker ? number : TMarker extends VariantMarkerArray<infer TValues> ? TValues[number] : never;
|
|
29
|
+
type RequiredNativePropKeys<TProps> = { [K in keyof TProps]: TProps[K] extends {
|
|
30
|
+
readonly __required: true;
|
|
31
|
+
} ? K : never }[keyof TProps];
|
|
32
|
+
type NativeComponentPropsFromMarkers<TProps> = { [K in RequiredNativePropKeys<TProps>]-?: NativePropValue<TProps[K]> } & { [K in Exclude<keyof TProps, RequiredNativePropKeys<TProps>>]?: NativePropValue<TProps[K]> };
|
|
33
|
+
type ResolvedNativeComponentProps<TProps extends Record<string, NativeComponentPropMarker>, TDefaults> = { [K in keyof TProps as K extends keyof TDefaults ? K : TProps[K] extends {
|
|
34
|
+
readonly __required: true;
|
|
35
|
+
} ? K : never]-?: NativePropValue<TProps[K]> } & { [K in keyof TProps as K extends keyof TDefaults ? never : TProps[K] extends {
|
|
36
|
+
readonly __required: true;
|
|
37
|
+
} ? never : K]?: NativePropValue<TProps[K]> };
|
|
38
|
+
type NativeLayerKind = 'view' | 'text' | 'image';
|
|
39
|
+
interface NativeLayerDefinition<TKind extends NativeLayerKind = NativeLayerKind, TPublicStyle extends string | undefined = string | undefined> {
|
|
40
|
+
readonly kind: TKind;
|
|
41
|
+
readonly styleProp?: TPublicStyle;
|
|
42
|
+
}
|
|
43
|
+
interface NativeLayerBuilder<TKind extends NativeLayerKind> extends NativeLayerDefinition<TKind, undefined> {
|
|
44
|
+
publicStyle<const TName extends string = 'style'>(name?: TName): NativeLayerDefinition<TKind, TName>;
|
|
45
|
+
}
|
|
46
|
+
/** Define a React Native style target. */
|
|
47
|
+
declare function nativeLayer<const TKind extends NativeLayerKind>(kind: TKind): NativeLayerBuilder<TKind>;
|
|
48
|
+
type NativeStyleValue = NativeTokenValue | readonly NativeStyleValue[] | {
|
|
49
|
+
readonly [key: string]: NativeStyleValue;
|
|
50
|
+
};
|
|
51
|
+
type NativeLayerStyle = Readonly<Record<string, NativeStyleValue>>;
|
|
52
|
+
type NativeLayerStyles = Readonly<Record<string, NativeLayerStyle>>;
|
|
53
|
+
type NativeLayerNames<TLayers> = keyof TLayers & string;
|
|
54
|
+
type LayerStylesFor<TLayers> = Partial<Record<NativeLayerNames<TLayers>, NativeLayerStyle>>;
|
|
55
|
+
interface NativeComponentStyles<TLayers extends Record<string, NativeLayerDefinition> = Record<string, NativeLayerDefinition>> {
|
|
56
|
+
readonly base?: LayerStylesFor<TLayers>;
|
|
57
|
+
readonly variants?: Readonly<Record<string, Readonly<Record<string, LayerStylesFor<TLayers>>>>>;
|
|
58
|
+
readonly booleans?: Readonly<Record<string, Readonly<{
|
|
59
|
+
true?: LayerStylesFor<TLayers>;
|
|
60
|
+
false?: LayerStylesFor<TLayers>;
|
|
61
|
+
}>>>;
|
|
62
|
+
readonly runtimeStates?: Readonly<Record<string, LayerStylesFor<TLayers>>>;
|
|
63
|
+
/** Scalar design values exposed to render code through `values.*()`. */
|
|
64
|
+
readonly values?: Readonly<Record<string, NativeTokenValue>>;
|
|
65
|
+
}
|
|
66
|
+
interface NativeComponentStyleHelpers {
|
|
67
|
+
token(name: string): TokenRef;
|
|
68
|
+
}
|
|
69
|
+
/** Serializable design data for one first-class native component. */
|
|
70
|
+
interface NativeComponentDefinition<TId extends string = string, TLayers extends Record<string, NativeLayerDefinition> = Record<string, NativeLayerDefinition>, TProps extends Record<string, NativeComponentPropMarker> = Record<string, NativeComponentPropMarker>, TDefaults extends Partial<NativeComponentPropsFromMarkers<TProps>> = Partial<NativeComponentPropsFromMarkers<TProps>>, TStyles extends NativeComponentStyles<TLayers> = NativeComponentStyles<TLayers>> {
|
|
71
|
+
readonly id: TId;
|
|
72
|
+
readonly layers: TLayers;
|
|
73
|
+
readonly props: TProps;
|
|
74
|
+
readonly defaultProps?: TDefaults;
|
|
75
|
+
readonly label?: string;
|
|
76
|
+
readonly description?: string;
|
|
77
|
+
readonly styles: TStyles;
|
|
78
|
+
}
|
|
79
|
+
type RegisteredNativeComponent<TId extends string = string, TLayers extends Record<string, NativeLayerDefinition> = Record<string, NativeLayerDefinition>, TProps extends Record<string, NativeComponentPropMarker> = Record<string, NativeComponentPropMarker>, TDefaults extends Partial<NativeComponentPropsFromMarkers<TProps>> = Partial<NativeComponentPropsFromMarkers<TProps>>, TStyles extends NativeComponentStyles<TLayers> = NativeComponentStyles<TLayers>> = NativeComponentDefinition<TId, TLayers, TProps, TDefaults, TStyles> & {
|
|
80
|
+
readonly __nativeComponent: true;
|
|
81
|
+
readonly __renderPath: string;
|
|
82
|
+
};
|
|
83
|
+
type RuntimeStateNames<TComponent> = TComponent extends NativeComponentDefinition<string, Record<string, NativeLayerDefinition>, Record<string, NativeComponentPropMarker>, Partial<NativeComponentPropsFromMarkers<Record<string, NativeComponentPropMarker>>>, infer TStyles> ? TStyles extends {
|
|
84
|
+
runtimeStates: infer TStates;
|
|
85
|
+
} ? keyof TStates & string : string : string;
|
|
86
|
+
type NamedValues<TComponent> = TComponent extends NativeComponentDefinition<string, Record<string, NativeLayerDefinition>, Record<string, NativeComponentPropMarker>, Partial<NativeComponentPropsFromMarkers<Record<string, NativeComponentPropMarker>>>, infer TStyles> ? TStyles extends {
|
|
87
|
+
values: infer TValues;
|
|
88
|
+
} ? keyof TValues & string : never : never;
|
|
89
|
+
type LayersOf<TComponent> = TComponent extends {
|
|
90
|
+
readonly layers: infer TLayers extends Record<string, NativeLayerDefinition>;
|
|
91
|
+
} ? TLayers : never;
|
|
92
|
+
type PropMarkersOf<TComponent> = TComponent extends {
|
|
93
|
+
readonly props: infer TProps extends Record<string, NativeComponentPropMarker>;
|
|
94
|
+
} ? TProps : never;
|
|
95
|
+
type DefaultsOf<TComponent> = TComponent extends {
|
|
96
|
+
readonly defaultProps?: infer TDefaults;
|
|
97
|
+
} ? TDefaults : Record<never, never>;
|
|
98
|
+
type NativeComponentProps<TComponent> = NativeComponentPropsFromMarkers<PropMarkersOf<TComponent>>;
|
|
99
|
+
type NativeGeneratedRenderProps<TComponent, TStyleByLayer extends Record<NativeLayerNames<LayersOf<TComponent>>, unknown>> = ResolvedNativeComponentProps<PropMarkersOf<TComponent>, DefaultsOf<TComponent>> & {
|
|
100
|
+
styles: { [K in NativeLayerNames<LayersOf<TComponent>>]: (state?: Partial<Record<RuntimeStateNames<TComponent>, boolean>>) => TStyleByLayer[K] };
|
|
101
|
+
values: { [K in NamedValues<TComponent>]: () => string | number | boolean };
|
|
102
|
+
};
|
|
103
|
+
/** Props the copied native render receives from its generated wrapper. */
|
|
104
|
+
type NativeRenderProps<TComponent, TStyleByLayer extends Record<NativeLayerNames<LayersOf<TComponent>>, unknown>, TRuntimeProps extends object = Record<never, never>> = TRuntimeProps extends unknown ? Omit<TRuntimeProps, keyof NativeComponentProps<TComponent>> & NativeGeneratedRenderProps<TComponent, TStyleByLayer> : never;
|
|
105
|
+
interface NativeComponentStyledBuilder<TId extends string, TLayers extends Record<string, NativeLayerDefinition>, TProps extends Record<string, NativeComponentPropMarker>, TDefaults extends Partial<NativeComponentPropsFromMarkers<TProps>>, TStyles extends NativeComponentStyles<TLayers>> extends NativeComponentDefinition<TId, TLayers, TProps, TDefaults, TStyles> {
|
|
106
|
+
render(path: string): RegisteredNativeComponent<TId, TLayers, TProps, TDefaults, TStyles>;
|
|
107
|
+
}
|
|
108
|
+
interface NativeComponentBuilder<TId extends string, TLayers extends Record<string, NativeLayerDefinition>, TProps extends Record<string, NativeComponentPropMarker>, TDefaults extends Partial<NativeComponentPropsFromMarkers<TProps>>> {
|
|
109
|
+
styles<const TStyles extends NativeComponentStyles<TLayers>>(callback: (helpers: NativeComponentStyleHelpers) => TStyles): NativeComponentStyledBuilder<TId, TLayers, TProps, TDefaults, TStyles>;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Define a first-class React Native component. The render path remains a
|
|
113
|
+
* build-only source pointer and is never serialized into native config data.
|
|
114
|
+
*/
|
|
115
|
+
declare function defineNativeComponent<const TId extends string, const TLayers extends Record<string, NativeLayerDefinition>, const TProps extends Record<string, NativeComponentPropMarker>, const TDefaults extends Partial<NativeComponentPropsFromMarkers<TProps>> = Record<never, never>>(definition: {
|
|
116
|
+
id: TId;
|
|
117
|
+
layers: TLayers;
|
|
118
|
+
props: (helpers: NativeComponentPropHelpers) => TProps;
|
|
119
|
+
defaultProps?: TDefaults;
|
|
120
|
+
label?: string;
|
|
121
|
+
description?: string;
|
|
122
|
+
}): NativeComponentBuilder<TId, TLayers, TProps, TDefaults>;
|
|
123
|
+
interface NativeComponentGroupDefinition<TComponents extends Record<string, RegisteredNativeComponent> = Record<string, RegisteredNativeComponent>> {
|
|
124
|
+
readonly components: TComponents;
|
|
125
|
+
readonly label?: string;
|
|
126
|
+
readonly description?: string;
|
|
127
|
+
}
|
|
128
|
+
declare function defineNativeComponentGroup<const TComponents extends Record<string, RegisteredNativeComponent>>(definition: {
|
|
129
|
+
components: TComponents;
|
|
130
|
+
label?: string;
|
|
131
|
+
description?: string;
|
|
132
|
+
}): NativeComponentGroupDefinition<TComponents>;
|
|
133
|
+
interface SerializedNativeComponentGroup {
|
|
134
|
+
readonly components: readonly string[];
|
|
135
|
+
readonly label?: string;
|
|
136
|
+
readonly description?: string;
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
export { NativeComponentBuilder, NativeComponentDefinition, NativeComponentGroupDefinition, NativeComponentPropMarker, NativeComponentProps, NativeComponentPropsFromMarkers, NativeComponentStyleHelpers, NativeComponentStyledBuilder, NativeComponentStyles, NativeLayerDefinition, NativeLayerKind, NativeLayerStyle, NativeLayerStyles, NativeRenderProps, NativeStyleValue, RegisteredNativeComponent, SerializedNativeComponentGroup, defineNativeComponent, defineNativeComponentGroup, nativeLayer };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { attachSourcePath, captureCallerPath } from "../captureCallerPath.js";
|
|
2
|
+
import { token } from "../refs.js";
|
|
3
|
+
import { boolean, number, slot, string, variant } from "../factories.js";
|
|
4
|
+
//#region src/native/components.ts
|
|
5
|
+
const nativeComponentPropHelpers = {
|
|
6
|
+
slot(options) {
|
|
7
|
+
return options === void 0 ? slot() : slot(options);
|
|
8
|
+
},
|
|
9
|
+
boolean,
|
|
10
|
+
string,
|
|
11
|
+
number,
|
|
12
|
+
variant
|
|
13
|
+
};
|
|
14
|
+
/** Define a React Native style target. */
|
|
15
|
+
function nativeLayer(kind) {
|
|
16
|
+
const layer = { kind };
|
|
17
|
+
Object.defineProperty(layer, "publicStyle", {
|
|
18
|
+
enumerable: false,
|
|
19
|
+
configurable: true,
|
|
20
|
+
value(name = "style") {
|
|
21
|
+
Object.defineProperty(layer, "styleProp", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
value: name
|
|
25
|
+
});
|
|
26
|
+
return layer;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return layer;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Define a first-class React Native component. The render path remains a
|
|
33
|
+
* build-only source pointer and is never serialized into native config data.
|
|
34
|
+
*/
|
|
35
|
+
function defineNativeComponent(definition) {
|
|
36
|
+
const sourcePath = captureCallerPath();
|
|
37
|
+
const props = definition.props(nativeComponentPropHelpers);
|
|
38
|
+
return { styles(callback) {
|
|
39
|
+
const component = attachSourcePath({
|
|
40
|
+
id: definition.id,
|
|
41
|
+
layers: definition.layers,
|
|
42
|
+
props,
|
|
43
|
+
...definition.defaultProps !== void 0 ? { defaultProps: definition.defaultProps } : {},
|
|
44
|
+
...definition.label !== void 0 ? { label: definition.label } : {},
|
|
45
|
+
...definition.description !== void 0 ? { description: definition.description } : {},
|
|
46
|
+
styles: callback({ token })
|
|
47
|
+
}, sourcePath);
|
|
48
|
+
Object.defineProperty(component, "render", {
|
|
49
|
+
enumerable: false,
|
|
50
|
+
configurable: true,
|
|
51
|
+
value(renderPath) {
|
|
52
|
+
Object.defineProperties(component, {
|
|
53
|
+
__nativeComponent: { value: true },
|
|
54
|
+
__renderPath: { value: renderPath }
|
|
55
|
+
});
|
|
56
|
+
return component;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return component;
|
|
60
|
+
} };
|
|
61
|
+
}
|
|
62
|
+
function defineNativeComponentGroup(definition) {
|
|
63
|
+
return attachSourcePath(definition, captureCallerPath());
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
export { defineNativeComponent, defineNativeComponentGroup, nativeLayer };
|
package/dist/native/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { AssetRef, TokenRef, asset, token } from "../refs.js";
|
|
|
2
2
|
import { ColorSpace, MixExpr, alpha, mix } from "../colorExpressions.js";
|
|
3
3
|
import { SystemLink, TokenType } from "../types.js";
|
|
4
4
|
import { DefinedTokenGroupValue } from "../factories.js";
|
|
5
|
-
import {
|
|
5
|
+
import { NativeComponentBuilder, NativeComponentDefinition, NativeComponentGroupDefinition, NativeComponentProps, NativeComponentStyleHelpers, NativeComponentStyledBuilder, NativeComponentStyles, NativeLayerDefinition, NativeLayerKind, NativeLayerStyle, NativeLayerStyles, NativeRenderProps, NativeStyleValue, RegisteredNativeComponent, SerializedNativeComponentGroup, defineNativeComponent, defineNativeComponentGroup, nativeLayer } from "./components.js";
|
|
6
|
+
import { ModeDefinition, NativeAppearanceModeOption, NativeAssetGroupDefinition, NativeBuildOptions, NativeColorExpression, NativeDefaultModes, NativeFontAssetGroupDefinition, NativeFontAssetMember, NativeLiteral, NativeModeDefinition, NativeModeOptionDefinition, NativeSelectableValue, NativeStyleEngine, NativeTokenDefinition, NativeTokenGroupDefinition, NativeTokenValue, NativeViewportModeOption, OperatingSystemInput, OperatingSystemValue, SerializedNativeConfig } from "./types.js";
|
|
6
7
|
import { NativeAssetGroupBuilder, NativeFontAssetGroupConfig, defineAssetGroup } from "./assets.js";
|
|
7
8
|
import { defineMode } from "./modes.js";
|
|
8
9
|
import { NativeConfigDiagnostic, NativeConfigDiagnosticCode, validateSerializedNativeConfig } from "./validation.js";
|
package/dist/native/index.js
CHANGED
package/dist/native/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AssetRef, TokenRef } from "../refs.js";
|
|
2
2
|
import { MixExpr } from "../colorExpressions.js";
|
|
3
3
|
import { LinkedSystemPin, TokenDefinitionFor, TokenGroupDefinitionFor, TokenModifierKey } from "../types.js";
|
|
4
|
+
import { NativeComponentDefinition, SerializedNativeComponentGroup } from "./components.js";
|
|
4
5
|
|
|
5
6
|
//#region src/native/types.d.ts
|
|
6
7
|
type NativeLiteral = string | number | boolean;
|
|
@@ -51,6 +52,10 @@ type ModeDefinition = NativeModeDefinition;
|
|
|
51
52
|
type NativeDefaultModes = Record<string, string>;
|
|
52
53
|
/** Styling runtime selected for generated native component and adapter files. */
|
|
53
54
|
type NativeStyleEngine = 'react-native' | 'unistyles';
|
|
55
|
+
interface NativeBuildOptions {
|
|
56
|
+
/** Trusted root containing native component definitions and render source. */
|
|
57
|
+
componentsDir?: string;
|
|
58
|
+
}
|
|
54
59
|
interface NativeFontAssetMember {
|
|
55
60
|
/** Family identifier React Native consumes after the app registers the font. */
|
|
56
61
|
fontFamily: string;
|
|
@@ -68,12 +73,15 @@ interface SerializedNativeConfig {
|
|
|
68
73
|
builtAt?: string;
|
|
69
74
|
namespace?: string;
|
|
70
75
|
styleEngine?: NativeStyleEngine;
|
|
76
|
+
buildOptions?: NativeBuildOptions;
|
|
71
77
|
defaultModes?: NativeDefaultModes;
|
|
72
78
|
modes?: Record<string, NativeModeDefinition>;
|
|
73
79
|
tokenGroups?: Record<string, NativeTokenGroupDefinition>;
|
|
74
80
|
assetGroups?: Record<string, NativeAssetGroupDefinition>;
|
|
81
|
+
components?: Record<string, NativeComponentDefinition>;
|
|
82
|
+
componentGroups?: Record<string, SerializedNativeComponentGroup>;
|
|
75
83
|
/** Source-system pins, same contract as the web `SerializedConfig`. */
|
|
76
84
|
linkedSystems?: Record<string, LinkedSystemPin>;
|
|
77
85
|
}
|
|
78
86
|
//#endregion
|
|
79
|
-
export { ModeDefinition, NativeAppearanceModeOption, NativeAssetGroupDefinition, NativeColorExpression, NativeDefaultModes, NativeFontAssetGroupDefinition, NativeFontAssetMember, NativeLiteral, NativeModeDefinition, NativeModeOptionDefinition, NativeSelectableValue, NativeStyleEngine, NativeTokenDefinition, NativeTokenGroupDefinition, NativeTokenValue, NativeViewportModeOption, OperatingSystemInput, OperatingSystemValue, SerializedNativeConfig };
|
|
87
|
+
export { ModeDefinition, NativeAppearanceModeOption, NativeAssetGroupDefinition, NativeBuildOptions, NativeColorExpression, NativeDefaultModes, NativeFontAssetGroupDefinition, NativeFontAssetMember, NativeLiteral, NativeModeDefinition, NativeModeOptionDefinition, NativeSelectableValue, NativeStyleEngine, NativeTokenDefinition, NativeTokenGroupDefinition, NativeTokenValue, NativeViewportModeOption, OperatingSystemInput, OperatingSystemValue, SerializedNativeConfig };
|