@canvakit/designkit 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 +97 -2
- package/dist/index.d.ts +466 -0
- package/dist/index.mjs +953 -0
- package/dist/index.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,98 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @canvakit/designkit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Optional designkit (DESIGN.md) bridge for **[canvakit](https://canvakit.sh)**.
|
|
4
|
+
|
|
5
|
+
Canvakit is the _template + data-source binding_ standard. Designkit (Google
|
|
6
|
+
Stitch's [DESIGN.md format](https://github.com/google-labs-code/design.md)) is
|
|
7
|
+
the _style_ standard — tokens + atomic components. They're orthogonal by design;
|
|
8
|
+
this package is the only seam that wires them together.
|
|
9
|
+
|
|
10
|
+
## What it does
|
|
11
|
+
|
|
12
|
+
Plugs in as a canvakit render extension. When an active DESIGN.md is available,
|
|
13
|
+
it:
|
|
14
|
+
|
|
15
|
+
1. Attaches flattened tokens under `$design.*` in the render context. Templates
|
|
16
|
+
can reference `{{$design.colors.primary}}` or `{{#$design}}…{{/$design}}` for
|
|
17
|
+
conditional rendering.
|
|
18
|
+
2. Appends a `<style data-design-kit="root">:root { --color-*: …; }</style>`
|
|
19
|
+
block to the rendered body so the CSS vars are available to any `var(--foo)`
|
|
20
|
+
expression in the template body.
|
|
21
|
+
|
|
22
|
+
Canvakit core has zero designkit dependency. If you don't wire this extension,
|
|
23
|
+
canvakit still runs — your templates just won't pick up theming.
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pnpm add @canvakit/core @canvakit/designkit
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Wire it up
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { render } from "@canvakit/core"
|
|
35
|
+
import { designkitExtension } from "@canvakit/designkit"
|
|
36
|
+
|
|
37
|
+
await render({
|
|
38
|
+
template,
|
|
39
|
+
filesystem,
|
|
40
|
+
extensions: [designkitExtension()],
|
|
41
|
+
})
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Resolution priority
|
|
45
|
+
|
|
46
|
+
When the extension runs, it looks for a DESIGN.md in this order (first match
|
|
47
|
+
wins):
|
|
48
|
+
|
|
49
|
+
1. **Workspace pointer** — `_design/active.txt` → `_design/<slug>.md`
|
|
50
|
+
2. **Workspace root** — `DESIGN.md` (Stitch drop-in)
|
|
51
|
+
3. **Template hint** — `design:` frontmatter field, accepts:
|
|
52
|
+
- `dk:<preset-id>` — a preset shipped with `@designkit-sh/core` (heritage,
|
|
53
|
+
modern-minimal, bold-tech, atelier, neon-grid, classic)
|
|
54
|
+
- any path ending in `.md` — resolved via the canvakit filesystem adapter
|
|
55
|
+
|
|
56
|
+
The operator's workspace choice overrides the author's hint — an active local
|
|
57
|
+
DESIGN.md is intent, not accident. The hint kicks in when a template is rendered
|
|
58
|
+
outside a workspace (CLI, gallery, CI).
|
|
59
|
+
|
|
60
|
+
## Author-friendly pattern
|
|
61
|
+
|
|
62
|
+
Templates that want to degrade gracefully when no design is wired use `var()`
|
|
63
|
+
fallbacks:
|
|
64
|
+
|
|
65
|
+
```css
|
|
66
|
+
body {
|
|
67
|
+
background: var(--color-background, #ffffff);
|
|
68
|
+
color: var(--color-ink, #111);
|
|
69
|
+
font-family: var(--font-body-md-family, ui-sans-serif, system-ui, sans-serif);
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Without the bridge wired, the inline literals render. With it, the `:root` block
|
|
74
|
+
the extension appends wins the cascade and the template re-themes.
|
|
75
|
+
|
|
76
|
+
## API
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import {
|
|
80
|
+
designkitExtension,
|
|
81
|
+
loadActiveDesign,
|
|
82
|
+
type DesignkitExtensionOptions,
|
|
83
|
+
} from "@canvakit/designkit"
|
|
84
|
+
|
|
85
|
+
// Full render pipeline integration
|
|
86
|
+
const extension = designkitExtension({
|
|
87
|
+
skipStylePrepend: false, // set true when the caller already emits :root elsewhere
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
// Lower-level — load and return the parsed DESIGN.md tokens
|
|
91
|
+
const tokens = await loadActiveDesign(fs, "dk:heritage")
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
[FSL-1.1-ALv2](./LICENSE), the Functional Source License with an Apache 2.0 future
|
|
97
|
+
license: free for any use except offering a competing product or service, and
|
|
98
|
+
each version becomes Apache-2.0 two years after its release. Copyright AGENTIK SAS.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import { FilesystemLike, ContextExtension } from '@canvakit/core';
|
|
2
|
+
import { DesignFrontmatter } from '@designkit-sh/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `DesignSourceRegistry` — pluggable resolver for design refs.
|
|
6
|
+
*
|
|
7
|
+
* A design ref is a `<scheme>:<id>` string. The registry dispatches
|
|
8
|
+
* to a registered handler by scheme prefix. Schemes are extensible:
|
|
9
|
+
* apps and packages register their own (`db:`, `npm:`, `https:`,
|
|
10
|
+
* `tailwind-theme:`) without touching the bridge core.
|
|
11
|
+
*
|
|
12
|
+
* Built-in schemes:
|
|
13
|
+
*
|
|
14
|
+
* - `dk:<id>` — designkit preset shipped with `@designkit-sh/core`.
|
|
15
|
+
* Examples: `dk:heritage`, `dk:modern-minimal`.
|
|
16
|
+
* - `ws:<path>` — workspace filesystem path. Accepts a leading `/`,
|
|
17
|
+
* stripped automatically. Examples:
|
|
18
|
+
* `ws:DESIGN.md`, `ws:_design/foo.md`,
|
|
19
|
+
* `ws:/_design/foo.md`.
|
|
20
|
+
* - `kit:<slug>` — sugar for `ws:_design/<slug>.md` — the canonical
|
|
21
|
+
* location of a guild's authored design kits.
|
|
22
|
+
* Examples: `kit:foo`, `kit:acme-editorial`.
|
|
23
|
+
*
|
|
24
|
+
* Plus a back-compat path: a bare `.md` filename (e.g. `brand.md`) or
|
|
25
|
+
* a path containing `/` (`./_design/x.md`) resolves as a workspace
|
|
26
|
+
* file — same as the previous `frontmatter.design` hint behaviour.
|
|
27
|
+
*
|
|
28
|
+
* Contract for resolvers:
|
|
29
|
+
* - **never throw** — return `null` on any failure (missing file,
|
|
30
|
+
* unknown preset, parse error). One `console.warn` per distinct
|
|
31
|
+
* failure so logs surface the issue without flooding.
|
|
32
|
+
* - return a `DesignArtifact` carrying `tokens` (mandatory) plus
|
|
33
|
+
* optional `tailwindExtend` and `fonts` for richer design packs.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Output of a resolver. `tokens` is the only required field; richer
|
|
38
|
+
* sources may also ship Tailwind theme overrides and explicit font
|
|
39
|
+
* imports — both consumed by the relevant extensions when present.
|
|
40
|
+
*/
|
|
41
|
+
interface DesignArtifact {
|
|
42
|
+
/** CSS variable tokens — emitted as `:root { --color-* ... }`. */
|
|
43
|
+
tokens: DesignFrontmatter;
|
|
44
|
+
/**
|
|
45
|
+
* Optional Tailwind `theme.extend` overrides. Merged shallow-deep
|
|
46
|
+
* (one level deep per top-level key) into `tailwindBridgeExtension`'s
|
|
47
|
+
* default config.
|
|
48
|
+
*/
|
|
49
|
+
tailwindExtend?: Record<string, Record<string, string>>;
|
|
50
|
+
/**
|
|
51
|
+
* Optional explicit font import URLs / family declarations. When
|
|
52
|
+
* present, the bridge uses these instead of (or in addition to)
|
|
53
|
+
* the auto-detected Google Fonts list. Each entry yields a
|
|
54
|
+
* `<link rel="stylesheet">` in the rendered body.
|
|
55
|
+
*/
|
|
56
|
+
fonts?: Array<{
|
|
57
|
+
family: string;
|
|
58
|
+
weights?: number[];
|
|
59
|
+
href?: string;
|
|
60
|
+
}>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Context passed to every resolver. Currently exposes the canvakit
|
|
64
|
+
* filesystem so `ws:` / `kit:` resolvers can read disk files. Future
|
|
65
|
+
* resolvers may need other capabilities (HTTP fetcher, db handle) —
|
|
66
|
+
* extend this struct as needed; resolvers ignore fields they don't
|
|
67
|
+
* use.
|
|
68
|
+
*/
|
|
69
|
+
interface DesignSourceContext {
|
|
70
|
+
fs: FilesystemLike;
|
|
71
|
+
}
|
|
72
|
+
type DesignResolver = (ref: string, ctx: DesignSourceContext) => Promise<DesignArtifact | null>;
|
|
73
|
+
/** One design source discoverable via `DesignSourceRegistry.list()`. */
|
|
74
|
+
interface DesignSourceEntry {
|
|
75
|
+
/** the full ref that would resolve this entry, e.g. "dk:heritage" */
|
|
76
|
+
ref: string;
|
|
77
|
+
/** human-readable display name, when known */
|
|
78
|
+
name?: string;
|
|
79
|
+
/** scheme prefix this entry came from, e.g. "dk" */
|
|
80
|
+
scheme: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Enumerate the design sources a scheme knows about. Optional — a scheme
|
|
84
|
+
* with no `list` (e.g. a future `db:`) simply doesn't contribute to
|
|
85
|
+
* `DesignSourceRegistry.list()`'s aggregate; it's still fully resolvable
|
|
86
|
+
* via `resolve()`. Same contract as `DesignResolver`: **never throw**,
|
|
87
|
+
* `console.warn` once per distinct failure, return `[]` on any failure.
|
|
88
|
+
*/
|
|
89
|
+
type DesignLister = (ctx: DesignSourceContext) => Promise<DesignSourceEntry[]>;
|
|
90
|
+
interface DesignSource {
|
|
91
|
+
/** Scheme prefix without the trailing colon — e.g. "dk", "ws", "db". */
|
|
92
|
+
scheme: string;
|
|
93
|
+
resolve: DesignResolver;
|
|
94
|
+
list?: DesignLister;
|
|
95
|
+
}
|
|
96
|
+
/** Internal: a resolver invoked when no scheme prefix matches. */
|
|
97
|
+
type FallbackResolver = (ref: string, ctx: DesignSourceContext) => Promise<DesignArtifact | null>;
|
|
98
|
+
/**
|
|
99
|
+
* Registry instance. Apps may add custom schemes via `register()`.
|
|
100
|
+
*
|
|
101
|
+
* Default-exported singleton (`defaultRegistry`) ships with the three
|
|
102
|
+
* built-in schemes wired. Apps that want isolation can `new
|
|
103
|
+
* DesignSourceRegistry()` and pass it to the bridge.
|
|
104
|
+
*/
|
|
105
|
+
declare class DesignSourceRegistry {
|
|
106
|
+
#private;
|
|
107
|
+
register(source: DesignSource): void;
|
|
108
|
+
/**
|
|
109
|
+
* Set the fallback resolver used when a ref has no recognised
|
|
110
|
+
* scheme prefix. Default fallback treats the ref as a workspace
|
|
111
|
+
* file path (back-compat with the original `frontmatter.design`
|
|
112
|
+
* hint shape).
|
|
113
|
+
*/
|
|
114
|
+
setFallback(resolver: FallbackResolver): void;
|
|
115
|
+
has(scheme: string): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Resolve a ref to a `DesignArtifact`. Splits on the first colon to
|
|
118
|
+
* extract the scheme; dispatches to the registered handler. Falls
|
|
119
|
+
* through to the fallback resolver (workspace path) when no scheme
|
|
120
|
+
* matches — keeps `design: brand.md` shorthand working.
|
|
121
|
+
*/
|
|
122
|
+
resolve(ref: string, ctx: DesignSourceContext): Promise<DesignArtifact | null>;
|
|
123
|
+
/**
|
|
124
|
+
* Enumerate every design source discoverable across all schemes that
|
|
125
|
+
* expose a `list`. Schemes without one (no `list` registered) are simply
|
|
126
|
+
* absent from the result — not an error. Aggregated result is sorted by
|
|
127
|
+
* `(scheme, ref)` and de-duplicated by `ref` (two schemes may legitimately
|
|
128
|
+
* point at the same underlying source — e.g. `ws:`/`kit:` both listing
|
|
129
|
+
* the workspace's `_design/` folder).
|
|
130
|
+
*/
|
|
131
|
+
list(ctx: DesignSourceContext): Promise<DesignSourceEntry[]>;
|
|
132
|
+
}
|
|
133
|
+
/** Build a registry pre-populated with the three built-in schemes. */
|
|
134
|
+
declare function createDefaultRegistry(): DesignSourceRegistry;
|
|
135
|
+
/**
|
|
136
|
+
* Default singleton — the bridge uses this unless an app passes its
|
|
137
|
+
* own registry instance. Apps that want to add custom schemes
|
|
138
|
+
* (`db:`, `npm:`, etc.) can either mutate this singleton or
|
|
139
|
+
* instantiate a fresh one and wire it explicitly.
|
|
140
|
+
*/
|
|
141
|
+
declare const defaultRegistry: DesignSourceRegistry;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Locate + load a design for a canvakit render.
|
|
145
|
+
*
|
|
146
|
+
* Resolution priority (highest first):
|
|
147
|
+
*
|
|
148
|
+
* 1. `overrideDesign` — runtime force from the caller
|
|
149
|
+
* (e.g. `renderCanvas({ designOverride: "dk:neon-grid" })`)
|
|
150
|
+
* 2. `frontmatter.forceDesign` — template author force; bypasses workspace
|
|
151
|
+
* 3. Workspace `_design/active.txt` → `_design/<slug>.md`
|
|
152
|
+
* 4. Workspace root `DESIGN.md` (Stitch drop-in)
|
|
153
|
+
* 5. `frontmatter.design` — template author *fallback* hint
|
|
154
|
+
*
|
|
155
|
+
* Forces (1, 2) bypass workspace selection — the caller / author is
|
|
156
|
+
* declaring "this canvas must render in <design X>". The fallback hint
|
|
157
|
+
* (5) only kicks in when no workspace design is set, preserving the
|
|
158
|
+
* original "operator intent overrides author preference" semantics.
|
|
159
|
+
*
|
|
160
|
+
* Each ref is resolved through `DesignSourceRegistry` — apps can
|
|
161
|
+
* register custom schemes (`db:`, `npm:`, `https:`) without touching
|
|
162
|
+
* this loader.
|
|
163
|
+
*
|
|
164
|
+
* Contract: **never throw**. A missing pointer, a missing design file,
|
|
165
|
+
* an unresolvable hint, or a validation failure all resolve to `null` —
|
|
166
|
+
* the canvakit render pipeline keeps working for workspaces that don't
|
|
167
|
+
* use designkit. One `console.warn` per distinct failure so the issue
|
|
168
|
+
* surfaces in logs without flooding them.
|
|
169
|
+
*/
|
|
170
|
+
|
|
171
|
+
interface LoadActiveDesignOptions {
|
|
172
|
+
/**
|
|
173
|
+
* Runtime force — highest priority. Bypasses workspace selection.
|
|
174
|
+
* Accepts the same scheme refs as `forceDesign` / `design` (`dk:…`,
|
|
175
|
+
* `ws:…`, `kit:…`, or a back-compat workspace path).
|
|
176
|
+
*/
|
|
177
|
+
overrideDesign?: string;
|
|
178
|
+
/**
|
|
179
|
+
* Template author force — second priority. Bypasses workspace
|
|
180
|
+
* selection. Read from `frontmatter.forceDesign`.
|
|
181
|
+
*/
|
|
182
|
+
forceDesign?: string;
|
|
183
|
+
/**
|
|
184
|
+
* Template author fallback hint — lowest priority. Only used when
|
|
185
|
+
* the workspace has no active design. Read from `frontmatter.design`.
|
|
186
|
+
*/
|
|
187
|
+
hint?: string;
|
|
188
|
+
/** Custom registry; defaults to the singleton with built-in schemes. */
|
|
189
|
+
registry?: DesignSourceRegistry;
|
|
190
|
+
}
|
|
191
|
+
declare function loadActiveDesign(fs: FilesystemLike, options?: LoadActiveDesignOptions): Promise<DesignArtifact | null>;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* `designkitExtension` — plug into canvakit's `render({ extensions })`.
|
|
195
|
+
*
|
|
196
|
+
* Contributes two things to a render:
|
|
197
|
+
* 1. `$design` context root — flattened design tokens so templates
|
|
198
|
+
* can reference `{{$design.colors.primary}}` or conditional
|
|
199
|
+
* `{{#$design}}…{{/$design}}`. `null` when no design is active.
|
|
200
|
+
* 2. Body transformer — injects a `<style data-design-kit="root">`
|
|
201
|
+
* block with the emitted `toCssVars` output (plus, in `fonts:
|
|
202
|
+
* "embed"` mode, inlined `@font-face` blocks) into the document
|
|
203
|
+
* `<head>` — just before `</head>` when present, so it lands after
|
|
204
|
+
* any template `<head>` styles but still inside `<head>` and wins
|
|
205
|
+
* the cascade over template defaults, and never after `</html>`
|
|
206
|
+
* (which forces quirks mode / can be dropped by non-browser
|
|
207
|
+
* renderers). Bare fragments with no `<head>` fall back to a
|
|
208
|
+
* prepend. Templates that want to override should use
|
|
209
|
+
* `var(--foo, fallback)` for per-property overrides.
|
|
210
|
+
*
|
|
211
|
+
* Design source priority (see `loadActiveDesign`):
|
|
212
|
+
* 1. `overrideDesign` option — runtime force from the caller
|
|
213
|
+
* 2. `frontmatter.forceDesign` — template author force
|
|
214
|
+
* 3. Workspace `_design/active.txt` → `_design/<slug>.md`
|
|
215
|
+
* 4. Workspace root `DESIGN.md`
|
|
216
|
+
* 5. `frontmatter.design` (fallback hint)
|
|
217
|
+
*
|
|
218
|
+
* All refs go through `DesignSourceRegistry` — schemes (`dk:`, `ws:`,
|
|
219
|
+
* `kit:`, plus any registered by apps) dispatch to the appropriate
|
|
220
|
+
* resolver. Bare paths fall back to a workspace-fs read.
|
|
221
|
+
*
|
|
222
|
+
* Both pieces are skipped cleanly when no design is found — the
|
|
223
|
+
* extension adds `$design: null` to the context (so
|
|
224
|
+
* `{{#$design}}…{{/$design}}` sections render empty) and returns the
|
|
225
|
+
* body unchanged.
|
|
226
|
+
*/
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* How font faces referenced by the active design are emitted:
|
|
230
|
+
* - `"link"` — Google Fonts `<link rel=stylesheet>` (served deployments,
|
|
231
|
+
* the historical default).
|
|
232
|
+
* - `"embed"` — self-contained `@font-face` blocks with `data:` URI `src`,
|
|
233
|
+
* inlined into the injected `<style>` so the render carries
|
|
234
|
+
* its own fonts (no network, CSP-safe, offline / PDF export).
|
|
235
|
+
* - `"none"` — emit no font CSS at all.
|
|
236
|
+
*/
|
|
237
|
+
type FontMode = "link" | "embed" | "none";
|
|
238
|
+
interface DesignkitExtensionOptions {
|
|
239
|
+
/** Skip the `<style>` append — useful when the caller already emits
|
|
240
|
+
* the CSS vars in a parent shell. */
|
|
241
|
+
skipStylePrepend?: boolean;
|
|
242
|
+
/**
|
|
243
|
+
* Auto-import font families referenced in the active design's
|
|
244
|
+
* typography tokens via Google Fonts. Default true. Set false if the
|
|
245
|
+
* caller injects their own font CSS / hosts fonts elsewhere.
|
|
246
|
+
*
|
|
247
|
+
* Superseded by `fonts` when that option is set — kept for back-compat
|
|
248
|
+
* (unset `fonts` ⇒ `loadGoogleFonts` true maps to `"link"`, false to
|
|
249
|
+
* `"none"`).
|
|
250
|
+
*/
|
|
251
|
+
loadGoogleFonts?: boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Font emission strategy. When set, takes precedence over
|
|
254
|
+
* `loadGoogleFonts`. Default (unset): derived from `loadGoogleFonts`
|
|
255
|
+
* so existing served deployments are unchanged (`"link"`).
|
|
256
|
+
*/
|
|
257
|
+
fonts?: FontMode;
|
|
258
|
+
/**
|
|
259
|
+
* Runtime override — highest-priority design ref. Bypasses workspace
|
|
260
|
+
* selection entirely. Accepts the same scheme-prefixed refs as
|
|
261
|
+
* `frontmatter.design` / `forceDesign` (`dk:<preset>`, `ws:<path>`,
|
|
262
|
+
* `kit:<slug>`, or a back-compat workspace path).
|
|
263
|
+
*
|
|
264
|
+
* Use case: `renderCanvas({ designOverride: "dk:neon-grid" })` — the
|
|
265
|
+
* caller forces a specific design for one render without touching the
|
|
266
|
+
* guild's active kit.
|
|
267
|
+
*/
|
|
268
|
+
overrideDesign?: string;
|
|
269
|
+
/**
|
|
270
|
+
* Custom design source registry. Defaults to the singleton with the
|
|
271
|
+
* three built-in schemes (`dk:`, `ws:`, `kit:`). Apps that add
|
|
272
|
+
* custom schemes (`db:`, `npm:`, `https:`) can pass their own
|
|
273
|
+
* registry instance for isolation.
|
|
274
|
+
*/
|
|
275
|
+
registry?: DesignSourceRegistry;
|
|
276
|
+
/**
|
|
277
|
+
* Injectable font-fetch capability for `embed` mode (see
|
|
278
|
+
* {@link FetchFontFaces}). When a declared typography family has no
|
|
279
|
+
* file-backed `artifact.fonts[]` entry, this is called to fetch + inline
|
|
280
|
+
* it as base64 `@font-face` — so `embed`'s offline/CSP-safe promise holds
|
|
281
|
+
* for declared-only kits too, not just file-backed ones.
|
|
282
|
+
*
|
|
283
|
+
* Default: `undefined` — no fetch ever happens; `render()` stays a pure
|
|
284
|
+
* function of its inputs. Missing declared families instead degrade to a
|
|
285
|
+
* Google-Fonts `<link>` (logged), same as a kit with no fetcher at all.
|
|
286
|
+
*/
|
|
287
|
+
fetchFontFaces?: FetchFontFaces;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* A family + the union of weights requested for it. Weights are sorted
|
|
291
|
+
* ascending and deduped so the `:wght@…` axis is deterministic.
|
|
292
|
+
*/
|
|
293
|
+
interface FamilyRequest {
|
|
294
|
+
family: string;
|
|
295
|
+
weights: number[];
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* A resolved face ready to inline as base64 `@font-face` — the return shape
|
|
299
|
+
* for an injected {@link FetchFontFaces} capability. `format` is the CSS
|
|
300
|
+
* `format()` token (e.g. `"woff2"`); `base64` is the raw font bytes,
|
|
301
|
+
* base64-encoded (no `data:` prefix — the extension builds the URI).
|
|
302
|
+
*/
|
|
303
|
+
interface FetchedFontFace {
|
|
304
|
+
family: string;
|
|
305
|
+
weight: number;
|
|
306
|
+
format: string;
|
|
307
|
+
base64: string;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Injectable capability: resolve a set of declared-only family+weight
|
|
311
|
+
* requests (families with no file-backed `artifact.fonts[]` entry) to
|
|
312
|
+
* inlinable font bytes. Return `null` on total failure, or an array that
|
|
313
|
+
* may be a PARTIAL match — any `{family, weight}` with no matching entry in
|
|
314
|
+
* the result is treated as unresolved and degrades to a Google-Fonts
|
|
315
|
+
* `<link>` for just that family, logged (never a silent system-font
|
|
316
|
+
* fallback). Throwing is also treated as total failure.
|
|
317
|
+
*
|
|
318
|
+
* Default: `undefined` — no capability, no fetch, `render()` stays a pure
|
|
319
|
+
* function of its inputs. Opt in via `DesignkitExtensionOptions.fetchFontFaces`
|
|
320
|
+
* (mirrors how the real vision critic is only wired in when
|
|
321
|
+
* `ANTHROPIC_API_KEY` is set — network capabilities are always the CALLER's
|
|
322
|
+
* choice, never a default of the render engine).
|
|
323
|
+
*/
|
|
324
|
+
type FetchFontFaces = (requests: FamilyRequest[]) => Promise<FetchedFontFace[] | null>;
|
|
325
|
+
declare function designkitExtension(options?: DesignkitExtensionOptions): ContextExtension;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* `defaultGoogleFontsFetcher` — a real-network implementation of
|
|
329
|
+
* `FetchFontFaces` (see `context-extension.ts`).
|
|
330
|
+
*
|
|
331
|
+
* NOT wired into `designkitExtension` by default. It's an explicit opt-in a
|
|
332
|
+
* caller injects via `DesignkitExtensionOptions.fetchFontFaces` when it
|
|
333
|
+
* wants `embed` mode to be truly self-contained for declared-only families
|
|
334
|
+
* too (no file-backed `artifact.fonts[]` entry) — mirroring how the real
|
|
335
|
+
* vision critic is only wired in when `ANTHROPIC_API_KEY` is set. Without
|
|
336
|
+
* this (or an equivalent custom fetcher), `render()` never calls `fetch()`.
|
|
337
|
+
*
|
|
338
|
+
* Fetches the requested family+weight set from Google Fonts' `css2` API
|
|
339
|
+
* (via `buildGoogleFontsUrl`), parses the returned CSS for each face's
|
|
340
|
+
* `src: url(...) format('woff2')`, downloads those bytes, and returns them
|
|
341
|
+
* base64-encoded for inline `@font-face` embedding — reusing the same
|
|
342
|
+
* `FetchedFontFace` shape `buildEmbeddedFontFaces`'s fs-read path produces.
|
|
343
|
+
*
|
|
344
|
+
* v1 scope — documented limitations:
|
|
345
|
+
* - **Latin subset only.** Google's `css2` response emits one
|
|
346
|
+
* `@font-face` block per `unicode-range` subset (latin, latin-ext,
|
|
347
|
+
* cyrillic, vietnamese, …) per family+weight, ordered with `latin` LAST.
|
|
348
|
+
* This fetcher parses each block's `unicode-range` and inlines the
|
|
349
|
+
* LATIN-covering block per family+weight (via `coversBasicLatin`) — NOT
|
|
350
|
+
* the first, which would be cyrillic and leave résumé text falling back
|
|
351
|
+
* to a system font. Non-Latin glyphs (CJK, Cyrillic, latin-ext beyond
|
|
352
|
+
* Latin-1, …) still fall back to the family's system fallback.
|
|
353
|
+
* Follow-up: inline ALL subsets (multiple faces with `unicode-range`).
|
|
354
|
+
* - **User-Agent spoofing required.** The `css2` endpoint serves a
|
|
355
|
+
* DIFFERENT font container per `User-Agent` — a bare fetch would be
|
|
356
|
+
* served legacy TTF/EOT, not woff2. This fetcher sends a hardcoded
|
|
357
|
+
* modern-browser UA to get woff2. Fragile: if Google changes its
|
|
358
|
+
* sniffing, parsing silently yields nothing (the parser only
|
|
359
|
+
* understands `format('woff2')`), which just degrades to the caller's
|
|
360
|
+
* `<link>` fallback — never a hard failure.
|
|
361
|
+
* - No retry/timeout tuning beyond `fetch`'s own defaults. A
|
|
362
|
+
* slow/unreachable network resolves to `null`/a partial result, which
|
|
363
|
+
* `FetchFontFaces`'s contract already treats as "fall back to `<link>`
|
|
364
|
+
* for what's missing."
|
|
365
|
+
*
|
|
366
|
+
* Caching: `defaultGoogleFontsFetcher()` returns a CLOSURE holding its own
|
|
367
|
+
* `Map` caches (css2 response text + downloaded font bytes), keyed by URL /
|
|
368
|
+
* `family::weight` — deliberately NOT module-global state, so each call
|
|
369
|
+
* site gets an isolated cache. Inject ONE instance across a whole
|
|
370
|
+
* `generate`/`refine`/`fitToPages` run (which can re-render the same
|
|
371
|
+
* document 5–13+ times with an unchanged font set) to dedupe network calls
|
|
372
|
+
* automatically; a fresh `defaultGoogleFontsFetcher()` call starts cold.
|
|
373
|
+
*/
|
|
374
|
+
|
|
375
|
+
/** Build a fresh `FetchFontFaces` capability with its own isolated cache. */
|
|
376
|
+
declare function defaultGoogleFontsFetcher(): FetchFontFaces;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* `tailwindBridgeExtension` — canvakit extension that styles the
|
|
380
|
+
* rendered canvas body with designkit-token-aware Tailwind utilities.
|
|
381
|
+
*
|
|
382
|
+
* Two modes (default `compile`):
|
|
383
|
+
*
|
|
384
|
+
* - `mode: "compile"` (default) — compile the Tailwind utilities
|
|
385
|
+
* ACTUALLY used in the rendered body into a single inline
|
|
386
|
+
* `<style>` block, server-side, via the Tailwind v4 engine
|
|
387
|
+
* (`@tailwindcss/node` + `@tailwindcss/oxide`, already in the
|
|
388
|
+
* monorepo). No external `<script src="cdn.tailwindcss.com">`, no
|
|
389
|
+
* runtime `eval`/JIT. This is the only mode that works inside an
|
|
390
|
+
* MCP-App sandboxed iframe under a strict CSP (which forbids both
|
|
391
|
+
* external scripts and `unsafe-eval`). The inline `<style>` also
|
|
392
|
+
* styles standalone (Chrome / file://) — one render, both targets.
|
|
393
|
+
*
|
|
394
|
+
* - `mode: "cdn"` — legacy: inject the Tailwind v3 Play CDN script +
|
|
395
|
+
* an inline `tailwind.config`. Only for CSP-free previews (e.g. the
|
|
396
|
+
* local web preview). Blocked under the MCP-App CSP.
|
|
397
|
+
*
|
|
398
|
+
* Composes with `designkitExtension`:
|
|
399
|
+
* - `designkitExtension()` emits `:root { --color-*: ...; }` (CSS
|
|
400
|
+
* vars from the active DESIGN.md).
|
|
401
|
+
* - This extension maps named utilities (`bg-primary`, `text-ink`,
|
|
402
|
+
* `font-heading`, `p-md`, `rounded-lg`, `shadow-md`) onto those
|
|
403
|
+
* same CSS vars.
|
|
404
|
+
*
|
|
405
|
+
* Token wiring (compile mode): the v3 `theme.extend` shape below is
|
|
406
|
+
* translated into a Tailwind v4 `@theme inline { ... }` block. `inline`
|
|
407
|
+
* means each generated utility INLINES its value (the
|
|
408
|
+
* `var(--color-primary, var(--color-accent, #6366f1))` fallback chain)
|
|
409
|
+
* rather than referencing a compiler-emitted `:root` variable — so the
|
|
410
|
+
* utilities resolve directly against the runtime `--color-*` vars that
|
|
411
|
+
* `designkitExtension` emits, with the same graceful fallbacks. Any
|
|
412
|
+
* self-referential `:root` declarations the engine would emit for these
|
|
413
|
+
* tokens are stripped (they would otherwise be CSS cycles); the inline
|
|
414
|
+
* utilities carry the full fallback chain, so nothing is lost.
|
|
415
|
+
*
|
|
416
|
+
* Templates remain free to:
|
|
417
|
+
* - Use raw inline `style="background: var(--color-surface)"` —
|
|
418
|
+
* CSS vars are always available.
|
|
419
|
+
* - Use their own `<style>` blocks — fully supported, no conflict.
|
|
420
|
+
* - Mix Tailwind utilities and inline styles arbitrarily — inline
|
|
421
|
+
* style wins per CSS specificity.
|
|
422
|
+
* - Re-scope tokens locally via `.my-scope { --color-primary: ...; }`
|
|
423
|
+
* to retheme a subtree.
|
|
424
|
+
*
|
|
425
|
+
* Order matters: this extension's `transformBody` runs after the body
|
|
426
|
+
* is rendered. The injected `<style>` is placed inside `<head>` (just
|
|
427
|
+
* before `</head>` when the render carries a document shell; a bare
|
|
428
|
+
* fragment falls back to an append), so it never lands after `</html>`.
|
|
429
|
+
*/
|
|
430
|
+
|
|
431
|
+
interface TailwindBridgeExtensionOptions {
|
|
432
|
+
/**
|
|
433
|
+
* Styling strategy. Default `"compile"` (CSP-safe, no CDN/eval).
|
|
434
|
+
* Use `"cdn"` only for CSP-free previews.
|
|
435
|
+
*/
|
|
436
|
+
mode?: "cdn" | "compile";
|
|
437
|
+
/**
|
|
438
|
+
* Override the Tailwind CDN URL. Default is the official v3 CDN.
|
|
439
|
+
* Pin to a specific version in production for reproducibility.
|
|
440
|
+
* Only used in `mode: "cdn"`.
|
|
441
|
+
*/
|
|
442
|
+
cdnUrl?: string;
|
|
443
|
+
/**
|
|
444
|
+
* Extra Tailwind config to merge into the default theme extension.
|
|
445
|
+
* Stringified verbatim into the body, so callers should provide a
|
|
446
|
+
* JSON-safe object — values that need to be JS expressions (like
|
|
447
|
+
* `var(--foo)`) should be string literals; the CDN's `tailwind.config`
|
|
448
|
+
* accepts strings for color/font/spacing values.
|
|
449
|
+
*
|
|
450
|
+
* In `mode: "compile"` this v3 `theme.extend` shape is translated to a
|
|
451
|
+
* Tailwind v4 `@theme inline` block (see `themeExtendToThemeCss`).
|
|
452
|
+
*/
|
|
453
|
+
themeExtend?: Record<string, unknown>;
|
|
454
|
+
/**
|
|
455
|
+
* Compat escape hatch for callers that already author their theme in
|
|
456
|
+
* Tailwind v4 CSS form. When provided (`mode: "compile"` only), this
|
|
457
|
+
* raw CSS is used verbatim as the body of the `@theme inline { … }`
|
|
458
|
+
* block instead of translating `themeExtend`. Lets a v4-native caller
|
|
459
|
+
* pass `@theme`-style declarations directly without going through the
|
|
460
|
+
* v3 object shape.
|
|
461
|
+
*/
|
|
462
|
+
themeCss?: string;
|
|
463
|
+
}
|
|
464
|
+
declare function tailwindBridgeExtension(options?: TailwindBridgeExtensionOptions): ContextExtension;
|
|
465
|
+
|
|
466
|
+
export { type DesignArtifact, type DesignLister, type DesignResolver, type DesignSource, type DesignSourceContext, type DesignSourceEntry, DesignSourceRegistry, type DesignkitExtensionOptions, type FamilyRequest, type FetchFontFaces, type FetchedFontFace, type FontMode, type LoadActiveDesignOptions, type TailwindBridgeExtensionOptions, createDefaultRegistry, defaultGoogleFontsFetcher, defaultRegistry, designkitExtension, loadActiveDesign, tailwindBridgeExtension };
|