@adobe/design-data-wasm 0.4.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/LICENSE +201 -0
- package/README.md +121 -0
- package/package.json +56 -0
- package/pkg/node/README.md +121 -0
- package/pkg/node/design_data_wasm.d.ts +439 -0
- package/pkg/node/design_data_wasm.js +897 -0
- package/pkg/node/design_data_wasm_bg.wasm +0 -0
- package/pkg/node/design_data_wasm_bg.wasm.d.ts +33 -0
- package/pkg/web/README.md +121 -0
- package/pkg/web/design_data_wasm.d.ts +497 -0
- package/pkg/web/design_data_wasm.js +981 -0
- package/pkg/web/design_data_wasm_bg.wasm +0 -0
- package/pkg/web/design_data_wasm_bg.wasm.d.ts +33 -0
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_dataset_free: (a: number, b: number) => void;
|
|
5
|
+
export const dataset_embedded: () => [number, number, number];
|
|
6
|
+
export const dataset_fromTokens: (a: any) => [number, number, number];
|
|
7
|
+
export const dataset_primer: (a: number) => [number, number, number];
|
|
8
|
+
export const dataset_query: (a: number, b: number, c: number) => [number, number, number];
|
|
9
|
+
export const dataset_suggest: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
10
|
+
export const dataset_validate: (a: number) => any;
|
|
11
|
+
export const dataset_resolve: (a: number, b: number, c: number, d: any) => [number, number, number];
|
|
12
|
+
export const dataset_resolveReference: (a: number, b: number, c: number, d: any) => [number, number, number];
|
|
13
|
+
export const dataset_diff: (a: number, b: number) => [number, number, number];
|
|
14
|
+
export const dataset_tokenCount: (a: number) => number;
|
|
15
|
+
export const getFieldValues: (a: number, b: number) => [number, number];
|
|
16
|
+
export const hasFieldValue: (a: number, b: number, c: number, d: number) => number;
|
|
17
|
+
export const getAdvisoryFields: () => [number, number];
|
|
18
|
+
export const getIndexedFields: () => [number, number];
|
|
19
|
+
export const getValues: (a: any) => [number, number, number, number];
|
|
20
|
+
export const findValue: (a: any, b: number, c: number) => [number, number, number];
|
|
21
|
+
export const hasValue: (a: any, b: number, c: number) => [number, number, number];
|
|
22
|
+
export const getDefault: (a: any) => [number, number, number];
|
|
23
|
+
export const getActiveValues: (a: any) => [number, number, number];
|
|
24
|
+
export const init: () => void;
|
|
25
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
26
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
27
|
+
export const __wbindgen_exn_store: (a: number) => void;
|
|
28
|
+
export const __externref_table_alloc: () => number;
|
|
29
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
30
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
31
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
32
|
+
export const __externref_drop_slice: (a: number, b: number) => void;
|
|
33
|
+
export const __wbindgen_start: () => void;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# [**@adobe/design-data-wasm**](https://github.com/adobe/design-data-wasm)
|
|
2
|
+
|
|
3
|
+
WebAssembly bindings for [`design-data-core`](../core/) — query, validate,
|
|
4
|
+
resolve, and diff Spectrum design tokens from JavaScript or TypeScript, with
|
|
5
|
+
zero native dependencies.
|
|
6
|
+
|
|
7
|
+
Generated TypeScript types are derived directly from the Rust types via
|
|
8
|
+
[tsify-next](https://github.com/nickel-lang/tsify-next) — no hand-maintained
|
|
9
|
+
parallel type surface.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pnpm add @adobe/design-data-wasm
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Node.js (synchronous — no `init()` required)
|
|
20
|
+
|
|
21
|
+
The `node` export condition resolves to a synchronous CommonJS build; named
|
|
22
|
+
imports work in ESM via cjs-module-lexer.
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { Dataset, getValues, findValue } from '@adobe/design-data-wasm';
|
|
26
|
+
|
|
27
|
+
// Use the canonical embedded Spectrum dataset (zero config):
|
|
28
|
+
const ds = Dataset.embedded();
|
|
29
|
+
|
|
30
|
+
// Or build a dataset from your own token objects:
|
|
31
|
+
const tokens = JSON.parse(fs.readFileSync('my-tokens.json', 'utf-8'));
|
|
32
|
+
const customDs = Dataset.fromTokens(tokens);
|
|
33
|
+
|
|
34
|
+
// Query
|
|
35
|
+
const colorTokens = ds.query('property=color,colorScheme=dark');
|
|
36
|
+
console.log(colorTokens[0].name, colorTokens[0].raw.value);
|
|
37
|
+
|
|
38
|
+
// Validate (relational rules — structural/JSON-Schema checks require the CLI)
|
|
39
|
+
const { valid, errors } = ds.validate();
|
|
40
|
+
|
|
41
|
+
// Resolve a property in a given context
|
|
42
|
+
const result = ds.resolve('background', { colorScheme: 'dark', scale: 'medium' });
|
|
43
|
+
if (result) console.log(result.token.raw.value, 'specificity:', result.specificity);
|
|
44
|
+
|
|
45
|
+
// Diff two datasets
|
|
46
|
+
const oldDs = Dataset.fromTokens(oldTokens);
|
|
47
|
+
const newDs = Dataset.fromTokens(newTokens);
|
|
48
|
+
const diff = oldDs.diff(newDs);
|
|
49
|
+
console.log(`${diff.added.length} added, ${diff.deleted.length} deleted`);
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Browser / bundler (requires `await init()`)
|
|
53
|
+
|
|
54
|
+
The `browser` export condition resolves to a browser ESM build. Call `init()`
|
|
55
|
+
with the URL of the `.wasm` file before using any API.
|
|
56
|
+
|
|
57
|
+
> **Note for Deno, Bun, and non-standard bundlers:** the package's `default` export
|
|
58
|
+
> condition also resolves to the web (browser ESM) build, so runtimes or bundlers that
|
|
59
|
+
> don't honour the `node` or `browser` condition will get this build and **must** call
|
|
60
|
+
> `await init()` before using any API.
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
import init, { Dataset } from '@adobe/design-data-wasm';
|
|
64
|
+
// or explicit browser path:
|
|
65
|
+
import init, { Dataset } from '@adobe/design-data-wasm/pkg/web/design_data_wasm.js';
|
|
66
|
+
|
|
67
|
+
await init(); // pass wasm URL if needed: await init(new URL('./wasm/design_data_wasm_bg.wasm', import.meta.url))
|
|
68
|
+
|
|
69
|
+
const ds = Dataset.fromTokens(tokens);
|
|
70
|
+
const results = ds.query('property=color');
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## API
|
|
74
|
+
|
|
75
|
+
### `Dataset`
|
|
76
|
+
|
|
77
|
+
| Method | Returns | Description |
|
|
78
|
+
| ------------------------------- | ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
79
|
+
| `Dataset.embedded()` | `Dataset` | Open the canonical embedded Spectrum dataset (prebuilt `.redb` cache — zero config). The full token dataset is compiled into the `.wasm` binary via `include_bytes!`; use `fromTokens()` instead if binary size is a concern. |
|
|
80
|
+
| `Dataset.fromTokens(tokens)` | `Dataset` | Build a dataset from an array of raw token JSON objects |
|
|
81
|
+
| `ds.query(filterExpr)` | `TokenResult[]` | Filter tokens. Syntax: `key=value` pairs joined with `,` (AND) or `\|` (OR); `!=` negation; `*` wildcard |
|
|
82
|
+
| `ds.validate()` | `ValidationResult` | Relational validation. `valid`, `errors[]`, `warnings[]` |
|
|
83
|
+
| `ds.resolve(property, context)` | `ResolveResult \| undefined` | Resolve a property in a mode-set context, e.g. `{ colorScheme: 'dark' }` |
|
|
84
|
+
| `ds.diff(otherDataset)` | `DiffResult` | Semantic diff. Fields: `renamed`, `deprecated`, `reverted`, `added`, `deleted`, `updated` |
|
|
85
|
+
| `ds.tokenCount()` | `number` | Number of tokens in the dataset |
|
|
86
|
+
|
|
87
|
+
### Registry helpers
|
|
88
|
+
|
|
89
|
+
These match the deprecated `@adobe/design-system-registry` API, accepting the
|
|
90
|
+
`{ values: [...] }` JSON shape from `@adobe/spectrum-design-data/registry/*.json`.
|
|
91
|
+
|
|
92
|
+
| Function | Description |
|
|
93
|
+
| --------------------------- | --------------------------------- |
|
|
94
|
+
| `getValues(registry)` | Return all value IDs |
|
|
95
|
+
| `findValue(registry, term)` | Find an entry by ID or alias |
|
|
96
|
+
| `hasValue(registry, term)` | Check if an ID or alias exists |
|
|
97
|
+
| `getDefault(registry)` | Return the default entry |
|
|
98
|
+
| `getActiveValues(registry)` | Return all non-deprecated entries |
|
|
99
|
+
|
|
100
|
+
### Embedded registry helpers
|
|
101
|
+
|
|
102
|
+
Fast lookups backed by the compile-time-embedded registry data (no JSON argument
|
|
103
|
+
needed):
|
|
104
|
+
|
|
105
|
+
| Function | Description |
|
|
106
|
+
| --------------------------------- | ----------------------------------------------------------------- |
|
|
107
|
+
| `getFieldValues(fieldName)` | All IDs+aliases for a name field (`"property"`, `"component"`, …) |
|
|
108
|
+
| `hasFieldValue(fieldName, value)` | Membership check for a name field |
|
|
109
|
+
| `getAdvisoryFields()` | Names of advisory (non-normative) fields |
|
|
110
|
+
|
|
111
|
+
## TypeScript
|
|
112
|
+
|
|
113
|
+
Types are generated from the Rust structs; no parallel declaration needed.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import type { TokenResult, ValidationResult, DiffResult, ResolveResult } from '@adobe/design-data-wasm';
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
Apache-2.0 — see [LICENSE](../../LICENSE).
|
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* A list of suggestion results from `Dataset.suggest()`. Typed as `SuggestResult[]` in TypeScript.
|
|
5
|
+
*/
|
|
6
|
+
export type SuggestResultArray = SuggestResult[];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A list of token results from a query. Typed as `TokenResult[]` in TypeScript.
|
|
10
|
+
*/
|
|
11
|
+
export type TokenResultArray = TokenResult[];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A mode-set context for token resolution.
|
|
15
|
+
*
|
|
16
|
+
* Maps mode-set names (e.g. `\"colorScheme\"`, `\"scale\"`) to their active mode
|
|
17
|
+
* values (e.g. `\"dark\"`, `\"medium\"`).
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* const result = ds.resolve(\"background\", { colorScheme: \"dark\", scale: \"medium\" });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export type ResolutionContext = Map<string, string>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A registry vocabulary object as read from `registry/*.json`.
|
|
27
|
+
*/
|
|
28
|
+
export interface RegistryObject {
|
|
29
|
+
values: RegistryEntry[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A single entry in a registry vocabulary (e.g. a size, state, or variant).
|
|
34
|
+
*
|
|
35
|
+
* Mirrors the shape of each object in `registry/*.json#values`.
|
|
36
|
+
*/
|
|
37
|
+
export interface RegistryEntry {
|
|
38
|
+
id: string;
|
|
39
|
+
label?: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
aliases?: string[];
|
|
42
|
+
default?: boolean;
|
|
43
|
+
deprecated?: boolean;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A single key→value change within a token\'s properties.
|
|
48
|
+
*/
|
|
49
|
+
export interface PropertyChange {
|
|
50
|
+
path: string;
|
|
51
|
+
changeType: string;
|
|
52
|
+
newValue?: Value;
|
|
53
|
+
originalValue?: Value;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A single ranked suggestion result from `Dataset.suggest()`.
|
|
58
|
+
*/
|
|
59
|
+
export interface SuggestResult {
|
|
60
|
+
tokenUuid?: string;
|
|
61
|
+
tokenName: string;
|
|
62
|
+
file: string;
|
|
63
|
+
layer: string;
|
|
64
|
+
confidence: number;
|
|
65
|
+
nameObject?: Value;
|
|
66
|
+
value?: Value;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* A single resolved token result from `Dataset.resolve()`.
|
|
71
|
+
*/
|
|
72
|
+
export interface ResolveResult {
|
|
73
|
+
token: TokenResult;
|
|
74
|
+
specificity: number;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A single validation diagnostic.
|
|
79
|
+
*/
|
|
80
|
+
export interface Diagnostic {
|
|
81
|
+
severity: Severity;
|
|
82
|
+
message: string;
|
|
83
|
+
ruleId?: string;
|
|
84
|
+
path?: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A token record as returned by query results.
|
|
89
|
+
*
|
|
90
|
+
* Reflects `design_data_core::graph::TokenRecord` — the canonical token object
|
|
91
|
+
* including its `name`, `value`, `uuid`, `$schema`, etc. in `raw`.
|
|
92
|
+
*/
|
|
93
|
+
export interface TokenResult {
|
|
94
|
+
name: string;
|
|
95
|
+
/**
|
|
96
|
+
* The token\'s full source JSON (all fields: name, value, uuid, $schema, etc.)
|
|
97
|
+
*/
|
|
98
|
+
raw: Value;
|
|
99
|
+
uuid?: string;
|
|
100
|
+
schemaUrl?: string;
|
|
101
|
+
aliasTarget?: string;
|
|
102
|
+
layer: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A token that gained a `deprecated` marker.
|
|
107
|
+
*/
|
|
108
|
+
export interface DeprecatedToken {
|
|
109
|
+
name: string;
|
|
110
|
+
uuid?: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* A token that had its `deprecated` marker removed.
|
|
115
|
+
*/
|
|
116
|
+
export interface RevertedToken {
|
|
117
|
+
name: string;
|
|
118
|
+
uuid?: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A token that had property-level changes (same name, same UUID).
|
|
123
|
+
*/
|
|
124
|
+
export interface UpdatedToken {
|
|
125
|
+
name: string;
|
|
126
|
+
uuid?: string;
|
|
127
|
+
propertyChanges: PropertyChange[];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* A token that was added.
|
|
132
|
+
*/
|
|
133
|
+
export interface AddedToken {
|
|
134
|
+
name: string;
|
|
135
|
+
uuid?: string;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* A token that was deleted.
|
|
140
|
+
*/
|
|
141
|
+
export interface DeletedToken {
|
|
142
|
+
name: string;
|
|
143
|
+
uuid?: string;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A token that was renamed (same UUID, different name).
|
|
148
|
+
*/
|
|
149
|
+
export interface RenamedToken {
|
|
150
|
+
oldName: string;
|
|
151
|
+
newName: string;
|
|
152
|
+
uuid?: string;
|
|
153
|
+
propertyChanges: PropertyChange[];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Severity level of a validation diagnostic.
|
|
158
|
+
*/
|
|
159
|
+
export type Severity = "error" | "warning" | "info";
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The result of `Dataset.diff()`.
|
|
163
|
+
*
|
|
164
|
+
* Mirrors `design_data_core::diff::DiffReport` with typed arrays for each change category.
|
|
165
|
+
*/
|
|
166
|
+
export interface DiffResult {
|
|
167
|
+
renamed: RenamedToken[];
|
|
168
|
+
deprecated: DeprecatedToken[];
|
|
169
|
+
reverted: RevertedToken[];
|
|
170
|
+
added: AddedToken[];
|
|
171
|
+
deleted: DeletedToken[];
|
|
172
|
+
updated: UpdatedToken[];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The result of `Dataset.resolveReference()`.
|
|
177
|
+
*
|
|
178
|
+
* Contains the resolved terminal value and the full chain of names/references
|
|
179
|
+
* traversed to reach it — mirrors the `getResolutionChain()` behaviour from
|
|
180
|
+
* the legacy inline `TokenResolver` in `docs/s2-tokens-viewer/index.html`.
|
|
181
|
+
*
|
|
182
|
+
* ```ts
|
|
183
|
+
* const r = ds.resolveReference(\"{accent-color-100}\", { colorScheme: \"light\" });
|
|
184
|
+
* // r.chain → [\"{accent-color-100}\", \"{blue-100}\", \"rgb(245, 249, 255)\"]
|
|
185
|
+
* // r.value → \"rgb(245, 249, 255)\
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export interface ReferenceChainResult {
|
|
189
|
+
/**
|
|
190
|
+
* The resolved terminal value (absent if the chain is empty or all aliases dangle).
|
|
191
|
+
*/
|
|
192
|
+
value?: Value;
|
|
193
|
+
/**
|
|
194
|
+
* Ordered list from original reference → intermediate names → final value string.
|
|
195
|
+
*/
|
|
196
|
+
chain: string[];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The result of `Dataset.validate()`.
|
|
201
|
+
*/
|
|
202
|
+
export interface ValidationResult {
|
|
203
|
+
valid: boolean;
|
|
204
|
+
errors: Diagnostic[];
|
|
205
|
+
warnings: Diagnostic[];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* A loaded token dataset you can query, validate, resolve, and diff.
|
|
211
|
+
*
|
|
212
|
+
* ```js
|
|
213
|
+
* import init, { Dataset } from "@adobe/design-data-wasm";
|
|
214
|
+
* await init();
|
|
215
|
+
*
|
|
216
|
+
* // Use the canonical embedded Spectrum dataset:
|
|
217
|
+
* const ds = Dataset.embedded();
|
|
218
|
+
* const results = ds.query("property=color,colorScheme=dark");
|
|
219
|
+
*
|
|
220
|
+
* // Or load your own tokens:
|
|
221
|
+
* const tokens = await fetch("/tokens.json").then(r => r.json());
|
|
222
|
+
* const ds2 = Dataset.fromTokens(tokens);
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
225
|
+
export class Dataset {
|
|
226
|
+
private constructor();
|
|
227
|
+
free(): void;
|
|
228
|
+
[Symbol.dispose](): void;
|
|
229
|
+
/**
|
|
230
|
+
* Compute the semantic diff between this dataset and another.
|
|
231
|
+
*
|
|
232
|
+
* Returns a [`DiffResult`] with arrays of renamed, deprecated, reverted, added,
|
|
233
|
+
* deleted, and updated tokens.
|
|
234
|
+
*
|
|
235
|
+
* ```js
|
|
236
|
+
* const oldDs = Dataset.fromTokens(oldTokens);
|
|
237
|
+
* const newDs = Dataset.fromTokens(newTokens);
|
|
238
|
+
* const diff = oldDs.diff(newDs);
|
|
239
|
+
* console.log(`${diff.added.length} tokens added`);
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
diff(other: Dataset): DiffResult;
|
|
243
|
+
/**
|
|
244
|
+
* Open the canonical embedded Spectrum dataset from the prebuilt cache.
|
|
245
|
+
*
|
|
246
|
+
* The cache is opened once and reused; subsequent calls are cheap.
|
|
247
|
+
*
|
|
248
|
+
* Throws if the embedded cache was not generated (run `moon run sdk-wasm:cache-build`).
|
|
249
|
+
*/
|
|
250
|
+
static embedded(): Dataset;
|
|
251
|
+
/**
|
|
252
|
+
* Build a dataset from an array of raw token JSON objects.
|
|
253
|
+
*
|
|
254
|
+
* Accepts the same format as the cascade token JSON files — an array of token
|
|
255
|
+
* objects each with a `name` object (e.g. `{ "name": { "property": "..." }, "value": ... }`).
|
|
256
|
+
*
|
|
257
|
+
* ```js
|
|
258
|
+
* const tokens = await fetch("/spectrum-tokens.json").then(r => r.json());
|
|
259
|
+
* const ds = Dataset.fromTokens(tokens);
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
static fromTokens(tokens_json: any): Dataset;
|
|
263
|
+
/**
|
|
264
|
+
* Emit a structural overview of the dataset for agent session start.
|
|
265
|
+
*
|
|
266
|
+
* Returns a plain JS object with the same shape as `design-data primer --format json`:
|
|
267
|
+
* `{ specVersion, tokenCount, modeSets, components, taxonomyFields, manifest, provenance }`.
|
|
268
|
+
*
|
|
269
|
+
* For the embedded Spectrum dataset (`Dataset.embedded()`), `taxonomyFields` and
|
|
270
|
+
* `manifest` are baked into the prebuilt `.redb` blob by the `cache-build` task.
|
|
271
|
+
* For in-memory datasets (`Dataset.fromTokens()`), both are empty / null.
|
|
272
|
+
*
|
|
273
|
+
* `provenance.source` is:
|
|
274
|
+
* - `"embedded"` when created via `Dataset.embedded()` (includes `designDataVersion`)
|
|
275
|
+
* - `"in-memory"` when created via `Dataset.fromTokens()`
|
|
276
|
+
*/
|
|
277
|
+
primer(): any;
|
|
278
|
+
/**
|
|
279
|
+
* Filter tokens using a query expression.
|
|
280
|
+
*
|
|
281
|
+
* **Syntax:** `key=value` pairs separated by `,` (AND) or `|` (OR).
|
|
282
|
+
* Use `!=` for negation and `*` as a wildcard suffix or prefix.
|
|
283
|
+
* Valid keys: `property`, `component`, `variant`, `state`, `colorScheme`,
|
|
284
|
+
* `scale`, `contrast`, `uuid`, `$schema`.
|
|
285
|
+
*
|
|
286
|
+
* ```js
|
|
287
|
+
* const results = ds.query("property=color,colorScheme=dark");
|
|
288
|
+
* const all = ds.query(""); // returns all tokens
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
query(filter_expr: string): TokenResultArray;
|
|
292
|
+
/**
|
|
293
|
+
* Resolve a token for a given property in a specific context.
|
|
294
|
+
*
|
|
295
|
+
* The `context` object maps mode-set names to their active mode values —
|
|
296
|
+
* e.g. `{ colorScheme: "dark", scale: "medium" }`.
|
|
297
|
+
*
|
|
298
|
+
* Returns the winning token record plus its specificity, or `undefined` if
|
|
299
|
+
* no token matches the property+context combination.
|
|
300
|
+
*
|
|
301
|
+
* ```js
|
|
302
|
+
* const result = ds.resolve("background", { colorScheme: "dark", scale: "medium" });
|
|
303
|
+
* if (result) console.log(result.token.raw.value);
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
resolve(property: string, context: ResolutionContext): ResolveResult | undefined;
|
|
307
|
+
/**
|
|
308
|
+
* Resolve a legacy token reference by slug in a given context, returning
|
|
309
|
+
* the terminal value and the full alias chain.
|
|
310
|
+
*
|
|
311
|
+
* Bridges the legacy *object-map* slug model used by `docs/s2-tokens-viewer`
|
|
312
|
+
* to the cascade dataset. The wasm `resolve()` method resolves by *property*
|
|
313
|
+
* name in a mode-set context; this method resolves by *legacy slug* and a flat
|
|
314
|
+
* context map matching name-object fields.
|
|
315
|
+
*
|
|
316
|
+
* Context keys mirror cascade name-object fields:
|
|
317
|
+
* - `{ colorScheme: "light" | "dark" | "wireframe" }`
|
|
318
|
+
* - `{ scale: "desktop" | "mobile" }`
|
|
319
|
+
*
|
|
320
|
+
* The candidate with the most matching context fields wins; tie-breaking is
|
|
321
|
+
* stable (secondary sort by uuid ascending). When an alias chain passes through
|
|
322
|
+
* a set-level UUID, the context-appropriate child is selected so that e.g.
|
|
323
|
+
* `{accent-color-900}` under `{ colorScheme: "dark" }` correctly resolves to
|
|
324
|
+
* the dark variant of `{blue-900}`.
|
|
325
|
+
*
|
|
326
|
+
* Dangling aliases (a `$ref` target absent from the embedded dataset) are
|
|
327
|
+
* handled gracefully: the walk stops and the partial chain is returned with
|
|
328
|
+
* `value: undefined`.
|
|
329
|
+
*
|
|
330
|
+
* ```js
|
|
331
|
+
* const r = ds.resolveReference("{accent-color-100}", { colorScheme: "light" });
|
|
332
|
+
* // r.chain → ["{accent-color-100}", "{blue-100}", "rgb(245, 249, 255)"]
|
|
333
|
+
* // r.value → "rgb(245, 249, 255)"
|
|
334
|
+
* ```
|
|
335
|
+
*/
|
|
336
|
+
resolveReference(token_ref: string, context: ResolutionContext): ReferenceChainResult | undefined;
|
|
337
|
+
/**
|
|
338
|
+
* Rank existing tokens by similarity to a natural-language `intent` string.
|
|
339
|
+
*
|
|
340
|
+
* Uses Jaccard similarity over the bag-of-words formed from each token's
|
|
341
|
+
* key segments, name-object field values, and description text. Optionally
|
|
342
|
+
* filter to tokens matching a specific `propertyHint` (e.g. `"color"`).
|
|
343
|
+
*
|
|
344
|
+
* ```js
|
|
345
|
+
* const results = ds.suggest("primary button background", undefined, 5);
|
|
346
|
+
* ```
|
|
347
|
+
*/
|
|
348
|
+
suggest(intent: string, property_hint: string | null | undefined, limit: number): SuggestResultArray;
|
|
349
|
+
/**
|
|
350
|
+
* Return the number of tokens in the dataset.
|
|
351
|
+
*/
|
|
352
|
+
tokenCount(): number;
|
|
353
|
+
/**
|
|
354
|
+
* Run relational validation rules over the dataset.
|
|
355
|
+
*
|
|
356
|
+
* Returns a [`ValidationResult`] with `valid`, `errors`, and `warnings`.
|
|
357
|
+
* This runs the same rules as `design-data validate` but without structural
|
|
358
|
+
* (JSON Schema) checks — those require filesystem access unavailable in wasm.
|
|
359
|
+
*
|
|
360
|
+
* ```js
|
|
361
|
+
* const result = ds.validate();
|
|
362
|
+
* if (!result.valid) console.error(result.errors);
|
|
363
|
+
* ```
|
|
364
|
+
*/
|
|
365
|
+
validate(): ValidationResult;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Find a registry entry by its ID or one of its aliases.
|
|
370
|
+
*
|
|
371
|
+
* Returns `undefined` if not found.
|
|
372
|
+
* Equivalent to `@adobe/design-system-registry`'s `findValue(registry, searchTerm)`.
|
|
373
|
+
*/
|
|
374
|
+
export function findValue(registry: any, search_term: string): any;
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Return all non-deprecated value entries.
|
|
378
|
+
*
|
|
379
|
+
* Equivalent to `@adobe/design-system-registry`'s `getActiveValues(registry)`.
|
|
380
|
+
*/
|
|
381
|
+
export function getActiveValues(registry: any): any;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Return the list of advisory field names (fields whose values are informational,
|
|
385
|
+
* not normative — e.g. `"variant"`, `"state"`).
|
|
386
|
+
*/
|
|
387
|
+
export function getAdvisoryFields(): string[];
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Return the default value entry, or `undefined` if none is marked as default.
|
|
391
|
+
*
|
|
392
|
+
* Equivalent to `@adobe/design-system-registry`'s `getDefault(registry)`.
|
|
393
|
+
*/
|
|
394
|
+
export function getDefault(registry: any): any;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Return all IDs (and aliases) registered for a given field name.
|
|
398
|
+
*
|
|
399
|
+
* `fieldName` should be the canonical field key as used in token `name` objects —
|
|
400
|
+
* e.g. `"property"`, `"component"`, `"variant"`, `"state"`.
|
|
401
|
+
*
|
|
402
|
+
* Returns `undefined` if the field is not in the embedded registry.
|
|
403
|
+
*/
|
|
404
|
+
export function getFieldValues(field_name: string): string[] | undefined;
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Return the list of field names that can be used as filter keys in query
|
|
408
|
+
* expressions (e.g. `"property"`, `"component"`, `"$schema"`).
|
|
409
|
+
*
|
|
410
|
+
* This is the canonical set maintained in `design_data_core::query::ALLOWED_KEYS`,
|
|
411
|
+
* exposed here so callers do not need to hard-code it.
|
|
412
|
+
*/
|
|
413
|
+
export function getIndexedFields(): string[];
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Return all value IDs from a registry vocabulary object.
|
|
417
|
+
*
|
|
418
|
+
* Equivalent to `@adobe/design-system-registry`'s `getValues(registry)`.
|
|
419
|
+
*/
|
|
420
|
+
export function getValues(registry: any): string[];
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Return `true` if `value` (an ID or alias) is registered for `fieldName`.
|
|
424
|
+
*/
|
|
425
|
+
export function hasFieldValue(field_name: string, value: string): boolean;
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Return `true` if `searchTerm` matches any value ID or alias in the registry.
|
|
429
|
+
*
|
|
430
|
+
* Equivalent to `@adobe/design-system-registry`'s `hasValue(registry, searchTerm)`.
|
|
431
|
+
*/
|
|
432
|
+
export function hasValue(registry: any, search_term: string): boolean;
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Initialise the panic hook so that Rust panics are forwarded to the browser console.
|
|
436
|
+
*
|
|
437
|
+
* Call this once when the wasm module loads. Idempotent.
|
|
438
|
+
*/
|
|
439
|
+
export function init(): void;
|
|
440
|
+
|
|
441
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
442
|
+
|
|
443
|
+
export interface InitOutput {
|
|
444
|
+
readonly memory: WebAssembly.Memory;
|
|
445
|
+
readonly __wbg_dataset_free: (a: number, b: number) => void;
|
|
446
|
+
readonly dataset_embedded: () => [number, number, number];
|
|
447
|
+
readonly dataset_fromTokens: (a: any) => [number, number, number];
|
|
448
|
+
readonly dataset_primer: (a: number) => [number, number, number];
|
|
449
|
+
readonly dataset_query: (a: number, b: number, c: number) => [number, number, number];
|
|
450
|
+
readonly dataset_suggest: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number];
|
|
451
|
+
readonly dataset_validate: (a: number) => any;
|
|
452
|
+
readonly dataset_resolve: (a: number, b: number, c: number, d: any) => [number, number, number];
|
|
453
|
+
readonly dataset_resolveReference: (a: number, b: number, c: number, d: any) => [number, number, number];
|
|
454
|
+
readonly dataset_diff: (a: number, b: number) => [number, number, number];
|
|
455
|
+
readonly dataset_tokenCount: (a: number) => number;
|
|
456
|
+
readonly getFieldValues: (a: number, b: number) => [number, number];
|
|
457
|
+
readonly hasFieldValue: (a: number, b: number, c: number, d: number) => number;
|
|
458
|
+
readonly getAdvisoryFields: () => [number, number];
|
|
459
|
+
readonly getIndexedFields: () => [number, number];
|
|
460
|
+
readonly getValues: (a: any) => [number, number, number, number];
|
|
461
|
+
readonly findValue: (a: any, b: number, c: number) => [number, number, number];
|
|
462
|
+
readonly hasValue: (a: any, b: number, c: number) => [number, number, number];
|
|
463
|
+
readonly getDefault: (a: any) => [number, number, number];
|
|
464
|
+
readonly getActiveValues: (a: any) => [number, number, number];
|
|
465
|
+
readonly init: () => void;
|
|
466
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
467
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
468
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
469
|
+
readonly __externref_table_alloc: () => number;
|
|
470
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
471
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
472
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
473
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
474
|
+
readonly __wbindgen_start: () => void;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
481
|
+
* a precompiled `WebAssembly.Module`.
|
|
482
|
+
*
|
|
483
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
484
|
+
*
|
|
485
|
+
* @returns {InitOutput}
|
|
486
|
+
*/
|
|
487
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
491
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
492
|
+
*
|
|
493
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
494
|
+
*
|
|
495
|
+
* @returns {Promise<InitOutput>}
|
|
496
|
+
*/
|
|
497
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|