@designkit-sh/core 0.0.0-stage → 0.2.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 +105 -0
- package/README.md +16 -2
- package/dist/index.d.ts +222 -0
- package/dist/index.mjs +674 -0
- package/dist/index.mjs.map +1 -0
- package/dist/presets.d.ts +34 -0
- package/dist/presets.mjs +835 -0
- package/dist/presets.mjs.map +1 -0
- package/package.json +61 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-ALv2
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 AGENTIK SAS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @designkit-sh/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
designkit.sh core: the pure reference implementation of the DESIGN.md open standard. Parse DESIGN.md, resolve token references, emit :root CSS custom properties, render a self-contained preview. zod + gray-matter only; no React, no node builtins: browser-safe.
|
|
4
|
+
|
|
5
|
+
Part of [canvakit](https://github.com/openagentik/canvakit).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @designkit-sh/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
|
|
15
|
+
[FSL-1.1-ALv2](./LICENSE), the Functional Source License with an Apache 2.0 future
|
|
16
|
+
license: free for any use except offering a competing product or service, and
|
|
17
|
+
each version becomes Apache-2.0 two years after its release. Copyright AGENTIK SAS.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Zod schemas for the DESIGN.md frontmatter shape.
|
|
5
|
+
*
|
|
6
|
+
* Intentionally permissive: partial designs are a first-class use case
|
|
7
|
+
* (an agent iterating on a draft, a human editing tokens one at a time).
|
|
8
|
+
* Every section is optional, every value defaults to something sensible,
|
|
9
|
+
* and unknown keys are preserved via `.loose()` so we don't eat
|
|
10
|
+
* tokens the consumer added but we didn't anticipate.
|
|
11
|
+
*
|
|
12
|
+
* Reference: https://github.com/google-labs-code/design.md
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
declare const colorsSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
16
|
+
declare const fontRuleSchema: z.ZodObject<{
|
|
17
|
+
family: z.ZodOptional<z.ZodString>;
|
|
18
|
+
size: z.ZodOptional<z.ZodString>;
|
|
19
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
20
|
+
lineHeight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
21
|
+
letterSpacing: z.ZodOptional<z.ZodString>;
|
|
22
|
+
textTransform: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, z.core.$loose>;
|
|
24
|
+
type FontRule = z.infer<typeof fontRuleSchema>;
|
|
25
|
+
declare const typographySchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
26
|
+
family: z.ZodOptional<z.ZodString>;
|
|
27
|
+
size: z.ZodOptional<z.ZodString>;
|
|
28
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
29
|
+
lineHeight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
30
|
+
letterSpacing: z.ZodOptional<z.ZodString>;
|
|
31
|
+
textTransform: z.ZodOptional<z.ZodString>;
|
|
32
|
+
}, z.core.$loose>>>;
|
|
33
|
+
declare const componentsSchema: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>, z.ZodPipe<z.ZodBoolean, z.ZodTransform<string, boolean>>]>>>>;
|
|
34
|
+
/**
|
|
35
|
+
* Full DESIGN.md frontmatter shape. Every section is optional — a
|
|
36
|
+
* design with just `colors:` is valid, a design with just `name:` is
|
|
37
|
+
* valid. Unknown top-level keys survive via `.loose()` so
|
|
38
|
+
* future additions don't need parser changes.
|
|
39
|
+
*
|
|
40
|
+
* Google's canonical DESIGN.md (https://stitch.withgoogle.com/docs/design-md)
|
|
41
|
+
* is prose-first with inline hex — no frontmatter schema. Our YAML is a
|
|
42
|
+
* machine-readable superset that compiles back to Google-flavored prose
|
|
43
|
+
* for Stitch compatibility. The fields below named after Google's
|
|
44
|
+
* sections (`atmosphere`, `layout`, `notes`, `motion`, `breakpoints`)
|
|
45
|
+
* are opt-in; skipping them leaves you with a schema that still reads
|
|
46
|
+
* as a canonical built-in kit.
|
|
47
|
+
*/
|
|
48
|
+
declare const designFrontmatterSchema: z.ZodObject<{
|
|
49
|
+
name: z.ZodOptional<z.ZodString>;
|
|
50
|
+
description: z.ZodOptional<z.ZodString>;
|
|
51
|
+
projectId: z.ZodOptional<z.ZodString>;
|
|
52
|
+
extends: z.ZodOptional<z.ZodString>;
|
|
53
|
+
colors: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
54
|
+
typography: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
55
|
+
family: z.ZodOptional<z.ZodString>;
|
|
56
|
+
size: z.ZodOptional<z.ZodString>;
|
|
57
|
+
weight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
58
|
+
lineHeight: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
59
|
+
letterSpacing: z.ZodOptional<z.ZodString>;
|
|
60
|
+
textTransform: z.ZodOptional<z.ZodString>;
|
|
61
|
+
}, z.core.$loose>>>;
|
|
62
|
+
spacing: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
63
|
+
rounded: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
64
|
+
shadows: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
65
|
+
components: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodPipe<z.ZodNumber, z.ZodTransform<string, number>>, z.ZodPipe<z.ZodBoolean, z.ZodTransform<string, boolean>>]>>>>;
|
|
66
|
+
motion: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
67
|
+
breakpoints: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
68
|
+
elevation: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
69
|
+
atmosphere: z.ZodOptional<z.ZodUnknown>;
|
|
70
|
+
layout: z.ZodOptional<z.ZodUnknown>;
|
|
71
|
+
notes: z.ZodOptional<z.ZodUnknown>;
|
|
72
|
+
}, z.core.$loose>;
|
|
73
|
+
type DesignFrontmatter = z.infer<typeof designFrontmatterSchema>;
|
|
74
|
+
/**
|
|
75
|
+
* What `parseDesign()` returns: the validated/resolved tokens (with
|
|
76
|
+
* `{path.to.token}` references already substituted), the markdown
|
|
77
|
+
* prose body, and the declared design name.
|
|
78
|
+
*/
|
|
79
|
+
interface ParsedDesign {
|
|
80
|
+
name: string | null;
|
|
81
|
+
tokens: DesignFrontmatter;
|
|
82
|
+
prose: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Parse a DESIGN.md source string into validated tokens + prose.
|
|
87
|
+
*
|
|
88
|
+
* Pipeline:
|
|
89
|
+
* 1. `gray-matter` splits the YAML frontmatter from the markdown body.
|
|
90
|
+
* 2. Zod validates the frontmatter shape (permissive — see schema.ts).
|
|
91
|
+
* 3. Token references of the form `{path.to.token}` are resolved
|
|
92
|
+
* recursively against the full frontmatter tree. Circular refs
|
|
93
|
+
* are detected and left as-is with a silent skip so a broken
|
|
94
|
+
* design doesn't crash the render pipeline.
|
|
95
|
+
*
|
|
96
|
+
* Unresolved references (pointing at a missing path) are left
|
|
97
|
+
* untouched — consumers can decide whether that's an error or a
|
|
98
|
+
* placeholder. We don't throw, because downstream (canvas-render,
|
|
99
|
+
* the editor) needs to keep working on in-progress designs.
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Options for `parseDesign`. The `parents` map is consulted when the
|
|
104
|
+
* frontmatter declares `extends: <name>` — the parser pulls the
|
|
105
|
+
* corresponding source string from the map, parses it (recursively,
|
|
106
|
+
* with cycle detection), and deep-merges its tokens before resolving
|
|
107
|
+
* references on this kit.
|
|
108
|
+
*/
|
|
109
|
+
interface ParseDesignOptions {
|
|
110
|
+
/** name → DESIGN.md source for any kit that may appear in an `extends` chain. */
|
|
111
|
+
parents?: Map<string, string>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Validation-error wrapper that carries the zod issue list so callers
|
|
115
|
+
* (e.g. `editDesign` tool) can surface precise field paths.
|
|
116
|
+
*/
|
|
117
|
+
declare class DesignValidationError extends Error {
|
|
118
|
+
readonly issues: {
|
|
119
|
+
path: string;
|
|
120
|
+
message: string;
|
|
121
|
+
}[];
|
|
122
|
+
constructor(message: string, issues: {
|
|
123
|
+
path: string;
|
|
124
|
+
message: string;
|
|
125
|
+
}[]);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Parse a DESIGN.md source string.
|
|
129
|
+
*
|
|
130
|
+
* - Empty / whitespace-only source returns a blank design (no tokens,
|
|
131
|
+
* empty prose) so callers can render "no design active" paths without
|
|
132
|
+
* branching on null.
|
|
133
|
+
* - Missing frontmatter is treated as an empty design (prose-only
|
|
134
|
+
* markdown is valid).
|
|
135
|
+
* - Invalid YAML throws a `DesignValidationError` with the underlying
|
|
136
|
+
* message so the caller can surface it to the agent.
|
|
137
|
+
* - `options.parents` provides the source for any kit referenced via
|
|
138
|
+
* `extends:` in the frontmatter. Parents are parsed first, their
|
|
139
|
+
* tokens deep-merged, then this kit's tokens overlay on top. Cycles
|
|
140
|
+
* and unknown parents raise DesignValidationError.
|
|
141
|
+
*/
|
|
142
|
+
declare function parseDesign(source: string, options?: ParseDesignOptions): ParsedDesign;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Emit a `:root { --token: value; }` block from a parsed design.
|
|
146
|
+
*
|
|
147
|
+
* Flattening rules:
|
|
148
|
+
* - Dotted paths join with `-` → `colors.primary` becomes
|
|
149
|
+
* `--color-primary`. We singularise the top-level section name
|
|
150
|
+
* (`colors` → `color`, `components` → `component`) because the
|
|
151
|
+
* variable reads more naturally: `var(--color-primary)` vs
|
|
152
|
+
* `var(--colors-primary)`. All other segments pass through as-is
|
|
153
|
+
* (kebab-cased).
|
|
154
|
+
* - Non-string leaves are coerced with `String()`.
|
|
155
|
+
* - `name` and `description` are skipped — they're metadata, not
|
|
156
|
+
* design tokens.
|
|
157
|
+
* - Unknown top-level keys that carry an object are flattened with
|
|
158
|
+
* their original plural so custom sections still produce CSS.
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Flatten kit tokens into a `Record<string, string>` of CSS-var names →
|
|
163
|
+
* sanitized values. Same flattening rules as `toCssVars()` but returns
|
|
164
|
+
* the map directly so callers can spread it onto a React inline-style
|
|
165
|
+
* prop or merge with other var sources without parsing a `:root { … }`
|
|
166
|
+
* string back into entries.
|
|
167
|
+
*/
|
|
168
|
+
declare function toCssVarMap(tokens: DesignFrontmatter): Record<string, string>;
|
|
169
|
+
declare function toCssVars(tokens: DesignFrontmatter): string;
|
|
170
|
+
/**
|
|
171
|
+
* Sanitise a single CSS declaration value so hostile token content
|
|
172
|
+
* can't escape the containing declaration. Removes:
|
|
173
|
+
* - newlines (broken CSS otherwise),
|
|
174
|
+
* - `{` / `}` (would close the surrounding `:root { ... }` block
|
|
175
|
+
* and inject sibling rules — e.g. `red;} body { background: url(https://evil/beacon)`),
|
|
176
|
+
* - everything after the first `;` (extra declarations injected into
|
|
177
|
+
* the same rule, e.g. `red;color:#f00` flipping a sibling token).
|
|
178
|
+
* - `<`/`>` so the value is safe to embed in an HTML `<style>…</style>`
|
|
179
|
+
* block without accidentally closing the element.
|
|
180
|
+
*
|
|
181
|
+
* Exported so the preview renderer and any future CSS-emitting
|
|
182
|
+
* consumer can share one authoritative sanitiser instead of
|
|
183
|
+
* re-implementing it inline.
|
|
184
|
+
*/
|
|
185
|
+
declare function sanitizeCssValue(raw: string): string;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Design-kit preview template — a self-contained HTML document that
|
|
189
|
+
* visualises a parsed DESIGN.md: colour swatches, typography ladder,
|
|
190
|
+
* spacing + radius bars, and a small components showcase.
|
|
191
|
+
*
|
|
192
|
+
* Rendering contract:
|
|
193
|
+
* - The consumer calls `renderPreviewHtml(tokens, options)` with a
|
|
194
|
+
* `DesignFrontmatter` (typically the `tokens` field returned by
|
|
195
|
+
* `parseDesign`).
|
|
196
|
+
* - The function builds pure HTML with inline styles that reference
|
|
197
|
+
* CSS custom properties (`var(--color-primary)`) emitted by
|
|
198
|
+
* `toCssVars`. A `<style>:root{…}</style>` block is prepended so
|
|
199
|
+
* the document is self-contained — it renders correctly as a
|
|
200
|
+
* stand-alone file in an iframe or when served directly.
|
|
201
|
+
* - No Mustache / template engine. We assemble the HTML
|
|
202
|
+
* programmatically because every section's structure depends on
|
|
203
|
+
* which tokens are present (a design with only `colors` shouldn't
|
|
204
|
+
* render an empty typography heading).
|
|
205
|
+
*
|
|
206
|
+
* Kept inside @designkit-sh/core so the preview stays colocated with
|
|
207
|
+
* the schema — any future schema addition (e.g. `motion`) can extend
|
|
208
|
+
* the preview in the same PR.
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
interface PreviewOptions {
|
|
212
|
+
/** Document title. Falls back to `tokens.name` or "Design Kit". */
|
|
213
|
+
title?: string;
|
|
214
|
+
/** Short description under the title. Falls back to `tokens.description`. */
|
|
215
|
+
subtitle?: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Render a full `<!DOCTYPE html>` preview for a parsed design.
|
|
219
|
+
*/
|
|
220
|
+
declare function renderPreviewHtml(tokens: DesignFrontmatter, options?: PreviewOptions): string;
|
|
221
|
+
|
|
222
|
+
export { type DesignFrontmatter, DesignValidationError, type FontRule, type ParseDesignOptions, type ParsedDesign, type PreviewOptions, colorsSchema, componentsSchema, designFrontmatterSchema, parseDesign, renderPreviewHtml, sanitizeCssValue, toCssVarMap, toCssVars, typographySchema };
|