@iksnerd/blazon 0.1.0 → 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.
Files changed (73) hide show
  1. package/README.md +14 -19
  2. package/dist/chunks/{site-builder-vpzUWoiA.js → site-builder-BtGOvjBC.js} +1836 -2111
  3. package/dist/cli/commands/tokens.d.ts +4 -0
  4. package/dist/cli/commands/tokens.d.ts.map +1 -1
  5. package/dist/cli/handlers/brand.d.ts +1 -1
  6. package/dist/cli/handlers/index.d.ts +2 -2
  7. package/dist/cli/index.js +915 -941
  8. package/dist/core/brand/export.d.ts +2 -9
  9. package/dist/core/brand/export.d.ts.map +1 -1
  10. package/dist/core/brand/schema.d.ts +0 -58
  11. package/dist/core/brand/schema.d.ts.map +1 -1
  12. package/dist/core/brand-theme.d.ts +0 -2
  13. package/dist/core/brand-theme.d.ts.map +1 -1
  14. package/dist/core/checker/catalogue.d.ts +18 -2
  15. package/dist/core/checker/catalogue.d.ts.map +1 -1
  16. package/dist/core/checker/contrast.d.ts +1 -1
  17. package/dist/core/checker/variables.d.ts +2 -2
  18. package/dist/core/checker/variables.d.ts.map +1 -1
  19. package/dist/core/config/removed-keys.d.ts +6 -0
  20. package/dist/core/config/removed-keys.d.ts.map +1 -0
  21. package/dist/core/config/validate.d.ts +1 -1
  22. package/dist/core/config/validate.d.ts.map +1 -1
  23. package/dist/core/docs/directives.d.ts +9 -0
  24. package/dist/core/docs/directives.d.ts.map +1 -1
  25. package/dist/core/docs/parser.d.ts.map +1 -1
  26. package/dist/core/emit.d.ts +1 -3
  27. package/dist/core/emit.d.ts.map +1 -1
  28. package/dist/core/index.d.ts.map +1 -1
  29. package/dist/core/operations/list.d.ts.map +1 -1
  30. package/dist/core/plugin-name.d.ts +1 -1
  31. package/dist/core/read/token.d.ts +1 -6
  32. package/dist/core/read/token.d.ts.map +1 -1
  33. package/dist/core/tokens/walk.d.ts.map +1 -1
  34. package/dist/index.js +33 -33
  35. package/dist/plugins/roles/integrate.d.ts +5 -2
  36. package/dist/plugins/roles/integrate.d.ts.map +1 -1
  37. package/dist/plugins/roles/roles.d.ts +9 -2
  38. package/dist/plugins/roles/roles.d.ts.map +1 -1
  39. package/dist/plugins/wire/profile.d.ts +5 -0
  40. package/dist/plugins/wire/profile.d.ts.map +1 -1
  41. package/dist/types/config.d.ts +1 -3
  42. package/dist/types/config.d.ts.map +1 -1
  43. package/dist/types/theme.d.ts +0 -3
  44. package/dist/types/theme.d.ts.map +1 -1
  45. package/dist/ui/assets/{index-BdbihVvH.js → index-CLKH0m9J.js} +45 -47
  46. package/dist/ui/index.html +1 -1
  47. package/package.json +1 -1
  48. package/plugins/blazon.brand-deck/bin/blazon-blazon.brand-deck./360/237/224/214 +24 -2
  49. package/plugins/blazon.copy/bin/blazon-blazon.copy./360/237/224/214 +25 -3
  50. package/plugins/blazon.favicons/bin/blazon-blazon.favicons./360/237/224/214 +26 -3
  51. package/plugins/blazon.logo-geometry/bin/blazon-blazon.logo-geometry./360/237/224/214 +37 -8
  52. package/plugins/blazon.logo-kit/bin/blazon-blazon.logo-kit./360/237/224/214 +37 -8
  53. package/plugins/blazon.office-template/bin/blazon-blazon.office-template./360/237/224/214 +37 -8
  54. package/plugins/blazon.platform-tokens/bin/blazon-blazon.platform-tokens./360/237/224/214 +37 -9
  55. package/plugins/blazon.press-kit/bin/blazon-blazon.press-kit./360/237/224/214 +37 -8
  56. package/plugins/blazon.print-book/README.md +3 -1
  57. package/plugins/blazon.print-book/bin/blazon-blazon.print-book./360/237/224/214 +43 -8
  58. package/plugins/blazon.shadcn/README.md +27 -0
  59. package/plugins/blazon.shadcn/bin/blazon-blazon.shadcn./360/237/224/214 +8273 -0
  60. package/plugins/blazon.shadcn/package.json +3 -0
  61. package/plugins/blazon.social-cards/bin/blazon-blazon.social-cards./360/237/224/214 +37 -8
  62. package/plugins/blazon.tailwind/README.md +23 -0
  63. package/plugins/blazon.tailwind/bin/blazon-blazon.tailwind./360/237/224/214 +420 -0
  64. package/plugins/blazon.tailwind/package.json +3 -0
  65. package/plugins/shipped.lock +24 -10
  66. package/template/AGENTS.md +1 -1
  67. package/template/blazon.json +0 -10
  68. package/template/docs/01-principles.md +1 -1
  69. package/template/docs/12-web.md +2 -2
  70. package/dist/core/tokens/formatters/tailwind.d.ts +0 -37
  71. package/dist/core/tokens/formatters/tailwind.d.ts.map +0 -1
  72. package/dist/core/tokens/shadcn.d.ts +0 -43
  73. package/dist/core/tokens/shadcn.d.ts.map +0 -1
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -193,10 +193,27 @@ var isObject$2 = (value) => typeof value === "object" && value !== null && !Arra
193
193
  function requireBrand(raw) {
194
194
  const shown = (value) => JSON.stringify(value) ?? "nothing";
195
195
  if (!isObject$2(raw) || raw.format !== "blazon-brand") throw new Cannot(`the brand in the request is not a blazon brand: its format is ${shown(isObject$2(raw) ? raw.format : void 0)}, not "blazon-brand"`);
196
- if (raw.version !== 1) throw new Cannot(`the brand in the request is version ${shown(raw.version)}; this reader understands version 1`);
196
+ if (raw.version !== 2) throw new Cannot(`the brand in the request is version ${shown(raw.version)}; this reader understands version 2`);
197
197
  return raw;
198
198
  }
199
- /** The request as an object of version 1, or Cannot with the reason. Its role and folders are for the plugin to check. */
199
+ /** The version of each request a plugin may get (RFC 0005 section 8): a check request is 1, a build request is 2 and may carry no `site_dir`. */
200
+ var REQUEST_VERSIONS = {
201
+ check: 1,
202
+ build: 2
203
+ };
204
+ /**
205
+ * The plugin needs the built site and this request has none: `blazon tokens` runs the build plugins before a site exists. The entry
206
+ * answers it as a skipped call (one info finding, nothing written), not as a plugin that could not answer.
207
+ */
208
+ var NeedsSite = class extends Cannot {};
209
+ /** The answer to a call that needed the site and had none: one `info` finding, as the entry prints it, and nothing written. */
210
+ var skippedForNoSite = (name, error) => ({ findings: [{
211
+ code: `${name}/needs-site`,
212
+ severity: "info",
213
+ path: "site_dir",
214
+ message: `${error.message}. Nothing was written; blazon build runs it.`
215
+ }] });
216
+ /** The request as an object of the version its role speaks, or Cannot with the reason. Its role and folders are for the plugin to check. */
200
217
  function readRequest(text) {
201
218
  let request;
202
219
  try {
@@ -205,19 +222,27 @@ function readRequest(text) {
205
222
  throw new Cannot("the request is not JSON");
206
223
  }
207
224
  if (!isObject$2(request)) throw new Cannot("the request is not a JSON object");
208
- if (request.v !== 1) throw new Cannot(`the request is version ${JSON.stringify(request.v)}; this plugin speaks version 1`);
225
+ const speaks = (typeof request.type === "string" ? REQUEST_VERSIONS[request.type] : void 0) ?? 1;
226
+ if (request.v !== speaks) throw new Cannot(`the request is version ${JSON.stringify(request.v)}; this plugin speaks version ${speaks}`);
209
227
  return request;
210
228
  }
211
- /** The build request in `text`, or Cannot with the reason: version 1, the build role, a site_dir with an index.html and an out_dir that is a folder. The brand and options are not checked here. */
212
- function buildJob(text) {
229
+ function buildRequest(text, site) {
213
230
  const request = readRequest(text);
214
231
  if (request.type !== "build") throw new Cannot(`the request is for the ${String(request.type)} role; this plugin is a build plugin`);
215
232
  const { site_dir: siteDir, out_dir: outDir } = request;
216
- if (typeof siteDir !== "string" || !node_fs.default.existsSync(node_path.default.join(siteDir, "index.html"))) throw new Cannot("site_dir has no index.html");
233
+ if (site === "needed") {
234
+ if (siteDir === void 0) throw new NeedsSite("site_dir is absent: this plugin reads the built site, which blazon tokens does not make");
235
+ if (typeof siteDir !== "string" || !node_fs.default.existsSync(node_path.default.join(siteDir, "index.html"))) throw new Cannot("site_dir has no index.html");
236
+ }
217
237
  if (typeof outDir !== "string" || !node_fs.default.statSync(outDir, { throwIfNoEntry: false })?.isDirectory()) throw new Cannot("out_dir is not a folder");
238
+ return request;
239
+ }
240
+ /** The build request in `text`, or Cannot with the reason: version 2, the build role, a site_dir with an index.html and an out_dir that is a folder. With no site_dir (`blazon tokens`) it is NeedsSite. The brand and options are not checked here. */
241
+ function buildJob(text) {
242
+ const request = buildRequest(text, "needed");
218
243
  return {
219
- siteDir,
220
- outDir,
244
+ siteDir: request.site_dir,
245
+ outDir: request.out_dir,
221
246
  brand: request.brand ?? {},
222
247
  options: request.options ?? {}
223
248
  };
@@ -1155,6 +1180,10 @@ async function main(argv) {
1155
1180
  process.stdout.write(`${JSON.stringify(await build(node_fs.default.readFileSync(0, "utf-8")))}\n`);
1156
1181
  return 0;
1157
1182
  } catch (error) {
1183
+ if (error instanceof NeedsSite) {
1184
+ process.stdout.write(`${JSON.stringify(skippedForNoSite(NAME, error))}\n`);
1185
+ return 0;
1186
+ }
1158
1187
  const reason = error instanceof Cannot ? error.message : `the browser could not draw the cards: ${String(error.message ?? error).split("\n")[0].slice(0, 500)}`;
1159
1188
  process.stdout.write(`${reason}\n`);
1160
1189
  return 2;
@@ -0,0 +1,23 @@
1
+ # blazon.tailwind
2
+
3
+ The plugin blazon ships to write a brand's tokens as a Tailwind v4 theme. It fills the `build` role and needs only Node: no browser. It reads `brand.json` through the plugin protocol and nothing else, and it reads no site, so `blazon tokens` runs it as well as `blazon build`. Blazon's core knows no CSS framework by name.
4
+
5
+ The source is `src/shipped/tailwind/`, and `npm run build:plugins` bundles it, with the blazon code it uses, into `bin/blazon-blazon.tailwind.🔌`, the one file that holds the plugin's code and that `plugins/shipped.lock` pins. It loads nothing from `node_modules`. The manual's plugins chapter says what to put in the config, and chapter 8 how to use the files.
6
+
7
+ ## What it writes
8
+
9
+ To `<tokensOutDir>/blazon.tailwind/` (`dist/tokens/blazon.tailwind/`):
10
+
11
+ | File | Holds |
12
+ |---|---|
13
+ | `tailwind.css` | An `@theme` block with a variable for each token that fills a Tailwind namespace: colors, font families, font sizes, font weights, radii, spacing, shadows, easings and the default transition duration |
14
+ | `tailwind-reset.css` | An `@theme` block that sets `initial` on each namespace the brand fills, so only the brand's values remain |
15
+
16
+ A brand with no token in any namespace gets neither file. The plugin takes no option.
17
+
18
+ ## Findings
19
+
20
+ | Code | Severity | When |
21
+ |---|---|---|
22
+ | `blazon.tailwind/variable-duplicate` | error | Two tokens with different values write one Tailwind variable (`color.brand` and `colors.brand` are both `--color-brand`); `tailwind.css` keeps the first |
23
+ | `blazon.tailwind/option-invalid` | error | The plugin is given an option, or options that are not an object |
@@ -0,0 +1,420 @@
1
+ #!/usr/bin/env node
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ let node_fs = require("node:fs");
23
+ node_fs = __toESM(node_fs, 1);
24
+ let node_path = require("node:path");
25
+ node_path = __toESM(node_path, 1);
26
+ /** What the findings may take on the wire, in bytes. The limit is 65,536; the rest is the envelope, the summary finding and a newline, with room to spare. */
27
+ var FINDINGS_BUDGET = 6e4;
28
+ var RANK = {
29
+ error: 0,
30
+ warning: 1,
31
+ info: 2
32
+ };
33
+ var rank = (severity) => RANK[severity] ?? 3;
34
+ var wire = (finding) => Buffer.byteLength(JSON.stringify(finding), "utf-8") + 1;
35
+ /**
36
+ * The findings as they are when they fit. When they do not, the first ones that fit, errors before warnings before notes and each
37
+ * group in the order it was found, then one `<name>/findings-left-out` warning that says how many are not shown. The summary is a
38
+ * warning so that it never hides that there were errors: the errors come first, and a run with any error is already failed.
39
+ */
40
+ function boundFindings(findings, name) {
41
+ let size = 0;
42
+ for (const finding of findings) size += wire(finding);
43
+ if (size <= 6e4) return findings;
44
+ const ordered = [...findings].sort((a, b) => rank(a.severity) - rank(b.severity));
45
+ const kept = [];
46
+ size = 0;
47
+ for (const finding of ordered) {
48
+ if (size + wire(finding) > 6e4) break;
49
+ size += wire(finding);
50
+ kept.push(finding);
51
+ }
52
+ const left = ordered.length - kept.length;
53
+ kept.push({
54
+ code: `${name}/findings-left-out`,
55
+ severity: "warning",
56
+ path: "findings",
57
+ message: `${left} more findings are not shown, because the answer would not fit the ${FINDINGS_BUDGET.toLocaleString("en-US")} bytes a plugin may print; fix the ones above and run again`
58
+ });
59
+ return kept;
60
+ }
61
+ /** The plugin cannot do what it was asked; the message is the reason blazon shows. */
62
+ var Cannot = class extends Error {};
63
+ /** The builder of a plugin's findings: `findingFor(NAME)('code', severity, path, message)` is a finding coded `NAME/code`. */
64
+ var findingFor = (name) => (code, severity, path, message) => ({
65
+ code: `${name}/${code}`,
66
+ severity,
67
+ path,
68
+ message
69
+ });
70
+ var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
71
+ /** The brand.json a plugin reads: the object when its format and version are the ones this reader understands, Cannot otherwise (RFC 0001: a reader checks both before it interprets anything). */
72
+ function requireBrand(raw) {
73
+ const shown = (value) => JSON.stringify(value) ?? "nothing";
74
+ if (!isObject(raw) || raw.format !== "blazon-brand") throw new Cannot(`the brand in the request is not a blazon brand: its format is ${shown(isObject(raw) ? raw.format : void 0)}, not "blazon-brand"`);
75
+ if (raw.version !== 2) throw new Cannot(`the brand in the request is version ${shown(raw.version)}; this reader understands version 2`);
76
+ return raw;
77
+ }
78
+ /** The version of each request a plugin may get (RFC 0005 section 8): a check request is 1, a build request is 2 and may carry no `site_dir`. */
79
+ var REQUEST_VERSIONS = {
80
+ check: 1,
81
+ build: 2
82
+ };
83
+ /**
84
+ * The plugin needs the built site and this request has none: `blazon tokens` runs the build plugins before a site exists. The entry
85
+ * answers it as a skipped call (one info finding, nothing written), not as a plugin that could not answer.
86
+ */
87
+ var NeedsSite = class extends Cannot {};
88
+ /** The answer to a call that needed the site and had none: one `info` finding, as the entry prints it, and nothing written. */
89
+ var skippedForNoSite = (name, error) => ({ findings: [{
90
+ code: `${name}/needs-site`,
91
+ severity: "info",
92
+ path: "site_dir",
93
+ message: `${error.message}. Nothing was written; blazon build runs it.`
94
+ }] });
95
+ /** The request as an object of the version its role speaks, or Cannot with the reason. Its role and folders are for the plugin to check. */
96
+ function readRequest(text) {
97
+ let request;
98
+ try {
99
+ request = JSON.parse(text);
100
+ } catch {
101
+ throw new Cannot("the request is not JSON");
102
+ }
103
+ if (!isObject(request)) throw new Cannot("the request is not a JSON object");
104
+ const speaks = (typeof request.type === "string" ? REQUEST_VERSIONS[request.type] : void 0) ?? 1;
105
+ if (request.v !== speaks) throw new Cannot(`the request is version ${JSON.stringify(request.v)}; this plugin speaks version ${speaks}`);
106
+ return request;
107
+ }
108
+ function buildRequest(text, site) {
109
+ const request = readRequest(text);
110
+ if (request.type !== "build") throw new Cannot(`the request is for the ${String(request.type)} role; this plugin is a build plugin`);
111
+ const { site_dir: siteDir, out_dir: outDir } = request;
112
+ if (site === "needed") {
113
+ if (siteDir === void 0) throw new NeedsSite("site_dir is absent: this plugin reads the built site, which blazon tokens does not make");
114
+ if (typeof siteDir !== "string" || !node_fs.default.existsSync(node_path.default.join(siteDir, "index.html"))) throw new Cannot("site_dir has no index.html");
115
+ }
116
+ if (typeof outDir !== "string" || !node_fs.default.statSync(outDir, { throwIfNoEntry: false })?.isDirectory()) throw new Cannot("out_dir is not a folder");
117
+ return request;
118
+ }
119
+ /** The build request in `text` for a plugin that reads no site, or Cannot with the reason: version 2, the build role and an out_dir that is a folder. A site_dir, when there is one, is ignored. */
120
+ function tokensJob(text) {
121
+ const request = buildRequest(text, "unused");
122
+ return {
123
+ outDir: request.out_dir,
124
+ brand: request.brand ?? {},
125
+ options: request.options ?? {}
126
+ };
127
+ }
128
+ /**
129
+ * The entry: `--blazon-manifest` prints the manifest; otherwise one request on standard input gets the answer of `build` as
130
+ * JSON, or exit 2 with the reason as the first line of standard output. `failure` starts the reason for an error that is
131
+ * not a Cannot. `name` is the plugin's, for the summary when the findings are bounded to what a call may print (bound.ts). Returns the exit status.
132
+ */
133
+ async function runPlugin(argv, manifest, build, failure, name) {
134
+ if (argv[0] === "--blazon-manifest") {
135
+ process.stdout.write(`${JSON.stringify(manifest)}\n`);
136
+ return 0;
137
+ }
138
+ try {
139
+ const answer = await build(node_fs.default.readFileSync(0, "utf-8"));
140
+ const bounded = isObject(answer) && Array.isArray(answer.findings) ? {
141
+ ...answer,
142
+ findings: boundFindings(answer.findings, name)
143
+ } : answer;
144
+ process.stdout.write(`${JSON.stringify(bounded)}\n`);
145
+ return 0;
146
+ } catch (error) {
147
+ if (error instanceof NeedsSite) {
148
+ process.stdout.write(`${JSON.stringify(skippedForNoSite(name, error))}\n`);
149
+ return 0;
150
+ }
151
+ const reason = error instanceof Cannot ? error.message : `${failure}: ${String(error.message ?? error).split("\n")[0].slice(0, 500)}`;
152
+ process.stdout.write(`${reason}\n`);
153
+ return 2;
154
+ }
155
+ }
156
+ function readBrand(brand) {
157
+ const root = requireBrand(brand);
158
+ return (Array.isArray(root.tokens) ? root.tokens : []).flatMap((item) => isObject(item) && typeof item.path === "string" && (typeof item.value === "string" || typeof item.value === "number") ? [{
159
+ path: item.path,
160
+ type: typeof item.type === "string" ? item.type : "",
161
+ value: String(item.value),
162
+ cssVariable: typeof item.cssVariable === "string" ? item.cssVariable : ""
163
+ }] : []);
164
+ }
165
+ /** The plugin's name, which blazon's config names it by, and the prefix of its finding codes */
166
+ var NAME = "blazon.tailwind";
167
+ var MANIFEST = {
168
+ v: 2,
169
+ roles: ["build"],
170
+ title: "Tailwind",
171
+ description: "Writes the brand's tokens as a Tailwind v4 theme (tailwind.css) and the reset that closes Tailwind's default theme (tailwind-reset.css).",
172
+ version: "1.0.0",
173
+ timeout_ms: 1e4,
174
+ env: []
175
+ };
176
+ /** The job a build request asks for, or Cannot with the reason. The options are checked later, and wrong ones are findings. */
177
+ function jobFor(text) {
178
+ return tokensJob(text);
179
+ }
180
+ var finding = findingFor(NAME);
181
+ /** The plugin has no option, so anything the config gives it is a finding: `blazon.tailwind` is listed with no `options`. */
182
+ function optionFindings(raw) {
183
+ if (!isObject(raw)) return [finding("option-invalid", "error", "options", "options must be an object")];
184
+ return Object.keys(raw).map((key) => finding("option-invalid", "error", "options", `unknown option "${key}"; this plugin has no options`));
185
+ }
186
+ var HEADER = [
187
+ "/**",
188
+ " * Blazon Design Tokens, as a Tailwind v4 theme",
189
+ " * Auto-generated by Blazon. Do not edit directly.",
190
+ " */",
191
+ ""
192
+ ];
193
+ function kebab(name) {
194
+ return name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
195
+ }
196
+ /** The group of a token: the first word of its path, in lower case. */
197
+ var groupOf = (token) => token.path.split(".")[0].toLowerCase();
198
+ var inGroup = (token, groups) => groups.includes(groupOf(token));
199
+ var lastIs = (path, word) => path[path.length - 1] === word;
200
+ var underFontSize = (path) => /(^|-)font-sizes?(-|$)/.test(path.slice(0, -1).join("-"));
201
+ /**
202
+ * Every Tailwind v4 theme namespace a token can fill. The order is the order of the tables in chapter 8 and of the reset file.
203
+ * A token type with no Tailwind namespace (border, transition and typography composites, gradients, other dimensions and numbers) is not here.
204
+ */
205
+ var TAILWIND_NAMESPACES = [
206
+ {
207
+ prefix: "color",
208
+ reset: "--color-*",
209
+ takes: "every `color` token",
210
+ match: (t) => t.type === "color",
211
+ drop: ["color", "colors"]
212
+ },
213
+ {
214
+ prefix: "font",
215
+ reset: "--font-*",
216
+ takes: "every `fontFamily` token",
217
+ match: (t) => t.type === "fontFamily",
218
+ drop: [
219
+ "font",
220
+ "fonts",
221
+ "family",
222
+ "families"
223
+ ],
224
+ dropAnywhere: true
225
+ },
226
+ {
227
+ prefix: "text",
228
+ reset: "--text-*",
229
+ takes: "`dimension` tokens under a `font-size` (or `font-sizes`) group",
230
+ match: (t, path) => t.type === "dimension" && underFontSize(path),
231
+ drop: [
232
+ "font",
233
+ "font-size",
234
+ "font-sizes",
235
+ "size",
236
+ "sizes"
237
+ ]
238
+ },
239
+ {
240
+ prefix: "font-weight",
241
+ reset: "--font-weight-*",
242
+ takes: "every `fontWeight` token",
243
+ match: (t) => t.type === "fontWeight",
244
+ drop: [
245
+ "font",
246
+ "fonts",
247
+ "weight",
248
+ "weights",
249
+ "font-weight",
250
+ "font-weights"
251
+ ]
252
+ },
253
+ {
254
+ prefix: "radius",
255
+ reset: "--radius-*",
256
+ takes: "`dimension` tokens in a `radius` (or `radii`, `rounded`) group",
257
+ match: (t) => t.type === "dimension" && inGroup(t, [
258
+ "radius",
259
+ "radii",
260
+ "rounded"
261
+ ]),
262
+ drop: [
263
+ "radius",
264
+ "radii",
265
+ "rounded"
266
+ ]
267
+ },
268
+ {
269
+ prefix: "spacing",
270
+ reset: "--spacing-*",
271
+ takes: "`dimension` tokens in a `spacing` (or `space`) group",
272
+ match: (t) => t.type === "dimension" && inGroup(t, ["spacing", "space"]),
273
+ drop: ["spacing", "space"]
274
+ },
275
+ {
276
+ prefix: "shadow",
277
+ reset: "--shadow-*",
278
+ takes: "every `shadow` token",
279
+ match: (t) => t.type === "shadow",
280
+ drop: [
281
+ "shadow",
282
+ "shadows",
283
+ "elevation"
284
+ ]
285
+ },
286
+ {
287
+ prefix: "ease",
288
+ reset: "--ease-*",
289
+ takes: "every `cubicBezier` token",
290
+ match: (t) => t.type === "cubicBezier",
291
+ drop: [
292
+ "motion",
293
+ "easing",
294
+ "easings",
295
+ "ease",
296
+ "timing"
297
+ ]
298
+ },
299
+ {
300
+ prefix: "default-transition-duration",
301
+ takes: "a `duration` token whose name is `default`, as `--default-transition-duration` (no other duration has a namespace)",
302
+ match: (t, path) => t.type === "duration" && lastIs(path, "default"),
303
+ drop: []
304
+ }
305
+ ];
306
+ function namespace(token) {
307
+ const path = token.path.split(".").map(kebab);
308
+ const ns = TAILWIND_NAMESPACES.find((n) => n.match(token, path));
309
+ return ns && {
310
+ ns,
311
+ path
312
+ };
313
+ }
314
+ /** The variable a token writes in tailwind.css, or undefined where the token maps to no Tailwind namespace. */
315
+ function tailwindVariable(token) {
316
+ const found = namespace(token);
317
+ if (!found) return void 0;
318
+ const { ns } = found;
319
+ if (ns.prefix === "default-transition-duration") return `--${ns.prefix}`;
320
+ let parts = found.path;
321
+ while (parts.length > 1 && ns.drop.includes(parts[0])) parts = parts.slice(1);
322
+ if (ns.dropAnywhere) parts = parts.filter((part, i) => i === parts.length - 1 || !ns.drop.includes(part));
323
+ return `--${ns.prefix}-${parts.join("-")}`;
324
+ }
325
+ /** The namespaces that at least one token of the brand fills, in the order of TAILWIND_NAMESPACES. */
326
+ function filledNamespaces(tokens) {
327
+ return TAILWIND_NAMESPACES.filter((ns) => tokens.some((token) => tailwindVariable(token) !== void 0 && namespace(token)?.ns === ns));
328
+ }
329
+ /**
330
+ * The tokens that fill a namespace of TAILWIND_NAMESPACES as a Tailwind v4 `@theme` block, with the default context's values. A variable
331
+ * named like one in theme.css (`--color-indigo`) holds the same value. A variable is written once, for the first token that maps to it.
332
+ * Undefined when no token maps to a Tailwind namespace.
333
+ */
334
+ function formatTailwindTheme(tokens) {
335
+ const seen = /* @__PURE__ */ new Set();
336
+ const lines = [];
337
+ for (const token of tokens) {
338
+ const variable = tailwindVariable(token);
339
+ if (!variable) continue;
340
+ if (seen.has(variable)) continue;
341
+ seen.add(variable);
342
+ lines.push(` ${variable}: ${token.value};`);
343
+ }
344
+ if (lines.length === 0) return void 0;
345
+ return [
346
+ ...HEADER,
347
+ "@theme {",
348
+ ...lines,
349
+ "}",
350
+ ""
351
+ ].join("\n");
352
+ }
353
+ var RESET_HEADER = (resets) => [
354
+ "/**",
355
+ " * Blazon Design Tokens, closing Tailwind's default theme",
356
+ " * Auto-generated by Blazon. Do not edit directly.",
357
+ " *",
358
+ ` * Removes Tailwind's default values for ${resets.join(", ")}: the namespaces this brand defines at least one token in.`,
359
+ " * Utilities such as rounded-xl or bg-blue-500 then generate nothing. `--color-*: initial` removes white and black too",
360
+ " * (bg-white, text-black), so a brand that wants them defines them. A namespace the brand has no token in is left alone.",
361
+ " *",
362
+ " * Import it after tailwindcss and before tailwind.css:",
363
+ " * @import \"tailwindcss\";",
364
+ " * @import \"./tailwind-reset.css\";",
365
+ " * @import \"./tailwind.css\";",
366
+ " */",
367
+ ""
368
+ ];
369
+ /**
370
+ * A `@theme` block that sets `initial` on each Tailwind namespace the brand fills, so only the brand's values remain once tailwind.css is
371
+ * imported after it. Undefined when no token maps to a namespace.
372
+ */
373
+ function formatTailwindReset(tokens) {
374
+ const resets = filledNamespaces(tokens).flatMap((ns) => ns.reset ? [ns.reset] : []);
375
+ if (resets.length === 0) return void 0;
376
+ return [
377
+ ...RESET_HEADER(resets.map((r) => `\`${r}\``)),
378
+ "@theme {",
379
+ ...resets.map((r) => ` ${r}: initial;`),
380
+ "}",
381
+ ""
382
+ ].join("\n");
383
+ }
384
+ /**
385
+ * Two tokens whose names reduce to one Tailwind variable (`color.brand` and `colors.brand`) overwrite each other, and tailwind.css keeps the
386
+ * first. The one that comes second is an error, unless both hold one value (a semantic alias and its primitive share a name by design) or both
387
+ * also write one CSS variable in theme.css, where the core's own check has already said so.
388
+ */
389
+ function collisions(tokens) {
390
+ const owner = /* @__PURE__ */ new Map();
391
+ const found = [];
392
+ for (const token of tokens) {
393
+ const variable = tailwindVariable(token);
394
+ if (!variable) continue;
395
+ const first = owner.get(variable);
396
+ if (!first) {
397
+ owner.set(variable, token);
398
+ continue;
399
+ }
400
+ if (first.path === token.path || token.value === first.value) continue;
401
+ if (token.cssVariable !== "" && token.cssVariable === first.cssVariable) continue;
402
+ found.push(finding("variable-duplicate", "error", token.path, `${token.path} and ${first.path} both write the CSS variable ${variable} in tailwind.css; rename one`));
403
+ }
404
+ return found;
405
+ }
406
+ async function build(text) {
407
+ const job = jobFor(text);
408
+ const tokens = readBrand(job.brand);
409
+ const findings = [...optionFindings(job.options), ...collisions(tokens)];
410
+ const files = /* @__PURE__ */ new Map();
411
+ const theme = formatTailwindTheme(tokens);
412
+ if (theme) files.set("tailwind.css", theme);
413
+ const reset = formatTailwindReset(tokens);
414
+ if (reset) files.set("tailwind-reset.css", reset);
415
+ for (const [file, data] of files) node_fs.default.writeFileSync(node_path.default.join(job.outDir, file), data);
416
+ return { findings };
417
+ }
418
+ runPlugin(process.argv.slice(2), MANIFEST, build, "the Tailwind files could not be written", NAME).then((code) => {
419
+ process.exitCode = code;
420
+ });
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -5,70 +5,84 @@
5
5
  "kind": "tree",
6
6
  "path": "blazon.brand-deck",
7
7
  "entry": "bin/blazon-blazon.brand-deck.🔌",
8
- "digest": "t1:b4cea23e446689158493465c05771f5c964d1f4898bf73415bdd42030a4975e9",
8
+ "digest": "t1:32cacf690499507ed1c54bd3a92641df96ced3a9322b3ffc18872e553dbba2ce",
9
9
  "source": "computed"
10
10
  },
11
11
  "blazon.copy": {
12
12
  "kind": "tree",
13
13
  "path": "blazon.copy",
14
14
  "entry": "bin/blazon-blazon.copy.🔌",
15
- "digest": "t1:eaef8379e41505a8d745e690abcce74da713b11652f57a74c052616a54475c56",
15
+ "digest": "t1:12a738a26cd30f0e459d8f6cdc31587f6fde3f8100cd9c86d603df44094e73f1",
16
16
  "source": "computed"
17
17
  },
18
18
  "blazon.favicons": {
19
19
  "kind": "tree",
20
20
  "path": "blazon.favicons",
21
21
  "entry": "bin/blazon-blazon.favicons.🔌",
22
- "digest": "t1:9735073b2d2cd97f75a401985d72e2709fceee2fdabd5decfeeaf61de3cf60e4",
22
+ "digest": "t1:f6b26e32cd05c4f0e98f765acb3f8f84a15c28c53482853bb5d06cca082c87e8",
23
23
  "source": "computed"
24
24
  },
25
25
  "blazon.logo-geometry": {
26
26
  "kind": "tree",
27
27
  "path": "blazon.logo-geometry",
28
28
  "entry": "bin/blazon-blazon.logo-geometry.🔌",
29
- "digest": "t1:fa879579711337c4bf4768ed5a860252c1bd9fc16c842727fc3615e0781a3ead",
29
+ "digest": "t1:95a7f7eac05b4f0619694c4fe5fc13c95bda0a6d52725401af231bad528b5986",
30
30
  "source": "computed"
31
31
  },
32
32
  "blazon.logo-kit": {
33
33
  "kind": "tree",
34
34
  "path": "blazon.logo-kit",
35
35
  "entry": "bin/blazon-blazon.logo-kit.🔌",
36
- "digest": "t1:ff45e1c3b003802247d1f219ac5652a2b9e77a904ab6e06be805eab38ea2ac71",
36
+ "digest": "t1:c89a4bf9bac5403cfbdb533d01f5efc7e54714e4d8a45dbf79763e55f6585585",
37
37
  "source": "computed"
38
38
  },
39
39
  "blazon.office-template": {
40
40
  "kind": "tree",
41
41
  "path": "blazon.office-template",
42
42
  "entry": "bin/blazon-blazon.office-template.🔌",
43
- "digest": "t1:9e5a155a6966b48382cdd04966575d4de9f2bf6aebe85668736f6dc3e49de819",
43
+ "digest": "t1:e78e58aaa53d9900ebe9acf15d750626c80625782bae03209c03544e940088a7",
44
44
  "source": "computed"
45
45
  },
46
46
  "blazon.platform-tokens": {
47
47
  "kind": "tree",
48
48
  "path": "blazon.platform-tokens",
49
49
  "entry": "bin/blazon-blazon.platform-tokens.🔌",
50
- "digest": "t1:e0e1231346857347a5d5a80e6bb784ea5250c6332c003b77d5708e2df360cf55",
50
+ "digest": "t1:0e82328c6e193a00c2881353edeb9e3717219fb477e7a888df2d08bf78b15def",
51
51
  "source": "computed"
52
52
  },
53
53
  "blazon.press-kit": {
54
54
  "kind": "tree",
55
55
  "path": "blazon.press-kit",
56
56
  "entry": "bin/blazon-blazon.press-kit.🔌",
57
- "digest": "t1:b458c8f760156d26a208ee09327b72421ede6a0a1d071b581535b5938dc242bd",
57
+ "digest": "t1:9f7fe4f495d1422de51f916bf3bffc4db5f9d94649dac53fa7893149d5213626",
58
58
  "source": "computed"
59
59
  },
60
60
  "blazon.print-book": {
61
61
  "kind": "tree",
62
62
  "path": "blazon.print-book",
63
63
  "entry": "bin/blazon-blazon.print-book.🔌",
64
- "digest": "t1:c14c7208420d47e8f4875a727b59c687120f8453ad7a96e5a6ac9059e2f0ade7",
64
+ "digest": "t1:1a9f2c39f75a14265498664eb49aa553dd2332b6f11b2420066c8bc53f7aa66f",
65
+ "source": "computed"
66
+ },
67
+ "blazon.shadcn": {
68
+ "kind": "tree",
69
+ "path": "blazon.shadcn",
70
+ "entry": "bin/blazon-blazon.shadcn.🔌",
71
+ "digest": "t1:4e28f311e7a5106cb7784354a2eec0543632a465844045dbcf9ccf73e95e21ac",
65
72
  "source": "computed"
66
73
  },
67
74
  "blazon.social-cards": {
68
75
  "kind": "tree",
69
76
  "path": "blazon.social-cards",
70
77
  "entry": "bin/blazon-blazon.social-cards.🔌",
71
- "digest": "t1:c7e58ee026ddf40d28c5485aefb3b654af423d13984c405e4d166db53b81a9ce",
78
+ "digest": "t1:874ba79e0e0c2ed8d761d320df0203ca4bf39deba7bdb84672de2631460576ec",
79
+ "source": "computed"
80
+ },
81
+ "blazon.tailwind": {
82
+ "kind": "tree",
83
+ "path": "blazon.tailwind",
84
+ "entry": "bin/blazon-blazon.tailwind.🔌",
85
+ "digest": "t1:01992d34f98e13b98bfe5aa6ec2cfc5f6ab7b28582f540ffe8aaab4ff9956804",
72
86
  "source": "computed"
73
87
  }
74
88
  }
@@ -32,7 +32,7 @@ Codes you meet first:
32
32
 
33
33
  ## The MCP server
34
34
 
35
- `blazon mcp` sets up blazon-mcp, a server that answers questions about this brand as Model Context Protocol tool calls: `check_brand`, `list_tokens`, `get_token`, `get_rules`, `can_use`, `get_fonts`, `get_logo`, `get_shadcn`. It is not published yet, so it runs only from a blazon source checkout with the server built. Run `blazon mcp --check` to learn whether it is ready; each failed check names the `fix` to run. Without it, the commands above do the same work. Setup: the `blazon-for-agents` chapter.
35
+ `blazon mcp` sets up blazon-mcp, a server that answers questions about this brand as Model Context Protocol tool calls: `check_brand`, `list_tokens`, `get_token`, `get_rules`, `can_use`, `get_fonts`, `get_logo`. It is not published yet, so it runs only from a blazon source checkout with the server built. Run `blazon mcp --check` to learn whether it is ready; each failed check names the `fix` to run. Without it, the commands above do the same work. Setup: the `blazon-for-agents` chapter.
36
36
 
37
37
  ## Building a site from this brand
38
38
 
@@ -44,16 +44,6 @@
44
44
  "fontBody": "font.family.body",
45
45
  "radius": "radius.hairline"
46
46
  },
47
- "shadcn": {
48
- "ring": "text.primary",
49
- "sidebar-ring": "text.primary",
50
- "destructive": "text.primary",
51
- "chart-1": "text.primary",
52
- "chart-2": "text.muted",
53
- "chart-3": "surface.canvas",
54
- "chart-4": "rule.default",
55
- "chart-5": "rule.quiet"
56
- },
57
47
  "fonts": [
58
48
  "https://fonts.googleapis.com/css2?family=Big+Shoulders+Display:wght@800&family=IBM+Plex+Sans:wght@400;600&display=swap",
59
49
  {
@@ -28,7 +28,7 @@ The brand and the build come from the same files. A build that breaks the brand'
28
28
  | Readable from any language | `blazon build` also writes `brand.json`: the tokens with their rules, the pages, the assets and the findings, with a JSON Schema. |
29
29
  | Open to plugins | A plugin is a program in any language. blazon ships ten, and a config names one to turn it on. |
30
30
 
31
- blazon is pre-release (0.1.0) and not on npm yet. The attributes above describe what is built today.
31
+ blazon is at version 0.1.0 and on npm as `@iksnerd/blazon`. The attributes above describe what is built today.
32
32
 
33
33
  ## Exposed structure
34
34